taskmap.ipynb
70 lines
| 3.2 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r4634 | { | |
"nbformat": 2, | |||
Brian E. Granger
|
r4637 | "metadata": { | |
"name": "taskmap" | |||
}, | |||
Brian E. Granger
|
r4634 | "worksheets": [ | |
{ | |||
"cells": [ | |||
{ | |||
"source": "# Load balanced map and parallel function decorator", | |||
"cell_type": "markdown" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [], | |||
"collapsed": true, | |||
"prompt_number": 4, | |||
"input": "from IPython.parallel import Client" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [], | |||
"collapsed": true, | |||
"prompt_number": 5, | |||
"input": "rc = Client()\nv = rc.load_balanced_view()" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "stream", | |||
"text": "Simple, default map: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" | |||
} | |||
], | |||
"collapsed": false, | |||
"prompt_number": 6, | |||
"input": "result = v.map(lambda x: 2*x, range(10))\nprint \"Simple, default map: \", list(result)" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "stream", | |||
"text": "Submitted tasks, got ids: ['2a25ff3f-f0d0-4428-909a-3fe808ca61f9', 'edd42168-fac2-4b3f-a696-ce61b37aa71d', '8a548908-7812-44e6-a8b1-68e941bee608', '26435a77-fe86-49b6-b59f-de864d59c99f', '6750c7b4-2168-49ec-bcc4-feb1e17c5e53', '117240d1-5dfc-4783-948f-e9523b2b2f6a', '6de16d46-f2e2-49bd-8180-e43d1d875529', '3d372b84-0c68-4315-92c8-a080c68478b7', '43acedae-e35c-4a17-87f0-9e5e672500f7', 'eb71dd1f-9500-4375-875d-c2c42999848c']\nUsing a mapper: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" | |||
} | |||
], | |||
"collapsed": false, | |||
"prompt_number": 7, | |||
"input": "ar = v.map_async(lambda x: 2*x, range(10))\nprint \"Submitted tasks, got ids: \", ar.msg_ids\nresult = ar.get()\nprint \"Using a mapper: \", result" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "stream", | |||
"text": "Using a parallel function: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" | |||
} | |||
], | |||
"collapsed": false, | |||
"prompt_number": 8, | |||
"input": "@v.parallel(block=True)\ndef f(x): return 2*x\n\nresult = f.map(range(10))\nprint \"Using a parallel function: \", result" | |||
} | |||
] | |||
} | |||
] | |||
} |