taskmap.ipynb
108 lines
| 2.6 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r4634 | { | |
MinRK
|
r5981 | "metadata": { | |
"name": "taskmap" | |||
Brian Granger
|
r6035 | }, | |
"nbformat": 3, | |||
MinRK
|
r5981 | "worksheets": [ | |
{ | |||
"cells": [ | |||
{ | |||
Brian Granger
|
r6035 | "cell_type": "markdown", | |
MinRK
|
r5981 | "source": [ | |
"# Load balanced map and parallel function decorator" | |||
] | |||
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": true, | |||
MinRK
|
r5981 | "input": [ | |
"from IPython.parallel import Client" | |||
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
"outputs": [], | |||
MinRK
|
r5981 | "prompt_number": 1 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": false, | |||
MinRK
|
r5981 | "input": [ | |
Brian Granger
|
r6035 | "rc = Client()", | |
MinRK
|
r5981 | "v = rc.load_balanced_view()" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
"outputs": [], | |||
MinRK
|
r5981 | "prompt_number": 3 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": false, | |||
MinRK
|
r5981 | "input": [ | |
Brian Granger
|
r6035 | "result = v.map(lambda x: 2*x, range(10))", | |
MinRK
|
r5981 | "print \"Simple, default map: \", list(result)" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r5981 | "outputs": [ | |
{ | |||
Brian Granger
|
r6035 | "output_type": "stream", | |
"stream": "stdout", | |||
MinRK
|
r5981 | "text": [ | |
"Simple, default map: " | |||
] | |||
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "output_type": "stream", | |
"stream": "stdout", | |||
MinRK
|
r5981 | "text": [ | |
"[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" | |||
] | |||
} | |||
Brian Granger
|
r6035 | ], | |
MinRK
|
r5981 | "prompt_number": 4 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": false, | |||
MinRK
|
r5981 | "input": [ | |
Brian Granger
|
r6035 | "ar = v.map_async(lambda x: 2*x, range(10))", | |
"print \"Submitted tasks, got ids: \", ar.msg_ids", | |||
"result = ar.get()", | |||
MinRK
|
r5981 | "print \"Using a mapper: \", result" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r5981 | "outputs": [ | |
{ | |||
Brian Granger
|
r6035 | "output_type": "stream", | |
"stream": "stdout", | |||
MinRK
|
r5981 | "text": [ | |
Brian Granger
|
r6035 | "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']", | |
MinRK
|
r5981 | "Using a mapper: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" | |
] | |||
} | |||
Brian Granger
|
r6035 | ], | |
MinRK
|
r5981 | "prompt_number": 5 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": false, | |||
MinRK
|
r5981 | "input": [ | |
Brian Granger
|
r6035 | "@v.parallel(block=True)", | |
"def f(x): return 2*x", | |||
"", | |||
"result = f.map(range(10))", | |||
MinRK
|
r5981 | "print \"Using a parallel function: \", result" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r5981 | "outputs": [ | |
{ | |||
Brian Granger
|
r6035 | "output_type": "stream", | |
"stream": "stdout", | |||
MinRK
|
r5981 | "text": [ | |
"Using a parallel function: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" | |||
] | |||
} | |||
Brian Granger
|
r6035 | ], | |
MinRK
|
r5981 | "prompt_number": 6 | |
} | |||
] | |||
} | |||
] | |||
Brian E. Granger
|
r4634 | } |