OpenCOVER
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 #endif
27 
28 #include <string>
29 #include <vector>
30 #include <util/coTypes.h>
31 
32 //#define DEBUG_MESSAGES
33 #ifdef DEBUG_MESSAGES
34 #define CLUSTER_MARK() \
35  ; \
36  coVRMSController::msController->checkMark(__FILE__, __LINE__);
37 #else
38 #define CLUSTER_MARK() ;
39 #endif
40 namespace covise
41 {
42 class Socket;
43 class Message;
44 }
45 #define MAX_NUMBER_OF_SLAVES 256
46 
47 namespace opencover
48 {
49 class coVRSlave;
50 class Rel_Mcast;
51 class coClusterStat;
52 class COVEREXPORT coVRMSController
53 {
54 public:
55  enum
56  {
57  SYNC_TCP = 0,
64  SYNC_MAGIC
65  };
66  enum
67  {
68  SYNC_APP = 0,
69  SYNC_DRAW
70  };
71 
72  enum
73  {
75  DrawTag
76  };
77 
78  class COVEREXPORT SlaveData
79  {
80  public:
85  SlaveData(int n);
86  virtual ~SlaveData();
87 
88  // Result vector
89  std::vector<void *> data;
90 
91  // Maximum size of a data element. NOT the size of the data array.
92  inline int size() const
93  {
94  return this->n;
95  }
96 
97  private:
98  SlaveData(const SlaveData &)
99  {
100  }
101  int n;
102  };
103 
104  static coVRMSController *instance();
105  coVRMSController(int AmyID = -1, const char *addr = NULL, int port = 0);
106 #ifdef HAS_MPI
107  coVRMSController(const MPI_Comm *comm);
108 #endif
109  ~coVRMSController();
110  void startSlaves();
111  void checkMark(const char *file, int line);
112  void connectToMaster(const char *addr, int port);
113  bool isMaster() const
114  {
115  return master;
116  };
117  bool isSlave() const
118  {
119  return !master;
120  };
121  bool isCluster() const
122  {
123  return (numSlaves > 0);
124  };
125  int readMaster(void *c, int n, bool mcastOverTCP);
126  int readMaster(void *c, int n);
127  int readMasterDraw(void *c, int n, bool mcastOverTCP);
128  int readMasterDraw(void *c, int n);
129  void sendMaster(const void *c, int n);
130  void sendMasterDraw(const void *c, int n);
131  int readSlave(int slaveNum, void *data, int num);
132  int readSlaves(SlaveData *c);
133  int readSlavesDraw(void *c, int n);
134  void sendSlave(int i, const void *c, int n);
135  void sendSlaves(const void *c, int n);
136  void sendSlaves(const SlaveData &c);
137  void sendSlavesDraw(const void *c, int n);
138  void sendSlaves(const covise::Message *msg);
139  int readMaster(covise::Message *msg);
140  void sendMaster(const covise::Message *msg);
141  void sendMaster(const std::string &s);
142  void readSlave(int i, std::string &s);
143  int getID()
144  {
145  return myID;
146  };
147  void sync();
148  void startupSync();
149  void syncApp(int frameNum);
150  void syncInt(int value);
151  void syncFloat(float value);
152  void syncStringStop(std::string name);
153  void syncDraw();
154  void syncTime();
155  int syncData(void *data, int size);
156  int syncMessage(covise::Message *msg);
157  bool syncBool(bool);
158  bool reduceOr(bool); // master will resceive logical or of all inputs
159  bool reduceAnd(bool);
160  bool allReduceOr(bool); // master and slaves will receive logical or of all inputs
161  bool allReduceAnd(bool);
162  std::string syncString(const std::string &s);
163  bool syncVRBMessages();
164  void waitForSlaves();
165  void waitForSlavesDraw();
166  void waitForMaster();
167  void sendGo();
168  void sendGoDraw();
169  void sendSerialGo();
170  void waitForSerialGo();
171  void sendParallelGo();
172  void waitForParallelGo();
173  void waitForParallelJoin();
174  void loadFile(const char *filename);
176  {
177  return numSlaves + 1;
178  }
179  void killClients();
180  int getNumSlaves() const
181  {
182  return this->numSlaves;
183  }
184 
185  void heartBeat(const std::string &name = "unnamed", bool draw = false);
186 
187  bool drawStatistics() const;
188  void setDrawStatistics(bool enable);
189 
190 #ifdef HAS_MPI
191  MPI_Comm getAppCommunicator() const
192  {
193  return this->appComm;
194  }
195 #endif
196 
197 private:
198  bool debugLevel(int l) const;
199  int m_debugLevel;
200  bool master;
201  bool slave;
202  int allChildren; // one bit for each child
203  int serial;
204  int parallel;
205  int myID;
206  int numSlaves;
207  int syncMode;
208  int syncProcess;
209  bool m_drawStatistics;
210  Rel_Mcast *multicast;
211  int multicastDebugLevel;
212  std::string multicastAddress;
213  int multicastPort;
214  std::string multicastInterface;
215  int multicastMTU;
216  int multicastTTL;
217  bool multicastLoop;
218  unsigned int multicastBufferSpace;
219  int multicastBlockSize;
220  int multicastNumParity;
221  unsigned int multicastTxCacheSize;
222  int multicastTxCacheMin;
223  int multicastTxCacheMax;
224  int multicastTxRate;
225  double multicastBackoffFactor;
226  int multicastSockBuffer;
227  int multicastClientTimeout;
228  int multicastServerTimeout;
229  int multicastRetryTimeout;
230  int multicastMaxLength;
231 
232  int magicFd; // filedescriptor for magic sync
233 
234  covise::Socket *socket;
235  covise::Socket *socketDraw;
236  coVRSlave *slaves[MAX_NUMBER_OF_SLAVES];
237  coClusterStat *stats[MAX_NUMBER_OF_SLAVES];
238  double networkSend;
239  double networkRecv;
240 
241 #ifdef HAS_MPI
242  MPI_Comm appComm;
243  MPI_Comm drawComm;
244 #endif
245 
246  int heartBeatCounter, heartBeatCounterDraw;
247  static coVRMSController *s_singleton;
248 };
249 }
250 #endif
#define MAX_NUMBER_OF_SLAVES
Definition: coVRMSController.h:45
int getNumSlaves() const
Definition: coVRMSController.h:180
Definition: coVRMSController.h:52
bool isSlave() const
Definition: coVRMSController.h:117
bool isMaster() const
Definition: coVRMSController.h:113
Definition: coVRMSController.h:59
bool isCluster() const
Definition: coVRMSController.h:121
int getID()
Definition: coVRMSController.h:143
Definition: coVRMSController.h:74
Definition: coVRMSController.h:78
Definition: coVRMSController.h:61
Definition: coVRMSController.h:58
Definition: coVRMSController.h:60
int clusterSize()
Definition: coVRMSController.h:175
std::vector< void * > data
Definition: coVRMSController.h:89
int size() const
Definition: coVRMSController.h:92
Definition: coVRMSController.h:62
Definition: coVRMSController.h:63