1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <title>Getting started</title>
6 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9 <link rel="up" href="../mpi.html" title="Chapter 26. Boost.MPI">
10 <link rel="prev" href="../mpi.html" title="Chapter 26. Boost.MPI">
11 <link rel="next" href="tutorial.html" title="Tutorial">
13 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14 <table cellpadding="2" width="100%"><tr>
15 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16 <td align="center"><a href="../../../index.html">Home</a></td>
17 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20 <td align="center"><a href="../../../more/index.htm">More</a></td>
23 <div class="spirit-nav">
24 <a accesskey="p" href="../mpi.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mpi.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
27 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
28 <a name="mpi.getting_started"></a><a class="link" href="getting_started.html" title="Getting started">Getting started</a>
29 </h2></div></div></div>
30 <div class="toc"><dl class="toc">
31 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.implementation">MPI Implementation</a></span></dt>
32 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.config">Configure and Build</a></span></dt>
33 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.using">Using Boost.MPI</a></span></dt>
36 Getting started with Boost.MPI requires a working MPI implementation, a recent
37 version of Boost, and some configuration information.
40 <div class="titlepage"><div><div><h3 class="title">
41 <a name="mpi.getting_started.implementation"></a><a class="link" href="getting_started.html#mpi.getting_started.implementation" title="MPI Implementation">MPI Implementation</a>
42 </h3></div></div></div>
44 To get started with Boost.MPI, you will first need a working MPI implementation.
45 There are many conforming <a href="http://www-unix.mcs.anl.gov/mpi/implementations.html" target="_top">MPI
46 implementations</a> available. Boost.MPI should work with any of the
47 implementations, although it has only been tested extensively with:
49 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
51 <a href="http://www.open-mpi.org" target="_top">Open MPI</a>
54 <a href="http://www-unix.mcs.anl.gov/mpi/mpich/" target="_top">MPICH2</a>
57 <a href="https://software.intel.com/en-us/intel-mpi-library" target="_top">Intel
62 You can test your implementation using the following simple program, which
63 passes a message from one processor to another. Each processor prints a message
66 <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">mpi</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span>
67 <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
69 <span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">argv</span><span class="special">[])</span>
70 <span class="special">{</span>
71 <span class="identifier">MPI_Init</span><span class="special">(&</span><span class="identifier">argc</span><span class="special">,</span> <span class="special">&</span><span class="identifier">argv</span><span class="special">);</span>
73 <span class="keyword">int</span> <span class="identifier">rank</span><span class="special">;</span>
74 <span class="identifier">MPI_Comm_rank</span><span class="special">(</span><span class="identifier">MPI_COMM_WORLD</span><span class="special">,</span> <span class="special">&</span><span class="identifier">rank</span><span class="special">);</span>
75 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">rank</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="special">{</span>
76 <span class="keyword">int</span> <span class="identifier">value</span> <span class="special">=</span> <span class="number">17</span><span class="special">;</span>
77 <span class="keyword">int</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">MPI_Send</span><span class="special">(&</span><span class="identifier">value</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">MPI_INT</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">MPI_COMM_WORLD</span><span class="special">);</span>
78 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">result</span> <span class="special">==</span> <span class="identifier">MPI_SUCCESS</span><span class="special">)</span>
79 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Rank 0 OK!"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
80 <span class="special">}</span> <span class="keyword">else</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">rank</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="special">{</span>
81 <span class="keyword">int</span> <span class="identifier">value</span><span class="special">;</span>
82 <span class="keyword">int</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">MPI_Recv</span><span class="special">(&</span><span class="identifier">value</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">MPI_INT</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">MPI_COMM_WORLD</span><span class="special">,</span>
83 <span class="identifier">MPI_STATUS_IGNORE</span><span class="special">);</span>
84 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">result</span> <span class="special">==</span> <span class="identifier">MPI_SUCCESS</span> <span class="special">&&</span> <span class="identifier">value</span> <span class="special">==</span> <span class="number">17</span><span class="special">)</span>
85 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Rank 1 OK!"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
86 <span class="special">}</span>
87 <span class="identifier">MPI_Finalize</span><span class="special">();</span>
88 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
89 <span class="special">}</span>
92 You should compile and run this program on two processors. To do this, consult
93 the documentation for your MPI implementation. With <a href="http://www.open-mpi.org" target="_top">OpenMPI</a>,
94 for instance, you compile with the <code class="computeroutput"><span class="identifier">mpiCC</span></code>
95 or <code class="computeroutput"><span class="identifier">mpic</span><span class="special">++</span></code>
96 compiler, boot the LAM/MPI daemon, and run your program via <code class="computeroutput"><span class="identifier">mpirun</span></code>. For instance, if your program is
97 called <code class="computeroutput"><span class="identifier">mpi</span><span class="special">-</span><span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span></code>,
98 use the following commands:
100 <pre class="programlisting">mpiCC -o mpi-test mpi-test.cpp
102 mpirun -np 2 ./mpi-test
106 When you run this program, you will see both <code class="computeroutput"><span class="identifier">Rank</span>
107 <span class="number">0</span> <span class="identifier">OK</span><span class="special">!</span></code> and <code class="computeroutput"><span class="identifier">Rank</span>
108 <span class="number">1</span> <span class="identifier">OK</span><span class="special">!</span></code> printed to the screen. However, they may
109 be printed in any order and may even overlap each other. The following output
110 is perfectly legitimate for this MPI program:
112 <pre class="programlisting">Rank Rank 1 OK!
116 If your output looks something like the above, your MPI implementation appears
117 to be working with a C++ compiler and we're ready to move on.
120 <div class="section">
121 <div class="titlepage"><div><div><h3 class="title">
122 <a name="mpi.getting_started.config"></a><a class="link" href="getting_started.html#mpi.getting_started.config" title="Configure and Build">Configure and Build</a>
123 </h3></div></div></div>
124 <div class="toc"><dl class="toc">
125 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.config.bootstrap">Bootstrap</a></span></dt>
126 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.config.setup">Setting up your MPI
127 Implementation</a></span></dt>
128 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.config.build">Build</a></span></dt>
129 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.config.tests">Tests</a></span></dt>
130 <dt><span class="section"><a href="getting_started.html#mpi.getting_started.config.installation">Installation</a></span></dt>
133 As the rest of Boost, Boost.MPI uses version 2 of the <a href="http://www.boost.org/doc/html/bbv2.html" target="_top">Boost.Build</a>
134 system for configuring and building the library binary.
137 Please refer to the general Boost installation instructions for <a href="http://www.boost.org/doc/libs/release/more/getting_started/unix-variants.html#prepare-to-use-a-boost-library-binary" target="_top">Unix
138 Variant</a> (including Unix, Linux and MacOS) or <a href="http://www.boost.org/doc/libs/1_58_0/more/getting_started/windows.html#prepare-to-use-a-boost-library-binary" target="_top">Windows</a>.
139 The simplified build instructions should apply on most platforms with a few
140 specific modifications described below.
142 <div class="section">
143 <div class="titlepage"><div><div><h4 class="title">
144 <a name="mpi.getting_started.config.bootstrap"></a><a class="link" href="getting_started.html#mpi.getting_started.config.bootstrap" title="Bootstrap">Bootstrap</a>
145 </h4></div></div></div>
147 As explained in the boost installation instructions, running the bootstrap
148 (<code class="computeroutput"><span class="special">./</span><span class="identifier">bootstrap</span><span class="special">.</span><span class="identifier">sh</span></code> for
149 unix variants or <code class="computeroutput"><span class="identifier">bootstrap</span><span class="special">.</span><span class="identifier">bat</span></code>
150 for Windows) from the boost root directory will produce a 'project-config.jam`
151 file. You need to edit that file and add the following line:
153 <pre class="programlisting"><span class="keyword">using</span> <span class="identifier">mpi</span> <span class="special">;</span>
156 Alternatively, you can explicitly provide the list of Boost libraries you
157 want to build. Please refer to the <code class="computeroutput"><span class="special">--</span><span class="identifier">help</span></code> option of the <code class="computeroutput"><span class="identifier">bootstrap</span></code>
161 <div class="section">
162 <div class="titlepage"><div><div><h4 class="title">
163 <a name="mpi.getting_started.config.setup"></a><a class="link" href="getting_started.html#mpi.getting_started.config.setup" title="Setting up your MPI Implementation">Setting up your MPI
165 </h4></div></div></div>
166 <div class="toc"><dl class="toc"><dt><span class="section"><a href="getting_started.html#mpi.getting_started.config.setup.troubleshooting">Trouble
167 shooting</a></span></dt></dl></div>
169 First, you need to scan the <code class="literal">include/boost/mpi/config.hpp</code>
170 file and check if some settings need to be modified for your MPI implementation
174 In particular, the <code class="computeroutput"><a class="link" href="../BOOST_MPI_HOMOGENEOUS.html" title="Macro BOOST_MPI_HOMOGENEOUS">BOOST_MPI_HOMOGENEOUS</a></code>
175 macro, that you will need to comment out if you plan to run on a heterogeneous
176 set of machines. See the <a class="link" href="tutorial.html#mpi.tutorial.performance_optimizations.homogeneous_machines" title="Homogeneous Machines">optimization</a>
180 Most MPI implementations require specific compilation and link options.
181 In order to mask theses details to the user, most MPI implementations provide
182 wrappers which silently pass those options to the compiler.
185 Depending on your MPI implementation, some work might be needed to tell
186 Boost which specific MPI option to use. This is done through the <code class="computeroutput"><span class="keyword">using</span> <span class="identifier">mpi</span> <span class="special">;</span></code> directive in the <code class="computeroutput"><span class="identifier">project</span><span class="special">-</span><span class="identifier">config</span><span class="special">.</span><span class="identifier">jam</span></code>
187 file those general form is (do not forget to leave spaces around <span class="bold"><strong>:</strong></span> and before <span class="bold"><strong>;</strong></span>):
189 <pre class="programlisting">using mpi
190 : [<MPI compiler wrapper>]
191 : [<compilation and link options>]
192 : [<mpi runner>] ;
195 Depending on your installation and MPI distribution, the build system might
196 be able to find all the required informations and you just need to specify:
198 <pre class="programlisting">using mpi ;
200 <div class="section">
201 <div class="titlepage"><div><div><h5 class="title">
202 <a name="mpi.getting_started.config.setup.troubleshooting"></a><a class="link" href="getting_started.html#mpi.getting_started.config.setup.troubleshooting" title="Trouble shooting">Trouble
204 </h5></div></div></div>
206 Most of the time, specially with production HPC clusters, some work will
210 Here is a list of the most common issues and suggestions on how to fix
213 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
214 <span class="bold"><strong>Your wrapper is not in your path or does ot
215 have a standard name </strong></span>
218 You will need to tell the build system how to call it using the first
221 <pre class="programlisting">using mpi : /opt/mpi/bullxmpi/1.2.8.3/bin/mpicc ;
223 <div class="warning"><table border="0" summary="Warning">
225 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../doc/src/images/warning.png"></td>
226 <th align="left">Warning</th>
228 <tr><td align="left" valign="top"><p>
229 Boost.MPI only uses the C interface, so specifying the C wrapper should
230 be enough. But some implementations will insist on importing the C++
234 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
235 <span class="bold"><strong>Your wrapper is really eccentric or does not
236 exist</strong></span>
239 With some implementations, or with some specific integration<a href="#ftn.mpi.getting_started.config.setup.troubleshooting.f0" class="footnote" name="mpi.getting_started.config.setup.troubleshooting.f0"><sup class="footnote">[10]</sup></a> you will need to provide the compilation and link options
240 through de second parameter using 'jam' directives. The following type
241 configuration used to be required for some specific Intel MPI implementation
242 (in such a case, the name of the wrapper can be left blank):
244 <pre class="programlisting">using mpi : mpiicc :
245 <library-path>/softs/intel/impi/5.0.1.035/intel64/lib
246 <library-path>/softs/intel/impi/5.0.1.035/intel64/lib/release_mt
247 <include>/softs/intel/impi/5.0.1.035/intel64/include
248 <find-shared-library>mpifort
249 <find-shared-library>mpi_mt
250 <find-shared-library>mpigi
251 <find-shared-library>dl
252 <find-shared-library>rt ;
255 As a convenience, MPI wrappers usually have an option that provides the
256 required informations, which usually starts with <code class="computeroutput"><span class="special">--</span><span class="identifier">show</span></code>. You can use those to find out
257 the requested jam directive:
259 <pre class="programlisting">$ mpiicc -show
260 icc -I/softs/.../include ... -L/softs/.../lib ... -Xlinker -rpath -Xlinker /softs/.../lib .... -lmpi -ldl -lrt -lpthread
263 <pre class="programlisting">$ mpicc --showme
264 icc -I/opt/.../include -pthread -L/opt/.../lib -lmpi -ldl -lm -lnuma -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl
265 $ mpicc --showme:compile
266 -I/opt/mpi/bullxmpi/1.2.8.3/include -pthread
267 $ mpicc --showme:link
268 -pthread -L/opt/.../lib -lmpi -ldl -lm -lnuma -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl
272 To see the results of MPI auto-detection, pass <code class="computeroutput"><span class="special">--</span><span class="identifier">debug</span><span class="special">-</span><span class="identifier">configuration</span></code> on the bjam command line.
274 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
275 <span class="bold"><strong>The launch syntax cannot be detected</strong></span>
277 <div class="note"><table border="0" summary="Note">
279 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
280 <th align="left">Note</th>
282 <tr><td align="left" valign="top"><p>
283 This is only used when <a class="link" href="getting_started.html#mpi.getting_started.config.tests" title="Tests">running
288 If you need to use a special command to launch an MPI program, you will
289 need to specify it through the third parameter of the <code class="computeroutput"><span class="keyword">using</span>
290 <span class="identifier">mpi</span></code> directive.
293 So, assuming you launch the <code class="computeroutput"><span class="identifier">all_gather_test</span></code>
296 <pre class="programlisting">$mpiexec.hydra -np 4 all_gather_test
299 The directive will look like:
301 <pre class="programlisting">using mpi : mpiicc :
302 [<compilation and link options>]
307 <div class="section">
308 <div class="titlepage"><div><div><h4 class="title">
309 <a name="mpi.getting_started.config.build"></a><a class="link" href="getting_started.html#mpi.getting_started.config.build" title="Build">Build</a>
310 </h4></div></div></div>
312 To build the whole Boost distribution:
314 <pre class="programlisting">$cd <boost distribution>
318 To build the Boost.MPI library and dependancies:
320 <pre class="programlisting">$cd <boost distribution>/lib/mpi/build
324 <div class="section">
325 <div class="titlepage"><div><div><h4 class="title">
326 <a name="mpi.getting_started.config.tests"></a><a class="link" href="getting_started.html#mpi.getting_started.config.tests" title="Tests">Tests</a>
327 </h4></div></div></div>
329 You can run the regression tests with:
331 <pre class="programlisting">$cd <boost distribution>/lib/mpi/test
335 <div class="section">
336 <div class="titlepage"><div><div><h4 class="title">
337 <a name="mpi.getting_started.config.installation"></a><a class="link" href="getting_started.html#mpi.getting_started.config.installation" title="Installation">Installation</a>
338 </h4></div></div></div>
340 To install the whole Boost distribution:
342 <pre class="programlisting">$cd <boost distribution>
347 <div class="section">
348 <div class="titlepage"><div><div><h3 class="title">
349 <a name="mpi.getting_started.using"></a><a class="link" href="getting_started.html#mpi.getting_started.using" title="Using Boost.MPI">Using Boost.MPI</a>
350 </h3></div></div></div>
352 To build applications based on Boost.MPI, compile and link them as you normally
353 would for MPI programs, but remember to link against the <code class="computeroutput"><span class="identifier">boost_mpi</span></code>
354 and <code class="computeroutput"><span class="identifier">boost_serialization</span></code> libraries,
357 <pre class="programlisting">mpic++ -I/path/to/boost/mpi my_application.cpp -Llibdir \
358 -lboost_mpi-gcc-mt-1_35 -lboost_serialization-gcc-d-1_35.a
361 If you plan to use the <a class="link" href="python.html" title="Python Bindings">Python bindings</a>
362 for Boost.MPI in conjunction with the C++ Boost.MPI, you will also need to
363 link against the boost_mpi_python library, e.g., by adding <code class="computeroutput"><span class="special">-</span><span class="identifier">lboost_mpi_python</span><span class="special">-</span><span class="identifier">gcc</span><span class="special">-</span><span class="identifier">mt</span><span class="special">-</span><span class="number">1</span><span class="identifier">_35</span></code> to your link command. This step will
364 only be necessary if you intend to <a class="link" href="python.html#mpi.python.user_data" title="Transmitting User-Defined Data">register
365 C++ types</a> or use the <a class="link" href="python.html#mpi.python.skeleton_content" title="Skeleton/Content Mechanism">skeleton/content
366 mechanism</a> from within Python.
369 <div class="footnotes">
370 <br><hr style="width:100; text-align:left;margin-left: 0">
371 <div id="ftn.mpi.getting_started.config.setup.troubleshooting.f0" class="footnote"><p><a href="#mpi.getting_started.config.setup.troubleshooting.f0" class="para"><sup class="para">[10] </sup></a>
372 Some HPC cluster will insist that the users uss theirs own in house
373 interface to the MPI system.
377 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
378 <td align="left"></td>
379 <td align="right"><div class="copyright-footer">Copyright © 2005-2007 Douglas Gregor,
380 Matthias Troyer, Trustees of Indiana University<p>
381 Distributed under the Boost Software License, Version 1.0. (See accompanying
382 file LICENSE_1_0.txt or copy at <ulink url="http://www.boost.org/LICENSE_1_0.txt">
383 http://www.boost.org/LICENSE_1_0.txt </ulink>)
388 <div class="spirit-nav">
389 <a accesskey="p" href="../mpi.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mpi.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>