{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6-element Array{Int64,1}:\n", " 18\n", " 19\n", " 20\n", " 21\n", " 22\n", " 23" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "addprocs(6)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 2.016586 seconds (472 allocations: 69.656 KiB)\n", " 4.040289 seconds (10.48 k allocations: 614.708 KiB)\n" ] } ], "source": [ "# define a slow function\n", "@everywhere slow(n) = (sleep(n); sum(rand(n)))\n", "\n", "# should take ~2 seconds \n", "@time pmap(slow, [2,2,2,2]);\n", "\n", "# define a new function that run pmaps on the slow function\n", "@everywhere pp(n) = (sleep(n); pmap(slow, [n for _ in 1:n]))\n", "\n", "# single invocation: 2 + 2 => 4\n", "@time pp(2);" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 5.746599 seconds (1.53 k allocations: 98.156 KiB)\n", " 4.011430 seconds (2.15 k allocations: 298.641 KiB)\n", " 4.011655 seconds (2.15 k allocations: 287.922 KiB)\n", " 4.012401 seconds (2.14 k allocations: 169.906 KiB)\n", " 4.010906 seconds (2.14 k allocations: 152.672 KiB)\n", " 4.011669 seconds (2.15 k allocations: 163.359 KiB)\n", " 4.012294 seconds (2.15 k allocations: 292.188 KiB)\n", " 4.075743 seconds (2.15 k allocations: 159.281 KiB)\n", " 4.011138 seconds (2.15 k allocations: 153.328 KiB)\n", " 4.010753 seconds (2.14 k allocations: 148.438 KiB)\n" ] } ], "source": [ "# if the nested pmap works properly then it should take ~4 seconds\n", "# if the nested pmap works serially then it should take ~6 seconds\n", "for i in 1:10\n", " @time pmap(pp, [2,2]);\n", "end" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.6.2", "language": "julia", "name": "julia-0.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }