I have scoured the internet for an answer, and nothing I can find applies to my situation. I have read about multiprocessing.Manager
, have tried passing things back and forth, and none of it seems to play well with NumPy arrays.I ahve tried using Pool
instead, but my target method does not return anything, it just makes changes to an array, so I wasn't sure how to set that up either.
Right Now I have:
def Multiprocess(self, sigmaI, sigmaX):
cpus = mp.cpu_count()
print('Number of cpu\'s to process WM: %d' % cpus)
processes = [mp.Process(target = self.CreateMatrixMp, args = (sigmaI, sigmaX, i,)) for i in range(self.numPixels)]
for p in processes:
p.start()
for p in processes:
p.join()
The target function, CreateMatrixMp
, takes the values passed, and after doing calculations, appends a value to an array data
. This array is declared as self.data = numpy.zeros(self.size, numpy.float64)
. If the details of the CreateMatrixMp
method would help, I can post that as well.
I tried adding this above where the processes are run:
mgr = mp.Manager()
sharedData = mgr.Array(ctypes.c_numpy.float64, self.data)
and then passing sharedData
to CreateMatrixMp
, where it can be modified. Once all the processes have run and the array is complete, I simply do self.data = sharedData
.
But this doesn't work (though I know I am not setting it up correctly). How should this be done with a NumPy array? I want each and every process (there will be thousands of them) to append to the same array.
Any help is enormously appreciated.