Repository URL to install this package:
|
Version:
0.13.2 ▾
|
{
"metadata": {
"name": "taskmap"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Load balanced map and parallel function decorator"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"from IPython.parallel import Client"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"rc = Client()\n",
"v = rc.load_balanced_view()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"result = v.map(lambda x: 2*x, range(10))\n",
"print \"Simple, default map: \", list(result)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Simple, default map: "
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"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"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"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"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"@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"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Using a parallel function: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}