{ "metadata": { "name": "helloworld" }, "nbformat": 2, "worksheets": [ { "cells": [ { "cell_type": "markdown", "source": [ "# Distributed hello world", "", "Originally by Ken Kinder (ken at kenkinder dom com)" ] }, { "cell_type": "code", "collapsed": true, "input": [ "from IPython.parallel import Client" ], "language": "python", "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": true, "input": [ "rc = Client()", "view = rc.load_balanced_view()" ], "language": "python", "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": true, "input": [ "def sleep_and_echo(t, msg):", " import time", " time.sleep(t)", " return msg" ], "language": "python", "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": true, "input": [ "world = view.apply_async(sleep_and_echo, 3, 'World!')", "hello = view.apply_async(sleep_and_echo, 2, 'Hello')" ], "language": "python", "outputs": [], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "print \"Submitted tasks:\", hello.msg_ids, world.msg_ids", "print hello.get(), world.get()" ], "language": "python", "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Submitted tasks: ['dd1052e0-aa75-4b25-9d35-ecbdaf6e3ed7'] ['1b46aa21-20d1-459c-bc36-2d8d03336f74']", "Hello" ] }, { "output_type": "stream", "stream": "stdout", "text": [ " World!" ] } ], "prompt_number": 5 } ] } ] }