TRIQS/mpi 2.0.0
C++ interface to MPI
Loading...
Searching...
No Matches
Utilities

Detailed Description

Miscellaneous helpers used throughout the mpi library.

The most user-facing entries are:

  • mpi::check_mpi_call: thin wrapper that turns a non-MPI_SUCCESS return code into a std::runtime_error. Used internally by every direct MPI C-API call in the library.
  • mpi::chunk and mpi::chunk_length: split a range across the processes of a communicator as evenly as possible. mpi::chunk returns the slice assigned to the calling rank; mpi::chunk_length is the integer-range variant with an optional min_size granularity.
  • mpi::MPICompatibleRange: concept that holds for contiguous, sized ranges whose value type satisfies mpi::has_mpi_type. This is what enables the fast paths in the generic range communication functions.

Concepts

concept  mpi::MPICompatibleRange
 A concept that checks if a range type is contiguous and sized and has an MPI compatible value type.

Functions

void mpi::check_mpi_call (int errcode, const std::string &mpi_routine)
 Check the success of an MPI call.
template<typename R>
auto mpi::chunk (R &&rg, communicator c={})
 Divide a given range as evenly as possible across the MPI processes in a communicator.
long mpi::chunk_length (long end, int n, int i, long min_size=1)
 Get the length of the ith subrange after splitting the integer range [0, end) as evenly as possible across n subranges.

Function Documentation

◆ check_mpi_call()

void mpi::check_mpi_call ( int errcode,
const std::string & mpi_routine )
inline

#include <mpi/utils.hpp>

Check the success of an MPI call.

It checks if the given error code returned by an MPI routine is equal to MPI_SUCCESS. If it isn't, it throws an exception.

Note
MPI routines only return an error code if the error handler is set to MPI_ERRORS_RETURN. By default, it uses MPI_ERRORS_ARE_FATAL, which aborts the program in case of an error.
Parameters
errcodeError code returned by an MPI routine.
mpi_routineName of the MPI routine used in the error message.

Definition at line 48 of file utils.hpp.

◆ chunk()

template<typename R>
auto mpi::chunk ( R && rg,
communicator c = {} )
nodiscard

#include <mpi/chunk.hpp>

Divide a given range as evenly as possible across the MPI processes in a communicator.

It calculates the subrange assigned to the calling process based on its rank in the given communicator and returns it as a slice of the original range.

Template Parameters
RRange type.
Parameters
rgRange to divide.
cmpi::communicator.
Returns
An itertools::sliced range assigned to the calling process.

Definition at line 71 of file chunk.hpp.

◆ chunk_length()

long mpi::chunk_length ( long end,
int n,
int i,
long min_size = 1 )
inlinenodiscard

#include <mpi/chunk.hpp>

Get the length of the ith subrange after splitting the integer range [0, end) as evenly as possible across n subranges.

The optional parameter min_size can be used to first divide the range into equal parts of size min_size before distributing them as evenly as possible across the number of specified subranges.

It is expected that min_size > 0 and that min_size is a divisor of end.

Parameters
endEnd of the integer range [0, end).
nNumber of subranges.
iIndex of the subrange of interest.
min_sizeMinimum size of the subranges.
Returns
Length of the ith subrange.

Definition at line 54 of file chunk.hpp.