New to multiprocessing and I can't get my head around the documentation. How can I run a function of this form across multiple processes? Here is my attempt. I want to run a convolution (of start with other) through multiple processes for speed.
from multiprocessing import Process, Value, Array
import numpy as np
import scipy
A = np.ones((10,10,4))
B = np.random.rand(10,10)
def loop(i):
C[:,:,i] = scipy.ndimage.convolve(A[:,:,i],B)
if __name__ == '__main__':
C = Array('i',np.zeros((10,10,4)))
arr = Array('i',range(4))
for i in arr:
p = Process(target = loop, args=i)
p.start()
p.join()
Current error:
Traceback (most recent call last):
File "", line 11, in y_test = Array('i',np.zeros((10,10,4)))
File "/usr/lib/python2.7/multiprocessing/init.py", line 260, in Array return Array(typecode_or_type, size_or_initializer, **kwds)
File "/usr/lib/python2.7/multiprocessing/sharedctypes.py", line 115, in Array obj = RawArray(typecode_or_type, size_or_initializer)
File "/usr/lib/python2.7/multiprocessing/sharedctypes.py", line 89, in RawArray result.init(*size_or_initializer)
TypeError: only length-1 arrays can be converted to Python scalars
y_test would be the ouput