I've attempted to run parallel processing on a locally defined function as follows:
import multiprocessing as mp
import numpy as np
import pdb
def testFunction():
x = np.asarray( range(1,10) )
y = np.asarray( range(1,10) )
def myFunc( i ):
return np.sum(x[0:i]) * y[i]
p = mp.Pool( mp.cpu_count() )
out = p.map( myFunc, range(0,x.size) )
print( out )
if __name__ == '__main__':
print( 'I got here' )
testFunction()
When I do so, I get the following error:
cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
How can I use multiprocessing to processing several arrays in parallel like I'm trying to do here? x and y are necessarily defined inside the function; I'd rather not make them global variables.
All help is appreciated.