Parallel Decorator and map.ipynb
119 lines
| 2.9 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r4634 | { | |
MinRK
|
r5981 | "metadata": { | |
Brian E. Granger
|
r16115 | "name": "", | |
"signature": "sha256:8781781d8835d77bf0f71b535b72ee2718405543c48e87ad0408242119cdb3cc" | |||
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": [ | |
Thomas Kluyver
|
r13997 | "from __future__ import print_function\n", | |
MinRK
|
r5981 | "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", | |
Thomas Kluyver
|
r13997 | "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": [ | |
Brian E. Granger
|
r16115 | "Simple, default map: [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", | |
Thomas Kluyver
|
r13997 | "print(\"Submitted tasks, got ids: \", ar.msg_ids)\n", | |
MinRK
|
r7739 | "result = ar.get()\n", | |
Thomas Kluyver
|
r13997 | "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": [ | |
Brian E. Granger
|
r16115 | "Submitted tasks, got ids: ['b4d86123-967a-4f21-b9c5-8a77a69a3ced', '97401998-891d-4729-8288-ae1b97c28235', '1586cf7e-32c7-4864-bd0e-6aab16e07a3f', 'f6770223-59c3-4344-a69a-5d555d1dfb7f', '0ebb71da-6e16-44ac-917a-be978fd3787d', '582443c5-937e-45b0-9f13-5607c53cba60', '8d453d87-d70d-4fbd-a2c4-994ab3a8b6c7', '0a680757-1a59-4826-969c-523a45f3d76f', '63a3e983-a205-4f07-b494-ec86b2cdd004', '79b34cbb-aa93-4d11-8746-28969dbdd3ec']\n", | |
MinRK
|
r7739 | "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", | |||
Thomas Kluyver
|
r13997 | "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 | } |