1
- Compiling MPI applications
2
- ==========================
1
+ Building MPI applications
2
+ =========================
3
3
4
4
.. JMS How can I create a TOC just for this page here at the top?
5
5
@@ -44,6 +44,10 @@ Simply use the following instead:
44
44
45
45
shell$ mpicc my_mpi_application.c -o my_mpi_application
46
46
47
+ .. caution :: It is *absolutely not sufficient* to simply add ``-lmpi``
48
+ to your link line and assume that you will obtain a valid
49
+ Open MPI executable.
50
+
47
51
Note that Open MPI's wrapper compilers do not do any actual compiling
48
52
or linking; all they do is manipulate the command line and add in all
49
53
the relevant compiler / linker flags and then invoke the underlying
@@ -57,7 +61,7 @@ fault of the Open MPI wrapper compiler.
57
61
Wait |mdash | what is ``mpifort ``? Shouldn't I use ``mpif77 `` and ``mpif90 ``?
58
62
-----------------------------------------------------------------------------
59
63
60
- ``mpifort `` is a new name for the Fortran wrapper compiler that
64
+ ``mpifort `` is the new name for the Fortran wrapper compiler that
61
65
debuted in Open MPI v1.7.
62
66
63
67
*It supports compiling all versions of Fortran *, and *utilizing all
@@ -68,27 +72,30 @@ mpi_f08``). There is no need to distinguish between "Fortran 77"
68
72
worry about what dialect it is, nor which MPI Fortran interface it
69
73
uses.
70
74
71
- Other MPI implementations will also soon support a wrapper compiler
72
- named ``mpifort ``, so hopefully we can move the whole world to this
73
- simpler wrapper compiler name, and eliminate the use of `` mpif77 `` and
74
- ``mpif90 ``.
75
+ Other MPI implementations also support a wrapper compiler named
76
+ ``mpifort ``; you do not lose any portability by using `` mpifort ``.
77
+ Please help us move the whole world to this simpler wrapper compiler
78
+ name, and completely eliminate the use of `` mpif77 `` and ``mpif90 ``.
75
79
76
- .. important :: ``mpif77`` and ``mpif90`` are
77
- deprecated as of Open MPI v1.7.
80
+ .. important :: ``mpif77`` and ``mpif90`` were deprecated back in Open
81
+ MPI v1.7.
78
82
79
- Although ``mpif77 `` and ``mpif90 `` still exist in Open MPI v1.7 for
80
- legacy reasons, they will likely be removed in some (undetermined)
81
- future release. It is in your interest to convert to ``mpifort `` now.
83
+ .. warning :: Although ``mpif77`` and ``mpif90`` still exist in Open
84
+ MPI for legacy reasons, they will likely be removed in
85
+ some (undetermined) future release. It is in your
86
+ interest to convert to ``mpifort `` now.
82
87
83
- Also note that these names are literally just sym links to `` mpifort ``
84
- under the covers. So you're using `` mpifort `` whether you realize it
85
- or not. :-)
88
+ Also note that the `` mpif77 `` and `` mpif90 `` names are literally just
89
+ symolic links to `` mpifort `` under the covers. Meaning: you're using
90
+ `` mpifort `` whether you realize it or not.
86
91
87
92
Basically, the 1980's called; they want their ``mpif77 `` wrapper
88
93
compiler back. *Let's let them have it. *
89
94
90
95
/////////////////////////////////////////////////////////////////////////
91
96
97
+ .. _faq-building-mpi-apps-wrapper-compiler-alternatives-label :
98
+
92
99
I can't / don't want to use Open MPI's wrapper compilers. What do I do?
93
100
-----------------------------------------------------------------------
94
101
@@ -106,12 +113,22 @@ Things are *much* better these days; wrapper compilers can handle
106
113
almost any situation, and are far more reliable than you attempting to
107
114
hard-code the Open MPI-specific compiler and linker flags manually.
108
115
109
- That being said, there *are * some |mdash | very, very few |mdash | situations
110
- where using wrapper compilers can be problematic |mdash | such as nesting
111
- multiple wrapper compilers of multiple projects. Hence, Open MPI
112
- provides a workaround to find out what command line flags you need to
113
- compile MPI applications. There are generally two sets of flags that
114
- you need: compile flags and link flags.
116
+ That being said, there *are * some situations |mdash | very, very few
117
+ situations |mdash | where using wrapper compilers can be problematic
118
+ |mdash | such as nesting multiple wrapper compilers of multiple
119
+ projects. Hence, Open MPI provides a workaround to find out what
120
+ command line flags you need to compile MPI applications. There are
121
+ generally two sets of flags that you need: compile flags and link
122
+ flags.
123
+
124
+ You can use one of two methods to dynamically discover what compiler /
125
+ linker flags are necessary on your system:
126
+
127
+ #. Use the ``--showme `` flags to Open MPI's wrapper compilers, or
128
+ #. Use the ``pkg-config(1) `` system.
129
+
130
+ Here's an example showing the use of the ``--showme `` wrapper compiler
131
+ flags:
115
132
116
133
.. code-block :: sh
117
134
:linenos:
@@ -126,16 +143,7 @@ The ``--showme:*`` flags work with all Open MPI wrapper compilers
126
143
(specifically: ``mpicc ``, ``mpiCC `` / ``mpicxx `` / ``mpic++ ``,
127
144
``mpifort ``, and if you really must use them, ``mpif77 ``, ``mpif90 ``).
128
145
129
- Hence, if you need to use some compiler other than Open MPI's wrapper
130
- compilers, we advise you to run the appropriate Open MPI wrapper
131
- compiler with the ``--showme `` flags to see what Open MPI needs to
132
- compile / link, and then use those with your compiler.
133
-
134
- .. caution :: It is *absolutely not sufficient* to simply add ``-lmpi``
135
- to your link line and assume that you will obtain a valid
136
- Open MPI executable.
137
-
138
- .. caution :: It is almost never a good idea to hard-code these results
146
+ .. warning :: It is almost never a good idea to hard-code these results
139
147
in a Makefile (or other build system). It is almost
140
148
always best to run (for example) ``mpicc
141
149
--showme:compile `` in a dynamic fashion to find out what
@@ -151,8 +159,34 @@ compile / link, and then use those with your compiler.
151
159
my_app: my_app.c
152
160
$(CC) $(MPI_COMPILE_FLAGS) my_app.c $(MPI_LINK_FLAGS) -o my_app
153
161
162
+ And here's an example showing how to use ``pkg-config `` |mdash | you
163
+ may need to add ``$prefix/lib/pkgconfig `` to the ``PKG_CONFIG_PATH ``
164
+ environment variable for Open MPI's config files to be found:
165
+
166
+ .. code-block :: sh
167
+ :linenos:
168
+
169
+ # Show the flags necessary to compile MPI C applications
170
+ shell$ export PKG_CONFIG_PATH=/opt/openmpi/lib/pkgconfig
171
+ shell$ pkg-config ompi-c --cflags
172
+
173
+ # Show the flags necessary to link MPI C applications
174
+ shell$ pkg-config ompi-c --libs
175
+
176
+ Open MPI supplies multiple ``pkg-config(1) `` configuration files; one
177
+ for each different wrapper compiler (language):
178
+
179
+ * ``ompi ``: Synonym for ``ompi-c ``; Open MPI applications using the C
180
+ MPI bindings
181
+ * ``ompi-c ``: Open MPI applications using the C MPI bindings
182
+ * ``ompi-cxx ``: Open MPI applications using the C MPI bindings
183
+ * ``ompi-fort ``: Open MPI applications using the Fortran MPI bindings
184
+
185
+
154
186
/////////////////////////////////////////////////////////////////////////
155
187
188
+ .. _faq-building-mpi-apps-override-wrapper-flags-label :
189
+
156
190
How do I override the flags specified by Open MPI's wrapper compilers?
157
191
----------------------------------------------------------------------
158
192
@@ -170,6 +204,8 @@ to ``$prefix/share/openmpi/WRAPPER_NAME-wrapper-data.txt``. A
170
204
few environment variables are available for run-time replacement of
171
205
the wrapper's default values (from the text files):
172
206
207
+ .. note :: You may need to scroll right in the following table.
208
+
173
209
.. list-table ::
174
210
:header-rows: 1
175
211
@@ -284,7 +320,7 @@ interesting for end-users:
284
320
285
321
/////////////////////////////////////////////////////////////////////////
286
322
287
- .. _faq-mpi-apps-showme-label :
323
+ .. _faq-building- mpi-apps-showme-label :
288
324
289
325
How can I tell what the wrapper compiler default flags are?
290
326
-----------------------------------------------------------
@@ -438,7 +474,7 @@ Due to popular user request, Open MPI changed its policy starting with
438
474
v1.7.4: by default on supported systems, Open MPI's wrapper compilers
439
475
*do * insert ``-rpath `` (or similar) flags when linking MPI applications.
440
476
You can see the exact flags added by the ``--showme `` functionality
441
- described in :ref: `this FAQ entry <faq-mpi-apps-showme-label >`.
477
+ described in :ref: `this FAQ entry <faq-building- mpi-apps-showme-label >`.
442
478
443
479
This behavior can be disabled by configuring Open MPI with the
444
480
``--disable-wrapper-rpath `` CLI option.
@@ -529,6 +565,6 @@ Starting with v4.0.0, Open MPI |mdash| by default |mdash| removes the
529
565
prototypes for MPI symbols that were deprecated in 1996 and finally
530
566
removed from the MPI standard in MPI-3.0 (2012).
531
567
532
- :doc: `See this FAQ category </faq/mpi-removed >` for much more
533
- information, including how to easily update your MPI application
568
+ :doc: `See this FAQ category </faq/removed- mpi-constructs >` for much
569
+ more information, including how to easily update your MPI application
534
570
to avoid these problems.
0 commit comments