You need to store A in such a way that it is guaranteed to continue to exist. If there is no other reference to it, it may e.g. be garbage collected. One way would be to store it in a global variable, or in a dictionary. Try e.g.:
@everywhere (global A=rand()) pmap(a->(global A;A)+x,1:3) Obviously, in real code you would wrap accessing A in a function instead of writing (global A;A) all the time. -erik On Mon, Sep 15, 2014 at 5:52 AM, <[email protected]> wrote: > I want to transfer a variable to all parallel workers. However, if I do: > > A=rand() > pmap(x->A+x,1:3) > > Return error: > exception on 2: ERROR: A not defined > in anonymous at none:1 > in anonymous at multi.jl:855 > in run_work_thunk at multi.jl:621 > in anonymous at task.jl:855 > exception on 3: ERROR: A not defined > in anonymous at none:1 > in anonymous at multi.jl:855 > in run_work_thunk at multi.jl:621 > in anonymous at task.jl:855 > 2-element Array{Any,1}: > UndefVarError(:A) > UndefVarError(:A) > > The result of > @everywhere A=rand() > pmap(x->A+x,1:3) > is not what I want, since I hope A in all mashines are the same. > > I know that pmap((x,y)->x+y,1:3,fill(A,3)) will be work, but I don't think > it is smart since A is expand in memery unnessarily. Is there any simple way > to just send a copy of A, or the reference of A, to all parallel mashines? -- Erik Schnetter <[email protected]> http://www.perimeterinstitute.ca/personal/eschnetter/
