Hi everyone,
I am trying to do distributed programming in cluster and I have tried a few tests but I can’t get what I expected. I think I don’t understand the basic of @everywhere
and @distributed
macro. The following is my testing code:
using Distributed, ClusterManagers
addprocs(40)
println(nworkers())
@everywhere summark = myid()
@everywhere println(summark)
@sync @distributed for i = 1:100
println(myid(), " , i = ", i, ", summark = ",summark)
end
In particular, I used @everywhere
to define summark in each of the processors to be the id of each processors. And @everywhere println(summark)
gives what I expected: for examples,
From worker 38: 38
From worker 3: 3
From worker 26: 26
From worker 19: 19
From worker 17: 17
From worker 14: 14
From worker 5: 5
From worker 12: 12
However, in the loop @sync @distributed for i = 1:100
, I get the following for “summark”:
From worker 80: 80 , i = 99, summark = 1
From worker 58: 58 , i = 77, summark = 1
From worker 66: 66 , i = 85, summark = 1
From worker 47: 47 , i = 66, summark = 1
From worker 63: 63 , i = 82, summark = 1
From worker 74: 74 , i = 93, summark = 1
From worker 68: 68 , i = 87, summark = 1
I used srun julia -p 40 Distributed_Test2.jl
to run.
What I want is to access the “summark” for the corresponding processors within the loop as did in @everywhere println(summark)
. In particular, my goal is to define some arrays on each processors and update them in the loop (I think SharedArray does not fit my algorithm, because of the complicated data type). But I get stuck in this simple example for a long time. I would appreciate any helps.