##// END OF EJS Templates
execute_on_complete_input...
execute_on_complete_input better name for check_complete

File last commit:

r9190:20a102a5
r11780:cb7dd5c2
Show More
parallel_mpi.ipynb
186 lines | 4.2 KiB | text/plain | TextLexer
Fernando Perez
Add simple MPI parallel example notebook.
r4911 {
MinRK
regenerate example notebooks to remove transformed output
r5981 "metadata": {
"name": "parallel_mpi"
Brian Granger
Updating example notebooks to v3 format.
r6035 },
"nbformat": 3,
MinRK
rebuild example notebooks...
r7739 "nbformat_minor": 0,
MinRK
regenerate example notebooks to remove transformed output
r5981 "worksheets": [
{
"cells": [
{
MinRK
rebuild example notebooks...
r7739 "cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Simple usage of a set of MPI engines"
]
},
{
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "source": [
MinRK
rebuild example notebooks...
r7739 "This example assumes you've started a cluster of N engines (4 in this example) as part\n",
"of an MPI world. \n",
"\n",
"Our documentation describes [how to create an MPI profile](http://ipython.org/ipython-doc/dev/parallel/parallel_process.html#using-ipcluster-in-mpiexec-mpirun-mode)\n",
"and explains [basic MPI usage of the IPython cluster](http://ipython.org/ipython-doc/dev/parallel/parallel_mpi.html).\n",
"\n",
"\n",
"For the simplest possible way to start 4 engines that belong to the same MPI world, \n",
"you can run this in a terminal:\n",
"\n",
"<pre>\n",
"ipcluster start --engines=MPI -n 4\n",
"</pre>\n",
"\n",
"or start an MPI cluster from the cluster tab if you have one configured.\n",
"\n",
MinRK
regenerate example notebooks to remove transformed output
r5981 "Once the cluster is running, we can connect to it and open a view into it:"
]
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": true,
MinRK
regenerate example notebooks to remove transformed output
r5981 "input": [
MinRK
rebuild example notebooks...
r7739 "from IPython.parallel import Client\n",
"c = Client()\n",
MinRK
regenerate example notebooks to remove transformed output
r5981 "view = c[:]"
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Brian Granger
Updating example notebooks to v3 format.
r6035 "outputs": [],
MinRK
rebuild example notebooks...
r7739 "prompt_number": 1
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "source": [
"Let's define a simple function that gets the MPI rank from each engine."
]
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": true,
MinRK
regenerate example notebooks to remove transformed output
r5981 "input": [
MinRK
rebuild example notebooks...
r7739 "@view.remote(block=True)\n",
"def mpi_rank():\n",
" from mpi4py import MPI\n",
" comm = MPI.COMM_WORLD\n",
MinRK
regenerate example notebooks to remove transformed output
r5981 " return comm.Get_rank()"
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Brian Granger
Updating example notebooks to v3 format.
r6035 "outputs": [],
MinRK
rebuild example notebooks...
r7739 "prompt_number": 2
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": false,
MinRK
regenerate example notebooks to remove transformed output
r5981 "input": [
"mpi_rank()"
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "outputs": [
{
Brian Granger
Updating example notebooks to v3 format.
r6035 "output_type": "pyout",
MinRK
rebuild example notebooks...
r7739 "prompt_number": 3,
MinRK
regenerate example notebooks to remove transformed output
r5981 "text": [
MinRK
rebuild example notebooks...
r7739 "[2, 3, 1, 0]"
MinRK
regenerate example notebooks to remove transformed output
r5981 ]
}
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
MinRK
rebuild example notebooks...
r7739 "prompt_number": 3
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "source": [
MinRK
rebuild example notebooks...
r7739 "To get a mapping of IPython IDs and MPI rank (these do not always match),\n",
"you can use the get_dict method on AsyncResults."
MinRK
regenerate example notebooks to remove transformed output
r5981 ]
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": false,
MinRK
regenerate example notebooks to remove transformed output
r5981 "input": [
MinRK
rebuild example notebooks...
r7739 "mpi_rank.block = False\n",
"ar = mpi_rank()\n",
"ar.get_dict()"
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "outputs": [
{
MinRK
rebuild example notebooks...
r7739 "output_type": "pyout",
"prompt_number": 4,
MinRK
regenerate example notebooks to remove transformed output
r5981 "text": [
MinRK
rebuild example notebooks...
r7739 "{0: 2, 1: 3, 2: 1, 3: 0}"
MinRK
regenerate example notebooks to remove transformed output
r5981 ]
}
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
MinRK
rebuild example notebooks...
r7739 "prompt_number": 4
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "source": [
MinRK
rebuild example notebooks...
r7739 "With %%px cell magic, the next cell will actually execute *entirely on each engine*:"
MinRK
regenerate example notebooks to remove transformed output
r5981 ]
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": true,
MinRK
regenerate example notebooks to remove transformed output
r5981 "input": [
MinRK
rebuild example notebooks...
r7739 "%%px\n",
"from mpi4py import MPI\n",
"\n",
"comm = MPI.COMM_WORLD\n",
"size = comm.Get_size()\n",
"rank = comm.Get_rank()\n",
"\n",
"if rank == 0:\n",
" data = [(i+1)**2 for i in range(size)]\n",
"else:\n",
" data = None\n",
"data = comm.scatter(data, root=0)\n",
"\n",
MinRK
regenerate example notebooks to remove transformed output
r5981 "assert data == (rank+1)**2, 'data=%s, rank=%s' % (data, rank)"
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Brian Granger
Updating example notebooks to v3 format.
r6035 "outputs": [],
MinRK
rebuild example notebooks...
r7739 "prompt_number": 5
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": false,
MinRK
regenerate example notebooks to remove transformed output
r5981 "input": [
"view['data']"
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
regenerate example notebooks to remove transformed output
r5981 "outputs": [
{
Brian Granger
Updating example notebooks to v3 format.
r6035 "output_type": "pyout",
MinRK
rebuild example notebooks...
r7739 "prompt_number": 6,
MinRK
regenerate example notebooks to remove transformed output
r5981 "text": [
MinRK
rebuild example notebooks...
r7739 "[9, 16, 4, 1]"
MinRK
regenerate example notebooks to remove transformed output
r5981 ]
}
Brian Granger
Updating example notebooks to v3 format.
r6035 ],
MinRK
rebuild example notebooks...
r7739 "prompt_number": 6
Brian Granger
Updating example notebooks to v3 format.
r6035 },
MinRK
regenerate example notebooks to remove transformed output
r5981 {
Brian Granger
Updating example notebooks to v3 format.
r6035 "cell_type": "code",
"collapsed": true,
"input": [],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
"outputs": [],
"prompt_number": 6
MinRK
regenerate example notebooks to remove transformed output
r5981 }
MinRK
rebuild example notebooks...
r7739 ],
"metadata": {}
MinRK
regenerate example notebooks to remove transformed output
r5981 }
]
Fernando Perez
Add simple MPI parallel example notebook.
r4911 }