I'm pretty new to multiprocessing using Python and I'm trying to understand how to use Pool properly. I have some code which looks like this:
import numpy as np
from multiprocessing.dummy import Pool as ThreadPool
...
pool = ThreadPool(15)
arb = np.arange(0,len(np.concatenate((P,V),axis=0)),1)
F = pool.map(tttt,arb)
pool.close()
pool.join()
NT = 1000
for test in range(0,NT):
(P,V) = Dynamics(P,V,F)
pool = ThreadPool(15)
F = pool.map(tttt,arb)
pool.close()
pool.join()
...
tttt and Dynamics are two functions that are previously defined. I want to use Pool to be able to calculate a lot of values simultaneosly using tttt but I also want to update the values that I use for those calculations (tttt depends on P and V although not explicitly).
Do I have to create and close the pool twice as I am doing right now or can I do it just once?