I have an embarrassingly parallel code that creates a list of arrays and I want to parallelize it (It's my first time working with python's multiprocessing so I'm still grasping the concepts). runNramps(*args) returns five arrays, t1,c1,e1,m1 and d1. I want to run this in multiple threads and join the answers from all jobs together.
Here's the code I'm trying to parallelize by running it in multiple processes. My jobs appear to execute, and close properly, however the queue is empty and queue.get() doesn't return anything. I think I'm missing the way to merge all the outputs together but I can't find any good example on SO/google.
Here is the threaded version of my code (I want to make minimal changes to the previous function and just call it multiple times, joining the results into one array).
def runPramps(numramps,rmpslope,nframes,cosmag=0,method='2pt',thresh=1.0):
output = mp.Queue()
processes = [mp.Process(target=runNramps, args=(numramps,rmpslope,nframes,cosmag,method,thresh)) for x in range(4)] #4 processes for example
for p in processes:
p.start()
print "started", p
for p in processes:
p.join()
print 'ended',p
results = output.get(False) #it hangs here
return results
I feel I have a small error/misunderstanding as I've made sure the processes are running and ending.
Many thanks for your help!