MPLR is a MPL revision.
MPLR is a message passing library written in C++17 based on the Message Passing Interface (MPI) standard. Since the C++ API has been dropped from the MPI standard in version 3.1, it is the aim of MPLR to provide a modern C++ message passing library for high performance computing.
MPLR will neither bring all functions of the C language MPI-API to C++ nor provide a direct mapping of the C API to some C++ functions and classes. The library's focus lies on the MPI core message passing functions, ease of use, type safety, and elegance. The aim of MPLR is to provide an idiomatic C++ message passing library without introducing a significant overhead compared to utilizing MPI via its plain C-API. This library is most useful for developers who have at least some basic knowledge of the Message Passing Interface standard and would like to utilize it via a more user-friendly interface in modern C++. Unlike Boost.MPI, MPLR does not rely on an external serialization library and has a negligible run-time overhead.
MPLR assumes that the underlying MPI implementation supports the version 3.1 of the Message Passing Interface standard. Future versions of MPLR may also employ features of the new version 4.0 or later MPI versions.
MPLR gives currently access via a convenient C++ interface to the following features of the Message Passing Interface standard:
- environmental management (implicit initialization and finalization, timers, but no error handling).
- point-to-point communication (blocking and non-blocking),
- collective communication (blocking and non-blocking),
- derived data types (happens automatically for many custom data types or via the
base_struct_builderhelper class and the layout classes of MPLR), - communicator- and group-management,
- process topologies (cartesian and graph topologies),
- inter-communicators,
- dynamic process creation and
- file i/o.
Currently, the following MPI features are not yet supported by MPLR:
- error handling and
- one-sided communication.
Although MPLR covers a subset of the MPI functionality only, it has probably the largest MPI-feature coverage among all alternative C++ interfaces to MPI.
MPLR is built on top of the Message Passing Interface (MPI) standard. Therefore, MPLR shares many concepts known from the MPI standard, e.g., the concept of a communicator. Communicators manage the message exchange between different processes, i.e., messages are sent and received with the help of a communicator.
The MPLR environment provides a global default communicator comm_world, which will
be used in the following Hello-World program. The program prints out some information
about each process:
- its rank,
- the total number of processes and
- the computer's name the process is running on.
If there are two or more processes, a message is sent from process 0 to process 1, which is also printed.
#include <cstdlib>
#include <iostream>
#include "mplr/mplr.hpp"
int main() {
// initialize environment
mplr::init();
// get communicator "world"
const auto comm_world{mplr::comm_world()};
// each process prints a message containing the processor name, the rank
// in communicator world and the size of communicator world
// output may depend on the underlying MPI implementation
std::cout << "Hello world! I am running on \"" << mplr::processor_name()
<< "\". My rank is " << comm_world.rank() << " out of " << comm_world.size()
<< " processes.\n";
// if there are two or more processes send a message from process 0 to process 1
if (comm_world.size() >= 2) {
if (comm_world.rank() == 0) {
std::string message{"Hello world!"};
comm_world.send(message, 1); // send message to rank 1
} else if (comm_world.rank() == 1) {
std::string message;
comm_world.recv(message, 0); // receive message from rank 0
std::cout << "got: \"" << message << "\"\n";
}
}
return EXIT_SUCCESS;
}For further documentation see the documentation, the blog posts
the presentation
- Message Passing mit modernem C++ (German only),
the book
- Parallel Programming for Science and Engineering by Victor Eijkhout, or
the workshop material
and the files in the examples directory of the source package.