I m trying to use multiprocess in order to decrease the time of calculation of functions whose depend of 2D arrays whose shape is 2000x2000. I have 2 inputs arrays for the function but with p.map it doesnt work...(with one it s ok). How can i do to enable that?
from multiprocessing import Pool
from numpy import *
import time
tic=time.clock()
Y=(arange(2000.))
X=(arange(2000.))
(xx,yy)=meshgrid(X,Y)
r = sqrt((xx)**2 + (yy)**2)
theta = (arctan2((yy),(xx)))
def f(theta,r):
return 1.*r**(-3/2.)*cos(-3/2.*theta)
p = Pool(4)
print p.map(f, theta,r)
toc=time.clock()
print 'Temps=', toc-tic
and i get an error : "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
mapis going to iterate over every item in the iterable you pass to it, and callfon each individual element. Is that actually what you want here? It looks like you want to pass both arrays in their entirety to the child process, and havefwork on the whole array. If that's the case,multiprocessing.Pool.mapwon't help improve performance at all.