{ "metadata": { "name": "taskmap" }, "nbformat": 2, "worksheets": [ { "cells": [ { "cell_type": "markdown", "source": [ "# Load balanced map and parallel function decorator" ] }, { "cell_type": "code", "collapsed": true, "input": [ "from IPython.parallel import Client" ], "language": "python", "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "rc = Client()", "v = rc.load_balanced_view()" ], "language": "python", "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "result = v.map(lambda x: 2*x, range(10))", "print \"Simple, default map: \", list(result)" ], "language": "python", "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Simple, default map: " ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "ar = v.map_async(lambda x: 2*x, range(10))", "print \"Submitted tasks, got ids: \", ar.msg_ids", "result = ar.get()", "print \"Using a mapper: \", result" ], "language": "python", "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Submitted tasks, got ids: ['5100a4c7-73a4-4832-aa91-e774f6f3ede8', 'd0cae1cf-2b32-4092-9eb7-f17b43fb3849', 'e08d3ee2-f221-47fe-9556-ed938e692030', '065585e4-cdf9-4240-a5fe-e44b2ae5d023', 'd2162f23-68e5-4318-ba1e-e34fd03a72ac', '5b3b835f-2099-4a70-9896-d1aa810c77e6', 'e2c2a823-bd44-4f91-8db3-c154d0d86e56', '991e0c25-f98a-44b5-9d9e-889d4180b9a5', '4ad41221-28bd-482f-a300-97c404648161', '5b730eb3-e0bb-4cdd-b228-c3b8d158828a']", "Using a mapper: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "@v.parallel(block=True)", "def f(x): return 2*x", "", "result = f.map(range(10))", "print \"Using a parallel function: \", result" ], "language": "python", "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Using a parallel function: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" ] } ], "prompt_number": 6 } ] } ] }