C++ mpi module for stochmagnet_main Package
MPI_CoreToCoreBMessage.h
1 #ifndef MPI_CoreToCoreBMessage_H
2 #define MPI_CoreToCoreBMessage_H
3 
4 //iniherited class header
5 #include "MPI_Object.h"
6 
7 //environment header
8 #include "MPI_Environment.h"
9 
10 //mpi type header
11 #include "MPI_Type.h"
12 
34 template<typename T>
36 
37  //attributes
38 private :
39  static MPI_Status mStatus;
40 
41  T* mBuffer;
42  size_t mBufferMPISize;
43 
44  int mMPITSize;//MPI size of T
45  int mOverHead;//over head size of T
46 public:
47  // CONSTRUCTORS
50  MPI_CoreToCoreBMessage(const tInteger& nElements,const tInteger& nMessage) {
51  mBuffer=NULL;
52 
53  //MPI size of T
54  MPI_Type::GetSize<T>(mMPITSize);
55 
56  //overhead size for type T
57  mOverHead=(int) (1+(MPI_BSEND_OVERHEAD*1.)/mMPITSize);
58 
59  //allccate the buffer to the number of nElements to send
60  allocateBuffer(nElements,1);
61  }
62 
63  // DESTRUCTORS
66  virtual ~MPI_CoreToCoreBMessage(void) {
67  if (mBuffer!=NULL) {
69  }
70  }
71 
72  //memory management
73  //=================
76  virtual tMemSize getMemorySize() const override{
77  return sizeof(*this)+getContentsMemorySize();
78  }
79 
83  inline static CORE_UniquePointer<MPI_CoreToCoreBMessage<T>> New() {
84  CORE_UniquePointer<MPI_CoreToCoreBMessage<T>> p(new MPI_CoreToCoreBMessage<T>(),
86  return p;
87  };
88 
89  //sender methods
90  //===============
99  inline void send(const MPI_Environment& env,const tMPICoreId& dstCore,
100  const T& data,const tMPITag& flag) const {
101  MPI_Bsend(&data,1,MPI_Type::GetPrimaryType<T>(),dstCore,flag,env.getWorld());
102  }
103 
104 
109  inline void allocateBuffer(const tInteger& nElements,const tInteger& nMessages) {
110  if (mBuffer!=NULL) {
112  }
113  mBufferMPISize=nMessages*(nElements+mOverHead);
114  mBuffer=(T*) malloc(mBufferMPISize*sizeof(T));
115  mBufferMPISize*=mMPITSize;
116 
117  //allocate memory
118  MPI_Buffer_attach(mBuffer,mBufferMPISize);
119  }
122  inline void desallocateBuffer() {
123  MPI_Buffer_detach(&mBuffer,&mBufferMPISize);
124  mBuffer==NULL;
125  }
126 
127 
128 
129 
130 };
131 
132 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
This class is a class to send / receive buffered messages from one to core to one core.
Definition: MPI_CoreToCoreBMessage.h:35
static CORE_UniquePointer< MPI_CoreToCoreBMessage< T > > New()
create an unique instance of the class This
Definition: MPI_CoreToCoreBMessage.h:83
void send(const MPI_Environment &env, const tMPICoreId &dstCore, const T &data, const tMPITag &flag) const
buffred sent of a data with flag to dstCore
Definition: MPI_CoreToCoreBMessage.h:99
MPI_CoreToCoreBMessage(const tInteger &nElements, const tInteger &nMessage)
create a buffer message with nMessages which each message is compozed by maximum of nElements of T
Definition: MPI_CoreToCoreBMessage.h:50
void allocateBuffer(const tInteger &nElements, const tInteger &nMessages)
allocate the buffer
Definition: MPI_CoreToCoreBMessage.h:109
void desallocateBuffer()
desallocate the buffer
Definition: MPI_CoreToCoreBMessage.h:122
virtual ~MPI_CoreToCoreBMessage(void)
destroy
Definition: MPI_CoreToCoreBMessage.h:66
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: MPI_CoreToCoreBMessage.h:76
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
const tMPIComm & getWorld() const
get the world of the environment for reading
Definition: MPI_Environment.h:165
This class is a base class of E-MicromM core package.
Definition: MPI_Object.h:32