##// END OF EJS Templates
Update of docs to reflect the new ipcluster version....
Brian Granger -
Show More
@@ -0,0 +1,251 b''
1 .. _parallel_process:
2
3 ===========================================
4 Starting the IPython controller and engines
5 ===========================================
6
7 To use IPython for parallel computing, you need to start one instance of
8 the controller and one or more instances of the engine. The controller
9 and each engine can run on different machines or on the same machine.
10 Because of this, there are many different possibilities.
11
12 Broadly speaking, there are two ways of going about starting a controller and engines:
13
14 * In an automated manner using the :command:`ipcluster` command.
15 * In a more manual way using the :command:`ipcontroller` and
16 :command:`ipengine` commands.
17
18 This document describes both of these methods. We recommend that new users start with the :command:`ipcluster` command as it simplifies many common usage cases.
19
20 General considerations
21 ======================
22
23 Before delving into the details about how you can start a controller and engines using the various methods, we outline some of the general issues that come up when starting the controller and engines. These things come up no matter which method you use to start your IPython cluster.
24
25 Let's say that you want to start the controller on ``host0`` and engines on hosts ``host1``-``hostn``. The following steps are then required:
26
27 1. Start the controller on ``host0`` by running :command:`ipcontroller` on
28 ``host0``.
29 2. Move the FURL file (:file:`ipcontroller-engine.furl`) created by the
30 controller from ``host0`` to hosts ``host1``-``hostn``.
31 3. Start the engines on hosts ``host1``-``hostn`` by running
32 :command:`ipengine`. This command has to be told where the FURL file
33 (:file:`ipcontroller-engine.furl`) is located.
34
35 At this point, the controller and engines will be connected. By default, the
36 FURL files created by the controller are put into the
37 :file:`~/.ipython/security` directory. If the engines share a filesystem with
38 the controller, step 2 can be skipped as the engines will automatically look
39 at that location.
40
41 The final step required required to actually use the running controller from a
42 client is to move the FURL files :file:`ipcontroller-mec.furl` and
43 :file:`ipcontroller-tc.furl` from ``host0`` to the host where the clients will
44 be run. If these file are put into the :file:`~/.ipython/security` directory of the client's host, they will be found automatically. Otherwise, the full path to them has to be passed to the client's constructor.
45
46 Using :command:`ipcluster`
47 ==========================
48
49 The :command:`ipcluster` command provides a simple way of starting a controller and engines in the following situations:
50
51 1. When the controller and engines are all run on localhost. This is useful
52 for testing or running on a multicore computer.
53 2. When engines are started using the :command:`mpirun` command that comes
54 with most MPI [MPI]_ implementations
55 3. When engines are started using the PBS [PBS]_ batch system.
56
57 .. note::
58
59 It is also possible for advanced users to add support to
60 :command:`ipcluster` for starting controllers and engines using other
61 methods (like Sun's Grid Engine for example).
62
63 .. note::
64
65 Currently :command:`ipcluster` requires that the
66 :file:`~/.ipython/security` directory live on a shared filesystem that is
67 seen by both the controller and engines. If you don't have a shared file
68 system you will need to use :command:`ipcontroller` and
69 :command:`ipengine` directly.
70
71 Underneath the hood, :command:`ipcluster` just uses :command:`ipcontroller`
72 and :command:`ipengine` to perform the steps described above.
73
74 Using :command:`ipcluster` in local mode
75 ----------------------------------------
76
77 To start one controller and 4 engines on localhost, just do::
78
79 $ ipcluster local -n 4
80
81 To see other command line options for the local mode, do::
82
83 $ ipcluster local -h
84
85 Using :command:`ipcluster` in mpirun mode
86 -----------------------------------------
87
88 The mpirun mode is useful if you:
89
90 1. Have MPI installed.
91 2. Your systems are configured to use the :command:`mpirun` command to start
92 processes.
93
94 If these are satisfied, you can start an IPython cluster using::
95
96 $ ipcluster mpirun -n 4
97
98 This does the following:
99
100 1. Starts the IPython controller on current host.
101 2. Uses :command:`mpirun` to start 4 engines.
102
103 On newer MPI implementations (such as OpenMPI), this will work even if you don't make any calls to MPI or call :func:`MPI_Init`. However, older MPI implementations actually require each process to call :func:`MPI_Init` upon starting. The easiest way of having this done is to install the mpi4py [mpi4py]_ package and then call ipcluster with the ``--mpi`` option::
104
105 $ ipcluster mpirun -n 4 --mpi=mpi4py
106
107 Unfortunately, even this won't work for some MPI implementations. If you are having problems with this, you will likely have to use a custom Python executable that itself calls :func:`MPI_Init` at the appropriate time. Fortunately, mpi4py comes with such a custom Python executable that is easy to install and use. However, this custom Python executable approach will not work with :command:`ipcluster` currently.
108
109 Additional command line options for this mode can be found by doing::
110
111 $ ipcluster mpirun -h
112
113 More details on using MPI with IPython can be found :ref:`here <parallelmpi>`.
114
115
116 Using :command:`ipcluster` in PBS mode
117 --------------------------------------
118
119 The PBS mode uses the Portable Batch System [PBS]_ to start the engines. To use this mode, you first need to create a PBS script template that will be used to start the engines. Here is a sample PBS script template:
120
121 .. sourcecode:: bash
122
123 #PBS -N ipython
124 #PBS -j oe
125 #PBS -l walltime=00:10:00
126 #PBS -l nodes=${n/4}:ppn=4
127 #PBS -q parallel
128
129 cd $$PBS_O_WORKDIR
130 export PATH=$$HOME/usr/local/bin
131 export PYTHONPATH=$$HOME/usr/local/lib/python2.4/site-packages
132 /usr/local/bin/mpiexec -n ${n} ipengine --logfile=$$PBS_O_WORKDIR/ipengine
133
134 There are a few important points about this template:
135
136 1. This template will be rendered at runtime using IPython's :mod:`Itpl`
137 template engine.
138
139 2. Instead of putting in the actual number of engines, use the notation
140 ``${n}`` to indicate the number of engines to be started. You can also uses
141 expressions like ``${n/4}`` in the template to indicate the number of
142 nodes.
143
144 3. Because ``$`` is a special character used by the template engine, you must
145 escape any ``$`` by using ``$$``. This is important when referring to
146 environment variables in the template.
147
148 4. Any options to :command:`ipengine` should be given in the batch script
149 template.
150
151 5. Depending on the configuration of you system, you may have to set
152 environment variables in the script template.
153
154 Once you have created such a script, save it with a name like :file:`pbs.template`. Now you are ready to start your job::
155
156 $ ipcluster pbs -n 128 --pbs-script=pbs.template
157
158 Additional command line options for this mode can be found by doing::
159
160 $ ipcluster pbs -h
161
162 Using the :command:`ipcontroller` and :command:`ipengine` commands
163 ==================================================================
164
165 It is also possible to use the :command:`ipcontroller` and :command:`ipengine` commands to start your controller and engines. This approach gives you full control over all aspects of the startup process.
166
167 Starting the controller and engine on your local machine
168 --------------------------------------------------------
169
170 To use :command:`ipcontroller` and :command:`ipengine` to start things on your
171 local machine, do the following.
172
173 First start the controller::
174
175 $ ipcontroller
176
177 Next, start however many instances of the engine you want using (repeatedly) the command::
178
179 $ ipengine
180
181 The engines should start and automatically connect to the controller using the FURL files in :file:`~./ipython/security`. You are now ready to use the controller and engines from IPython.
182
183 .. warning::
184
185 The order of the above operations is very important. You *must*
186 start the controller before the engines, since the engines connect
187 to the controller as they get started.
188
189 .. note::
190
191 On some platforms (OS X), to put the controller and engine into the
192 background you may need to give these commands in the form ``(ipcontroller
193 &)`` and ``(ipengine &)`` (with the parentheses) for them to work
194 properly.
195
196 Starting the controller and engines on different hosts
197 ------------------------------------------------------
198
199 When the controller and engines are running on different hosts, things are
200 slightly more complicated, but the underlying ideas are the same:
201
202 1. Start the controller on a host using :command:`ipcontroller`.
203 2. Copy :file:`ipcontroller-engine.furl` from :file:`~./ipython/security` on the controller's host to the host where the engines will run.
204 3. Use :command:`ipengine` on the engine's hosts to start the engines.
205
206 The only thing you have to be careful of is to tell :command:`ipengine` where the :file:`ipcontroller-engine.furl` file is located. There are two ways you can do this:
207
208 * Put :file:`ipcontroller-engine.furl` in the :file:`~./ipython/security`
209 directory on the engine's host, where it will be found automatically.
210 * Call :command:`ipengine` with the ``--furl-file=full_path_to_the_file``
211 flag.
212
213 The ``--furl-file`` flag works like this::
214
215 $ ipengine --furl-file=/path/to/my/ipcontroller-engine.furl
216
217 .. note::
218
219 If the controller's and engine's hosts all have a shared file system
220 (:file:`~./ipython/security` is the same on all of them), then things
221 will just work!
222
223 Make FURL files persistent
224 ---------------------------
225
226 At fist glance it may seem that that managing the FURL files is a bit annoying. Going back to the house and key analogy, copying the FURL around each time you start the controller is like having to make a new key every time you want to unlock the door and enter your house. As with your house, you want to be able to create the key (or FURL file) once, and then simply use it at any point in the future.
227
228 This is possible. The only thing you have to do is decide what ports the controller will listen on for the engines and clients. This is done as follows::
229
230 $ ipcontroller -r --client-port=10101 --engine-port=10102
231
232 Then, just copy the furl files over the first time and you are set. You can start and stop the controller and engines any many times as you want in the future, just make sure to tell the controller to use the *same* ports.
233
234 .. note::
235
236 You may ask the question: what ports does the controller listen on if you
237 don't tell is to use specific ones? The default is to use high random port
238 numbers. We do this for two reasons: i) to increase security through
239 obscurity and ii) to multiple controllers on a given host to start and
240 automatically use different ports.
241
242 Log files
243 ---------
244
245 All of the components of IPython have log files associated with them.
246 These log files can be extremely useful in debugging problems with
247 IPython and can be found in the directory :file:`~/.ipython/log`. Sending
248 the log files to us will often help us to debug any problems.
249
250
251 .. [PBS] Portable Batch System. http://www.openpbs.org/
@@ -358,7 +358,8 b' def main_mpirun(args):'
358 raw_args.append('ipengine')
358 raw_args.append('ipengine')
359 raw_args.append('-l')
359 raw_args.append('-l')
360 raw_args.append(pjoin(args.logdir,'ipengine%s-' % cont_pid))
360 raw_args.append(pjoin(args.logdir,'ipengine%s-' % cont_pid))
361 raw_args.append('--mpi=%s' % args.mpi)
361 if args.mpi:
362 raw_args.append('--mpi=%s' % args.mpi)
362 eset = ProcessLauncher(raw_args)
363 eset = ProcessLauncher(raw_args)
363 def shutdown(signum, frame):
364 def shutdown(signum, frame):
364 log.msg('Stopping local cluster')
365 log.msg('Stopping local cluster')
@@ -454,8 +455,7 b' def get_args():'
454 parser_mpirun.add_argument(
455 parser_mpirun.add_argument(
455 "--mpi",
456 "--mpi",
456 type=str,
457 type=str,
457 dest="mpi",
458 dest="mpi", # Don't put a default here to allow no MPI support
458 default='mpi4py',
459 help="how to call MPI_Init (default=mpi4py)"
459 help="how to call MPI_Init (default=mpi4py)"
460 )
460 )
461 parser_mpirun.set_defaults(func=main_mpirun)
461 parser_mpirun.set_defaults(func=main_mpirun)
@@ -3,7 +3,7 b' Configuration and customization'
3 ===============================
3 ===============================
4
4
5 .. toctree::
5 .. toctree::
6 :maxdepth: 1
6 :maxdepth: 2
7
7
8 initial_config.txt
8 initial_config.txt
9 customization.txt
9 customization.txt
@@ -4,8 +4,6 b''
4 Development roadmap
4 Development roadmap
5 ===================
5 ===================
6
6
7 .. contents::
8
9 IPython is an ambitious project that is still under heavy development. However, we want IPython to become useful to as many people as possible, as quickly as possible. To help us accomplish this, we are laying out a roadmap of where we are headed and what needs to happen to get there. Hopefully, this will help the IPython developers figure out the best things to work on for each upcoming release.
7 IPython is an ambitious project that is still under heavy development. However, we want IPython to become useful to as many people as possible, as quickly as possible. To help us accomplish this, we are laying out a roadmap of where we are headed and what needs to happen to get there. Hopefully, this will help the IPython developers figure out the best things to work on for each upcoming release.
10
8
11 Speaking of releases, we are going to begin releasing a new version of IPython every four weeks. We are hoping that a regular release schedule, along with a clear roadmap of where we are headed will propel the project forward.
9 Speaking of releases, we are going to begin releasing a new version of IPython every four weeks. We are hoping that a regular release schedule, along with a clear roadmap of where we are headed will propel the project forward.
@@ -24,9 +24,7 b' IPython Documentation'
24 license_and_copyright.txt
24 license_and_copyright.txt
25 credits.txt
25 credits.txt
26
26
27
28 .. htmlonly::
27 .. htmlonly::
29
28 * :ref:`genindex`
30 * :ref:`genindex`
29 * :ref:`modindex`
31 * :ref:`modindex`
30 * :ref:`search`
32 * :ref:`search`
@@ -119,7 +119,13 b' Most users on OS X will want to get the full :mod:`readline` module. To get a w'
119
119
120 If needed, the readline egg can be build and installed from source (see the wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard).
120 If needed, the readline egg can be build and installed from source (see the wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard).
121
121
122 On Windows, you will need the PyReadline module. PyReadline is a separate, Windows only implementation of readline that uses native Windows calls through :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary installer available `here <http://ipython.scipy.org/dist/>`_. The :mod:`ctypes` module, which comes with Python 2.5 and greater, is required by PyReadline. It is available for Python 2.4 at http://python.net/crew/theller/ctypes.
122 On Windows, you will need the PyReadline module. PyReadline is a separate,
123 Windows only implementation of readline that uses native Windows calls through
124 :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary
125 installer available `here <http://ipython.scipy.org/dist/>`_. The
126 :mod:`ctypes` module, which comes with Python 2.5 and greater, is required by
127 PyReadline. It is available for Python 2.4 at
128 http://python.net/crew/theller/ctypes.
123
129
124 nose
130 nose
125 ----
131 ----
@@ -164,7 +170,9 b' On a Unix style platform (including OS X), if you want to use :mod:`setuptools`,'
164 zope.interface and Twisted
170 zope.interface and Twisted
165 --------------------------
171 --------------------------
166
172
167 On Unix style platforms (including OS X), the simplest way of getting the these is to use :command:`easy_install`::
173 Twisted [Twisted]_ and zope.interface [ZopeInterface]_ are used for networking related things. On Unix
174 style platforms (including OS X), the simplest way of getting the these is to
175 use :command:`easy_install`::
168
176
169 $ easy_install zope.interface
177 $ easy_install zope.interface
170 $ easy_install Twisted
178 $ easy_install Twisted
@@ -176,7 +184,7 b' Windows is a bit different. For zope.interface and Twisted, simply get the late'
176 Foolscap
184 Foolscap
177 --------
185 --------
178
186
179 Foolscap uses Twisted to provide a very nice secure RPC protocol that we use to implement our parallel computing features.
187 Foolscap [Foolscap]_ uses Twisted to provide a very nice secure RPC protocol that we use to implement our parallel computing features.
180
188
181 On all platforms a simple::
189 On all platforms a simple::
182
190
@@ -187,7 +195,7 b' should work. You can also download the source tarballs from the `Foolscap websi'
187 pyOpenSSL
195 pyOpenSSL
188 ---------
196 ---------
189
197
190 IPython requires an older version of pyOpenSSL (0.6 rather than the current 0.7). There are a couple of options for getting this:
198 IPython requires an older version of pyOpenSSL [pyOpenSSL]_ (0.6 rather than the current 0.7). There are a couple of options for getting this:
191
199
192 1. Most Linux distributions have packages for pyOpenSSL.
200 1. Most Linux distributions have packages for pyOpenSSL.
193 2. The built-in Python 2.5 on OS X 10.5 already has it installed.
201 2. The built-in Python 2.5 on OS X 10.5 already has it installed.
@@ -201,4 +209,9 b' Dependencies for IPython.frontend (the IPython GUI)'
201 wxPython
209 wxPython
202 --------
210 --------
203
211
204 Starting with IPython 0.9, IPython has a new IPython.frontend package that has a nice wxPython based IPython GUI. As you would expect, this GUI requires wxPython. Most Linux distributions have wxPython packages available and the built-in Python on OS X comes with wxPython preinstalled. For Windows, a binary installer is available on the `wxPython website <http://www.wxpython.org/>`_. No newline at end of file
212 Starting with IPython 0.9, IPython has a new IPython.frontend package that has a nice wxPython based IPython GUI. As you would expect, this GUI requires wxPython. Most Linux distributions have wxPython packages available and the built-in Python on OS X comes with wxPython preinstalled. For Windows, a binary installer is available on the `wxPython website <http://www.wxpython.org/>`_.
213
214 .. [Twisted] Twisted matrix. http://twistedmatrix.org
215 .. [ZopeInterface] http://pypi.python.org/pypi/zope.interface
216 .. [Foolscap] Foolscap network protocol. http://foolscap.lothar.com/trac
217 .. [pyOpenSSL] pyOpenSSL. http://pyopenssl.sourceforge.net No newline at end of file
@@ -3,7 +3,7 b' Using IPython for interactive work'
3 ==================================
3 ==================================
4
4
5 .. toctree::
5 .. toctree::
6 :maxdepth: 1
6 :maxdepth: 2
7
7
8 tutorial.txt
8 tutorial.txt
9 reference.txt
9 reference.txt
@@ -1,13 +1,7 b''
1 .. IPython documentation master file, created by sphinx-quickstart.py on Mon Mar 24 17:01:34 2008.
2 You can adapt this file completely to your liking, but it should at least
3 contain the root 'toctree' directive.
4
5 =================
1 =================
6 IPython reference
2 IPython reference
7 =================
3 =================
8
4
9 .. contents::
10
11 .. _command_line_options:
5 .. _command_line_options:
12
6
13 Command-line usage
7 Command-line usage
@@ -4,8 +4,6 b''
4 Quick IPython tutorial
4 Quick IPython tutorial
5 ======================
5 ======================
6
6
7 .. contents::
8
9 IPython can be used as an improved replacement for the Python prompt,
7 IPython can be used as an improved replacement for the Python prompt,
10 and for that you don't really need to read any more of this manual. But
8 and for that you don't really need to read any more of this manual. But
11 in this section we'll try to summarize a few tips on how to make the
9 in this section we'll try to summarize a few tips on how to make the
@@ -13,39 +13,43 b' IPython is licensed under the terms of the new or revised BSD license, as follow'
13
13
14 All rights reserved.
14 All rights reserved.
15
15
16 Redistribution and use in source and binary forms, with or without modification,
16 Redistribution and use in source and binary forms, with or without
17 are permitted provided that the following conditions are met:
17 modification, are permitted provided that the following conditions are
18
18 met:
19 Redistributions of source code must retain the above copyright notice, this list of
19
20 conditions and the following disclaimer.
20 Redistributions of source code must retain the above copyright notice,
21
21 this list of conditions and the following disclaimer.
22 Redistributions in binary form must reproduce the above copyright notice, this list
22
23 of conditions and the following disclaimer in the documentation and/or other
23 Redistributions in binary form must reproduce the above copyright notice,
24 materials provided with the distribution.
24 this list of conditions and the following disclaimer in the documentation
25
25 and/or other materials provided with the distribution.
26 Neither the name of the IPython Development Team nor the names of its contributors
26
27 may be used to endorse or promote products derived from this software without
27 Neither the name of the IPython Development Team nor the names of its
28 specific prior written permission.
28 contributors may be used to endorse or promote products derived from this
29
29 software without specific prior written permission.
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
30
31 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
32 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 POSSIBILITY OF SUCH DAMAGE.
39 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
42
41 About the IPython Development Team
43 About the IPython Development Team
42 ==================================
44 ==================================
43
45
44 Fernando Perez began IPython in 2001 based on code from Janko Hauser <jhauser@zscout.de>
46 Fernando Perez began IPython in 2001 based on code from Janko Hauser
45 and Nathaniel Gray <n8gray@caltech.edu>. Fernando is still the project lead.
47 <jhauser@zscout.de> and Nathaniel Gray <n8gray@caltech.edu>. Fernando is still
48 the project lead.
46
49
47 The IPython Development Team is the set of all contributors to the IPython project.
50 The IPython Development Team is the set of all contributors to the IPython
48 This includes all of the IPython subprojects. Here is a list of the currently active contributors:
51 project. This includes all of the IPython subprojects. Here is a list of the
52 currently active contributors:
49
53
50 * Matthieu Brucher
54 * Matthieu Brucher
51 * Ondrej Certik
55 * Ondrej Certik
@@ -65,23 +69,23 b' If your name is missing, please add it.'
65 Our Copyright Policy
69 Our Copyright Policy
66 ====================
70 ====================
67
71
68 IPython uses a shared copyright model. Each contributor maintains copyright over
72 IPython uses a shared copyright model. Each contributor maintains copyright
69 their contributions to IPython. But, it is important to note that these
73 over their contributions to IPython. But, it is important to note that these
70 contributions are typically only changes to the repositories. Thus, the IPython
74 contributions are typically only changes to the repositories. Thus, the
71 source code, in its entirety is not the copyright of any single person or
75 IPython source code, in its entirety is not the copyright of any single person
72 institution. Instead, it is the collective copyright of the entire IPython
76 or institution. Instead, it is the collective copyright of the entire IPython
73 Development Team. If individual contributors want to maintain a record of what
77 Development Team. If individual contributors want to maintain a record of what
74 changes/contributions they have specific copyright on, they should indicate their
78 changes/contributions they have specific copyright on, they should indicate
75 copyright in the commit message of the change, when they commit the change to
79 their copyright in the commit message of the change, when they commit the
76 one of the IPython repositories.
80 change to one of the IPython repositories.
77
81
78 Miscellaneous
82 Miscellaneous
79 =============
83 =============
80
84
81 Some files (DPyGetOpt.py, for example) may be licensed under different
85 Some files (DPyGetOpt.py, for example) may be licensed under different
82 conditions. Ultimately each file indicates clearly the conditions under
86 conditions. Ultimately each file indicates clearly the conditions under which
83 which its author/authors have decided to publish the code.
87 its author/authors have decided to publish the code.
84
88
85 Versions of IPython up to and including 0.6.3 were released under the
89 Versions of IPython up to and including 0.6.3 were released under the GNU
86 GNU Lesser General Public License (LGPL), available at
90 Lesser General Public License (LGPL), available at
87 http://www.gnu.org/copyleft/lesser.html. No newline at end of file
91 http://www.gnu.org/copyleft/lesser.html.
@@ -4,20 +4,17 b''
4 Overview and getting started
4 Overview and getting started
5 ============================
5 ============================
6
6
7 .. contents::
8
9 Introduction
7 Introduction
10 ============
8 ============
11
9
12 This file gives an overview of IPython's sophisticated and
10 This section gives an overview of IPython's sophisticated and powerful
13 powerful architecture for parallel and distributed computing. This
11 architecture for parallel and distributed computing. This architecture
14 architecture abstracts out parallelism in a very general way, which
12 abstracts out parallelism in a very general way, which enables IPython to
15 enables IPython to support many different styles of parallelism
13 support many different styles of parallelism including:
16 including:
17
14
18 * Single program, multiple data (SPMD) parallelism.
15 * Single program, multiple data (SPMD) parallelism.
19 * Multiple program, multiple data (MPMD) parallelism.
16 * Multiple program, multiple data (MPMD) parallelism.
20 * Message passing using ``MPI``.
17 * Message passing using MPI.
21 * Task farming.
18 * Task farming.
22 * Data parallel.
19 * Data parallel.
23 * Combinations of these approaches.
20 * Combinations of these approaches.
@@ -97,8 +94,8 b' The controller also provides a single point of contact for users who wish'
97 to utilize the engines connected to the controller. There are different
94 to utilize the engines connected to the controller. There are different
98 ways of working with a controller. In IPython these ways correspond to different interfaces that the controller is adapted to. Currently we have two default interfaces to the controller:
95 ways of working with a controller. In IPython these ways correspond to different interfaces that the controller is adapted to. Currently we have two default interfaces to the controller:
99
96
100 * The MultiEngine interface, which provides the simplest possible way of working
97 * The MultiEngine interface, which provides the simplest possible way of
101 with engines interactively.
98 working with engines interactively.
102 * The Task interface, which provides presents the engines as a load balanced
99 * The Task interface, which provides presents the engines as a load balanced
103 task farming system.
100 task farming system.
104
101
@@ -124,29 +121,27 b' interface. Here are the two default clients:'
124 Security
121 Security
125 --------
122 --------
126
123
127 By default (as long as `pyOpenSSL` is installed) all network connections between the controller and engines and the controller and clients are secure. What does this mean? First of all, all of the connections will be encrypted using SSL. Second, the connections are authenticated. We handle authentication in a `capabilities`__ based security model. In this model, a "capability (known in some systems as a key) is a communicable, unforgeable token of authority". Put simply, a capability is like a key to your house. If you have the key to your house, you can get in. If not, you can't.
124 By default (as long as `pyOpenSSL` is installed) all network connections between the controller and engines and the controller and clients are secure. What does this mean? First of all, all of the connections will be encrypted using SSL. Second, the connections are authenticated. We handle authentication in a capability based security model [Capability]_. In this model, a "capability (known in some systems as a key) is a communicable, unforgeable token of authority". Put simply, a capability is like a key to your house. If you have the key to your house, you can get in. If not, you can't.
128
129 .. __: http://en.wikipedia.org/wiki/Capability-based_security
130
125
131 In our architecture, the controller is the only process that listens on network ports, and is thus responsible to creating these keys. In IPython, these keys are known as Foolscap URLs, or FURLs, because of the underlying network protocol we are using. As a user, you don't need to know anything about the details of these FURLs, other than that when the controller starts, it saves a set of FURLs to files named :file:`something.furl`. The default location of these files is the :file:`~./ipython/security` directory.
126 In our architecture, the controller is the only process that listens on network ports, and is thus responsible to creating these keys. In IPython, these keys are known as Foolscap URLs, or FURLs, because of the underlying network protocol we are using. As a user, you don't need to know anything about the details of these FURLs, other than that when the controller starts, it saves a set of FURLs to files named :file:`something.furl`. The default location of these files is the :file:`~./ipython/security` directory.
132
127
133 To connect and authenticate to the controller an engine or client simply needs to present an appropriate furl (that was originally created by the controller) to the controller. Thus, the .furl files need to be copied to a location where the clients and engines can find them. Typically, this is the :file:`~./ipython/security` directory on the host where the client/engine is running (which could be a different host than the controller). Once the .furl files are copied over, everything should work fine.
128 To connect and authenticate to the controller an engine or client simply needs to present an appropriate FURL (that was originally created by the controller) to the controller. Thus, the FURL files need to be copied to a location where the clients and engines can find them. Typically, this is the :file:`~./ipython/security` directory on the host where the client/engine is running (which could be a different host than the controller). Once the FURL files are copied over, everything should work fine.
134
129
135 Currently, there are three .furl files that the controller creates:
130 Currently, there are three FURL files that the controller creates:
136
131
137 ipcontroller-engine.furl
132 ipcontroller-engine.furl
138 This ``.furl`` file is the key that gives an engine the ability to connect
133 This FURL file is the key that gives an engine the ability to connect
139 to a controller.
134 to a controller.
140
135
141 ipcontroller-tc.furl
136 ipcontroller-tc.furl
142 This ``.furl`` file is the key that a :class:`TaskClient` must use to
137 This FURL file is the key that a :class:`TaskClient` must use to
143 connect to the task interface of a controller.
138 connect to the task interface of a controller.
144
139
145 ipcontroller-mec.furl
140 ipcontroller-mec.furl
146 This ``.furl`` file is the key that a :class:`MultiEngineClient` must use to
141 This FURL file is the key that a :class:`MultiEngineClient` must use
147 connect to the multiengine interface of a controller.
142 to connect to the multiengine interface of a controller.
148
143
149 More details of how these ``.furl`` files are used are given below.
144 More details of how these FURL files are used are given below.
150
145
151 A detailed description of the security model and its implementation in IPython
146 A detailed description of the security model and its implementation in IPython
152 can be found :ref:`here <parallelsecurity>`.
147 can be found :ref:`here <parallelsecurity>`.
@@ -157,13 +152,15 b' Getting Started'
157 To use IPython for parallel computing, you need to start one instance of
152 To use IPython for parallel computing, you need to start one instance of
158 the controller and one or more instances of the engine. Initially, it is best to simply start a controller and engines on a single host using the :command:`ipcluster` command. To start a controller and 4 engines on you localhost, just do::
153 the controller and one or more instances of the engine. Initially, it is best to simply start a controller and engines on a single host using the :command:`ipcluster` command. To start a controller and 4 engines on you localhost, just do::
159
154
160 $ ipcluster -n 4
155 $ ipcluster local -n 4
161
156
162 More details about starting the IPython controller and engines can be found :ref:`here <parallel_process>`
157 More details about starting the IPython controller and engines can be found :ref:`here <parallel_process>`
163
158
164 Once you have started the IPython controller and one or more engines, you
159 Once you have started the IPython controller and one or more engines, you
165 are ready to use the engines to do something useful. To make sure
160 are ready to use the engines to do something useful. To make sure
166 everything is working correctly, try the following commands::
161 everything is working correctly, try the following commands:
162
163 .. sourcecode:: ipython
167
164
168 In [1]: from IPython.kernel import client
165 In [1]: from IPython.kernel import client
169
166
@@ -187,7 +184,7 b' everything is working correctly, try the following commands::'
187 [3] In [1]: print "Hello World"
184 [3] In [1]: print "Hello World"
188 [3] Out[1]: Hello World
185 [3] Out[1]: Hello World
189
186
190 Remember, a client also needs to present a ``.furl`` file to the controller. How does this happen? When a multiengine client is created with no arguments, the client tries to find the corresponding ``.furl`` file in the local :file:`~./ipython/security` directory. If it finds it, you are set. If you have put the ``.furl`` file in a different location or it has a different name, create the client like this::
187 Remember, a client also needs to present a FURL file to the controller. How does this happen? When a multiengine client is created with no arguments, the client tries to find the corresponding FURL file in the local :file:`~./ipython/security` directory. If it finds it, you are set. If you have put the FURL file in a different location or it has a different name, create the client like this::
191
188
192 mec = client.MultiEngineClient('/path/to/my/ipcontroller-mec.furl')
189 mec = client.MultiEngineClient('/path/to/my/ipcontroller-mec.furl')
193
190
@@ -200,5 +197,9 b' You are now ready to learn more about the :ref:`MultiEngine <parallelmultiengine'
200 .. note::
197 .. note::
201
198
202 Don't forget that the engine, multiengine client and task client all have
199 Don't forget that the engine, multiengine client and task client all have
203 *different* furl files. You must move *each* of these around to an appropriate
200 *different* furl files. You must move *each* of these around to an
204 location so that the engines and clients can use them to connect to the controller.
201 appropriate location so that the engines and clients can use them to
202 connect to the controller.
203
204 .. [Capability] Capability-based security, http://en.wikipedia.org/wiki/Capability-based_security
205
@@ -6,37 +6,47 b' Using MPI with IPython'
6
6
7 Often, a parallel algorithm will require moving data between the engines. One way of accomplishing this is by doing a pull and then a push using the multiengine client. However, this will be slow as all the data has to go through the controller to the client and then back through the controller, to its final destination.
7 Often, a parallel algorithm will require moving data between the engines. One way of accomplishing this is by doing a pull and then a push using the multiengine client. However, this will be slow as all the data has to go through the controller to the client and then back through the controller, to its final destination.
8
8
9 A much better way of moving data between engines is to use a message passing library, such as the Message Passing Interface (`MPI`_). IPython's parallel computing architecture has been designed from the ground up to integrate with `MPI`_. This document describe how to use MPI with IPython.
9 A much better way of moving data between engines is to use a message passing library, such as the Message Passing Interface (MPI) [MPI]_. IPython's parallel computing architecture has been designed from the ground up to integrate with MPI. This document describes how to use MPI with IPython.
10
10
11 Additional installation requirements
11 Additional installation requirements
12 ====================================
12 ====================================
13
13
14 If you want to use MPI with IPython, you will need to install:
14 If you want to use MPI with IPython, you will need to install:
15
15
16 * A standard MPI implementation such as `Open MPI`_ or MPICH.
16 * A standard MPI implementation such as OpenMPI [OpenMPI]_ or MPICH.
17 * The `mpi4py`_ package.
17 * The mpi4py [mpi4py]_ package.
18
18
19 .. note::
19 .. note::
20
20
21 The `mpi4py`_ package is not a strict requirement. However, you need to
21 The mpi4py package is not a strict requirement. However, you need to
22 have *some* way of calling MPI from Python. You also need some way of
22 have *some* way of calling MPI from Python. You also need some way of
23 making sure that :func:`MPI_Init` is called when the IPython engines start
23 making sure that :func:`MPI_Init` is called when the IPython engines start
24 up. There are a number of ways of doing this and a good number of
24 up. There are a number of ways of doing this and a good number of
25 associated subtleties. We highly recommend just using `mpi4py`_ as it
25 associated subtleties. We highly recommend just using mpi4py as it
26 takes care of most of these problems. If you want to do something
26 takes care of most of these problems. If you want to do something
27 different, let us know and we can help you get started.
27 different, let us know and we can help you get started.
28
28
29 Starting the engines with MPI enabled
29 Starting the engines with MPI enabled
30 =====================================
30 =====================================
31
31
32 To use code that calls `MPI`_, there are typically two things that `MPI`_ requires.
32 To use code that calls MPI, there are typically two things that MPI requires.
33
33
34 1. The process that wants to call `MPI`_ must be started using
34 1. The process that wants to call MPI must be started using
35 :command:`mpirun` or a batch system (like PBS) that has `MPI`_ support.
35 :command:`mpirun` or a batch system (like PBS) that has MPI support.
36 2. Once the process starts, it must call :func:`MPI_Init`.
36 2. Once the process starts, it must call :func:`MPI_Init`.
37
37
38 There are a couple of ways that you can start the IPython engines and get these things to happen.
38 There are a couple of ways that you can start the IPython engines and get these things to happen.
39
39
40 Automatic starting using :command:`mpirun` and :command:`ipcluster`
41 -------------------------------------------------------------------
42
43 The easiest approach is to use the `mpirun` mode of :command:`ipcluster`, which will first start a controller and then a set of engines using :command:`mpirun`::
44
45 $ ipcluster mpirun -n 4
46
47 This approach is best as interrupting :command:`ipcluster` will automatically
48 stop and clean up the controller and engines.
49
40 Manual starting using :command:`mpirun`
50 Manual starting using :command:`mpirun`
41 ---------------------------------------
51 ---------------------------------------
42
52
@@ -44,19 +54,13 b' If you want to start the IPython engines using the :command:`mpirun`, just do::'
44
54
45 $ mpirun -n 4 ipengine --mpi=mpi4py
55 $ mpirun -n 4 ipengine --mpi=mpi4py
46
56
47 This requires that you already have a controller running. We also have built
57 This requires that you already have a controller running and that the FURL
48 in support for `PyTrilinos`_, which can be used (assuming `PyTrilinos`_ is
58 files for the engines are in place. We also have built in support for
49 installed) by starting the engines with::
59 PyTrilinos [PyTrilinos]_, which can be used (assuming is installed) by
60 starting the engines with::
50
61
51 mpirun -n 4 ipengine --mpi=pytrilinos
62 mpirun -n 4 ipengine --mpi=pytrilinos
52
63
53 Automatic starting using :command:`mpirun` and :command:`ipcluster`
54 -------------------------------------------------------------------
55
56 The easiest approach is to use the `mpirun` mode of :command:`ipcluster`, which will first start a controller and then a set of engines using :command:`mpirun`::
57
58 $ ipcluster mpirun -n 4
59
60 Automatic starting using PBS and :command:`ipcluster`
64 Automatic starting using PBS and :command:`ipcluster`
61 -----------------------------------------------------
65 -----------------------------------------------------
62
66
@@ -65,9 +69,11 b' The :command:`ipcluster` command also has built-in integration with PBS. For mor'
65 Actually using MPI
69 Actually using MPI
66 ==================
70 ==================
67
71
68 Once the engines are running with `MPI`_ enabled, you are ready to go. You can now call any code that uses MPI in the IPython engines. And, all of this can be done interactively. Here we show a simple example that uses `mpi4py`_.
72 Once the engines are running with MPI enabled, you are ready to go. You can now call any code that uses MPI in the IPython engines. And, all of this can be done interactively. Here we show a simple example that uses mpi4py [mpi4py]_.
69
73
70 First, lets define a simply function that uses MPI to calculate the sum of a distributed array. Save the following text in a file called :file:`psum.py`::
74 First, lets define a simply function that uses MPI to calculate the sum of a distributed array. Save the following text in a file called :file:`psum.py`:
75
76 .. sourcecode:: python
71
77
72 from mpi4py import MPI
78 from mpi4py import MPI
73 import numpy as np
79 import numpy as np
@@ -80,7 +86,9 b' Now, start an IPython cluster in the same directory as :file:`psum.py`::'
80
86
81 $ ipcluster mpirun -n 4
87 $ ipcluster mpirun -n 4
82
88
83 Finally, connect to the cluster and use this function interactively. In this case, we create a random array on each engine and sum up all the random arrays using our :func:`psum` function::
89 Finally, connect to the cluster and use this function interactively. In this case, we create a random array on each engine and sum up all the random arrays using our :func:`psum` function:
90
91 .. sourcecode:: ipython
84
92
85 In [1]: from IPython.kernel import client
93 In [1]: from IPython.kernel import client
86
94
@@ -140,16 +148,10 b' Finally, connect to the cluster and use this function interactively. In this ca'
140 [3] In [18]: print s
148 [3] In [18]: print s
141 [3] Out[18]: 187.451545803
149 [3] Out[18]: 187.451545803
142
150
143 Any Python code that makes calls to MPI [MPIref]_ can be used in this manner.
151 Any Python code that makes calls to MPI can be used in this manner, including
144
152 compiled C, C++ and Fortran libraries that have been exposed to Python.
145 Complications
146 =============
147
148 Talk about how some older MPI implementations are broken and need to have a custom Python mail loop.
149
150 .. [MPIref] http://www-unix.mcs.anl.gov/mpi/
151
153
152 .. _MPI: http://www-unix.mcs.anl.gov/mpi/
154 .. [MPI] Message Passing Interface. http://www-unix.mcs.anl.gov/mpi/
153 .. _mpi4py: http://mpi4py.scipy.org/
155 .. [mpi4py] MPI for Python. mpi4py: http://mpi4py.scipy.org/
154 .. _Open MPI: http://www.open-mpi.org/
156 .. [OpenMPI] Open MPI. http://www.open-mpi.org/
155 .. _PyTrilinos: http://trilinos.sandia.gov/packages/pytrilinos/ No newline at end of file
157 .. [PyTrilinos] PyTrilinos. http://trilinos.sandia.gov/packages/pytrilinos/ No newline at end of file
@@ -4,8 +4,6 b''
4 IPython's multiengine interface
4 IPython's multiengine interface
5 ===============================
5 ===============================
6
6
7 .. contents::
8
9 The multiengine interface represents one possible way of working with a set of
7 The multiengine interface represents one possible way of working with a set of
10 IPython engines. The basic idea behind the multiengine interface is that the
8 IPython engines. The basic idea behind the multiengine interface is that the
11 capabilities of each engine are directly and explicitly exposed to the user.
9 capabilities of each engine are directly and explicitly exposed to the user.
@@ -21,7 +19,7 b' To follow along with this tutorial, you will need to start the IPython'
21 controller and four IPython engines. The simplest way of doing this is to use
19 controller and four IPython engines. The simplest way of doing this is to use
22 the :command:`ipcluster` command::
20 the :command:`ipcluster` command::
23
21
24 $ ipcluster -n 4
22 $ ipcluster local -n 4
25
23
26 For more detailed information about starting the controller and engines, see
24 For more detailed information about starting the controller and engines, see
27 our :ref:`introduction <ip1par>` to using IPython for parallel computing.
25 our :ref:`introduction <ip1par>` to using IPython for parallel computing.
@@ -30,7 +28,9 b' Creating a ``MultiEngineClient`` instance'
30 =========================================
28 =========================================
31
29
32 The first step is to import the IPython :mod:`IPython.kernel.client` module
30 The first step is to import the IPython :mod:`IPython.kernel.client` module
33 and then create a :class:`MultiEngineClient` instance::
31 and then create a :class:`MultiEngineClient` instance:
32
33 .. sourcecode:: ipython
34
34
35 In [1]: from IPython.kernel import client
35 In [1]: from IPython.kernel import client
36
36
@@ -38,13 +38,17 b' and then create a :class:`MultiEngineClient` instance::'
38
38
39 This form assumes that the :file:`ipcontroller-mec.furl` is in the
39 This form assumes that the :file:`ipcontroller-mec.furl` is in the
40 :file:`~./ipython/security` directory on the client's host. If not, the
40 :file:`~./ipython/security` directory on the client's host. If not, the
41 location of the ``.furl`` file must be given as an argument to the
41 location of the FURL file must be given as an argument to the
42 constructor::
42 constructor:
43
44 .. sourcecode:: ipython
43
45
44 In[2]: mec = client.MultiEngineClient('/path/to/my/ipcontroller-mec.furl')
46 In [2]: mec = client.MultiEngineClient('/path/to/my/ipcontroller-mec.furl')
45
47
46 To make sure there are engines connected to the controller, use can get a list
48 To make sure there are engines connected to the controller, use can get a list
47 of engine ids::
49 of engine ids:
50
51 .. sourcecode:: ipython
48
52
49 In [3]: mec.get_ids()
53 In [3]: mec.get_ids()
50 Out[3]: [0, 1, 2, 3]
54 Out[3]: [0, 1, 2, 3]
@@ -62,7 +66,9 b' Parallel map'
62 Python's builtin :func:`map` functions allows a function to be applied to a
66 Python's builtin :func:`map` functions allows a function to be applied to a
63 sequence element-by-element. This type of code is typically trivial to
67 sequence element-by-element. This type of code is typically trivial to
64 parallelize. In fact, the multiengine interface in IPython already has a
68 parallelize. In fact, the multiengine interface in IPython already has a
65 parallel version of :meth:`map` that works just like its serial counterpart::
69 parallel version of :meth:`map` that works just like its serial counterpart:
70
71 .. sourcecode:: ipython
66
72
67 In [63]: serial_result = map(lambda x:x**10, range(32))
73 In [63]: serial_result = map(lambda x:x**10, range(32))
68
74
@@ -84,7 +90,9 b' parallel version of :meth:`map` that works just like its serial counterpart::'
84 Parallel function decorator
90 Parallel function decorator
85 ---------------------------
91 ---------------------------
86
92
87 Parallel functions are just like normal function, but they can be called on sequences and *in parallel*. The multiengine interface provides a decorator that turns any Python function into a parallel function::
93 Parallel functions are just like normal function, but they can be called on sequences and *in parallel*. The multiengine interface provides a decorator that turns any Python function into a parallel function:
94
95 .. sourcecode:: ipython
88
96
89 In [10]: @mec.parallel()
97 In [10]: @mec.parallel()
90 ....: def f(x):
98 ....: def f(x):
@@ -110,7 +118,9 b' Blocking execution'
110 In blocking mode, the :class:`MultiEngineClient` object (called ``mec`` in
118 In blocking mode, the :class:`MultiEngineClient` object (called ``mec`` in
111 these examples) submits the command to the controller, which places the
119 these examples) submits the command to the controller, which places the
112 command in the engines' queues for execution. The :meth:`execute` call then
120 command in the engines' queues for execution. The :meth:`execute` call then
113 blocks until the engines are done executing the command::
121 blocks until the engines are done executing the command:
122
123 .. sourcecode:: ipython
114
124
115 # The default is to run on all engines
125 # The default is to run on all engines
116 In [4]: mec.execute('a=5')
126 In [4]: mec.execute('a=5')
@@ -130,7 +140,9 b' blocks until the engines are done executing the command::'
130 [3] In [2]: b=10
140 [3] In [2]: b=10
131
141
132 Python commands can be executed on specific engines by calling execute using
142 Python commands can be executed on specific engines by calling execute using
133 the ``targets`` keyword argument::
143 the ``targets`` keyword argument:
144
145 .. sourcecode:: ipython
134
146
135 In [6]: mec.execute('c=a+b',targets=[0,2])
147 In [6]: mec.execute('c=a+b',targets=[0,2])
136 Out[6]:
148 Out[6]:
@@ -163,7 +175,9 b' the ``targets`` keyword argument::'
163
175
164 This example also shows one of the most important things about the IPython
176 This example also shows one of the most important things about the IPython
165 engines: they have a persistent user namespaces. The :meth:`execute` method
177 engines: they have a persistent user namespaces. The :meth:`execute` method
166 returns a Python ``dict`` that contains useful information::
178 returns a Python ``dict`` that contains useful information:
179
180 .. sourcecode:: ipython
167
181
168 In [9]: result_dict = mec.execute('d=10; print d')
182 In [9]: result_dict = mec.execute('d=10; print d')
169
183
@@ -184,7 +198,9 b' then returns a :class:`PendingResult` object immediately. The'
184 :class:`PendingResult` object gives you a way of getting a result at a later
198 :class:`PendingResult` object gives you a way of getting a result at a later
185 time through its :meth:`get_result` method or :attr:`r` attribute. This allows
199 time through its :meth:`get_result` method or :attr:`r` attribute. This allows
186 you to quickly submit long running commands without blocking your local
200 you to quickly submit long running commands without blocking your local
187 Python/IPython session::
201 Python/IPython session:
202
203 .. sourcecode:: ipython
188
204
189 # In blocking mode
205 # In blocking mode
190 In [6]: mec.execute('import time')
206 In [6]: mec.execute('import time')
@@ -225,7 +241,9 b' Python/IPython session::'
225 Often, it is desirable to wait until a set of :class:`PendingResult` objects
241 Often, it is desirable to wait until a set of :class:`PendingResult` objects
226 are done. For this, there is a the method :meth:`barrier`. This method takes a
242 are done. For this, there is a the method :meth:`barrier`. This method takes a
227 tuple of :class:`PendingResult` objects and blocks until all of the associated
243 tuple of :class:`PendingResult` objects and blocks until all of the associated
228 results are ready::
244 results are ready:
245
246 .. sourcecode:: ipython
229
247
230 In [72]: mec.block=False
248 In [72]: mec.block=False
231
249
@@ -259,7 +277,9 b' and :attr:`targets`:'
259 * If no keyword argument is provided, the instance attributes are used.
277 * If no keyword argument is provided, the instance attributes are used.
260 * Keyword argument, if provided override the instance attributes.
278 * Keyword argument, if provided override the instance attributes.
261
279
262 The following examples demonstrate how to use the instance attributes::
280 The following examples demonstrate how to use the instance attributes:
281
282 .. sourcecode:: ipython
263
283
264 In [16]: mec.targets = [0,2]
284 In [16]: mec.targets = [0,2]
265
285
@@ -305,7 +325,9 b' that make it more pleasant to execute Python commands on the engines'
305 interactively. These are simply shortcuts to :meth:`execute` and
325 interactively. These are simply shortcuts to :meth:`execute` and
306 :meth:`get_result`. The ``%px`` magic executes a single Python command on the
326 :meth:`get_result`. The ``%px`` magic executes a single Python command on the
307 engines specified by the :attr:`targets` attribute of the
327 engines specified by the :attr:`targets` attribute of the
308 :class:`MultiEngineClient` instance (by default this is ``'all'``)::
328 :class:`MultiEngineClient` instance (by default this is ``'all'``):
329
330 .. sourcecode:: ipython
309
331
310 # Make this MultiEngineClient active for parallel magic commands
332 # Make this MultiEngineClient active for parallel magic commands
311 In [23]: mec.activate()
333 In [23]: mec.activate()
@@ -352,7 +374,9 b' engines specified by the :attr:`targets` attribute of the'
352
374
353 The ``%result`` magic gets and prints the stdin/stdout/stderr of the last
375 The ``%result`` magic gets and prints the stdin/stdout/stderr of the last
354 command executed on each engine. It is simply a shortcut to the
376 command executed on each engine. It is simply a shortcut to the
355 :meth:`get_result` method::
377 :meth:`get_result` method:
378
379 .. sourcecode:: ipython
356
380
357 In [29]: %result
381 In [29]: %result
358 Out[29]:
382 Out[29]:
@@ -370,7 +394,9 b' command executed on each engine. It is simply a shortcut to the'
370 [3] Out[9]: [ 0.83664764 -0.25602658]
394 [3] Out[9]: [ 0.83664764 -0.25602658]
371
395
372 The ``%autopx`` magic switches to a mode where everything you type is executed
396 The ``%autopx`` magic switches to a mode where everything you type is executed
373 on the engines given by the :attr:`targets` attribute::
397 on the engines given by the :attr:`targets` attribute:
398
399 .. sourcecode:: ipython
374
400
375 In [30]: mec.block=False
401 In [30]: mec.block=False
376
402
@@ -423,7 +449,9 b' are called :meth:`push` (sending an object to the engines) and :meth:`pull`'
423 Basic push and pull
449 Basic push and pull
424 -------------------
450 -------------------
425
451
426 Here are some examples of how you use :meth:`push` and :meth:`pull`::
452 Here are some examples of how you use :meth:`push` and :meth:`pull`:
453
454 .. sourcecode:: ipython
427
455
428 In [38]: mec.push(dict(a=1.03234,b=3453))
456 In [38]: mec.push(dict(a=1.03234,b=3453))
429 Out[38]: [None, None, None, None]
457 Out[38]: [None, None, None, None]
@@ -460,7 +488,9 b' Here are some examples of how you use :meth:`push` and :meth:`pull`::'
460 [3] Out[13]: speed
488 [3] Out[13]: speed
461
489
462 In non-blocking mode :meth:`push` and :meth:`pull` also return
490 In non-blocking mode :meth:`push` and :meth:`pull` also return
463 :class:`PendingResult` objects::
491 :class:`PendingResult` objects:
492
493 .. sourcecode:: ipython
464
494
465 In [47]: mec.block=False
495 In [47]: mec.block=False
466
496
@@ -474,8 +504,9 b' Push and pull for functions'
474 ---------------------------
504 ---------------------------
475
505
476 Functions can also be pushed and pulled using :meth:`push_function` and
506 Functions can also be pushed and pulled using :meth:`push_function` and
477 :meth:`pull_function`::
507 :meth:`pull_function`:
478
508
509 .. sourcecode:: ipython
479
510
480 In [52]: mec.block=True
511 In [52]: mec.block=True
481
512
@@ -518,7 +549,9 b' Dictionary interface'
518 As a shorthand to :meth:`push` and :meth:`pull`, the
549 As a shorthand to :meth:`push` and :meth:`pull`, the
519 :class:`MultiEngineClient` class implements some of the Python dictionary
550 :class:`MultiEngineClient` class implements some of the Python dictionary
520 interface. This make the remote namespaces of the engines appear as a local
551 interface. This make the remote namespaces of the engines appear as a local
521 dictionary. Underneath, this uses :meth:`push` and :meth:`pull`::
552 dictionary. Underneath, this uses :meth:`push` and :meth:`pull`:
553
554 .. sourcecode:: ipython
522
555
523 In [50]: mec.block=True
556 In [50]: mec.block=True
524
557
@@ -536,7 +569,9 b' follow that terminology. However, it is important to remember that in'
536 IPython's :class:`MultiEngineClient` class, :meth:`scatter` is from the
569 IPython's :class:`MultiEngineClient` class, :meth:`scatter` is from the
537 interactive IPython session to the engines and :meth:`gather` is from the
570 interactive IPython session to the engines and :meth:`gather` is from the
538 engines back to the interactive IPython session. For scatter/gather operations
571 engines back to the interactive IPython session. For scatter/gather operations
539 between engines, MPI should be used::
572 between engines, MPI should be used:
573
574 .. sourcecode:: ipython
540
575
541 In [58]: mec.scatter('a',range(16))
576 In [58]: mec.scatter('a',range(16))
542 Out[58]: [None, None, None, None]
577 Out[58]: [None, None, None, None]
@@ -569,7 +604,9 b' How to do parallel list comprehensions'
569
604
570 In many cases list comprehensions are nicer than using the map function. While
605 In many cases list comprehensions are nicer than using the map function. While
571 we don't have fully parallel list comprehensions, it is simple to get the
606 we don't have fully parallel list comprehensions, it is simple to get the
572 basic effect using :meth:`scatter` and :meth:`gather`::
607 basic effect using :meth:`scatter` and :meth:`gather`:
608
609 .. sourcecode:: ipython
573
610
574 In [66]: mec.scatter('x',range(64))
611 In [66]: mec.scatter('x',range(64))
575 Out[66]: [None, None, None, None]
612 Out[66]: [None, None, None, None]
@@ -598,7 +635,9 b' parallel command can actually raise multiple exceptions (one for each engine'
598 the command was run on). To express this idea, the MultiEngine interface has a
635 the command was run on). To express this idea, the MultiEngine interface has a
599 :exc:`CompositeError` exception class that will be raised in most cases. The
636 :exc:`CompositeError` exception class that will be raised in most cases. The
600 :exc:`CompositeError` class is a special type of exception that wraps one or
637 :exc:`CompositeError` class is a special type of exception that wraps one or
601 more other types of exceptions. Here is how it works::
638 more other types of exceptions. Here is how it works:
639
640 .. sourcecode:: ipython
602
641
603 In [76]: mec.block=True
642 In [76]: mec.block=True
604
643
@@ -628,7 +667,9 b' more other types of exceptions. Here is how it works::'
628 [2:execute]: ZeroDivisionError: integer division or modulo by zero
667 [2:execute]: ZeroDivisionError: integer division or modulo by zero
629 [3:execute]: ZeroDivisionError: integer division or modulo by zero
668 [3:execute]: ZeroDivisionError: integer division or modulo by zero
630
669
631 Notice how the error message printed when :exc:`CompositeError` is raised has information about the individual exceptions that were raised on each engine. If you want, you can even raise one of these original exceptions::
670 Notice how the error message printed when :exc:`CompositeError` is raised has information about the individual exceptions that were raised on each engine. If you want, you can even raise one of these original exceptions:
671
672 .. sourcecode:: ipython
632
673
633 In [80]: try:
674 In [80]: try:
634 ....: mec.execute('1/0')
675 ....: mec.execute('1/0')
@@ -652,7 +693,9 b' Notice how the error message printed when :exc:`CompositeError` is raised has in'
652
693
653 If you are working in IPython, you can simple type ``%debug`` after one of
694 If you are working in IPython, you can simple type ``%debug`` after one of
654 these :exc:`CompositeError` exceptions is raised, and inspect the exception
695 these :exc:`CompositeError` exceptions is raised, and inspect the exception
655 instance::
696 instance:
697
698 .. sourcecode:: ipython
656
699
657 In [81]: mec.execute('1/0')
700 In [81]: mec.execute('1/0')
658 ---------------------------------------------------------------------------
701 ---------------------------------------------------------------------------
@@ -734,7 +777,9 b' instance::'
734 The above example appears to be broken right now because of a change in
777 The above example appears to be broken right now because of a change in
735 how we are using Twisted.
778 how we are using Twisted.
736
779
737 All of this same error handling magic even works in non-blocking mode::
780 All of this same error handling magic even works in non-blocking mode:
781
782 .. sourcecode:: ipython
738
783
739 In [83]: mec.block=False
784 In [83]: mec.block=False
740
785
@@ -1,6 +1,5 b''
1 .. _parallelsecurity:
1 .. _parallelsecurity:
2
2
3
4 ===========================
3 ===========================
5 Security details of IPython
4 Security details of IPython
6 ===========================
5 ===========================
@@ -73,31 +72,30 b' engines and controller are fully encrypted and authenticated. This section'
73 describes the details of the encryption and authentication approached used
72 describes the details of the encryption and authentication approached used
74 within IPython.
73 within IPython.
75
74
76 IPython uses the `Foolscap <http://foolscap.lothar.com/trac>`_ network
75 IPython uses the Foolscap network protocol [Foolscap]_ for all communications
77 protocol for all communications between processes. Thus, the details of
76 between processes. Thus, the details of IPython's security model are directly
78 IPython's security model are directly related to those of Foolscap. Thus, much
77 related to those of Foolscap. Thus, much of the following discussion is
79 of the following discussion is actually just a discussion of the security that
78 actually just a discussion of the security that is built in to Foolscap.
80 is built in to Foolscap.
81
79
82 Encryption
80 Encryption
83 ----------
81 ----------
84
82
85 For encryption purposes, IPython and Foolscap use the well known Secure Socket
83 For encryption purposes, IPython and Foolscap use the well known Secure Socket
86 Layer (SSL) protocol (`RFC5246 <http://tools.ietf.org/html/rfc5246>`_). We use
84 Layer (SSL) protocol [RFC5246]_. We use the implementation of this protocol
87 the implementation of this protocol provided by the OpenSSL project through
85 provided by the OpenSSL project through the pyOpenSSL [pyOpenSSL]_ Python
88 the `pyOpenSSL <http://pyopenssl.sourceforge.net/>`_ Python bindings to OpenSSL.
86 bindings to OpenSSL.
89
87
90 Authentication
88 Authentication
91 --------------
89 --------------
92
90
93 IPython clients and engines must also authenticate themselves with the
91 IPython clients and engines must also authenticate themselves with the
94 controller. This is handled in a `capabilities based security model
92 controller. This is handled in a capabilities based security model
95 <http://en.wikipedia.org/wiki/Capability-based_security>`_. In this model, the
93 [Capability]_. In this model, the controller creates a strong cryptographic
96 controller creates a strong cryptographic key or token that represents each
94 key or token that represents each set of capability that the controller
97 set of capability that the controller offers. Any party who has this key and
95 offers. Any party who has this key and presents it to the controller has full
98 presents it to the controller has full access to the corresponding
96 access to the corresponding capabilities of the controller. This model is
99 capabilities of the controller. This model is analogous to using a physical
97 analogous to using a physical key to gain access to physical items
100 key to gain access to physical items (capabilities) behind a locked door.
98 (capabilities) behind a locked door.
101
99
102 For a capabilities based authentication system to prevent unauthorized access,
100 For a capabilities based authentication system to prevent unauthorized access,
103 two things must be ensured:
101 two things must be ensured:
@@ -118,7 +116,7 b' controller creates a number of FURLs for different purposes:'
118 to execute.
116 to execute.
119
117
120 Upon starting, the controller creates these different FURLS and writes them
118 Upon starting, the controller creates these different FURLS and writes them
121 files in the user-read-only directory $HOME/.ipython/security. Thus, only the
119 files in the user-read-only directory :file:`$HOME/.ipython/security`. Thus, only the
122 user who starts the controller has access to the FURLs.
120 user who starts the controller has access to the FURLs.
123
121
124 For an IPython client or engine to authenticate with a controller, it must
122 For an IPython client or engine to authenticate with a controller, it must
@@ -361,3 +359,5 b' the certificate of their peer. This mutual authentication is handled by the'
361 SSL handshake and is separate and independent from the additional
359 SSL handshake and is separate and independent from the additional
362 authentication steps that the CLIENT and SERVER perform after an encrypted
360 authentication steps that the CLIENT and SERVER perform after an encrypted
363 channel is established.
361 channel is established.
362
363 .. [RFC5246] <http://tools.ietf.org/html/rfc5246>
@@ -4,8 +4,6 b''
4 The IPython task interface
4 The IPython task interface
5 ==========================
5 ==========================
6
6
7 .. contents::
8
9 The task interface to the controller presents the engines as a fault tolerant, dynamic load-balanced system or workers. Unlike the multiengine interface, in the task interface, the user have no direct access to individual engines. In some ways, this interface is simpler, but in other ways it is more powerful.
7 The task interface to the controller presents the engines as a fault tolerant, dynamic load-balanced system or workers. Unlike the multiengine interface, in the task interface, the user have no direct access to individual engines. In some ways, this interface is simpler, but in other ways it is more powerful.
10
8
11 Best of all the user can use both of these interfaces running at the same time to take advantage or both of their strengths. When the user can break up the user's work into segments that do not depend on previous execution, the task interface is ideal. But it also has more power and flexibility, allowing the user to guide the distribution of jobs, without having to assign tasks to engines explicitly.
9 Best of all the user can use both of these interfaces running at the same time to take advantage or both of their strengths. When the user can break up the user's work into segments that do not depend on previous execution, the task interface is ideal. But it also has more power and flexibility, allowing the user to guide the distribution of jobs, without having to assign tasks to engines explicitly.
@@ -17,7 +15,7 b' To follow along with this tutorial, you will need to start the IPython'
17 controller and four IPython engines. The simplest way of doing this is to use
15 controller and four IPython engines. The simplest way of doing this is to use
18 the :command:`ipcluster` command::
16 the :command:`ipcluster` command::
19
17
20 $ ipcluster -n 4
18 $ ipcluster local -n 4
21
19
22 For more detailed information about starting the controller and engines, see
20 For more detailed information about starting the controller and engines, see
23 our :ref:`introduction <ip1par>` to using IPython for parallel computing.
21 our :ref:`introduction <ip1par>` to using IPython for parallel computing.
@@ -26,7 +24,9 b' Creating a ``TaskClient`` instance'
26 =========================================
24 =========================================
27
25
28 The first step is to import the IPython :mod:`IPython.kernel.client` module
26 The first step is to import the IPython :mod:`IPython.kernel.client` module
29 and then create a :class:`TaskClient` instance::
27 and then create a :class:`TaskClient` instance:
28
29 .. sourcecode:: ipython
30
30
31 In [1]: from IPython.kernel import client
31 In [1]: from IPython.kernel import client
32
32
@@ -34,10 +34,12 b' and then create a :class:`TaskClient` instance::'
34
34
35 This form assumes that the :file:`ipcontroller-tc.furl` is in the
35 This form assumes that the :file:`ipcontroller-tc.furl` is in the
36 :file:`~./ipython/security` directory on the client's host. If not, the
36 :file:`~./ipython/security` directory on the client's host. If not, the
37 location of the ``.furl`` file must be given as an argument to the
37 location of the FURL file must be given as an argument to the
38 constructor::
38 constructor:
39
40 .. sourcecode:: ipython
39
41
40 In[2]: mec = client.TaskClient('/path/to/my/ipcontroller-tc.furl')
42 In [2]: mec = client.TaskClient('/path/to/my/ipcontroller-tc.furl')
41
43
42 Quick and easy parallelism
44 Quick and easy parallelism
43 ==========================
45 ==========================
@@ -47,7 +49,9 b' In many cases, you simply want to apply a Python function to a sequence of objec'
47 Parallel map
49 Parallel map
48 ------------
50 ------------
49
51
50 The parallel :meth:`map` in the task interface is similar to that in the multiengine interface::
52 The parallel :meth:`map` in the task interface is similar to that in the multiengine interface:
53
54 .. sourcecode:: ipython
51
55
52 In [63]: serial_result = map(lambda x:x**10, range(32))
56 In [63]: serial_result = map(lambda x:x**10, range(32))
53
57
@@ -59,7 +63,9 b' The parallel :meth:`map` in the task interface is similar to that in the multien'
59 Parallel function decorator
63 Parallel function decorator
60 ---------------------------
64 ---------------------------
61
65
62 Parallel functions are just like normal function, but they can be called on sequences and *in parallel*. The multiengine interface provides a decorator that turns any Python function into a parallel function::
66 Parallel functions are just like normal function, but they can be called on sequences and *in parallel*. The multiengine interface provides a decorator that turns any Python function into a parallel function:
67
68 .. sourcecode:: ipython
63
69
64 In [10]: @tc.parallel()
70 In [10]: @tc.parallel()
65 ....: def f(x):
71 ....: def f(x):
General Comments 0
You need to be logged in to leave comments. Login now