Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "metadata": {
  5. "trusted": true,
  6. "collapsed": false
  7. },
  8. "cell_type": "code",
  9. "source": "from IPython.parallel import Client\nc = Client(profile='parallel_python2.7')\ndview = c.direct_view()\nlview = c.load_balanced_view()",
  10. "execution_count": 16,
  11. "outputs": []
  12. },
  13. {
  14. "metadata": {
  15. "trusted": true,
  16. "collapsed": false,
  17. "scrolled": true
  18. },
  19. "cell_type": "code",
  20. "source": "from matplotlib import pyplot as plt\n%matplotlib inline\nwith dview.sync_imports():\n import numpy",
  21. "execution_count": 21,
  22. "outputs": [
  23. {
  24. "output_type": "stream",
  25. "text": "importing numpy on engine(s)\n",
  26. "name": "stdout"
  27. }
  28. ]
  29. },
  30. {
  31. "metadata": {
  32. "trusted": true,
  33. "collapsed": false
  34. },
  35. "cell_type": "code",
  36. "source": "%%px\nprint 'Hello from engines'",
  37. "execution_count": 18,
  38. "outputs": [
  39. {
  40. "output_type": "stream",
  41. "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",
  42. "name": "stdout"
  43. }
  44. ]
  45. },
  46. {
  47. "metadata": {
  48. "trusted": true,
  49. "collapsed": false
  50. },
  51. "cell_type": "code",
  52. "source": "%%px --local\nprint 'Hello from engines AND client'",
  53. "execution_count": 5,
  54. "outputs": [
  55. {
  56. "output_type": "stream",
  57. "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",
  58. "name": "stdout"
  59. }
  60. ]
  61. },
  62. {
  63. "metadata": {
  64. "trusted": true,
  65. "collapsed": false
  66. },
  67. "cell_type": "code",
  68. "source": "# create a work array\nw_full = numpy.random.rand(10000)\ndview.scatter('w', w_full)",
  69. "execution_count": 19,
  70. "outputs": [
  71. {
  72. "output_type": "execute_result",
  73. "data": {
  74. "text/plain": "<AsyncResult: finished>"
  75. },
  76. "metadata": {},
  77. "execution_count": 19
  78. }
  79. ]
  80. },
  81. {
  82. "metadata": {
  83. "trusted": true,
  84. "collapsed": false
  85. },
  86. "cell_type": "code",
  87. "source": "%%px\nprint len(w)\n# work on the array on the engines\nwsq = numpy.square(w)",
  88. "execution_count": 22,
  89. "outputs": [
  90. {
  91. "output_type": "stream",
  92. "text": "[stdout:0] 2500\n[stdout:1] 2500\n[stdout:2] 2500\n[stdout:3] 2500\n",
  93. "name": "stdout"
  94. }
  95. ]
  96. },
  97. {
  98. "metadata": {
  99. "trusted": true,
  100. "collapsed": false
  101. },
  102. "cell_type": "code",
  103. "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)",
  104. "execution_count": 23,
  105. "outputs": []
  106. },
  107. {
  108. "metadata": {
  109. "trusted": true,
  110. "collapsed": true
  111. },
  112. "cell_type": "code",
  113. "source": "",
  114. "execution_count": null,
  115. "outputs": []
  116. }
  117. ],
  118. "metadata": {
  119. "kernelspec": {
  120. "name": "python2",
  121. "display_name": "Python 2.7",
  122. "language": "python"
  123. },
  124. "language_info": {
  125. "mimetype": "text/x-python",
  126. "codemirror_mode": {
  127. "name": "ipython",
  128. "version": 2
  129. },
  130. "name": "python",
  131. "file_extension": ".py",
  132. "pygments_lexer": "ipython2",
  133. "nbconvert_exporter": "python",
  134. "version": "2.7.10"
  135. }
  136. },
  137. "nbformat": 4,
  138. "nbformat_minor": 0
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement