I have a question about the use of pmap. I think it's a simple/obvious answer but still can't figure it out! I am currently running a loop where each of 50 iterations is separate and so running it in parallel should be possible and should improve speed. It uses a function that has multiple inputs and outputs, which are both a mixture of vectors and scalars. I need to save the outputs of the function for each of the 50 iterations for later use. Here are the basics of the code when not in parallel.
A=Array(Float64, 500,50) b=Array(Float64,50) for i in 1:50 A[:,i],b[i] = func(i,x,y,z) end
Any advice for how to implement this is parallel? I'm using v0.3 Julia.
Thanks in advance.
This worked for me.
@everywhere x,y,z = 1,2,3 @everywhere function f(i,x,y,z) sleep(1) return(ones(500)*i, i+x+y+z) end naive = @time map(i -> f(i,x,y,z), 1:50) parallel = @time pmap(i -> f(i,x,y,z), 1:50) A = [x for x in parallel] b = [x for x in parallel]
Let me know if anyone can suggest a more elegant way to get A and b out of the array of tuples that is produced by pmap.
The timings (when run on 8 processes) are as we would expect
elapsed time: 5.063214725 seconds (94436 bytes allocated) elapsed time: 0.815228485 seconds (288864 bytes allocated)