PROBLEM: I have a for loop which takes a very long time to run. I was hoping to parallelize it to speed it up. However I feel that I have been complicating the problem more than I should be. The loop will be given below. Each variable (rtran-MDvals) is constant. For a bit extra information Nr is equal to 100. The two functions M_B and M_D are fairly complicated but essentially only the rv term is different since it is related to j by the list rvm. Ill show my attempt to parallelize it below the code.
CODE:
MBvals = []
MDvals = []
radialvalue = 0
rv = 0
rtran = 0
j = 0
def tran_for_loop(j,rtran,Nr,Rb,n,b_n,M_B_tot,MBvals,Rd,M_D_tot,MDvals):
for j in range(Nr):
rv=rvm[j] # the jth term from the list rvm is assigned to rv
MB_rv = M_B(rv,Rb,n,b_n, M_B_tot) # rv is inputed into the function M_B
MBvals.append(MB_rv) # the value of that function MB_rv is appended to the list MBvals
MD_rv = M_D(rv,Rd,M_D_tot) # rv is inputed into the function M_D
MDvals.append(MD_rv) # the value of that function MD_rv is appended to the list MBvals
# outputs are the two lists MBvals and MDvals
ATTEMPT:
if __name__ =='__main__':
pool = mp.Pool(mp.cpu_count())
pool.map(tran_for_loop, [j for j in range(Nr)])
pool.close()
ERROR
INDEXERROR: LIST INDEX IS OUT OF RANGE
I tried debugging to figure out if this error is coming after the Parallelization or during, and as far as I can tell it is during. I have a feeling I either just completely messed up the syntax of I'm not able to append lists in Parallel like I think I can. Any help would be appreciated. If something is not clear please let me know.
EDITS
rvm is a list of 100 values ranging from .1 to 100.
rvmis defined. That seems to be an important variable in this problem. Can you edit the question to include the definition ofrvm?