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