PSCF v1.1
MpiStructBuilder.cpp
1#ifdef UTIL_MPI
2
3#include "MpiStructBuilder.h"
4#include <util/global.h>
5
6namespace Util
7{
8
11 : base_(0),
12 nMember_(0)
13 {}
14
15 /*
16 * Record address of a pointer to an instance of the class.
17 */
18 void MpiStructBuilder::setBase(void* objectAddress)
19 {
20 base_ = MPI::Get_address(objectAddress);
21 }
22
23 /*
24 * Add a member variable to the struct definition
25 */
26 void MpiStructBuilder::addMember(void* memberAddress, MPI::Datatype type, int count)
27 {
28 addresses_[nMember_] = MPI::Get_address(memberAddress);
29 types_[nMember_] = type;
30 counts_[nMember_] = count;
31 ++nMember_;
32 }
33
34 /*
35 * Build and commit a user-defined MPI Struct datatype.
36 *
37 * \param mpiType new MPI datatype (on output).
38 */
39 void MpiStructBuilder::commit(MPI::Datatype& mpiType)
40 {
41 for (int i = 0; i < nMember_; ++i) {
42 addresses_[i] = addresses_[i] - base_;
43 }
44 mpiType =
45 MPI::Datatype::Create_struct(nMember_, counts_, addresses_, types_);
46 mpiType.Commit();
47 }
48
49}
50#endif
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.
MpiStructBuilder()
Default constructor.
void commit(MPI::Datatype &newType)
Build and commit a user-defined MPI Struct datatype.
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1