21#include <kassert/kassert.hpp>
24#include "kamping/assertion_levels.hpp"
27#include "kamping/span.hpp"
51template <InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
233 template <
typename T>
235#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
240#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
252 template <
typename T = std::
byte>
254#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
261#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
265 static_cast<size_t>(
buffer_size) %
sizeof(T) ==
size_t{0},
266 "The buffer size is not a multiple of the size of T."
286#if defined(__GNUC__) and not defined(__clang__)
287 #pragma GCC diagnostic push
288 #pragma GCC diagnostic ignored "-Wterminate"
290 KASSERT(
false,
"MPI_Finalized call failed.");
291#if defined(__GNUC__) and not defined(__clang__)
292 #pragma GCC diagnostic pop
299#if defined(__GNUC__) and not defined(__clang__)
300 #pragma GCC diagnostic push
301 #pragma GCC diagnostic ignored "-Wterminate"
304#if defined(__GNUC__) and not defined(__clang__)
305 #pragma GCC diagnostic pop
312 bool _finalize =
false;
313#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
Helper functions that make casts safer.
Wrapper for MPI functions that don't require a communicator. If the template parameter init_finalize_...
Definition environment.hpp:52
Environment(int &argc, char **&argv)
Calls MPI_Init with arguments.
Definition environment.hpp:58
void buffer_attach(Span< T > buffer)
Attach a buffer to use for buffered send operations to the environment.
Definition environment.hpp:234
static int tag_upper_bound()
The upper bound on message tags defined by the MPI implementation.
Definition environment.hpp:171
bool initialized() const
Checks whether MPI_Init has been called.
Definition environment.hpp:138
static void free(MPI_Datatype type)
Free an MPI data type.
Definition environment.hpp:198
void init(int &argc, char **&argv) const
Calls MPI_Init with arguments. Checks whether MPI_Init has already been called first.
Definition environment.hpp:115
void finalize() const
Calls MPI_Finalize and frees all registered MPI data types.
Definition environment.hpp:128
static bool is_valid_tag(int tag)
Checks if the given tag is a valid message tag.
Definition environment.hpp:181
static void commit(MPI_Datatype type)
Commit an MPI data type (without registering it with KaMPIng).
Definition environment.hpp:192
void init_unchecked(int &argc, char **&argv) const
Calls MPI_Init with arguments and doesn't check whether MPI_Init has already been called.
Definition environment.hpp:96
static double wtime()
Returns the elapsed time since an arbitrary time in the past.
Definition environment.hpp:158
static size_t const bsend_overhead
Definition environment.hpp:224
static void free_registered_mpi_types()
Free all registered MPI data types.
Definition environment.hpp:215
static void register_mpi_type(MPI_Datatype type)
Register a new MPI data type to KaMPIng that will be freed when using Environment to finalize MPI.
Definition environment.hpp:187
bool finalized() const
Checks whether MPI_Finalize has been called.
Definition environment.hpp:148
~Environment()
Calls MPI_Finalize if finalize() has not been called before. Also frees all registered MPI data types...
Definition environment.hpp:274
static void commit_and_register(MPI_Datatype type)
Commit an MPI data type and register it with KaMPIng.
Definition environment.hpp:206
void init_unchecked() const
Calls MPI_Init without arguments and doesn't check whether MPI_Init has already been called.
Definition environment.hpp:86
Span< T > buffer_detach()
Detach a buffer attached via buffer_attach().
Definition environment.hpp:253
void init() const
Calls MPI_Init without arguments. Checks whether MPI_Init has already been called first.
Definition environment.hpp:103
static double wtick()
Returns the resolution of Environment::wtime().
Definition environment.hpp:165
Environment()
Calls MPI_Init without arguments.
Definition environment.hpp:72
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
The exception type used when an MPI call did not return MPI_SUCCESS.
Definition error_handling.hpp:47
InitMPIMode
Configuration for the behavior of the constructors and destructor of kamping::Environment.
Definition environment.hpp:37
@ InitFinalize
Call MPI_Init in the constructor of Environment.
@ NoInitFinalize
Do not call MPI_Init in the constructor of Environment.
@ InitFinalizeIfNecessary
Environment< InitMPIMode::NoInitFinalize > const mpi_env
A global environment object to use when you don't want to create a new Environment object.
Definition environment.hpp:323
#define THROW_IF_MPI_ERROR(error_code, function)
Wrapper around THROWING_KASSERT for MPI errors.
Definition error_handling.hpp:33
auto tag(internal::any_tag_t)
Indicates to use MPI_ANY_TAG as tag in the underlying call.
Definition named_parameters.hpp:1064
std::vector< MPI_Datatype > registered_mpi_types
A global list of MPI data types registered to KaMPIng.
Definition environment.hpp:33