with parallel
addprocs(2)
println("Number of processors", nprocs())
@everywhere function foo(x,y)
println(myid()," ", x, " ", y)
return x + y
end
let a = rand()
@sync @parallel for x in 1:3
foo(a,x)
end
end
On Monday, September 15, 2014 3:14:50 PM UTC+1, [email protected] wrote:
>
> "you could precreate A and then define it everywhere"
> Could you please show me some code how to do it?
>
> On Monday, September 15, 2014 2:51:08 PM UTC+2, John Drummond wrote:
>>
>> Chris Strickland
>> <https://groups.google.com/forum/#!msg/julia-users/jlKoEtErRL4/0ZcB_hxyJlYJ>
>> lists one approach for the general problem
>>
>> you could precreate A and then define it everywhere, or send a copy over
>> as a parameter to whatever function you use in pmap, similar but not the
>> same as above
>>
>> Another approach which was useful to me was the @parallel for loops
>> "Any variables used inside the parallel loop will be copied and
>> broadcast to each process."
>> <http://julia.readthedocs.org/en/latest/manual/parallel-computing/>
>>
>> and shared arrays
>> <http://julia.readthedocs.org/en/latest/manual/parallel-computing/#shared-arrays-experimental-unix-only-feature>
>>
>> if using linux could be useful (I've not tried them).
>>
>>
>>
>> On Monday, September 15, 2014 10:52:33 AM UTC+1, [email protected]
>> wrote:
>>>
>>> I want to transfer a variable to all parallel workers. However, if I do:
>>>
>>> A=rand()
>>> pmap(x->A+x,1:3)
>>>
>>> Return error:
>>> exception on 2: ERROR: A not defined
>>> in anonymous at none:1
>>> in anonymous at multi.jl:855
>>> in run_work_thunk at multi.jl:621
>>> in anonymous at task.jl:855
>>> exception on 3: ERROR: A not defined
>>> in anonymous at none:1
>>> in anonymous at multi.jl:855
>>> in run_work_thunk at multi.jl:621
>>> in anonymous at task.jl:855
>>> 2-element Array{Any,1}:
>>> UndefVarError(:A)
>>> UndefVarError(:A)
>>>
>>> The result of
>>> @everywhere A=rand()
>>> pmap(x->A+x,1:3)
>>> is not what I want, since I hope A in all mashines are the same.
>>>
>>> I know that pmap((x,y)->x+y,1:3,fill(A,3)) will be work, but I don't
>>> think it is smart since A is expand in memery unnessarily. Is there any
>>> simple way to just send a copy of A, or the reference of A, to all parallel
>>> mashines?
>>>
>>