'Multiprocessing with results not shown in python
I am trying to integrate the orbit so I try with the multiprocessing with 2 time to give it a shot and the code is
#multiprocessing, define function first. Then run it
ws2 = np.zeros((500,6))
ws = np.zeros((2,500,6))
def funcws(num,*params):
integrator.set_initial_value([8+xinit[num],yinit[num],8+zinit[num],vxinit[num],150+vyinit[num],vzinit[num]])
for it in range(500):
times[it] = integrator.t
integrator.integrate(integrator.t+0.01)
ws2[it] = integrator.y
return ws2
def func(index):
ws[index] = funcws(index)
pool = Pool(processes=4)
for _ in tqdm(pool.imap(func,range(2)),total=2):
pass
# tqdm.write('scheduled')
pool.close()
pool.join()
however when I print ws or ws2 they will be zeros. but if I print it inside the function they will show results. Is there something wrong that I need to change? Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|