forked from minrk/IPython-parallel-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnestedloop.py
More file actions
21 lines (13 loc) · 716 Bytes
/
nestedloop.py
File metadata and controls
21 lines (13 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# To parallelize every call with map, you just need to get a list for each argument.
# You can use `itertools.product` + `zip` to get this:
import itertools
product = list(itertools.product(widths, heights))
# [(1, 6), (1, 7), (2, 6), (2, 7), (3, 6), (3, 7)]
# So we have a "list of pairs",
# but what we really want is a single list for each argument, i.e. a "pair of lists".
# This is exactly what the slightly weird `zip(*product)` syntax gets us:
allwidths, allheights = zip(*itertools.product(widths, heights))
print " widths", allwidths
print "heights", allheights
# Now we just map our function onto those two lists, to parallelize nested for loops:
ar = lview.map_async(area, allwidths, allheights)