Julia's parallel constructs assume that globals are available on all processors, but will copy any locals used to every processor. So one way to fix your example is:
julia> A = let t3=t3; pmap(i -> test2(t3[i], t, t2), 1:3); end On Fri, Apr 24, 2015 at 9:57 AM Archibald Pontier < [email protected]> wrote: > Hi everyone, > > I have the following problem which originates from the fact that > SharedArray doesn't seem to accept composite types as argument. Consider > the following sequence (I started julia with -p 2): > > julia> @everywhere type T > t::Array{Float64, 1} > end > > julia> @everywhere type T2 > t::Array{Float64, 1} > end > > julia> @everywhere type T3 > t::Array{Float64, 1} > end > > julia> @everywhere function test(t::T, t2::T2, i) > return T3([t.t[i], t2.t[i]]); > end > > julia> @everywhere t = T(rand(3)) > > julia> @everywhere t2 = T2(rand(3)) > > julia> t3 = pmap(i -> test(t, t2, i), 1:3) > 3-element Array{Any,1}: > T3([0.521706,0.0155359]) > T3([0.112277,0.59876]) > T3([0.0399843,0.373688]) > > julia> @everywhere function test2(t3::T3, t::T, t2::T2) > t.t[1] += t3.t[1]; > t2.t[2] += t3.t[2]; > return (t, t2); > end > > julia> A = pmap(i -> test2(t3[i], t, t2), 1:3) > exception on exception on 2: 3: ERROR: t3 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 > ERROR: t3 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(:t3) > UndefVarError(:t3) > > The problem solves itself if I do @everywhere t3 = pmap(...), however from > my understanding this would only lead to every operation done on every > process, which defeats the purpose of doing things in parallel in the first > place. Am I wrong with this conclusion? > > Regards, > Archibald >
