##// END OF EJS Templates
Merge pull request #1768 from minrk/parallelmagics...
Merge pull request #1768 from minrk/parallelmagics Update parallel magics They now display all output, so you can do parallel plotting or other actions with complex display. The `px` magic has now both line and cell modes, and in cell mode finer control has been added about how to collate output from multiple engines. Tests, docs and example notebook added.

File last commit:

r6035:3077781f
r7060:a1360828 merge
Show More
taskmap.ipynb
108 lines | 2.6 KiB | text/plain | TextLexer

Load balanced map and parallel function decorator

In [1]:
from IPython.parallel import Client
In [3]:
rc = Client()
v = rc.load_balanced_view()
In [4]:
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 [5]:
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:  ['5100a4c7-73a4-4832-aa91-e774f6f3ede8', 'd0cae1cf-2b32-4092-9eb7-f17b43fb3849', 'e08d3ee2-f221-47fe-9556-ed938e692030', '065585e4-cdf9-4240-a5fe-e44b2ae5d023', 'd2162f23-68e5-4318-ba1e-e34fd03a72ac', '5b3b835f-2099-4a70-9896-d1aa810c77e6', 'e2c2a823-bd44-4f91-8db3-c154d0d86e56', '991e0c25-f98a-44b5-9d9e-889d4180b9a5', '4ad41221-28bd-482f-a300-97c404648161', '5b730eb3-e0bb-4cdd-b228-c3b8d158828a']
Using a mapper:  [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
In [6]:
@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]