Find a Message Passing Interface (MPI) implementation.
The Message Passing Interface (MPI) is a library used to write high-performance distributed-memory parallel applications, and is typically deployed on a cluster. MPI is a standard interface (defined by the MPI forum) for which many implementations are available.
The module exposes the components C
, CXX
, MPICXX
and Fortran
. Each of these controls the various MPI languages to search for. The difference between CXX
and MPICXX
is that CXX
refers to the MPI C API being usable from C++, whereas MPICXX
refers to the MPI-2 C++ API that was removed again in MPI-3.
Depending on the enabled components the following variables will be set:
MPI_FOUND
MPICXX
component does not affect this variable.MPI_VERSION
This module will set the following variables per language in your project, where <lang>
is one of C, CXX, or Fortran:
MPI_<lang>_FOUND
<lang>
were found and that simple MPI test programs compile with the provided settings.MPI_<lang>_COMPILER
<lang>
if such a program exists.MPI_<lang>_COMPILE_OPTIONS
<lang>
, given as a ;-list.MPI_<lang>_COMPILE_DEFINITIONS
<lang>
, given as a ;-list.MPI_<lang>_INCLUDE_DIRS
MPI_<lang>_LINK_FLAGS
MPI_<lang>_LIBRARIES
Additionally, the following IMPORTED
targets are defined:
MPI::MPI_<lang>
<lang>
.The following variables indicating which bindings are present will be defined:
MPI_MPICXX_FOUND
MPI_Fortran_HAVE_F77_HEADER
mpif.h
is available.MPI_Fortran_HAVE_F90_MODULE
mpi
can be used for accessing MPI (MPI-2 and higher only).MPI_Fortran_HAVE_F08_MODULE
mpi_f08
is available to MPI programs (MPI-3 and higher only).If possible, the MPI version will be determined by this module. The facilities to detect the MPI version were introduced with MPI-1.2, and therefore cannot be found for older MPI versions.
MPI_<lang>_VERSION_MAJOR
<lang>
by the MPI distribution.MPI_<lang>_VERSION_MINOR
<lang>
by the MPI distribution.MPI_<lang>_VERSION
<lang>
by the MPI distribution.Note that there’s no variable for the C bindings being accessible through mpi.h
, since the MPI standards always have required this binding to work in both C and C++ code.
For running MPI programs, the module sets the following variables
MPIEXEC_EXECUTABLE
MPIEXEC_NUMPROC_FLAG
mpiexec
before giving it the number of processors to run on.MPIEXEC_MAX_NUMPROCS
MPIEXEC_PREFLAGS
mpiexec
directly before the executable to run.MPIEXEC_POSTFLAGS
mpiexec
after other flags.This module performs a three step search for an MPI implementation:
CMAKE_<LANG>_COMPILER
or if they’re on a Cray system.For controlling the second step, the following variables may be set:
MPI_<lang>_COMPILER
MPI_<lang>_COMPILER_FLAGS
MPI_COMPILER_FLAGS
MPI_<lang>_COMPILER_FLAGS
if no language specific flag has been given. Empty by default.MPI_EXECUTABLE_SUFFIX
.mpich
or .openmpi
to prefer the one or the other on Debian and its derivatives.In order to control the guessing step, the following variable may be set:
MPI_GUESS_LIBRARY_NAME
MSMPI
and MPICH2
. If set, only the given library will be searched for. By default, MSMPI
will be preferred over MPICH2
if both are available. This also sets MPI_SKIP_COMPILER_WRAPPER
to true
, which may be overridden.Each of the search steps may be skipped with the following control variables:
MPI_ASSUME_NO_BUILTIN_MPI
MPI_SKIP_COMPILER_WRAPPER
MPI_SKIP_GUESSING
Additionally, the following control variable is available to change search behavior:
MPI_CXX_SKIP_MPICXX
If the find procedure fails for a variable MPI_<lang>_WORKS
, then the settings detected by or passed to the module did not work and even a simple MPI test program failed to compile.
If all of these parameters were not sufficient to find the right MPI implementation, a user may disable the entire autodetection process by specifying both a list of libraries in MPI_<lang>_LIBRARIES
and a list of include directories in MPI_<lang>_ADDITIONAL_INCLUDE_DIRS
. Any other variable may be set in addition to these two. The module will then validate the MPI settings and store the settings in the cache.
The variable MPI_<lang>_INCLUDE_DIRS
will be assembled from the following variables. For C and CXX:
MPI_<lang>_HEADER_DIR
mpi.h
header on disk.For Fortran:
MPI_Fortran_F77_HEADER_DIR
mpif.h
, if it exists.MPI_Fortran_MODULE_DIR
mpi
or mpi_f08
modules, if available.For all languages the following variables are additionally considered:
MPI_<lang>_ADDITIONAL_INCLUDE_DIRS
MPI_<include_name>_INCLUDE_DIR
<include_name>
.MPI_<lang>_ADDITIONAL_INCLUDE_VARS
<include_name>
that will be added to the include locations of <lang>
.The variable MPI_<lang>_LIBRARIES
will be assembled from the following variables:
MPI_<lib_name>_LIBRARY
<lib_name>
for use with MPI.MPI_<lang>_LIB_NAMES
<lib_name>
that will be added to the include locations of <lang>
.When using MPIEXEC_EXECUTABLE
to execute MPI applications, you should typically use all of the MPIEXEC_EXECUTABLE
flags as follows:
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS
where EXECUTABLE
is the MPI program, and ARGS
are the arguments to pass to the MPI program.
The module can perform some advanced feature detections upon explicit request.
Important notice: The following checks cannot be performed without executing an MPI test program. Consider the special considerations for the behavior of try_run()
during cross compilation. Moreover, running an MPI program can cause additional issues, like a firewall notification on some systems. You should only enable these detections if you absolutely need the information.
If the following variables are set to true, the respective search will be performed:
MPI_DETERMINE_Fortran_CAPABILITIES
MPI_SUBARRAYS_SUPPORTED
and MPI_ASYNC_PROTECTS_NONBLOCKING
are and make their values available as MPI_Fortran_<binding>_SUBARRAYS
and MPI_Fortran_<binding>_ASYNCPROT
, where <binding>
is one of F77_HEADER
, F90_MODULE
and F08_MODULE
.MPI_DETERMINE_LIBRARY_VERSION
MPI_Get_library_version
and make it available as MPI_<lang>_LIBRARY_VERSION_STRING
. This information is usually tied to the runtime component of an MPI implementation and might differ depending on <lang>
. Note that the return value is entirely implementation defined. This information might be used to identify the MPI vendor and for example pick the correct one of multiple third party binaries that matches the MPI vendor.For backward compatibility with older versions of FindMPI, these variables are set, but deprecated:
MPI_COMPILER MPI_LIBRARY MPI_EXTRA_LIBRARY MPI_COMPILE_FLAGS MPI_INCLUDE_PATH MPI_LINK_FLAGS MPI_LIBRARIES
In new projects, please use the MPI_<lang>_XXX
equivalents. Additionally, the following variables are deprecated:
MPI_<lang>_COMPILE_FLAGS
MPI_<lang>_COMPILE_OPTIONS
and MPI_<lang>_COMPILE_DEFINITIONS
instead.MPI_<lang>_INCLUDE_PATH
MPI_<lang>_INCLUDE_DIRS
and for specifying folders use MPI_<lang>_ADDITIONAL_INCLUDE_DIRS
instead.MPIEXEC
MPIEXEC_EXECUTABLE
instead.
© 2000–2019 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/v3.15/module/FindMPI.html