Help for basic usage of @distributed for

Hello,

I have a computation that I want to perform several times for several realizations of disorder. For this I wrote a serial script doing only one computation, and a separate script that calls it and distributes these independent computations among all workers.

In another script, I used pmap (because the computations were heavy and parallelized over only a few workers) and the serial function was saving data alone, and everything worked fine, since I did not need to retrieve data.

Now I need to compute some final computations (sum, means) on the overall array after the distributed for loop, but I am running into problems as when I try to do this I recover arrays of zeros.

Here is the sample code of my parallel script: (called with julia -p nprocs parallel_script.jl)

# Broadcast script
@everywhere using SharedArrays
@everywhere path = joinpath(@__DIR__, "serial_script.jl")
@everywhere include(path)

# Define SharedArrays
array_one = SharedArray{Float64}(N)
array_two = SharedArray{Float64}(N)
array_three = SharedMatrix{Float64}(N,N)

# Parallel independent realizations
@distributed for i in 1:N
    array_one[i], array_two[i], array_three[:,i] = my_serial_function()
end

# Now I would like to do retrieve the data, sum(array_three,dims=2) and save it ! How?
# Doing fetch(Epsilon) etc... gives all zeros.

Please note that variables such as N are declared in serial_script.jl i.e. the code is not crashing whatsoever.

Thank you for your help!

maybe you should using @sync @distributed instead or

t = @distributed for i in 1:N
    array_one[i], array_two[i], array_three[:,i] = my_serial_function()
end

wait(t)

? @distributed just scheduale the task.