To parallelize each call, you just need to get a list for each argument. You can use itertools.product
+ zip
to get the following:
allzeniths, allazimuths = zip(*itertools.product(zeniths, azimuths))
Then you can use the map:
amr = dview.map(f, allzeniths, allazimuths)
To go deeper into the steps, here is an example:
zeniths = range(1,4) azimuths = range(6,8) product = list(itertools.product(zeniths, azimuths))
So, we have a βlist of pairsβ, but we really need a single list for each argument, i.e. "a couple of lists." This is exactly what gives us the slightly strange zip(*product)
syntax:
allzeniths, allazimuths = zip(*itertools.product(zeniths, azimuths)) print allzeniths
Now we simply map our function to these two lists in order to parallelize the nested for loops:
def f(z,a): return z*a view.map(f, allzeniths, allazimuths)
And there is nothing special in that there are only two - this method should extend to an arbitrary number of nested loops.