TRIQS/mpi 1.3.0
C++ interface to MPI
Loading...
Searching...
No Matches
MPI essentials

Detailed Description

Simplify the initialization/finalization of an MPI environment and the usage of an MPI_Comm object by wrapping it in a C++ class.

A typical Hello world! program using mpi::environment and mpi::communicator is as easy as:

#include <iostream>
int main(int argc, char** argv) {
// initialize MPI environment
mpi::environment env(argc, argv);
// get rank and greet world
int rank = world.rank();
std::cout << "Hello from processor " << rank << "\n";
}
C++ wrapper around MPI_Comm providing various convenience functions.
int rank() const
Get the rank of the calling process in the communicator.
Provides a C++ wrapper class for an MPI_Comm object.
RAII class to initialize and finalize MPI.

Output (depends on the number of processes and the order is arbitrary):

Hello from processor 2
Hello from processor 3
Hello from processor 0
Hello from processor 1

Classes

class  mpi::communicator
 C++ wrapper around MPI_Comm providing various convenience functions. More...
 
struct  mpi::environment
 RAII class to initialize and finalize MPI. More...
 

Functions

bool mpi::is_initialized () noexcept
 Check if MPI has been initialized.
 

Variables

static const bool mpi::has_env
 Boolean variable that is true, if one of the environment variables OMPI_COMM_WORLD_RANK, PMI_RANK, CRAY_MPICH_VERSION or FORCE_MPI_INIT is set, false otherwise.
 

Function Documentation

◆ is_initialized()

bool mpi::is_initialized ( )
inlinenodiscardnoexcept

#include <mpi/environment.hpp>

Check if MPI has been initialized.

It throws an exception in case a call to the MPI C library fails.

Returns
True if MPI_Init has been called, false otherwise.

Definition at line 42 of file environment.hpp.

Variable Documentation

◆ has_env

const bool mpi::has_env
static

#include <mpi/environment.hpp>

Initial value:
= []() {
if (std::getenv("OMPI_COMM_WORLD_RANK") != nullptr or std::getenv("PMI_RANK") != nullptr or std::getenv("CRAY_MPICH_VERSION") != nullptr
or std::getenv("FORCE_MPI_INIT") != nullptr)
return true;
else
return false;
}()

Boolean variable that is true, if one of the environment variables OMPI_COMM_WORLD_RANK, PMI_RANK, CRAY_MPICH_VERSION or FORCE_MPI_INIT is set, false otherwise.

The environment variables are set, when a program is executed with mpirun or mpiexec.

Definition at line 54 of file environment.hpp.