I use the @parallel for
macro to run simulations for a range of parameters. Each run results in a 1-dimensional vector. In the end I would like to collect the results in a DataFrame
.
Up until now I had always created an intermediate array and reduced the for-loop with vcat
; then constructed the DataFrame
. I thought it might also work to push!
the result of each calculation to the master process via remotecall
. A minimal example would look like
X=Float64[]
@sync @parallel for i in linspace(1.,10.,10)
remotecall_fetch(()->push!(X,i),1)
end
The result of which is consistently an array X
with 9 not 10 elements. The number of dropped elements becomes larger as more workers are added.
This is on julia-0.6.1.
I thought I had understood julia's parallel computing structure, but it seems not.
What is the reason for this behavior? And how can I do it better and safely?