TRIQS/mpi 1.3.0
C++ interface to MPI
|
mpi is a header only library. To use it in your own C++
code, you simply have to include the relevant header files and tell your compiler/build system where it can find the necessary files.
For example:
In the following, we describe some common ways to achieve this (with special focus on CMake).
If you use CMake to build your source code, it is recommended to fetch the source code directly from the Github repository using CMake's FetchContent module:
Note that the above will also build goolgetest and the unit tests for mpi. To disable this, you can put set(Build_Tests OFF CACHE BOOL "" FORCE)
before fetching the content or by specifying -DBuild_Tests=OFF
on the command line.
If you have already installed mpi on your system by following the instructions from the Installation page, you can also make use of CMake's find_package command. This has the advantage that you don't need to download anything, i.e. no internet connection is required.
Let's assume that mpi has been installed to path_to_install_dir
. Then linking your project to mpi with CMake is as easy as
In case, CMake cannot find the package, you might have to tell it where to look for the mpi-config.cmake
file by setting the variable mpi_DIR
to path_to_install_dir/lib/cmake/mpi
or by sourcing the provided mpivars.sh
before running CMake:
You can also integrate mpi into our CMake project by placing the entire source tree in a subdirectory and call add_subdirectory()
:
Here, it is assumed that the mpi source tree is in a subdirectory deps/mpi
relative to your CMakeLists.txt
file.
Since mpi is header-only, you can also simply copy the relevant files directly into our project. For example, you could place the c++/mpi
directory from the mpi source tree into the include path of your project. You can then build or compile it with any available method.