PSCF v1.1
Public Member Functions | List of all members
Util::MpiStructBuilder Class Reference

A MpiStructBuilder objects is used to create an MPI Struct datatype. More...

#include <MpiStructBuilder.h>

Public Member Functions

 MpiStructBuilder ()
 Default constructor. More...
 
void setBase (void *objectAddress)
 Set address of an class instance. More...
 
void addMember (void *memberAddress, MPI::Datatype type, int count=1)
 Add a new member variable to the type map. More...
 
void commit (MPI::Datatype &newType)
 Build and commit a user-defined MPI Struct datatype. More...
 

Detailed Description

A MpiStructBuilder objects is used to create an MPI Struct datatype.

This class provides methods to simplify construction of an MPI data type that can stores instances of a C struct or C++ class.

As an example, consider the creation of an MPI datatype MyClassMpi for class MyClass, with a class definition:

class MyClass
{
double x[3];
int i, j;
}

The code required to build and commit the MPI datatype MyClassMpi is:

MyClass object;
MPI::Datatype MyClassMpi;
builder.setBase(&object)
builder.addMember(&object.x, MPI::DOUBLE, 3);
builder.addMember(&object.i, MPI::INT, 1);
builder.addMember(&object.j, MPI::INT, 1);
builder.commit(&MyClassMpi);
A MpiStructBuilder objects is used to create an MPI Struct datatype.
void addMember(void *memberAddress, MPI::Datatype type, int count=1)
Add a new member variable to the type map.
void setBase(void *objectAddress)
Set address of an class instance.
void commit(MPI::Datatype &newType)
Build and commit a user-defined MPI Struct datatype.

The setBase and addMember classes require addresses of an instance of the class and of its members, respectively. These addresses must all refer to same instance. The commit method calculates the offset of each member by subtracting the address of the object from the address of each of its members.

Definition at line 54 of file MpiStructBuilder.h.

Constructor & Destructor Documentation

◆ MpiStructBuilder()

Util::MpiStructBuilder::MpiStructBuilder ( )

Default constructor.

Definition at line 10 of file MpiStructBuilder.cpp.

Member Function Documentation

◆ setBase()

void Util::MpiStructBuilder::setBase ( void *  objectAddress)

◆ addMember()

void Util::MpiStructBuilder::addMember ( void *  memberAddress,
MPI::Datatype  type,
int  count = 1 
)

Add a new member variable to the type map.

This method must be called once for each member. The address parameter must be a pointer to a member variable of the object whose base address is passed to setBase().

The count parameter is required only for array members: the default value of count=1 may be used for scalar members.

Parameters
memberAddressdisplacement of variable, in bytes.
typedata type (MPI::INT, MPI::DOUBLE, etc.)
countnumber of contiguous variables (array count)

Definition at line 26 of file MpiStructBuilder.cpp.

Referenced by Util::FArray< Data, Capacity >::commitMpiType(), Util::Pair< Data >::commitMpiType(), Util::IntVector::commitMpiType(), Util::Tensor::commitMpiType(), and Util::Vector::commitMpiType().

◆ commit()

void Util::MpiStructBuilder::commit ( MPI::Datatype &  newType)

Build and commit a user-defined MPI Struct datatype.

The setBase() method must be called once and the addMember() method must be called once per member before calling this method.

Parameters
newTypenew MPI datatype (on output).

Definition at line 39 of file MpiStructBuilder.cpp.

Referenced by Util::FArray< Data, Capacity >::commitMpiType(), Util::Pair< Data >::commitMpiType(), Util::IntVector::commitMpiType(), Util::Tensor::commitMpiType(), and Util::Vector::commitMpiType().


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