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?




Am 01.03.2015 um 01:47 schrieb Max Shron <m...@polynumeral.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 

Reply via email to