C++ mpi module for stochmagnet_main Package
MPI_MessageData.h
1 #ifndef MPI_MessageData_H
2 #define MPI_MessageData_H
3 
4 //inherited class object
5 #include "MPI_Object.h"
6 
7 //MPI types header
8 #include "MPI_Type.h"
9 
17 class MPI_MessageData : public MPI_Object {
18 
19  //attributes
20 private :
21  tMPIRequest mRequest;
22  tMPIStatus mStatus;
23  tMPIInteger mIsAvaliable;
24  tMPIInteger mIsFinished;
25  tBoolean mIsUsed;
26 protected:
27  // CONSTRUCTORS
28 
32  clear();
33  }
34 
35 
36  // DESTRUCTORS
39  virtual ~MPI_MessageData(void) {
40 
41  }
42 
43 public:
56  virtual tMemSize getMemorySize() const {
57  return sizeof(*this)+getContentsMemorySize();
58  }
59 
68  virtual tMemSize getContentsMemorySize() const {
69  tMemSize mem=MPI_Object::getContentsMemorySize();
70  return mem;
71  }
72 
76  inline static CORE_UniquePointer<MPI_MessageData> New() {
77  CORE_UniquePointer<MPI_MessageData> p(new MPI_MessagData(),
79  return p;
80  };
81 
84  inline void clear() {
85  mIsAvaliable=0;
86  mIsFinished=0;
87  mIsUsed=false;
88 
89  }
95  inline void update(const MPI_Environment& env,
96  const tMPICoreId& sourceCore,
97  const tMPITag& tag) {
98  MPI_Iprobe(sourceCore,tag,env.getWorld(),&mIsAvaliable,&mStatus);
99  }
104  inline void update(const MPI_Environment& env,
105  const tMPITag& tag) {
106  MPI_Iprobe(MPI_ANY_SOURCE,tag,env.getWorld(),&mIsAvaliable,&mStatus);
107  }
111  inline void update(const MPI_Environment& env) {
112 
113  MPI_Iprobe(MPI_ANY_SOURCE,MPI_ANY_TAG,env.getWorld(),&mIsAvaliable,&mStatus);
114  }
115 
118  inline tMPIRequest& request() { return mRequest; }
119 
122  inline tBoolean isAvaliable() const {
123 
124  return (mIsAvaliable==1);
125  }
126 
129  inline tMPICoreId getSourceCore() const {
130  return (mIsAvaliable==1)?mStatus.MPI_SOURCE:-1;
131  }
134  inline tMPICoreId getTag() const {
135  return (mIsAvaliable==1)?mStatus.MPI_TAG:-1;
136  }
142  template<typename T>
143  inline tBoolean getCount(tMPICount& nElements) {
144  return (MPI_Get_count(&mStatus,MPI_Type::GetPrimaryType<T>(),&nElements)==MPI_SUCCESS);
145  }
146 
149  inline tBoolean isFinished() {
150  MPI_Test(&mRequest,&mIsFinished,&mStatus);
151  return (mIsFinished==1);
152  }
155  inline const tBoolean& isUsed() {
156  return mIsUsed;
157  }
161  inline void setIsUsed(const tBoolean& b) {
162  mIsUsed=b;
163  }
164 
167  inline tBoolean wait() {
168  return (MPI_Wait(&mRequest,&mStatus)==MPI_SUCCESS);
169  }
173  inline static void WaitAll(std::valarray<MPI_MessageData>& messages) {
174  tBoolean allAreFinished=true;
175  tMPIInteger isFinished;
176  do {
177  allAreFinished=true;
178  for (auto& message:messages) {
179  MPI_Test(&message.request(),&isFinished,MPI_STATUS_IGNORE);
180  allAreFinished=allAreFinished && (isFinished==1);
181  }
182  } while (!allAreFinished);
183 
184  }
185 };
186 
187 
188 #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 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 describes a message status & request.
Definition: MPI_MessageData.h:17
virtual ~MPI_MessageData(void)
destroy
Definition: MPI_MessageData.h:39
tBoolean isFinished()
return true if the message has been received
Definition: MPI_MessageData.h:149
tMPICoreId getTag() const
get the tag of the message
Definition: MPI_MessageData.h:134
MPI_MessageData()
create a root environment
Definition: MPI_MessageData.h:31
const tBoolean & isUsed()
return true if the message is obsolete
Definition: MPI_MessageData.h:155
void update(const MPI_Environment &env, const tMPITag &tag)
update the data of the message
Definition: MPI_MessageData.h:104
tBoolean wait()
wait for the message is received
Definition: MPI_MessageData.h:167
void setIsUsed(const tBoolean &b)
turn the message into obsolete state
Definition: MPI_MessageData.h:161
tBoolean isAvaliable() const
return if the mesage is valiable
Definition: MPI_MessageData.h:122
static CORE_UniquePointer< MPI_MessageData > New()
create an unique instance of the class This
Definition: MPI_MessageData.h:76
void update(const MPI_Environment &env)
update the data of the message
Definition: MPI_MessageData.h:111
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: MPI_MessageData.h:56
tMPICoreId getSourceCore() const
get the source core of the mesasage
Definition: MPI_MessageData.h:129
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: MPI_MessageData.h:68
tMPIRequest & request()
return the request of the message
Definition: MPI_MessageData.h:118
static void WaitAll(std::valarray< MPI_MessageData > &messages)
wait for all the messages are received
Definition: MPI_MessageData.h:173
void update(const MPI_Environment &env, const tMPICoreId &sourceCore, const tMPITag &tag)
update the data of the message
Definition: MPI_MessageData.h:95
tBoolean getCount(tMPICount &nElements)
get the number of elements of the message
Definition: MPI_MessageData.h:143
void clear()
clear the data of the message
Definition: MPI_MessageData.h:84
This class is a base class of E-MicromM core package.
Definition: MPI_Object.h:32
This class is a Test class for EMicroM package which uses the module tests.
Definition: MPI_Test.h:15