##// END OF EJS Templates
Updated the docs for using MPI with IPython.
Brian Granger -
Show More
@@ -1,15 +1,16 b''
1 1 .. _parallel_index:
2 2
3 3 ====================================
4 4 Using IPython for parallel computing
5 5 ====================================
6 6
7 7 .. toctree::
8 8 :maxdepth: 2
9 9
10 10 parallel_intro.txt
11 parallel_process.txt
11 12 parallel_multiengine.txt
12 13 parallel_task.txt
13 14 parallel_mpi.txt
14 15 parallel_security.txt
15 16
@@ -1,330 +1,204 b''
1 1 .. _ip1par:
2 2
3 3 ============================
4 4 Overview and getting started
5 5 ============================
6 6
7 7 .. contents::
8 8
9 9 Introduction
10 10 ============
11 11
12 12 This file gives an overview of IPython's sophisticated and
13 13 powerful architecture for parallel and distributed computing. This
14 14 architecture abstracts out parallelism in a very general way, which
15 15 enables IPython to support many different styles of parallelism
16 16 including:
17 17
18 18 * Single program, multiple data (SPMD) parallelism.
19 19 * Multiple program, multiple data (MPMD) parallelism.
20 20 * Message passing using ``MPI``.
21 21 * Task farming.
22 22 * Data parallel.
23 23 * Combinations of these approaches.
24 24 * Custom user defined approaches.
25 25
26 26 Most importantly, IPython enables all types of parallel applications to
27 27 be developed, executed, debugged and monitored *interactively*. Hence,
28 28 the ``I`` in IPython. The following are some example usage cases for IPython:
29 29
30 30 * Quickly parallelize algorithms that are embarrassingly parallel
31 31 using a number of simple approaches. Many simple things can be
32 32 parallelized interactively in one or two lines of code.
33 33
34 34 * Steer traditional MPI applications on a supercomputer from an
35 35 IPython session on your laptop.
36 36
37 37 * Analyze and visualize large datasets (that could be remote and/or
38 38 distributed) interactively using IPython and tools like
39 39 matplotlib/TVTK.
40 40
41 41 * Develop, test and debug new parallel algorithms
42 42 (that may use MPI) interactively.
43 43
44 44 * Tie together multiple MPI jobs running on different systems into
45 45 one giant distributed and parallel system.
46 46
47 47 * Start a parallel job on your cluster and then have a remote
48 48 collaborator connect to it and pull back data into their
49 49 local IPython session for plotting and analysis.
50 50
51 51 * Run a set of tasks on a set of CPUs using dynamic load balancing.
52 52
53 53 Architecture overview
54 54 =====================
55 55
56 56 The IPython architecture consists of three components:
57 57
58 58 * The IPython engine.
59 59 * The IPython controller.
60 60 * Various controller clients.
61 61
62 62 These components live in the :mod:`IPython.kernel` package and are
63 63 installed with IPython. They do, however, have additional dependencies
64 64 that must be installed. For more information, see our
65 65 :ref:`installation documentation <install_index>`.
66 66
67 67 IPython engine
68 68 ---------------
69 69
70 70 The IPython engine is a Python instance that takes Python commands over a
71 71 network connection. Eventually, the IPython engine will be a full IPython
72 72 interpreter, but for now, it is a regular Python interpreter. The engine
73 73 can also handle incoming and outgoing Python objects sent over a network
74 74 connection. When multiple engines are started, parallel and distributed
75 75 computing becomes possible. An important feature of an IPython engine is
76 76 that it blocks while user code is being executed. Read on for how the
77 77 IPython controller solves this problem to expose a clean asynchronous API
78 78 to the user.
79 79
80 80 IPython controller
81 81 ------------------
82 82
83 83 The IPython controller provides an interface for working with a set of
84 84 engines. At an general level, the controller is a process to which
85 85 IPython engines can connect. For each connected engine, the controller
86 86 manages a queue. All actions that can be performed on the engine go
87 87 through this queue. While the engines themselves block when user code is
88 88 run, the controller hides that from the user to provide a fully
89 89 asynchronous interface to a set of engines.
90 90
91 91 .. note::
92 92
93 93 Because the controller listens on a network port for engines to
94 94 connect to it, it must be started *before* any engines are started.
95 95
96 96 The controller also provides a single point of contact for users who wish
97 97 to utilize the engines connected to the controller. There are different
98 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:
99 99
100 100 * The MultiEngine interface, which provides the simplest possible way of working
101 101 with engines interactively.
102 102 * The Task interface, which provides presents the engines as a load balanced
103 103 task farming system.
104 104
105 105 Advanced users can easily add new custom interfaces to enable other
106 106 styles of parallelism.
107 107
108 108 .. note::
109 109
110 110 A single controller and set of engines can be accessed
111 111 through multiple interfaces simultaneously. This opens the
112 112 door for lots of interesting things.
113 113
114 114 Controller clients
115 115 ------------------
116 116
117 117 For each controller interface, there is a corresponding client. These
118 118 clients allow users to interact with a set of engines through the
119 119 interface. Here are the two default clients:
120 120
121 121 * The :class:`MultiEngineClient` class.
122 122 * The :class:`TaskClient` class.
123 123
124 124 Security
125 125 --------
126 126
127 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.
128 128
129 129 .. __: http://en.wikipedia.org/wiki/Capability-based_security
130 130
131 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.
132 132
133 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.
134 134
135 135 Currently, there are three .furl files that the controller creates:
136 136
137 137 ipcontroller-engine.furl
138 138 This ``.furl`` file is the key that gives an engine the ability to connect
139 139 to a controller.
140 140
141 141 ipcontroller-tc.furl
142 142 This ``.furl`` file is the key that a :class:`TaskClient` must use to
143 143 connect to the task interface of a controller.
144 144
145 145 ipcontroller-mec.furl
146 146 This ``.furl`` file is the key that a :class:`MultiEngineClient` must use to
147 147 connect to the multiengine interface of a controller.
148 148
149 149 More details of how these ``.furl`` files are used are given below.
150 150
151 151 A detailed description of the security model and its implementation in IPython
152 152 can be found :ref:`here <parallelsecurity>`.
153 153
154 154 Getting Started
155 155 ===============
156 156
157 157 To use IPython for parallel computing, you need to start one instance of
158 the controller and one or more instances of the engine. The controller
159 and each engine can run on different machines or on the same machine.
160 Because of this, there are many different possibilities for setting up
161 the IP addresses and ports used by the various processes.
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::
162 159
163 Starting the controller and engine on your local machine
164 --------------------------------------------------------
160 $ ipcluster -n 4
165 161
166 This is the simplest configuration that can be used and is useful for
167 testing the system and on machines that have multiple cores and/or
168 multple CPUs. The easiest way of getting started is to use the :command:`ipcluster`
169 command::
170
171 $ ipcluster -n 4
172
173 This will start an IPython controller and then 4 engines that connect to
174 the controller. Lastly, the script will print out the Python commands
175 that you can use to connect to the controller. It is that easy.
176
177 .. warning::
178
179 The :command:`ipcluster` does not currently work on Windows. We are
180 working on it though.
181
182 Underneath the hood, the controller creates ``.furl`` files in the
183 :file:`~./ipython/security` directory. Because the engines are on the
184 same host, they automatically find the needed :file:`ipcontroller-engine.furl`
185 there and use it to connect to the controller.
186
187 The :command:`ipcluster` script uses two other top-level
188 scripts that you can also use yourself. These scripts are
189 :command:`ipcontroller`, which starts the controller and :command:`ipengine` which
190 starts one engine. To use these scripts to start things on your local
191 machine, do the following.
192
193 First start the controller::
194
195 $ ipcontroller
196
197 Next, start however many instances of the engine you want using (repeatedly) the command::
198
199 $ ipengine
200
201 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.
202
203 .. warning::
204
205 The order of the above operations is very important. You *must*
206 start the controller before the engines, since the engines connect
207 to the controller as they get started.
208
209 .. note::
210
211 On some platforms (OS X), to put the controller and engine into the background
212 you may need to give these commands in the form ``(ipcontroller &)``
213 and ``(ipengine &)`` (with the parentheses) for them to work properly.
214
215
216 Starting the controller and engines on different hosts
217 ------------------------------------------------------
218
219 When the controller and engines are running on different hosts, things are
220 slightly more complicated, but the underlying ideas are the same:
221
222 1. Start the controller on a host using :command:`ipcontroler`.
223 2. Copy :file:`ipcontroller-engine.furl` from :file:`~./ipython/security` on the controller's host to the host where the engines will run.
224 3. Use :command:`ipengine` on the engine's hosts to start the engines.
225
226 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:
227
228 * Put :file:`ipcontroller-engine.furl` in the :file:`~./ipython/security` directory
229 on the engine's host, where it will be found automatically.
230 * Call :command:`ipengine` with the ``--furl-file=full_path_to_the_file`` flag.
231
232 The ``--furl-file`` flag works like this::
233
234 $ ipengine --furl-file=/path/to/my/ipcontroller-engine.furl
235
236 .. note::
237
238 If the controller's and engine's hosts all have a shared file system
239 (:file:`~./ipython/security` is the same on all of them), then things
240 will just work!
241
242 Make .furl files persistent
243 ---------------------------
244
245 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 everytime 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.
246
247 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::
248
249 $ ipcontroller --client-port=10101 --engine-port=10102
250
251 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.
252
253 .. note::
254
255 You may ask the question: what ports does the controller listen on if you
256 don't tell is to use specific ones? The default is to use high random port
257 numbers. We do this for two reasons: i) to increase security through obcurity
258 and ii) to multiple controllers on a given host to start and automatically
259 use different ports.
260
261 Starting engines using ``mpirun``
262 ---------------------------------
263
264 The IPython engines can be started using ``mpirun``/``mpiexec``, even if
265 the engines don't call ``MPI_Init()`` or use the MPI API in any way. This is
266 supported on modern MPI implementations like `Open MPI`_.. This provides
267 an really nice way of starting a bunch of engine. On a system with MPI
268 installed you can do::
269
270 mpirun -n 4 ipengine
271
272 to start 4 engine on a cluster. This works even if you don't have any
273 Python-MPI bindings installed.
274
275 .. _Open MPI: http://www.open-mpi.org/
276
277 More details on using MPI with IPython can be found :ref:`here <parallelmpi>`.
278
279 Log files
280 ---------
281
282 All of the components of IPython have log files associated with them.
283 These log files can be extremely useful in debugging problems with
284 IPython and can be found in the directory ``~/.ipython/log``. Sending
285 the log files to us will often help us to debug any problems.
286
287 Next Steps
288 ==========
162 More details about starting the IPython controller and engines can be found :ref:`here <parallel_process>`
289 163
290 164 Once you have started the IPython controller and one or more engines, you
291 165 are ready to use the engines to do something useful. To make sure
292 166 everything is working correctly, try the following commands::
293 167
294 168 In [1]: from IPython.kernel import client
295 169
296 170 In [2]: mec = client.MultiEngineClient()
297 171
298 172 In [4]: mec.get_ids()
299 173 Out[4]: [0, 1, 2, 3]
300 174
301 175 In [5]: mec.execute('print "Hello World"')
302 176 Out[5]:
303 177 <Results List>
304 178 [0] In [1]: print "Hello World"
305 179 [0] Out[1]: Hello World
306 180
307 181 [1] In [1]: print "Hello World"
308 182 [1] Out[1]: Hello World
309 183
310 184 [2] In [1]: print "Hello World"
311 185 [2] Out[1]: Hello World
312 186
313 187 [3] In [1]: print "Hello World"
314 188 [3] Out[1]: Hello World
315 189
316 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::
317 191
318 192 mec = client.MultiEngineClient('/path/to/my/ipcontroller-mec.furl')
319 193
320 194 Same thing hold true of creating a task client::
321 195
322 196 tc = client.TaskClient('/path/to/my/ipcontroller-tc.furl')
323 197
324 198 You are now ready to learn more about the :ref:`MultiEngine <parallelmultiengine>` and :ref:`Task <paralleltask>` interfaces to the controller.
325 199
326 200 .. note::
327 201
328 202 Don't forget that the engine, multiengine client and task client all have
329 203 *different* furl files. You must move *each* of these around to an appropriate
330 204 location so that the engines and clients can use them to connect to the controller.
@@ -1,22 +1,78 b''
1 1 .. _parallelmpi:
2 2
3 3 =======================
4 4 Using MPI with IPython
5 5 =======================
6 6
7 The simplest way of getting started with MPI is to install an MPI implementation
8 (we recommend `Open MPI`_) and `mpi4py`_ and then start the engines using the
9 ``mpirun`` command::
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.
10 8
11 mpirun -n 4 ipengine --mpi=mpi4py
12
13 This will automatically import `mpi4py`_ and make sure that `MPI_Init` is called
14 at the right time. We also have built in support for `PyTrilinos`_, which can be
15 used (assuming `PyTrilinos`_ is installed) by starting the engines with::
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.
16 10
17 mpirun -n 4 ipengine --mpi=pytrilinos
11 Additional installation requirements
12 ====================================
13
14 If you want to use MPI with IPython, you will need to install:
15
16 * A standard MPI implementation such as `Open MPI`_ or MPICH.
17 * The `mpi4py`_ package.
18
19 .. note::
20
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
23 making sure that `MPI_Init` is called when the IPython engines start up.
24 There are a number of ways of doing this and a good number of associated
25 subtleties. We highly recommend just using `mpi4py`_ as it takes care of
26 most of these problems. If you want to do something different, let us know
27 and we can help you get started.
28
29 Starting the engines with MPI enabled
30 =====================================
31
32 To use code that calls `MPI`_, there are typically two things that `MPI`_ requires.
33
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.
36 2. Once the process starts, it must call `MPI_Init`.
37
38 There are a couple of ways that you can start the IPython engines and get these things to happen.
39
40 Manual starting using :command:`mpirun`
41 ---------------------------------------
42
43 If you want to start the IPython engines using the :command:`mpirun`, just do::
44
45 $ mpirun -n 4 ipengine --mpi=mpi4py
46
47 This requires that you already have a controller running. We also have built
48 in support for `PyTrilinos`_, which can be used (assuming `PyTrilinos`_ is
49 installed) by starting the engines with::
50
51 mpirun -n 4 ipengine --mpi=pytrilinos
52
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`
61 -----------------------------------------------------
62
63 The :command:`ipcluster` command also has built-in integration with PBS. For more information on this approach, see our documentation on :ref:`ipcluster <parallel_process>`.
64
65 Actually using MPI
66 ==================
67
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.
69
70 Complications
71 =============
72
73 Talk about how some older MPI implementations are broken and need to have a custom Python mail loop.
18 74
19 75 .. _MPI: http://www-unix.mcs.anl.gov/mpi/
20 76 .. _mpi4py: http://mpi4py.scipy.org/
21 77 .. _Open MPI: http://www.open-mpi.org/
22 78 .. _PyTrilinos: http://trilinos.sandia.gov/packages/pytrilinos/ No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now