OpenM++ runtime library (libopenm)
msgEmpty.h
Go to the documentation of this file.
1 
5 // Copyright (c) 2013-2015 OpenM++
6 // This code is licensed under the MIT license (see LICENSE.txt for details)
7 
8 #ifndef MSG_EMPTY_H
9 #define MSG_EMPTY_H
10 
11 using namespace std;
12 
13 #include "msgExecBase.h"
14 
15 namespace openm
16 {
19  {
20  public:
22  EmptyPackedAdapter(MsgTag i_tag) : msgTag(i_tag) { }
23 
25  MsgTag tag(void) const noexcept override { return msgTag; }
26 
28  const vector<char> pack(const IRowBaseVec & /* i_rowVec */) const override
29  {
30  lock_guard<recursive_mutex> lck(msgMutex);
31  vector<char> packedData;
32  return packedData;
33  }
34 
36  void unpackTo(int /* i_packSize */, void * /* i_packedData */, IRowBaseVec & /* io_rowVec */) const override { }
37 
38  private:
39  MsgTag msgTag; // message tag
40  };
41 
50  class MsgEmptyExec : public IMsgExec, public MsgExecBase
51  {
52  public:
54  MsgEmptyExec(int & /* argc */, char ** & /* argv */, IFinalState * i_final) : MsgExecBase(i_final) { }
55 
57  ~MsgEmptyExec(void) noexcept { }
58 
60  int worldSize(void) const override { return MsgExecBase::worldSize(); }
61 
63  int rank(void) const override { return MsgExecBase::rank(); }
64 
66  int groupRank(void) const noexcept override { return MsgExecBase::groupRank(); }
67 
69  void setCleanExit(bool /*i_isClean*/) override { }
70 
72  void createGroups(int /*i_groupSize*/, int /*i_groupCount*/) override { }
73 
75  void bcastValue(
76  int /*i_groupOne*/, const type_info & /*i_type*/, void * /*io_value*/
77  ) override { }
78 
80  void bcastSend(
81  int /*i_groupOne*/, const type_info & /*i_type*/, size_t /*i_size*/, void * /*io_valueArr*/
82  ) override { }
83 
86  int /*i_groupOne*/, const type_info & /*i_type*/, size_t /*i_size*/, void * /*io_valueArr*/
87  ) override { }
88 
91  int /*i_groupOne*/, IRowBaseVec & /*io_rowVec*/, const IPackedAdapter & /*i_adapter*/
92  ) override { }
93 
96  int /*i_groupOne*/, IRowBaseVec & /*io_rowVec*/, const IPackedAdapter & /*i_adapter*/
97  ) override { }
98 
100  void startSend(int i_sendTo, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * i_valueArr) override
101  { MsgExecBase::startSend(i_sendTo, i_msgTag, i_type, i_size, i_valueArr); }
102 
104  void startSendPacked(int i_sendTo, const IRowBaseVec & i_rowVec, const IPackedAdapter & i_adapter) override
105  { MsgExecBase::startSendPacked(i_sendTo, i_rowVec, i_adapter); }
106 
108  bool tryReceive(int i_recvFrom, IRowBaseVec & io_resultRowVec, const IPackedAdapter & i_adapter) const override
109  { return MsgExecBase::tryReceive(i_recvFrom, io_resultRowVec, i_adapter); }
110 
112  bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * io_valueArr) const override
113  { return MsgExecBase::tryReceive(i_recvFrom, i_msgTag, i_type, i_size, io_valueArr); }
114 
116  void waitSendAll(void) override { MsgExecBase::waitSendAll(); }
117 
118  private:
119  MsgEmptyExec(const MsgEmptyExec & i_exec) = delete;
120  MsgEmptyExec & operator=(const MsgEmptyExec & i_exec) = delete;
121  };
122 
125  {
126  public:
128  MsgEmptySendBase(int i_selfRank, int i_sendTo, MsgTag i_msgTag) :
129  msgTag((int)i_msgTag),
130  selfRank(i_selfRank),
131  sendToRank(i_sendTo)
132  { }
133 
135  virtual ~MsgEmptySendBase(void) noexcept { }
136 
137  protected:
138  int msgTag; // MPI message tag
139  int selfRank; // source (ourself) MPI process rank
140  int sendToRank; // destination MPI process rank
141 
142  private:
143  MsgEmptySendBase(const MsgEmptySendBase & i_send) = delete;
144  MsgEmptySendBase & operator=(const MsgEmptySendBase & i_send) = delete;
145  };
146 
149  {
150  public:
153  int i_selfRank, int i_sendTo, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * i_valueArr
154  ) :
155  MsgEmptySendBase(i_selfRank, i_sendTo, i_msgTag),
156  valueType(i_type),
157  arrSize(i_size),
158  valueArr(i_valueArr)
159  { }
160 
162  ~MsgEmptySendArray(void) noexcept { }
163 
165  bool isCompleted(void) { return true; }
166 
167  private:
168  const type_info & valueType; // type of value in array
169  size_t arrSize; // size of array
170  void * valueArr; // value array
171 
172  private:
173  MsgEmptySendArray(const MsgEmptySendArray & i_send) = delete;
174  MsgEmptySendArray & operator=(const MsgEmptySendArray & i_send) = delete;
175  };
176 
179  {
180  public:
183  int i_selfRank, int i_sendTo, const IRowBaseVec & i_rowVec, const IPackedAdapter & i_adapter
184  ) :
185  MsgEmptySendBase(i_selfRank, i_sendTo, i_adapter.tag()),
186  rowVec(i_rowVec),
187  packAdp(i_adapter)
188  { }
189 
191  ~MsgEmptySendPacked(void) noexcept { }
192 
194  bool isCompleted(void) { return true; }
195 
196  private:
197  const IRowBaseVec & rowVec; // vector of db rows
198  const IPackedAdapter & packAdp; // adapter to pack db rows data
199 
200  private:
201  MsgEmptySendPacked(const MsgEmptySendPacked & i_send) = delete;
202  MsgEmptySendPacked & operator=(const MsgEmptySendPacked & i_send) = delete;
203  };
204 
207  {
208  public:
211  int i_selfRank, int i_recvFrom, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * io_valueArr
212  ) :
213  msgTag((int)i_msgTag),
214  selfRank(i_selfRank),
215  recvFromRank(i_recvFrom),
216  valueType(i_type),
217  resultSize(i_size),
218  resultValueArr(io_valueArr)
219  { }
220 
222  ~MsgEmptyRecvArray(void) noexcept { }
223 
225  bool tryReceive(void) { return true; }
226 
227  private:
228  int msgTag; // message tag
229  int selfRank; // destination (ourself) process rank
230  int recvFromRank; // source process rank
231  const type_info & valueType; // type of value in array
232  size_t resultSize; // expected size of array
233  void * resultValueArr; // received data
234 
235  private:
236  MsgEmptyRecvArray(const MsgEmptyRecvArray & i_recv) = delete;
237  MsgEmptyRecvArray & operator=(const MsgEmptyRecvArray & i_recv) = delete;
238  };
239 
242  {
243  public:
246  int i_selfRank, int i_recvFrom, IRowBaseVec & io_resultRowVec, const IPackedAdapter & i_adapter
247  ) :
248  selfRank(i_selfRank),
249  recvFromRank(i_recvFrom),
250  resultRowVec(io_resultRowVec),
251  packAdp(i_adapter)
252  { }
253 
255  ~MsgEmptyRecvPacked(void) noexcept { }
256 
258  bool tryReceive(void) { return true; }
259 
260  private:
261  int selfRank; // destination (ourself) process rank
262  int recvFromRank; // source process rank
263  IRowBaseVec & resultRowVec; // received data
264  const IPackedAdapter & packAdp; // adapter to unpack received data
265 
266  private:
267  MsgEmptyRecvPacked(const MsgEmptyRecvPacked & i_recv) = delete;
268  MsgEmptyRecvPacked & operator=(const MsgEmptyRecvPacked & i_recv) = delete;
269  };
270 }
271 
272 #endif // MSG_EMPTY_H
public interface for message passing
Definition: msg.h:126
public interface to receive value array
Definition: msgCommon.h:90
public interface to receive packed data
Definition: msgCommon.h:112
public interface to send value array
Definition: msgCommon.h:37
public interface to send packed data.
Definition: msgCommon.h:59
message passing main class.
Definition: msgEmpty.h:51
bool tryReceive(int i_recvFrom, IRowBaseVec &io_resultRowVec, const IPackedAdapter &i_adapter) const override
try to non-blocking receive and unpack vector of db rows, return true if completed.
Definition: msgEmpty.h:108
int worldSize(void) const override
return total number of processes in world communicator: always = 1.
Definition: msgEmpty.h:60
void startSendPacked(int i_sendTo, const IRowBaseVec &i_rowVec, const IPackedAdapter &i_adapter) override
pack and start non-blocking send of vector of db rows to i_sendTo process.
Definition: msgEmpty.h:104
bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *io_valueArr) const override
try to non-blocking receive value array, return true if completed.
Definition: msgEmpty.h:112
int groupRank(void) const noexcept override
return rank in modeling group: always = 0.
Definition: msgEmpty.h:66
int rank(void) const override
return current process rank: always = 0.
Definition: msgEmpty.h:63
void startSend(int i_sendTo, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *i_valueArr) override
start non-blocking send of value array to i_sendTo process.
Definition: msgEmpty.h:100
void bcastReceivePacked(int, IRowBaseVec &, const IPackedAdapter &) override
receive broadcasted vector of db rows from root (does nothing).
Definition: msgEmpty.h:95
~MsgEmptyExec(void) noexcept
cleanup message passing resources (empty destructor).
Definition: msgEmpty.h:57
MsgEmptyExec(int &, char **&, IFinalState *i_final)
create new message passing interface (empty constructor)
Definition: msgEmpty.h:54
void createGroups(int, int) override
create groups for parallel run of modeling task (does nothing).
Definition: msgEmpty.h:72
void setCleanExit(bool) override
set clean exit flag for normal shutdown of message passing interface.
Definition: msgEmpty.h:69
void waitSendAll(void) override
wait for non-blocking send to be completed.
Definition: msgEmpty.h:116
void bcastReceive(int, const type_info &, size_t, void *) override
receive broadcasted value array from root process (does nothing).
Definition: msgEmpty.h:85
void bcastValue(int, const type_info &, void *) override
broadcast value from root to all other processes (does nothing).
Definition: msgEmpty.h:75
void bcastSend(int, const type_info &, size_t, void *) override
send broadcast value array from root to all other processes (does nothing).
Definition: msgEmpty.h:80
void bcastSendPacked(int, IRowBaseVec &, const IPackedAdapter &) override
send broadcast vector of db rows from root to all other processes (does nothing).
Definition: msgEmpty.h:90
non-blocking receive of value array (empty implementation)
Definition: msgEmpty.h:207
~MsgEmptyRecvArray(void) noexcept
cleanup message receiver resources (does nothing).
Definition: msgEmpty.h:222
bool tryReceive(void)
try to non-blocking receive value array, return true if completed (always true).
Definition: msgEmpty.h:225
MsgEmptyRecvArray(int i_selfRank, int i_recvFrom, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *io_valueArr)
create sender and initiate non-blocking receive of value array (does nothing).
Definition: msgEmpty.h:210
non-blocking receive of packed data (empty implementation)
Definition: msgEmpty.h:242
bool tryReceive(void)
try to non-blocking receive and unpack the data, return true if completed (always true).
Definition: msgEmpty.h:258
~MsgEmptyRecvPacked(void) noexcept
cleanup message receiver resources (does nothing).
Definition: msgEmpty.h:255
MsgEmptyRecvPacked(int i_selfRank, int i_recvFrom, IRowBaseVec &io_resultRowVec, const IPackedAdapter &i_adapter)
create sender and initiate non-blocking receive of packed data (does nothing).
Definition: msgEmpty.h:245
non-blocking send of value array (empty implementation)
Definition: msgEmpty.h:149
~MsgEmptySendArray(void) noexcept
cleanup message sender resources (does nothing).
Definition: msgEmpty.h:162
bool isCompleted(void)
return true if send completed (always true).
Definition: msgEmpty.h:165
MsgEmptySendArray(int i_selfRank, int i_sendTo, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *i_valueArr)
create sender and initiate non-blocking send of value array (does nothing).
Definition: msgEmpty.h:152
base class for non-blocking send (empty implementation)
Definition: msgEmpty.h:125
MsgEmptySendBase(int i_selfRank, int i_sendTo, MsgTag i_msgTag)
create sender and initiate non-blocking send (does nothing).
Definition: msgEmpty.h:128
virtual ~MsgEmptySendBase(void) noexcept
cleanup message sender resources (does nothing).
Definition: msgEmpty.h:135
non-blocking send of packed data (empty implementation)
Definition: msgEmpty.h:179
bool isCompleted(void)
return true if send completed (always true).
Definition: msgEmpty.h:194
~MsgEmptySendPacked(void) noexcept
cleanup message sender resources (does nothing).
Definition: msgEmpty.h:191
MsgEmptySendPacked(int i_selfRank, int i_sendTo, const IRowBaseVec &i_rowVec, const IPackedAdapter &i_adapter)
create sender and initiate non-blocking send of packed data (does nothing).
Definition: msgEmpty.h:182
message passing base class
Definition: msgExecBase.h:22
OpenM++: message passing library base class.
openM++ namespace
Definition: log.h:32
MsgTag
tag to identify message content
Definition: msg.h:29
recursive_mutex msgMutex
mutex to lock messaging operations
Definition: msgExecBase.cpp:14
std::vector< IRowBaseUptr > IRowBaseVec
db rows: vector of unique pointers to db row
Definition: omHelper.h:203
pack and unpack adapter for metadata table db rows (empty implementation).
Definition: msgEmpty.h:19
const vector< char > pack(const IRowBaseVec &) const override
pack vector of db rows into char vector: return empty vector.
Definition: msgEmpty.h:28
void unpackTo(int, void *, IRowBaseVec &) const override
unpack from char[] into vector of rows (does nothing).
Definition: msgEmpty.h:36
MsgTag tag(void) const noexcept override
return message tag
Definition: msgEmpty.h:25
EmptyPackedAdapter(MsgTag i_tag)
create pack and unpack adapter for metadata table db rows
Definition: msgEmpty.h:22
final model run state public interface: thread safe
Definition: omHelper.h:210
public interface to pack and unpack rows of metadata db-table
Definition: msg.h:87