SharedArray + pmap question

80 views
Skip to first unread message

Max Shron

unread,
Mar 1, 2015, 5:57:40 AM3/1/15
to julia...@googlegroups.com
Hi all,

I looked around but have been unable to find an answer to this question. Here is a very minimal example of how I'd like to use a SharedArray:

S = SharedArray(Int, (3))
pmap((i -> S[i]), 1:3)

When I run this with julia -p 3 (with 0.3.6), I get the following error:

ERROR: S not defined

or with Master (0.4.0-dev+3631)

ERROR: UndefVarError: S not defined

If I call procs(S) I get back [1,2,3] as expected. What else do I need to do to make S visible to the other processes? Presumably if I use @everywhere S = SharedArray(Int, (3)) that defeats the purpose of SharedArray, right?

I'm running OS X 10.9.5.

Thanks,
Max 

René Donner

unread,
Mar 2, 2015, 10:03:10 AM3/2/15
to julia...@googlegroups.com
If I run your code in the REPL I see the same behavior. Putting it into a function works:

julia> function test()
S = SharedArray(Int, (3,))
pmap(i->S[i], 1:3)
end
test (generic function with 1 method)

julia> test()
3-element Array{Any,1}:
0
0
0


The same holds true when you use an ordinary Array instead of a SharedArray.

Can someone explain the reason why anonymous functions referencing variables in the global scope are handled differently?
Reply all
Reply to author
Forward
0 new messages