Q:

passing shared array in julia using @everywhere

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? 

A:

While it's tempting to use "named variables" on workers, it generally seems to work better if you access them via references. Schematically, you might do something like this:
mat = [@spawnat p rand(3,3) for p in workers()] # process 1 holds references to objects on workers
@sync for (i, p) in enumerate(workers())
    @spawnat p foo(mat[i], sharedarray)
end

