##// END OF EJS Templates
Adding back deleted file.
Brian Granger -
Show More
@@ -0,0 +1,118 b''
1 {
2 "metadata": {
3 "name": "task_1"
4 },
5 "nbformat": 3,
6 "worksheets": [
7 {
8 "cells": [
9 {
10 "cell_type": "markdown",
11 "source": [
12 "# Simple task farming example"
13 ]
14 },
15 {
16 "cell_type": "code",
17 "collapsed": true,
18 "input": [
19 "from IPython.parallel import Client"
20 ],
21 "language": "python",
22 "outputs": [],
23 "prompt_number": 3
24 },
25 {
26 "cell_type": "markdown",
27 "source": [
28 "A `Client.load_balanced_view` is used to get the object used for working with load balanced tasks."
29 ]
30 },
31 {
32 "cell_type": "code",
33 "collapsed": true,
34 "input": [
35 "rc = Client()",
36 "v = rc.load_balanced_view()"
37 ],
38 "language": "python",
39 "outputs": [],
40 "prompt_number": 4
41 },
42 {
43 "cell_type": "markdown",
44 "source": [
45 "Set the variable `d` on all engines:"
46 ]
47 },
48 {
49 "cell_type": "code",
50 "collapsed": true,
51 "input": [
52 "rc[:]['d'] = 30"
53 ],
54 "language": "python",
55 "outputs": [],
56 "prompt_number": 5
57 },
58 {
59 "cell_type": "markdown",
60 "source": [
61 "Define a function that will be our task:"
62 ]
63 },
64 {
65 "cell_type": "code",
66 "collapsed": true,
67 "input": [
68 "def task(a):",
69 " return a, 10*d, a*10*d"
70 ],
71 "language": "python",
72 "outputs": [],
73 "prompt_number": 6
74 },
75 {
76 "cell_type": "markdown",
77 "source": [
78 "Run the task once:"
79 ]
80 },
81 {
82 "cell_type": "code",
83 "collapsed": true,
84 "input": [
85 "ar = v.apply(task, 5)"
86 ],
87 "language": "python",
88 "outputs": [],
89 "prompt_number": 7
90 },
91 {
92 "cell_type": "markdown",
93 "source": [
94 "Print the results:"
95 ]
96 },
97 {
98 "cell_type": "code",
99 "collapsed": false,
100 "input": [
101 "print \"a, b, c: \", ar.get()"
102 ],
103 "language": "python",
104 "outputs": [
105 {
106 "output_type": "stream",
107 "stream": "stdout",
108 "text": [
109 "a, b, c: [5, 300, 1500]"
110 ]
111 }
112 ],
113 "prompt_number": 8
114 }
115 ]
116 }
117 ]
118 } No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now