##// END OF EJS Templates
upate exmaple notebooks to nbformat v4
upate exmaple notebooks to nbformat v4

File last commit:

r18669:b6d2fd61
r18669:b6d2fd61
Show More
Parallel Decorator and map.ipynb
114 lines | 2.6 KiB | text/plain | TextLexer
/ examples / Parallel Computing / Parallel Decorator and map.ipynb
Brian E. Granger
Converting notebooks to JSON format.
r4634 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load balanced map and parallel function decorator"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"from IPython.parallel import Client"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"rc = Client()\n",
"v = rc.load_balanced_view()"
]
},
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "name": "stdout",
"output_type": "stream",
"text": [
"Simple, default map: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n"
MinRK
regenerate example notebooks to remove transformed output
r5981 ]
Min RK
upate exmaple notebooks to nbformat v4
r18669 }
],
"source": [
"result = v.map(lambda x: 2*x, range(10))\n",
"print(\"Simple, default map: \", list(result))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "name": "stdout",
"output_type": "stream",
"text": [
"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",
"Using a mapper: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n"
]
}
],
"source": [
"ar = v.map_async(lambda x: 2*x, range(10))\n",
"print(\"Submitted tasks, got ids: \", ar.msg_ids)\n",
"result = ar.get()\n",
"print(\"Using a mapper: \", result)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
MinRK
rebuild example notebooks...
r7739 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "name": "stdout",
"output_type": "stream",
"text": [
"Using a parallel function: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n"
]
MinRK
regenerate example notebooks to remove transformed output
r5981 }
MinRK
rebuild example notebooks...
r7739 ],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"@v.parallel(block=True)\n",
"def f(x): return 2*x\n",
"\n",
"result = f.map(range(10))\n",
"print(\"Using a parallel function: \", result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
MinRK
regenerate example notebooks to remove transformed output
r5981 }
Min RK
upate exmaple notebooks to nbformat v4
r18669 ],
"metadata": {
"signature": "sha256:8781781d8835d77bf0f71b535b72ee2718405543c48e87ad0408242119cdb3cc"
},
"nbformat": 4,
"nbformat_minor": 0
Brian E. Granger
Converting notebooks to JSON format.
r4634 }