OpenM++ runtime library (libopenm)
msgMpiExec.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_MPI_EXEC_H
9#define MSG_MPI_EXEC_H
10
11using namespace std;
12
13#include "msgCommon.h"
14#include "msgExecBase.h"
15#include "msgMpiPacked.h"
16#include "msgMpiSend.h"
17#include "msgMpiRecv.h"
18
19namespace openm
20{
22 class MpiExec : public IMsgExec, public MsgExecBase
23 {
24 public:
26 MpiExec(int & argc, char ** & argv, IFinalState * i_final);
27
29 ~MpiExec(void) noexcept;
30
32 int worldSize(void) const noexcept override { return MsgExecBase::worldSize(); }
33
35 int rank(void) const noexcept override { return MsgExecBase::rank(); }
36
38 int groupRank(void) const noexcept override { return MsgExecBase::groupRank(); }
39
41 void setCleanExit(bool i_isClean = false) override;
42
44 void createGroups(int i_groupSize, int i_groupCount) override;
45
47 void bcastValue(int i_groupOne, const type_info & i_type, void * io_value) override;
48
50 void bcastSend(int i_groupOne, const type_info & i_type, size_t i_size, void * io_valueArr) override;
51
53 void bcastReceive(int i_groupOne, const type_info & i_type, size_t i_size, void * io_valueArr) override;
54
56 void bcastSendPacked(int i_groupOne, IRowBaseVec & io_rowVec, const IPackedAdapter & i_adapter) override;
57
59 void bcastReceivePacked(int i_groupOne, IRowBaseVec & io_rowVec, const IPackedAdapter & i_adapter) override;
60
62 void startSend(int i_sendTo, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * i_valueArr) override
63 { MsgExecBase::startSend(i_sendTo, i_msgTag, i_type, i_size, i_valueArr); }
64
66 void startSendPacked(int i_sendTo, const IRowBaseVec & i_rowVec, const IPackedAdapter & i_adapter) override
67 { MsgExecBase::startSendPacked(i_sendTo, i_rowVec, i_adapter); }
68
70 bool tryReceive(int i_recvFrom, IRowBaseVec & io_resultRowVec, const IPackedAdapter & i_adapter) const override
71 { return MsgExecBase::tryReceive(i_recvFrom, io_resultRowVec, i_adapter); }
72
74 bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info & i_type, size_t i_size, void * io_valueArr) const override
75 { return MsgExecBase::tryReceive(i_recvFrom, i_msgTag, i_type, i_size, io_valueArr); }
76
78 void waitSendAll(void) override { MsgExecBase::waitSendAll(); }
79
80 private:
81 bool isCleanExit; // if false then process exit by error or exception
82 MPI_Group worldGroup; // MPI world global group
83 MPI_Comm groupComm; // modeling group communicator for current process
84 vector<MPI_Group> mpiGroupVec; // handles of modeling groups
85 vector<MPI_Comm> mpiCommVec; // handles of communicators
86
87 // cleanup MPI resources
88 void cleanup(void) noexcept;
89
91 MPI_Comm commByGroupOne(int i_groupOne);
92
94 void waitRequest(int i_pollTime, MPI_Request & io_request) const;
95
96 private:
97 MpiExec(const MpiExec & i_exec) = delete;
98 MpiExec & operator=(const MpiExec & i_exec) = delete;
99 };
100}
101
102#endif // MSG_MPI_EXEC_H
public interface for message passing
Definition: msg.h:138
message passing library main class for MPI-based implementation
Definition: msgMpiExec.h:23
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: msgMpiExec.h:74
void waitSendAll(void) override
wait for non-blocking send to be completed.
Definition: msgMpiExec.h:78
void setCleanExit(bool i_isClean=false) override
set clean exit flag for normal shutdown messaging else abort MPI.
Definition: msgMpiExec.cpp:108
void bcastReceivePacked(int i_groupOne, IRowBaseVec &io_rowVec, const IPackedAdapter &i_adapter) override
receive broadcasted vector of db rows from root.
Definition: msgMpiExec.cpp:438
void createGroups(int i_groupSize, int i_groupCount) override
create groups for parallel run of modeling task.
Definition: msgMpiExec.cpp:115
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: msgMpiExec.h:66
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: msgMpiExec.h:70
void bcastValue(int i_groupOne, const type_info &i_type, void *io_value) override
broadcast value from root to all other processes.
Definition: msgMpiExec.cpp:230
void bcastSend(int i_groupOne, const type_info &i_type, size_t i_size, void *io_valueArr) override
send broadcast value array from root to all other processes.
Definition: msgMpiExec.cpp:264
int rank(void) const noexcept override
return current process MPI rank.
Definition: msgMpiExec.h:35
void bcastSendPacked(int i_groupOne, IRowBaseVec &io_rowVec, const IPackedAdapter &i_adapter) override
send broadcast vector of db rows from root to all other processes.
Definition: msgMpiExec.cpp:393
int groupRank(void) const noexcept override
return rank in modeling group.
Definition: msgMpiExec.h:38
void bcastReceive(int i_groupOne, const type_info &i_type, size_t i_size, void *io_valueArr) override
receive broadcasted value array from root process.
Definition: msgMpiExec.cpp:330
MpiExec(int &argc, char **&argv, IFinalState *i_final)
create message passing interface by MPI_Init.
Definition: msgMpiExec.cpp:22
~MpiExec(void) noexcept
cleanup message passing resources by MPI_Finalize.
Definition: msgMpiExec.cpp:69
int worldSize(void) const noexcept override
return total number of processes in MPI world communicator.
Definition: msgMpiExec.h:32
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: msgMpiExec.h:62
message passing base class
Definition: msgExecBase.h:22
void startSendPacked(int i_sendTo, const IRowBaseVec &i_rowVec, const IPackedAdapter &i_adapter)
pack and start non-blocking send of vector of db rows to i_sendTo process.
Definition: msgExecBase.cpp:74
void startSend(int i_sendTo, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *i_valueArr)
start non-blocking send of value array to i_sendTo process.
Definition: msgExecBase.cpp:46
int rank(void) const
return current process rank.
Definition: msgExecBase.cpp:24
int groupRank(void) const
return rank in modeling group.
Definition: msgExecBase.cpp:31
void waitSendAll(void)
wait for non-blocking send to be completed.
Definition: msgExecBase.cpp:148
bool tryReceive(int i_recvFrom, MsgTag i_msgTag, const type_info &i_type, size_t i_size, void *io_valueArr) const
try to non-blocking receive value array, return return true if completed.
Definition: msgExecBase.cpp:102
int worldSize(void) const
return total number of processes in MPI world communicator.
Definition: msgExecBase.cpp:17
OpenM++: message passing library common classes and interfaces.
OpenM++: message passing library base class.
OpenM++ message passing library: pack and unpack wrapper class for MPI-based implementation.
OpenM++ message passing library: receiver class for MPI-based implementation.
OpenM++ message passing library: sender class for MPI-based implementation.
openM++ namespace
Definition: log.h:32
MsgTag
tag to identify message content
Definition: msg.h:29
std::vector< IRowBaseUptr > IRowBaseVec
db rows: vector of unique pointers to db row
Definition: omHelper.h:239
final model run state public interface: thread safe
Definition: omHelper.h:246
public interface to pack and unpack rows of metadata db-table
Definition: msg.h:99