KaMPIng 0.1.1
Flexible and (near) zero-overhead C++ bindings for MPI
Loading...
Searching...
No Matches
kamping::Environment< init_finalize_mode > Class Template Reference

Wrapper for MPI functions that don't require a communicator. If the template parameter init_finalize_mode is set to InitMPIMode::InitFinalize (default), MPI_Init is called in the constructor, and MPI_Finalize is called in the destructor. More...

#include <environment.hpp>

Public Member Functions

 Environment (int &argc, char **&argv)
 Calls MPI_Init with arguments.
 
 Environment ()
 Calls MPI_Init without arguments.
 
void init_unchecked () const
 Calls MPI_Init without arguments and doesn't check whether MPI_Init has already been called.
 
void init_unchecked (int &argc, char **&argv) const
 Calls MPI_Init with arguments and doesn't check whether MPI_Init has already been called.
 
void init () const
 Calls MPI_Init without arguments. Checks whether MPI_Init has already been called first.
 
void init (int &argc, char **&argv) const
 Calls MPI_Init with arguments. Checks whether MPI_Init has already been called first.
 
void finalize () const
 Calls MPI_Finalize and frees all registered MPI data types.
 
bool initialized () const
 Checks whether MPI_Init has been called.
 
bool finalized () const
 Checks whether MPI_Finalize has been called.
 
template<typename T >
void buffer_attach (Span< T > buffer)
 Attach a buffer to use for buffered send operations to the environment.
 
template<typename T = std::byte>
Span< T > buffer_detach ()
 Detach a buffer attached via buffer_attach().
 
 ~Environment ()
 Calls MPI_Finalize if finalize() has not been called before. Also frees all registered MPI data types.
 

Static Public Member Functions

static double wtime ()
 Returns the elapsed time since an arbitrary time in the past.
 
static double wtick ()
 Returns the resolution of Environment::wtime().
 
static int tag_upper_bound ()
 The upper bound on message tags defined by the MPI implementation.
 
static bool is_valid_tag (int tag)
 Checks if the given tag is a valid message tag.
 
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.
 
static void commit (MPI_Datatype type)
 Commit an MPI data type (without registering it with KaMPIng).
 
static void free (MPI_Datatype type)
 Free an MPI data type.
 
static void commit_and_register (MPI_Datatype type)
 Commit an MPI data type and register it with KaMPIng.
 
static void free_registered_mpi_types ()
 Free all registered MPI data types.
 

Static Public Attributes

static size_t const bsend_overhead = MPI_BSEND_OVERHEAD
 

Detailed Description

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
class kamping::Environment< init_finalize_mode >

Wrapper for MPI functions that don't require a communicator. If the template parameter init_finalize_mode is set to InitMPIMode::InitFinalize (default), MPI_Init is called in the constructor, and MPI_Finalize is called in the destructor.

Note that MPI_Init and MPI_Finalize are global, meaning that if they are called on an Environment object they must not be called again in any Environment object (or directly vie the MPI_* calls).

Constructor & Destructor Documentation

◆ Environment()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
kamping::Environment< init_finalize_mode >::Environment ( int & argc,
char **& argv )
inline

Calls MPI_Init with arguments.

Parameters
argcNumber of arguments.
argvThe arguments.

Member Function Documentation

◆ buffer_attach()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
template<typename T >
void kamping::Environment< init_finalize_mode >::buffer_attach ( Span< T > buffer)
inline

Attach a buffer to use for buffered send operations to the environment.

Template Parameters
TThe type of the buffer.
Parameters
bufferThe buffer. The user is responsible for allocating the buffer, attaching it, detaching it and freeing the memory after detaching. For convenience, the buffer may be a span of any type, but the type is ignored by MPI.

◆ buffer_detach()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
template<typename T = std::byte>
Span< T > kamping::Environment< init_finalize_mode >::buffer_detach ( )
inline

Detach a buffer attached via buffer_attach().

Template Parameters
TThe type of the span to return. Defaults to std::byte.
Returns
A span pointing to the previously attached buffer. The type of the returned span can be controlled via the parameter T. The pointer to the buffer stored internally by MPI is reinterpreted accordingly.

◆ commit_and_register()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static void kamping::Environment< init_finalize_mode >::commit_and_register ( MPI_Datatype type)
inlinestatic

Commit an MPI data type and register it with KaMPIng.

See also
commit()
register_type()

◆ finalize()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
void kamping::Environment< init_finalize_mode >::finalize ( ) const
inline

Calls MPI_Finalize and frees all registered MPI data types.

Even if you chose InitMPIMode::InitFinalize, you might want to call this function: As MPI_Finalize could potentially return an error, this function can be used if you want to be able to handle that error. Otherwise the destructor will call MPI_Finalize and not throw on any errors returned.

◆ finalized()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
bool kamping::Environment< init_finalize_mode >::finalized ( ) const
inline

Checks whether MPI_Finalize has been called.

Returns
true if MPI_Finalize has been called, false otherwise.

◆ free_registered_mpi_types()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static void kamping::Environment< init_finalize_mode >::free_registered_mpi_types ( )
inlinestatic

Free all registered MPI data types.

Only call this when you no longer want to use any MPI data types created by KaMPIng as other KaMPIng functions will assume the created types still exist.

◆ init()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
void kamping::Environment< init_finalize_mode >::init ( int & argc,
char **& argv ) const
inline

Calls MPI_Init with arguments. Checks whether MPI_Init has already been called first.

Parameters
argcNumber of arguments.
argvThe arguments.

◆ init_unchecked()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
void kamping::Environment< init_finalize_mode >::init_unchecked ( int & argc,
char **& argv ) const
inline

Calls MPI_Init with arguments and doesn't check whether MPI_Init has already been called.

Parameters
argcNumber of arguments.
argvThe arguments.

◆ initialized()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
bool kamping::Environment< init_finalize_mode >::initialized ( ) const
inline

Checks whether MPI_Init has been called.

Returns
true if MPI_Init has been called, false otherwise.

◆ is_valid_tag()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static bool kamping::Environment< init_finalize_mode >::is_valid_tag ( int tag)
inlinestatic

Checks if the given tag is a valid message tag.

Returns
Whether the tag is valid.

◆ register_mpi_type()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static void kamping::Environment< init_finalize_mode >::register_mpi_type ( MPI_Datatype type)
inlinestatic

Register a new MPI data type to KaMPIng that will be freed when using Environment to finalize MPI.

Parameters
typeThe MPI data type to register.

◆ tag_upper_bound()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static int kamping::Environment< init_finalize_mode >::tag_upper_bound ( )
inlinestatic

The upper bound on message tags defined by the MPI implementation.

Returns
The upper bound for tags.

◆ wtick()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static double kamping::Environment< init_finalize_mode >::wtick ( )
inlinestatic

Returns the resolution of Environment::wtime().

Returns
The resolution in seconds.

◆ wtime()

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
static double kamping::Environment< init_finalize_mode >::wtime ( )
inlinestatic

Returns the elapsed time since an arbitrary time in the past.

Returns
The elapsed time in seconds.

Member Data Documentation

◆ bsend_overhead

template<InitMPIMode init_finalize_mode = InitMPIMode::InitFinalize>
size_t const kamping::Environment< init_finalize_mode >::bsend_overhead = MPI_BSEND_OVERHEAD
inlinestatic

Provides an upper bound on the additional memory required by buffered send operations.


The documentation for this class was generated from the following file: