I found this post - Shared array usage in Julia, which is clearly close but I still don't really understand what to do in my case.
I am trying to pass a shared array to a function I define, and call that function using @everywhere. The following, which has no shared array, works:
@everywhere mat = rand(3,3)
@everywhere foo1(x::Array) = det(x)
Then this
@everywhere println(foo1(mat))
properly produces different results from each worker. Now let me include a shared array:
test = SharedArray(Float64,10)
@everywhere foo2(x::Array,y::SharedArray) = det(x) + sum(y)
Then this
@everywhere println(foo2(mat,test))
fails on the workers.
ERROR: On worker 2:
UndefVarError: test not defined
etc. I can get what I want like this:
for w in procs()
@spawnat w println(foo2(eval(:mat),test))
end
This works - but is it optimal? Is there a way to make it work with @everywhere?