{
 "metadata": {
  "name": "helloworld"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "# Distributed hello world\n",
      "\n",
      "Originally by Ken Kinder (ken at kenkinder dom com)"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "from IPython.parallel import Client"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "rc = Client()\n",
      "view = rc.load_balanced_view()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "def sleep_and_echo(t, msg):\n",
      "    import time\n",
      "    time.sleep(t)\n",
      "    return msg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "world = view.apply_async(sleep_and_echo, 3, 'World!')\n",
      "hello = view.apply_async(sleep_and_echo, 2, 'Hello')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Submitted tasks:\", hello.msg_ids + world.msg_ids\n",
      "print hello.get(), world.get()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Submitted tasks: ['04670c2d-b2fd-4b6b-a5ac-dee15e533683', 'fc802284-507b-4c29-a526-67396e17718c']\n",
        "Hello World!\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}