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 
35 
37  initial,
38 
40  langLst = 32,
41 
43  langWord,
44 
46  modelDic,
47 
49  typeDic,
50 
53 
56 
59 
61  tableDic,
62 
64  tableDims,
65 
67  tableAcc,
68 
70  tableExpr,
71 
73  runOption,
74 
76  codeValue,
77 
79  //inParam,
80 
82  outSubValueBase = 128
83  };
84 
87  {
88  public:
89  virtual ~IPackedAdapter(void) noexcept { }
90 
96  static IPackedAdapter * create(MsgTag i_msgTag);
97 
99  virtual MsgTag tag(void) const noexcept = 0;
100 
106  virtual const vector<char> pack(const IRowBaseVec & i_rowVec) const = 0;
107 
115  virtual void unpackTo(int i_packSize, void * i_packedData, IRowBaseVec & io_rowVec) const = 0;
116 
118  static size_t packedSize(const type_info & i_type, size_t i_size);
119 
121  static unique_ptr<char> packArray(const type_info & i_type, size_t i_size, void * i_valueArr);
122  };
123 
125  class IMsgExec
126  {
127  public:
129  virtual ~IMsgExec(void) noexcept = 0;
130 
138  static IMsgExec * create(int argc, char **argv, IFinalState * i_final);
139 
141  static const int rootRank = 0;
142 
144  bool isRoot(void) const { return rank() == rootRank; }
145 
147  virtual int worldSize(void) const = 0;
148 
150  virtual int rank(void) const = 0;
151 
153  virtual int groupRank(void) const = 0;
154 
156  virtual void setCleanExit(bool i_isClean = false) = 0;
157 
163  virtual void createGroups(int i_groupSize, int i_groupCount) = 0;
164 
172  virtual void bcastValue(int i_groupOne, const type_info & i_type, void * io_value) = 0;
173 
180  void bcastInt(int i_groupOne, void * io_value) { bcastValue(i_groupOne, typeid(int), io_value); }
181 
189  virtual void bcastSend(int i_groupOne, const type_info & i_type, size_t i_size, void * io_valueArr) = 0;
190 
199  virtual void bcastReceive(int i_groupOne, const type_info & i_type, size_t i_size, void * io_valueArr) = 0;
200 
201 
208  virtual void bcastSendPacked(int i_groupOne, IRowBaseVec & io_rowVec, const IPackedAdapter & i_adapter) = 0;
209 
216  virtual void bcastReceivePacked(int i_groupOne, IRowBaseVec & io_rowVec, const IPackedAdapter & i_adapter) = 0;
217 
227  virtual void startSend(int i_sendTo, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * i_valueArr) = 0;
228 
236  virtual void startSendPacked(int i_sendTo, const IRowBaseVec & i_rowVec, const IPackedAdapter & i_adapter) = 0;
237 
247  virtual bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * io_valueArr) const = 0;
248 
256  virtual bool tryReceive(int i_recvFrom, IRowBaseVec & io_resultRowVec, const IPackedAdapter & i_adapter) const = 0;
257 
259  virtual void waitSendAll(void) = 0;
260  };
261 }
262 
263 #endif // OM_MSG_H
public interface for message passing
Definition: msg.h:126
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:180
bool isRoot(void) const
if root process then true (root process rank == 0)
Definition: msg.h:144
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
@ 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
@ 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
@ 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:203
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:210
public interface to pack and unpack rows of metadata db-table
Definition: msg.h:87
virtual MsgTag tag(void) const noexcept=0
return message tag
virtual const vector< char > pack(const IRowBaseVec &i_rowVec) const =0
pack vector of db rows into char vector.
virtual void unpackTo(int i_packSize, void *i_packedData, IRowBaseVec &io_rowVec) const =0
unpack from char[] into vector of rows.