Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / mpi / doc / getting_started.qbk
1 [section:getting_started Getting started]
2
3 Getting started with Boost.MPI requires a working MPI implementation,
4 a recent version of Boost, and some configuration information.
5
6 [section:implementation MPI Implementation]
7 To get started with Boost.MPI, you will first need a working
8 MPI implementation. There are many conforming _MPI_implementations_
9 available. Boost.MPI should work with any of the
10 implementations, although it has only been tested extensively with:
11
12 * [@http://www.open-mpi.org Open MPI]
13 * [@http://www-unix.mcs.anl.gov/mpi/mpich/ MPICH2]
14 * [@https://software.intel.com/en-us/intel-mpi-library Intel MPI]
15
16 You can test your implementation using the following simple program,
17 which passes a message from one processor to another. Each processor
18 prints a message to standard output. 
19
20   #include <mpi.h>
21   #include <iostream>
22
23   int main(int argc, char* argv[])
24   {
25     MPI_Init(&argc, &argv);
26
27     int rank;
28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29     if (rank == 0) {
30       int value = 17;
31       int result = MPI_Send(&value, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
32       if (result == MPI_SUCCESS)
33         std::cout << "Rank 0 OK!" << std::endl;
34     } else if (rank == 1) {
35       int value;
36       int result = MPI_Recv(&value, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
37                           MPI_STATUS_IGNORE);
38       if (result == MPI_SUCCESS && value == 17)
39         std::cout << "Rank 1 OK!" << std::endl;
40     }
41     MPI_Finalize();
42     return 0;
43   } 
44
45 You should compile and run this program on two processors. To do this,
46 consult the documentation for your MPI implementation. With _OpenMPI_, for
47 instance, you compile with the `mpiCC` or `mpic++` compiler, boot the
48 LAM/MPI daemon, and run your program via `mpirun`. For instance, if
49 your program is called `mpi-test.cpp`, use the following commands:
50
51 [pre
52 mpiCC -o mpi-test mpi-test.cpp
53 lamboot
54 mpirun -np 2 ./mpi-test
55 lamhalt
56 ]
57
58 When you run this program, you will see both `Rank 0 OK!` and `Rank 1
59 OK!` printed to the screen. However, they may be printed in any order
60 and may even overlap each other. The following output is perfectly
61 legitimate for this MPI program:
62
63 [pre
64 Rank Rank 1 OK!
65 0 OK!
66 ]
67
68 If your output looks something like the above, your MPI implementation
69 appears to be working with a C++ compiler and we're ready to move on.
70 [endsect]
71
72 [section:config Configure and Build]
73
74 As the rest of Boost, Boost.MPI uses version 2 of the
75 [@http://www.boost.org/doc/html/bbv2.html Boost.Build] system for
76 configuring and building the library binary.
77
78 Please refer to the general Boost installation instructions for
79 [@http://www.boost.org/doc/libs/release/more/getting_started/unix-variants.html#prepare-to-use-a-boost-library-binary Unix Variant]
80 (including Unix, Linux and MacOS) or
81 [@http://www.boost.org/doc/libs/1_58_0/more/getting_started/windows.html#prepare-to-use-a-boost-library-binary Windows]. 
82 The simplified build instructions should apply on most platforms with a few specific modifications described below.
83
84 [section:bootstrap Bootstrap]
85
86 As explained in the boost installation instructions, running the bootstrap  (`./bootstrap.sh` for unix variants or `bootstrap.bat` for Windows) from the boost root directory will produce a 'project-config.jam` file. You need to edit that file and add the following line:
87
88   using mpi ;
89
90 Alternatively, you can explicitly provide the list of Boost libraries you want to build.
91 Please refer to the `--help` option of the `bootstrap` script.
92
93 [endsect:bootstrap]
94 [section:setup Setting up your MPI Implementation]
95
96 First, you need to scan the =include/boost/mpi/config.hpp= file and check if some 
97 settings need to be modified for your MPI implementation or preferences. 
98
99 In particular, the [macroref BOOST_MPI_HOMOGENEOUS] macro, that you will need to comment out 
100 if you plan to run on a heterogeneous set of machines. See the [link mpi.tutorial.performance_optimizations.homogeneous_machines optimization] notes below.
101
102 Most MPI implementations require specific compilation and link options. 
103 In order to mask theses details to the user, most MPI implementations provide
104 wrappers which silently pass those options to the compiler.
105
106 Depending on your MPI implementation, some work might be needed to tell Boost which 
107 specific MPI option to use. This is done through the `using mpi ;` directive in the `project-config.jam` file those general form is  (do not forget to leave spaces around *:* and before *;*):
108
109 [pre
110 using mpi 
111    : \[<MPI compiler wrapper>\] 
112    : \[<compilation and link options>\] 
113    : \[<mpi runner>\] ;
114 ]
115
116 Depending on your installation and MPI distribution, the build system might be able to find all the required informations and you just need to specify: 
117
118 [pre
119 using mpi ;
120 ]
121
122 [section:troubleshooting Trouble shooting]
123
124 Most of the time, specially with production HPC clusters, some work will need to be done.
125
126 Here is a list of the most common issues and suggestions on how to fix those.
127
128 * [*Your wrapper is not in your path or does ot have a standard name ]
129
130 You will need to tell the build system how to call it using the first parameter:
131
132 [pre
133 using mpi : /opt/mpi/bullxmpi/1.2.8.3/bin/mpicc ;
134 ]
135
136 [warning
137 Boost.MPI only uses the C interface, so specifying the C wrapper should be enough. But some implementations will insist on importing the C++ bindings.
138 ]
139
140 * [*Your wrapper is really eccentric or does not exist]
141
142 With some implementations, or with some specific integration[footnote Some HPC cluster will insist that the users uss theirs own in house interface to the MPI system.] you will need to provide the compilation and link options through de second parameter using 'jam' directives.
143 The following type configuration used to be required for some specific Intel MPI implementation (in such a case, the name of the wrapper can be left blank):
144
145 [pre
146 using mpi : mpiicc : 
147       <library-path>/softs/intel/impi/5.0.1.035/intel64/lib
148       <library-path>/softs/intel/impi/5.0.1.035/intel64/lib/release_mt
149       <include>/softs/intel/impi/5.0.1.035/intel64/include
150       <find-shared-library>mpifort
151       <find-shared-library>mpi_mt
152       <find-shared-library>mpigi
153       <find-shared-library>dl
154       <find-shared-library>rt ;
155 ]
156
157 As a convenience, MPI wrappers usually have an option that provides the required informations, which usually starts with `--show`. You can use those to find out the requested jam directive:
158 [pre
159 $ mpiicc -show
160 icc -I/softs/...\/include ... -L/softs/...\/lib ... -Xlinker -rpath -Xlinker \/softs/...\/lib .... -lmpi -ldl -lrt -lpthread
161
162 ]
163 [pre
164 $ mpicc --showme
165 icc -I/opt/...\/include -pthread -L/opt/...\/lib -lmpi -ldl -lm -lnuma -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl
166 $ mpicc --showme:compile
167 -I/opt/mpi/bullxmpi/1.2.8.3/include -pthread
168 $ mpicc --showme:link
169 -pthread -L/opt/...\/lib -lmpi -ldl -lm -lnuma -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl
170
171 ]
172
173 To see the results of MPI auto-detection, pass `--debug-configuration` on
174 the bjam command line.
175
176 * [*The launch syntax cannot be detected]
177
178 [note This is only used when [link mpi.getting_started.config.tests running the tests].]
179
180 If you need to use a special command to launch an MPI program, you will need to specify it through the third parameter of the `using mpi` directive.
181
182 So, assuming you launch the `all_gather_test` program with:
183
184 [pre
185 $mpiexec.hydra -np 4 all_gather_test
186 ]
187
188 The directive will look like:
189
190 [pre
191 using mpi : mpiicc : 
192      \[<compilation and link options>\]
193  : mpiexec.hydra -n  ;
194 ]
195
196 [endsect:troubleshooting]
197 [endsect:setup]
198 [section:build Build]
199
200 To build the whole Boost distribution:
201 [pre
202 $cd <boost distribution>
203 $./b2 
204 ]
205 To build the Boost.MPI library and dependancies:
206 [pre
207 $cd <boost distribution>\/lib/mpi/build
208 $..\/../../b2 
209 ]
210
211 [endsect:build]
212 [section:tests Tests]
213
214 You can run the regression tests with:
215 [pre
216 $cd <boost distribution>\/lib/mpi/test
217 $..\/../../b2
218 ]
219
220 [endsect:tests]
221 [section:installation Installation]
222
223 To install the whole Boost distribution:
224 [pre
225 $cd <boost distribution>
226 $./b2 install
227 ]
228
229 [endsect:installation]
230 [endsect:config]
231 [section:using Using Boost.MPI]
232
233 To build applications based on Boost.MPI, compile and link them as you
234 normally would for MPI programs, but remember to link against the
235 `boost_mpi` and `boost_serialization` libraries, e.g.,
236
237 [pre
238 mpic++ -I/path/to/boost/mpi my_application.cpp -Llibdir \
239   -lboost_mpi-gcc-mt-1_35 -lboost_serialization-gcc-d-1_35.a
240 ]
241
242 If you plan to use the [link mpi.python Python bindings] for
243 Boost.MPI in conjunction with the C++ Boost.MPI, you will also need to
244 link against the boost_mpi_python library, e.g., by adding
245 `-lboost_mpi_python-gcc-mt-1_35` to your link command. This step will
246 only be necessary if you intend to [link mpi.python.user_data
247 register C++ types] or use the [link
248 mpi.python.skeleton_content skeleton/content mechanism] from
249 within Python.
250
251 [endsect:using]
252 [endsect:getting_started]