taskmap.py
35 lines
| 594 B
| text/x-python
|
PythonLexer
Brian E. Granger
|
r4581 | # <nbformat>2</nbformat> | ||
# <markdowncell> | ||||
# # Load balanced map and parallel function decorator | ||||
# <codecell> | ||||
MinRK
|
r3690 | from IPython.parallel import Client | ||
Brian E. Granger
|
r4581 | # <codecell> | ||
MinRK
|
r3690 | rc = Client() | ||
v = rc.load_balanced_view() | ||||
Brian E. Granger
|
r4581 | # <codecell> | ||
MinRK
|
r3690 | result = v.map(lambda x: 2*x, range(10)) | ||
print "Simple, default map: ", list(result) | ||||
Brian E. Granger
|
r4581 | # <codecell> | ||
MinRK
|
r3690 | ar = v.map_async(lambda x: 2*x, range(10)) | ||
print "Submitted tasks, got ids: ", ar.msg_ids | ||||
result = ar.get() | ||||
print "Using a mapper: ", result | ||||
Brian E. Granger
|
r4581 | # <codecell> | ||
MinRK
|
r3690 | @v.parallel(block=True) | ||
def f(x): return 2*x | ||||
result = f.map(range(10)) | ||||
Brian E. Granger
|
r4581 | print "Using a parallel function: ", result | ||