##// END OF EJS Templates
Adding back deleted file.
Adding back deleted file.

File last commit:

r6033:0359fcaa
r6033:0359fcaa
Show More
task_1.ipynb
117 lines | 2.1 KiB | text/plain | TextLexer
Brian Granger
Adding back deleted file.
r6033 {
"metadata": {
"name": "task_1"
},
"nbformat": 3,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Simple task farming example"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"from IPython.parallel import Client"
],
"language": "python",
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"source": [
"A `Client.load_balanced_view` is used to get the object used for working with load balanced tasks."
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"rc = Client()",
"v = rc.load_balanced_view()"
],
"language": "python",
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"source": [
"Set the variable `d` on all engines:"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"rc[:]['d'] = 30"
],
"language": "python",
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "markdown",
"source": [
"Define a function that will be our task:"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"def task(a):",
" return a, 10*d, a*10*d"
],
"language": "python",
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "markdown",
"source": [
"Run the task once:"
]
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"ar = v.apply(task, 5)"
],
"language": "python",
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "markdown",
"source": [
"Print the results:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"a, b, c: \", ar.get()"
],
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"a, b, c: [5, 300, 1500]"
]
}
],
"prompt_number": 8
}
]
}
]
}