On Tuesday, July 22, 2014 9:49:08 AM UTC-5, Sebastian Vollmer wrote: > > I can create shared variables like > > @everywhere i=1 > > but how do I create variables local to a worker. The only possibility is > through RemoteRefs with take and put, but this seems overly complicated. > > What I have in mind is a problem where all the workers only need > communicated with the main thread for scheduling and all the computations > can be done locally. I would like the results to be stored in local array > and be fetched to the main thread once all calculations have finished. For > this I need to create a local array on each worker. But I don't know how. >
Hi Sebastian, if you use @parallel you can assign local variables inside the loop (see <http://julia.readthedocs.org/en/latest/manual/parallel-computing/#parallel-map-and-loops>); i.e. @parallel (vcat) for j=1:5 x = randn(500) maximum(x) end 5-element Array{Float64,1}: 2.87438 3.33624 2.61933 3.29437 3.78962 The function "pmap" is similar and you can just use local variables inside a function: @everywhere function myfn(i) x = randn(500) maximum(x) end julia> pmap(myfn, 1:5) 5-element Array{Any,1}: 3.53792 3.15902 3.19144 3.28444 2.91617 (see <http://julia.readthedocs.org/en/latest/manual/parallel-computing/#synchronization-with-remote-references>). If neither approach works, it might help to post a simplified version of the code you want to run in parallel. --Gray
