Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "metadata": {
- "trusted": true,
- "collapsed": false
- },
- "cell_type": "code",
- "source": "from IPython.parallel import Client\nc = Client(profile='parallel_python2.7')\ndview = c.direct_view()\nlview = c.load_balanced_view()",
- "execution_count": 16,
- "outputs": []
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": false,
- "scrolled": true
- },
- "cell_type": "code",
- "source": "from matplotlib import pyplot as plt\n%matplotlib inline\nwith dview.sync_imports():\n import numpy",
- "execution_count": 21,
- "outputs": [
- {
- "output_type": "stream",
- "text": "importing numpy on engine(s)\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": false
- },
- "cell_type": "code",
- "source": "%%px\nprint 'Hello from engines'",
- "execution_count": 18,
- "outputs": [
- {
- "output_type": "stream",
- "text": "[stdout:0] Hello from engines\n[stdout:1] Hello from engines\n[stdout:2] Hello from engines\n[stdout:3] Hello from engines\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": false
- },
- "cell_type": "code",
- "source": "%%px --local\nprint 'Hello from engines AND client'",
- "execution_count": 5,
- "outputs": [
- {
- "output_type": "stream",
- "text": "Hello from engines AND client\n[stdout:0] Hello from engines AND client\n[stdout:1] Hello from engines AND client\n[stdout:2] Hello from engines AND client\n[stdout:3] Hello from engines AND client\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": false
- },
- "cell_type": "code",
- "source": "# create a work array\nw_full = numpy.random.rand(10000)\ndview.scatter('w', w_full)",
- "execution_count": 19,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": "<AsyncResult: finished>"
- },
- "metadata": {},
- "execution_count": 19
- }
- ]
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": false
- },
- "cell_type": "code",
- "source": "%%px\nprint len(w)\n# work on the array on the engines\nwsq = numpy.square(w)",
- "execution_count": 22,
- "outputs": [
- {
- "output_type": "stream",
- "text": "[stdout:0] 2500\n[stdout:1] 2500\n[stdout:2] 2500\n[stdout:3] 2500\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": false
- },
- "cell_type": "code",
- "source": "# get the result back on the client\nwsq_full = dview.gather('wsq').get()\n# check result\nnumpy.testing.assert_allclose(w_full**2, wsq_full)",
- "execution_count": 23,
- "outputs": []
- },
- {
- "metadata": {
- "trusted": true,
- "collapsed": true
- },
- "cell_type": "code",
- "source": "",
- "execution_count": null,
- "outputs": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "name": "python2",
- "display_name": "Python 2.7",
- "language": "python"
- },
- "language_info": {
- "mimetype": "text/x-python",
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "name": "python",
- "file_extension": ".py",
- "pygments_lexer": "ipython2",
- "nbconvert_exporter": "python",
- "version": "2.7.10"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement