I've been browsing for some time but couldn't find any constructive answer that I could comprehend.
How should I paralellize the following code:
import random
import math
import numpy as np
import sys
import multiprocessing
boot = 20#number of iterations to be performed
def myscript(iteration_number):
#stuff that the code actually does
def main(unused_command_line_args):
for i in xrange(boot):
myscript(i)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
or where can I read about it? I'm not really sure how to search for it even.
There's pretty much a natural progression from a for loop to parallel for a batch of embarrassingly parallel jobs.
So how to address this function in parallel?
The last form is an unordered iterator, which tends to be the fastest… but you can't care about what order the results come back in -- they are unordered, and not guaranteed to return in the same order they were submitted.
Note also that I've used
multiprocess
(a fork) instead ofmultiprocessing
… but purely becausemultiprocess
is better when dealing with interactively defined functions. Otherwise the code above is the same formultiprocessing
.