How To Parallelize This Nested Loop In Python That Calls Abaqus
I have the nested loops below. How can i parallelize the outside loop so i can distribute the outside loop into 4 simultaneous runs and wait for all 4 runs to complete before movin
Solution 1:
Use concurrent.futures
module if multiprocessing is what you want.
from concurrent.futures import ProcessPoolExecutor
defeach(r):
for k inrange( r*nAnalysis/4, (r+1)*nAnalysis/4 ):
writeABQfile(ppos,props,totalTime[k],recInt[k],inpFiles[k],i,lineNum[k],aPath[k])
delFile(aPath[k]+"/"+inpFiles[k]+".lck")
runABQfile(inpFiles[k],aPath[k])
with ProcessPoolExecutor(max_workers=4) as executor:
output = executor.map(each, range(4)) # returns an iterable
If you just want to "do" stuff rather than "produce", check out as_completed
function from the same module. There are direct examples in the doc.
Post a Comment for "How To Parallelize This Nested Loop In Python That Calls Abaqus"