##// END OF EJS Templates
Miscellaneous Py 3 fixes
Miscellaneous Py 3 fixes

File last commit:

r9190:20a102a5
r13358:900c7173
Show More
taskmap.ipynb
124 lines | 2.9 KiB | text/plain | TextLexer

Load balanced map and parallel function decorator

In [1]:
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:  ['d482fcb3-f8e9-41ff-ba16-9fd4118324f1', 'e4fe38dd-8a4d-4f3a-a111-e4c9fdbea7c3', '580431f4-ac66-4517-b03e-a58aa690a87b', '19a012cf-5d9d-4cf3-9656-d56263958c0e', '012ebbb5-5def-47ad-a247-20f88d2c8980', '0dea6cdb-5b22-4bac-a1bb-7544c0ef44e6', '909d073f-7eee-42a7-8f3b-8f7aa32e7639', 'be6c7466-d541-47a0-b12d-bc408d40ad77', 'b97b5967-a5a3-45c5-95cc-44e0823fd646', '69b06902-9526-42d9-bda6-c943be19cc5a']
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 [ ]: