I have also found the combination of shared arrays, anonymous functions and 
parallel constructs confusing.

StackOverflow question helped me Shared array usage in Julia 
<http://stackoverflow.com/questions/35751420/shared-array-usage-in-julia>

In essence, "although the underlying data is shared to all workers, the 
declaration is not. You will still need to pass in the reference to [the 
shared array]"

S = SharedArray(Int,3,4)
S[:] = 1:length(S)
@everywhere f(S,i) = (println("S[$i] = $(S[i])"); S[i])

output1 = pmap(i -> f(S,i), 1:length(S))    # error
output2 = pmap((S,i) -> f(S,i), fill(S,length(S)), 1:length(S))
output3 = pmap(f, fill(S,length(S)), 1:length(S))


In seems then, in version1, the reference S is local to the worker, but S 
is not defined on the worker -> error.
In versions 2&3 the local S is passed as argument to worker and all works 
as expected.

Reply via email to