Good day
I am trying to speed up a computation that involves many independent integrations. To do this I am using pythons Joblib and multiprocessing. So far I have succeeded with parallelizing the inner loop of my computation, but I would like to do the same with the outer loop. Since parallel programming messes with my mind, I am wondering if someone could help me. So far I have:
from joblib import Parallel, delayed
import multiprocessing
N = 10 # Some number
inputs = range(1,N,2)
num_cores = multiprocessing.cpu_count()
def processInput(n):
u_1 = lambda x,y: f(x,y)g(n,m) # Some function
Cn = scintegrate.nquad(u_1, [[A,B],[C,D]]) # A number
return Cn*F(x,y)*G(n,m)
resultsN = []
for m in range(1,N,2): # How can this be parallelized?
add = Parallel(n_jobs=num_cores)(delayed(processInput)(n) for n in inputs)
resultsN = add + resultsN
resultsN = sum(resultsN)
This have so far produced the correct results. Now I would like to do the same with outer loop. Does anyone have an idea how I can do this?
I am also wondering if the u_1 declaration can be done outside the processInput, and any other suggestions for improvement will be appreciated.
Thanks for any replies.