OpenM++ runtime library (libopenm)
msg.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 OM_MSG_H
9 #define OM_MSG_H
10 
11 #include <string>
12 using namespace std;
13 
14 #include "libopenm/omLog.h"
17 #include "libopenm/db/dbCommon.h"
18 
19 namespace openm
20 {
22  extern const char msgUnknownErrorMessage[];
23 
26 
28  enum class MsgTag
29  {
31  unused = 0,
32 
34  initial,
35 
38 
41 
43  microdata,
44 
46  langLst = 32,
47 
49  langWord,
50 
52  modelDic,
53 
55  typeDic,
56 
59 
62 
65 
67  tableDic,
68 
70  tableDims,
71 
73  tableAcc,
74 
76  tableExpr,
77 
79  entityDic,
80 
82  entityAttr,
83 
85  runOption,
86 
88  codeValue,
89 
91  //inParam,
92 
94  outSubValueBase = 128
95  };
96 
99  {
100  public:
101  virtual ~IPackedAdapter(void) noexcept { }
102 
108  static IPackedAdapter * create(MsgTag i_msgTag);
109 
111  virtual MsgTag tag(void) const noexcept = 0;
112 
118  virtual const vector<uint8_t> pack(const IRowBaseVec & i_rowVec) const = 0;
119 
127  virtual void unpackTo(int i_packSize, void * i_packedData, IRowBaseVec & io_rowVec) const = 0;
128 
130  static size_t packedSize(const type_info & i_type, size_t i_size);
131 
133  static unique_ptr<uint8_t[]> packArray(const type_info & i_type, size_t i_size, void * i_valueArr);
134  };
135 
137  class IMsgExec
138  {
139  public:
141  virtual ~IMsgExec(void) noexcept = 0;
142 
150  static IMsgExec * create(int argc, char **argv, IFinalState * i_final);
151 
153  static const int rootRank = 0;
154 
156  bool isRoot(void) const { return rank() == rootRank; }
157 
159  virtual int worldSize(void) const = 0;
160 
162  virtual int rank(void) const = 0;
163 
165  virtual int groupRank(void) const = 0;
166 
168  virtual void setCleanExit(bool i_isClean = false) = 0;
169 
175  virtual void createGroups(int i_groupSize, int i_groupCount) = 0;
176 
184  virtual void bcastValue(int i_groupOne, const type_info & i_type, void * io_value) = 0;
185 
192  void bcastInt(int i_groupOne, void * io_value) { bcastValue(i_groupOne, typeid(int), io_value); }
193 
201  virtual void bcastSend(int i_groupOne, const type_info & i_type, size_t i_size, void * io_valueArr) = 0;
202 
211  virtual void bcastReceive(int i_groupOne, const type_info & i_type, size_t i_size, void * io_valueArr) = 0;
212 
213 
220  virtual void bcastSendPacked(int i_groupOne, IRowBaseVec & io_rowVec, const IPackedAdapter & i_adapter) = 0;
221 
228  virtual void bcastReceivePacked(int i_groupOne, IRowBaseVec & io_rowVec, const IPackedAdapter & i_adapter) = 0;
229 
239  virtual void startSend(int i_sendTo, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * i_valueArr) = 0;
240 
248  virtual void startSendPacked(int i_sendTo, const IRowBaseVec & i_rowVec, const IPackedAdapter & i_adapter) = 0;
249 
259  virtual bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * io_valueArr) const = 0;
260 
268  virtual bool tryReceive(int i_recvFrom, IRowBaseVec & io_resultRowVec, const IPackedAdapter & i_adapter) const = 0;
269 
271  virtual void waitSendAll(void) = 0;
272  };
273 }
274 
275 #endif // OM_MSG_H
public interface for message passing
Definition: msg.h:138
virtual void bcastReceivePacked(int i_groupOne, IRowBaseVec &io_rowVec, const IPackedAdapter &i_adapter)=0
receive broadcasted vector of db rows from root.
virtual int groupRank(void) const =0
return rank in modeling group.
virtual void createGroups(int i_groupSize, int i_groupCount)=0
create groups for parallel run of modeling task.
void bcastInt(int i_groupOne, void *io_value)
broadcast integer value from root to all other processes.
Definition: msg.h:192
bool isRoot(void) const
if root process then true (root process rank == 0)
Definition: msg.h:156
virtual void waitSendAll(void)=0
wait for non-blocking send to be completed
virtual void bcastValue(int i_groupOne, const type_info &i_type, void *io_value)=0
broadcast value from root to all other processes.
virtual void startSendPacked(int i_sendTo, const IRowBaseVec &i_rowVec, const IPackedAdapter &i_adapter)=0
pack and start non-blocking send of vector of db rows to i_sendTo process.
virtual bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *io_valueArr) const =0
try to non-blocking receive value array, return true if completed.
virtual void startSend(int i_sendTo, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *i_valueArr)=0
start non-blocking send of value array to i_sendTo process.
virtual void setCleanExit(bool i_isClean=false)=0
set clean exit flag for normal shutdown of message passing interface.
virtual int worldSize(void) const =0
return total number of processes in world communicator.
virtual void bcastSend(int i_groupOne, const type_info &i_type, size_t i_size, void *io_valueArr)=0
send broadcast value array from root to all other processes.
virtual bool tryReceive(int i_recvFrom, IRowBaseVec &io_resultRowVec, const IPackedAdapter &i_adapter) const =0
try to non-blocking receive and unpack vector of db rows, return true if completed.
virtual void bcastReceive(int i_groupOne, const type_info &i_type, size_t i_size, void *io_valueArr)=0
receive broadcasted value array from root process.
virtual int rank(void) const =0
return current process rank.
virtual void bcastSendPacked(int i_groupOne, IRowBaseVec &io_rowVec, const IPackedAdapter &i_adapter)=0
send broadcast vector of db rows from root to all other processes.
openM++ exceptions
Definition: omError.h:19
OpenM++ data library: public interface for db common structures.
openM++ namespace
Definition: log.h:32
const char msgUnknownErrorMessage[]
messaging library default error message: "unknown messaging error"
Definition: msgCommon.cpp:11
MsgTag
tag to identify message content
Definition: msg.h:29
@ microdataSize
microdata row count for each entity
@ tableAcc
table_acc db rows
@ tableExpr
table_expr db rows
@ langWord
lang_word db rows
@ tableDic
table_dic db rows
@ modelDic
model_dic db rows
@ entityAttr
entity_attr db rows
@ runOption
run_option db rows
@ typeDic
type_dic db rows
@ langLst
lang_lst db rows
@ outSubValueBase
input parameter
@ statusUpdate
modeling job status
@ typeEnumLst
type_enum_lst db rows
@ tableDims
table_dims db rows
@ initial
initial message at process start
@ entityDic
entity_dic db rows
@ microdata
microdata entity rows
@ codeValue
generic (code,value) db rows
@ parameterDic
parameter_dic db rows
@ parameterDims
parameter_dims db rows
@ unused
reserved and should not be used
OpenmException< 4000, msgUnknownErrorMessage > MsgException
messaging library exception
Definition: msg.h:25
std::vector< IRowBaseUptr > IRowBaseVec
db rows: vector of unique pointers to db row
Definition: omHelper.h:241
OpenM++ common helper utilities.
OpenM++: public interface for log and trace support.
OpenM++ modeling library: model run state public interface.
final model run state public interface: thread safe
Definition: omHelper.h:248
public interface to pack and unpack rows of metadata db-table
Definition: msg.h:99
virtual const vector< uint8_t > pack(const IRowBaseVec &i_rowVec) const =0
pack vector of db rows into byte vector.
virtual MsgTag tag(void) const noexcept=0
return message tag
virtual void unpackTo(int i_packSize, void *i_packedData, IRowBaseVec &io_rowVec) const =0
unpack from byte[] into vector of rows.