Something like this?
@everywhere function fill(A::SharedArray)
for idx in Base.localindexes(A)
A[idx] = rand()
end
end
function fill_array(m, n)
A = SharedArray(Float64, (m, n))
@sync begin
for p in procs(q)
@async remotecall_wait(p, fill, A)
end
end
A
end
fill_array(9, 60)
On Tuesday, August 11, 2015 at 12:23:02 AM UTC+2, Júlio Hoffimann wrote:
>
> What am I doing wrong in the following code?
>
> function foo(N; parallel=false)
> if parallel && nprocs() < CPU_CORES
> addprocs(CPU_CORES - nprocs())
> end
>
> result = SharedArray(Float64, 9, N)
> @parallel for i=1:N
> sleep(1)
> result[:,i] = rand(3,3)[:]
> end
>
> result
> end
>
> If I call foo(60, parallel=true), result is all zeros. Expected behavior
> is a random matrix.
>
> -Júlio
>