helloworld.ipynb
100 lines
| 2.0 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r4634 | { | |
MinRK
|
r5981 | "metadata": { | |
"name": "helloworld" | |||
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": [ | |
MinRK
|
r7739 | "# Distributed hello world\n", | |
"\n", | |||
MinRK
|
r5981 | "Originally by Ken Kinder (ken at kenkinder dom com)" | |
] | |||
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": true, | |||
MinRK
|
r5981 | "input": [ | |
"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": true, | |||
MinRK
|
r5981 | "input": [ | |
MinRK
|
r7739 | "rc = Client()\n", | |
MinRK
|
r5981 | "view = rc.load_balanced_view()" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r7739 | "metadata": {}, | |
Brian Granger
|
r6035 | "outputs": [], | |
MinRK
|
r5981 | "prompt_number": 2 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": true, | |||
MinRK
|
r5981 | "input": [ | |
MinRK
|
r7739 | "def sleep_and_echo(t, msg):\n", | |
" import time\n", | |||
" time.sleep(t)\n", | |||
MinRK
|
r5981 | " return msg" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r7739 | "metadata": {}, | |
Brian Granger
|
r6035 | "outputs": [], | |
MinRK
|
r5981 | "prompt_number": 3 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": true, | |||
MinRK
|
r5981 | "input": [ | |
MinRK
|
r7739 | "world = view.apply_async(sleep_and_echo, 3, 'World!')\n", | |
MinRK
|
r5981 | "hello = view.apply_async(sleep_and_echo, 2, 'Hello')" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r7739 | "metadata": {}, | |
Brian Granger
|
r6035 | "outputs": [], | |
MinRK
|
r5981 | "prompt_number": 4 | |
Brian Granger
|
r6035 | }, | |
MinRK
|
r5981 | { | |
Brian Granger
|
r6035 | "cell_type": "code", | |
"collapsed": false, | |||
MinRK
|
r5981 | "input": [ | |
MinRK
|
r7739 | "print \"Submitted tasks:\", hello.msg_ids + world.msg_ids\n", | |
MinRK
|
r5981 | "print hello.get(), world.get()" | |
Brian Granger
|
r6035 | ], | |
"language": "python", | |||
MinRK
|
r7739 | "metadata": {}, | |
MinRK
|
r5981 | "outputs": [ | |
{ | |||
Brian Granger
|
r6035 | "output_type": "stream", | |
"stream": "stdout", | |||
MinRK
|
r5981 | "text": [ | |
MinRK
|
r7739 | "Submitted tasks: ['04670c2d-b2fd-4b6b-a5ac-dee15e533683', 'fc802284-507b-4c29-a526-67396e17718c']\n", | |
"Hello World!\n" | |||
MinRK
|
r5981 | ] | |
} | |||
Brian Granger
|
r6035 | ], | |
MinRK
|
r7739 | "prompt_number": 6 | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [] | |||
MinRK
|
r5981 | } | |
MinRK
|
r7739 | ], | |
"metadata": {} | |||
MinRK
|
r5981 | } | |
] | |||
Brian E. Granger
|
r4634 | } |