##// END OF EJS Templates
Finishing the index files.
Finishing the index files.

File last commit:

r16115:c70632c7
r16118:61d31e5b
Show More
Parallel Decorator and map.ipynb
119 lines | 2.9 KiB | text/plain | TextLexer
/ examples / Parallel / Parallel Decorator and map.ipynb

Load balanced map and parallel function decorator

In [1]:
from __future__ import print_function
from IPython.parallel import Client
In [2]:
rc = Client()
v = rc.load_balanced_view()
In [3]:
result = v.map(lambda x: 2*x, range(10))
print("Simple, default map: ", list(result))
Simple, default map:  [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
In [4]:
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)
Submitted tasks, got ids:  ['b4d86123-967a-4f21-b9c5-8a77a69a3ced', '97401998-891d-4729-8288-ae1b97c28235', '1586cf7e-32c7-4864-bd0e-6aab16e07a3f', 'f6770223-59c3-4344-a69a-5d555d1dfb7f', '0ebb71da-6e16-44ac-917a-be978fd3787d', '582443c5-937e-45b0-9f13-5607c53cba60', '8d453d87-d70d-4fbd-a2c4-994ab3a8b6c7', '0a680757-1a59-4826-969c-523a45f3d76f', '63a3e983-a205-4f07-b494-ec86b2cdd004', '79b34cbb-aa93-4d11-8746-28969dbdd3ec']
Using a mapper:  [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
In [5]:
@v.parallel(block=True)
def f(x): return 2*x

result = f.map(range(10))
print("Using a parallel function: ", result)
Using a parallel function:  [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
In [ ]: