OpenCOVER
coVRMSController.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef CO_VRMSController_H
9#define CO_VRMSController_H
10
24#ifdef HAS_MPI
25#include <mpi.h>
26#ifdef __APPLE__
27typedef void pthread_barrier_t;
28#else
29#include <pthread.h>
30#endif
31#endif
32
33#include <string>
34#include <vector>
35#include <util/coTypes.h>
36
37//#define DEBUG_MESSAGES
38#ifdef DEBUG_MESSAGES
39#define CLUSTER_MARK() \
40 ; \
41 coVRMSController::msController->checkMark(__FILE__, __LINE__);
42#else
43#define CLUSTER_MARK() ;
44#endif
45#define UDP_MESSAGE_HEADER_SIZE 3 *sizeof(int)
46
47namespace covise
48{
49class Socket;
50class Message;
51class UdpMessage;
52}
53#define MAX_NUMBER_OF_SLAVES 256
54
55namespace opencover
56{
57class coVRSlave;
58class Rel_Mcast;
59class coClusterStat;
60class COVEREXPORT coVRMSController
61{
62public:
63 enum
64 {
65 SYNC_TCP = 0,
72 SYNC_MAGIC
73 };
74 enum
75 {
76 SYNC_APP = 0,
77 SYNC_DRAW
78 };
79
80 enum
81 {
83 DrawTag
84 };
85
86 class COVEREXPORT SlaveData
87 {
88 public:
93 SlaveData(int n);
94 virtual ~SlaveData();
95 // Result vector
96 std::vector<void *> data;
97
98 // Maximum size of a data element. NOT the size of the data array.
99 inline int size() const
100 {
101 return this->n;
102 }
103
104 private:
105 SlaveData(const SlaveData &)
106 {
107 }
108 int n;
109 };
110
112 coVRMSController(int AmyID = -1, const char *addr = NULL, int port = 0);
113#ifdef HAS_MPI
114 coVRMSController(const MPI_Comm *comm, pthread_barrier_t *shmBarrier = nullptr);
115#endif
118 void checkMark(const char *file, int line);
119 void connectToMaster(const char *addr, int port);
120 bool isMaster() const
121 {
122 return master;
123 };
124 bool isSlave() const
125 {
126 return !master;
127 };
128 bool isCluster() const
129 {
130 return (numSlaves > 0);
131 };
132 int readMaster(void *c, int n, bool mcastOverTCP);
133 int readMaster(void *c, int n);
134 int readMasterDraw(void *c, int n, bool mcastOverTCP);
135 int readMasterDraw(void *c, int n);
136 void sendMaster(const void *c, int n);
137 void sendMasterDraw(const void *c, int n);
138 int readSlave(int slaveNum, void *data, int num);
140 int readSlavesDraw(void *c, int n);
141 void sendSlave(int i, const void *c, int n);
142 void sendSlaves(const void *c, int n);
143 void sendSlaves(const SlaveData &c);
144 void sendSlavesDraw(const void *c, int n);
145 void sendSlaves(const covise::Message *msg);
146 void sendSlaves(const covise::UdpMessage* msg);
147 int readMaster(covise::Message *msg);
148 void sendMaster(const covise::Message *msg);
149 int readMaster(covise::UdpMessage* msg);
150 void sendMaster(const std::string &s);
151 void readSlave(int i, std::string &s);
152 int getID()
153 {
154 return myID;
155 };
156 void shmBarrier(); // barrier among all ranks on a node accessing the same shmem segment
157 void sync();
159 void syncApp(int frameNum);
160 void syncInt(int value);
161 void syncFloat(float value);
162 void syncStringStop(std::string name);
163 void syncDraw();
164 void syncTime();
165 int syncData(void *data, int size);
166 int syncMessage(covise::Message *msg);
167 bool syncBool(bool);
168 bool reduceOr(bool); // master will receive logical or of all inputs
169 bool reduceAnd(bool);
170 bool allReduceOr(bool); // master and slaves will receive logical or of all inputs
171 bool allReduceAnd(bool);
172 std::string syncString(const std::string &s);
177 void sendGo();
184 void loadFile(const char *filename);
186 {
187 return numSlaves + 1;
188 }
190 int getNumSlaves() const
191 {
192 return this->numSlaves;
193 }
194
195 void heartBeat(const std::string &name = "unnamed", bool draw = false);
196
197 bool drawStatistics() const;
198 void setDrawStatistics(bool enable);
199
200#ifdef HAS_MPI
201 MPI_Comm getAppCommunicator() const
202 {
203 return this->appComm;
204 }
205#endif
206
207private:
208 bool debugLevel(int l) const;
209 int m_debugLevel;
210 bool master;
211 bool slave;
212 int allChildren; // one bit for each child
213 int serial;
214 int parallel;
215 int myID;
216 int numSlaves;
217 int syncMode;
218 int syncProcess;
219 bool m_drawStatistics;
220 Rel_Mcast *multicast;
221 int multicastDebugLevel;
222 std::string multicastAddress;
223 int multicastPort;
224 std::string multicastInterface;
225 int multicastMTU;
226 int multicastTTL;
227 bool multicastLoop;
228 unsigned int multicastBufferSpace;
229 int multicastBlockSize;
230 int multicastNumParity;
231 unsigned int multicastTxCacheSize;
232 int multicastTxCacheMin;
233 int multicastTxCacheMax;
234 int multicastTxRate;
235 double multicastBackoffFactor;
236 int multicastSockBuffer;
237 int multicastClientTimeout;
238 int multicastServerTimeout;
239 int multicastRetryTimeout;
240 int multicastMaxLength;
241
242 int magicFd; // filedescriptor for magic sync
243 covise::Socket *socket;
244 covise::Socket *socketDraw;
247 double networkSend;
248 double networkRecv;
249
250#ifdef HAS_MPI
251 MPI_Comm appComm;
252 MPI_Comm drawComm;
253 std::vector<int> drawRank;
254 pthread_barrier_t *pthreadShmBarrier = nullptr;
255#endif
256
257 int heartBeatCounter, heartBeatCounterDraw;
258 static coVRMSController *s_singleton;
259};
260}
261#endif
#define MAX_NUMBER_OF_SLAVES
Definition: coVRMSController.h:53
Definition: ARToolKit.h:33
Definition: coTabletUI.h:51
Definition: coClusterStat.h:63
Definition: coVRMSController.h:61
void connectToMaster(const char *addr, int port)
int readSlavesDraw(void *c, int n)
void checkMark(const char *file, int line)
int readMaster(covise::Message *msg)
int readMaster(covise::UdpMessage *msg)
bool isMaster() const
Definition: coVRMSController.h:120
void syncApp(int frameNum)
void heartBeat(const std::string &name="unnamed", bool draw=false)
void syncStringStop(std::string name)
static coVRMSController * instance()
void sendSlaves(const void *c, int n)
bool isSlave() const
Definition: coVRMSController.h:124
int readMasterDraw(void *c, int n)
coVRMSController(int AmyID=-1, const char *addr=NULL, int port=0)
@ SYNC_TCP_SERIAL
Definition: coVRMSController.h:68
@ SYNC_SERIAL
Definition: coVRMSController.h:67
@ SYNC_MULTICAST
Definition: coVRMSController.h:70
@ SYNC_UDP
Definition: coVRMSController.h:66
@ SYNC_MPI
Definition: coVRMSController.h:71
@ SYNC_PARA
Definition: coVRMSController.h:69
void sendSlaves(const covise::UdpMessage *msg)
void setDrawStatistics(bool enable)
bool isCluster() const
Definition: coVRMSController.h:128
std::string syncString(const std::string &s)
int getID()
Definition: coVRMSController.h:152
void sendSlaves(const SlaveData &c)
int readMaster(void *c, int n)
int readSlaves(SlaveData *c)
void sendMaster(const covise::Message *msg)
int syncMessage(covise::Message *msg)
void sendMasterDraw(const void *c, int n)
void sendMaster(const void *c, int n)
int clusterSize()
Definition: coVRMSController.h:185
void sendSlavesDraw(const void *c, int n)
int readMasterDraw(void *c, int n, bool mcastOverTCP)
void loadFile(const char *filename)
int readMaster(void *c, int n, bool mcastOverTCP)
void syncFloat(float value)
@ AppTag
Definition: coVRMSController.h:82
int readSlave(int slaveNum, void *data, int num)
void sendSlaves(const covise::Message *msg)
void sendMaster(const std::string &s)
void sendSlave(int i, const void *c, int n)
void readSlave(int i, std::string &s)
int syncData(void *data, int size)
int getNumSlaves() const
Definition: coVRMSController.h:190
Definition: coVRMSController.h:87
int size() const
Definition: coVRMSController.h:99
std::vector< void * > data
Definition: coVRMSController.h:96
Definition: coVRSlave.h:38
Definition: rel_mcast-old.h:198