I am processing some ascii-data, make some operations, and then writing everything back to another file (job done by post_processing_0.main
, without returning anything). I want to parallelize the code with the multiprocessing module, see the following code snippet:
from multiprocessing import Pool
import post_processing_0
def chunks(lst,n):
return [ lst[i::n] for i in xrange(n) ]
def main():
pool = Pool(processes=proc_num)
P={}
for i in range(0,proc_num):
P['process_'+str(i)]=pool.apply_async(post_processing_0.main, [split_list[i]])
pool.close()
pool.join()
proc_num=8
timesteps=100
list_to_do=range(0,timesteps)
split_list=chunks(list_to_do,proc_num)
main()
I read the difference between map and async, but I don t understand it very well. Is my application of multiprocessing module correct?
In this case, should I use map_async or apply_async? And why?
Edit:
I don't think this is a duplicate of the question Python multiprocessing.Pool: when to use apply, apply_async or map?. In the question, the answer focus on the order of the result that can be obtained using the two functions. Here i am asking: what is it the difference when nothing is returned?