Scippy

UG

Ubiquity Generator framework

paraComm.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and software framework */
4 /* UG --- Ubquity Generator Framework */
5 /* */
6 /* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7 /* Copyright (C) 2021 by Zuse Institute Berlin, */
8 /* licensed under LGPL version 3 or later. */
9 /* Commercial licenses are available through <licenses@zib.de> */
10 /* */
11 /* This code is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public License */
13 /* as published by the Free Software Foundation; either version 3 */
14 /* of the License, or (at your option) any later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* */
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25 
26 /**@file paraComm.h
27  * @brief Base class of communicator for UG Framework
28  * @author Yuji Shinano
29  *
30  *
31  *
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 
37 #ifndef __PARA_COMM_H__
38 #define __PARA_COMM_H__
39 #include <sstream>
40 #include "paraDef.h"
41 #include "paraTagDef.h"
42 #include "paraParamSet.h"
43 
44 namespace UG
45 {
46 
47 #define PARA_COMM_CALL( paracommcall ) \
48  { \
49  int _status = paracommcall; \
50  if( _status ) \
51  { \
52  std::ostringstream s_; \
53  s_ << "[PARA_COMM_CALL ERROR: " << __FILE__ << "] func = " \
54  << __func__ << ", line = " << __LINE__ << ": " \
55  << "error_code = " << _status << std::endl; \
56  throw std::logic_error( s_.str() ); \
57  }\
58  }
59 
60 ///
61 /// standard transfer data types
62 ///
63 static const int TYPE_FIRST = 0;
64 static const int ParaCHAR = TYPE_FIRST + 0;
65 static const int ParaSHORT = TYPE_FIRST + 1;
66 static const int ParaINT = TYPE_FIRST + 2;
67 static const int ParaLONG = TYPE_FIRST + 3;
68 static const int ParaLONG_LONG = TYPE_FIRST + 4;
69 static const int ParaSIGNED_CHAR = TYPE_FIRST + 5;
70 static const int ParaUNSIGNED_CHAR = TYPE_FIRST + 6;
71 static const int ParaUNSIGNED_SHORT = TYPE_FIRST + 7;
72 static const int ParaUNSIGNED = TYPE_FIRST + 8;
73 static const int ParaUNSIGNED_LONG = TYPE_FIRST + 9;
74 static const int ParaUNSIGNED_LONG_LONG = TYPE_FIRST + 10;
75 static const int ParaFLOAT = TYPE_FIRST + 11;
76 static const int ParaDOUBLE = TYPE_FIRST + 12;
77 static const int ParaLONG_DOUBLE = TYPE_FIRST + 13;
78 static const int ParaBOOL = TYPE_FIRST + 14;
79 static const int ParaBYTE = TYPE_FIRST + 15;
80 static const int TYPE_LAST = TYPE_FIRST + 15;
81 static const int TYPE_LIST_SIZE = TYPE_LAST - TYPE_FIRST + 1;
82 
83 static const int NumMaxWorkers = 20000;
84 
86 class ParaParamSet;
87 class ParaSolverState;
89 class ParaInstance;
90 class ParaDiffSubproblem;
91 class ParaSolution;
92 class ParaInitialStat;
94 class ParaTask;
95 class ParaTimer;
96 class TaskId;
97 
98 ///
99 /// Base class of communicator object
100 ///
101 class ParaComm
102 {
103 public:
104 
105  ///
106  /// default constructor of ParaComm
107  ///
109  )
110  {
111  }
112 
113  ///
114  /// destructor of ParaComm
115  ///
116  virtual ~ParaComm(
117  )
118  {
119  }
120 
121  ///
122  /// initializer of this object
123  ///
124  virtual void init(
125  int argc, ///< number of arguments
126  char **argv ///< pointers to the arguments
127  ) = 0;
128 
129  ///
130  /// get rank of this process or this thread depending on run-time environment
131  /// @return rank
132  ///
133  virtual int getRank() = 0;
134 
135  ///
136  /// get number of UG processes or UG threads depending on run-time environment
137  /// @return the number of UG processes or UG threads
138  ///
139  virtual int getSize() = 0;
140 
141  ///
142  /// get size of the messageQueueTable
143  /// @return the size of the messageQueueTable
144  ///
145  virtual int getNumOfMessagesWaitingToSend(
146  int dest ///< destination of message
147  ) = 0;
148 
149  ///
150  /// special initializer when this object is used in LoadCoordinator
151  ///
152  virtual void lcInit(
153  ParaParamSet *paraParamSet ///< UG parameter set
154  ) = 0;
155 
156  ///
157  /// special initializer when this object is used in Solver
158  ///
159  virtual void solverInit(
160  ParaParamSet *paraParamSet ///< UG parameter set
161  ) = 0;
162 
163  ///
164  // set local rank in case of using a communicator for shared memory
165  //
166  virtual void setLocalRank(
167  int inRank
168  )
169  {
170  }
171 
172  ///
173  /// abort function for this communicator
174  /// (how to abort depends on which library used for communication)
175  ///
176  virtual void abort(
177  ) = 0;
178 
179  ///
180  /// function to wait Terminated message
181  /// (This function is not used currently)
182  /// @return true when MPI communication is used, false when thread communication used
183  ///
184  virtual bool waitTerminatedMessage(
185  ) = 0;
186 
187  ///
188  /// wait token when UG runs with deterministic mode
189  /// @return true, when token is arrived to the rank
190  ///
191  virtual bool waitToken(
192  int rank ///< rank to check if token is arrived
193  )
194  {
195  return true;
196  }
197 
198  ///
199  /// pass token to from the rank to the next
200  ///
201  virtual void passToken(
202  int rank ///< from this rank, the token is passed
203  )
204  {
205  }
206 
207  ///
208  /// pass termination token from the rank to the next
209  /// @return true, when the termination token is passed from this rank, false otherwise
210  ///
211  virtual bool passTermToken(
212  int rank ///< from this rank, the termination token is passed
213  )
214  {
215  return true;
216  }
217 
218  ///
219  /// set received token to this communicator
220  ///
221  virtual void setToken(
222  int rank, ///< rank to set the token
223  int *token ///< token to be set
224  )
225  {
226  }
227 
228  ///
229  /// lock UG application to synchronize with other threads
230  ///
231  virtual void lockApp(
232  ) = 0;
233 
234  ///
235  /// lock UG application to synchronize with other threads
236  /// (for debug)
237  ///
238  virtual void lockApp(
239  char const *f, ///< string to indicate what is locked
240  int l ///< a number to show something
241  ){lockApp();}
242 
243  ///
244  /// unlock UG application to synchronize with other threads
245  ///
246  virtual void unlockApp(
247  ) = 0;
248 
249  ///
250  /// unlock UG application to synchronize with other threads
251  /// (for debug)
252  ///
253  virtual void unlockApp(
254  char const *f, ///< string to indicate what is locked
255  int l ///< a number to show something
256  ){unlockApp();}
257 
258  /////////////////////////////////
259  ///
260  /// transfer object factory
261  ///
262  /// /////////////////////////////
263 
264  ///
265  /// create ParaCalculationState object by default constructor
266  /// @return pointer to ParaCalculationState object
267  ///
269  ) = 0;
270 
271 
272  ///
273  /// create ParaRacingRampUpParamSet object
274  /// @return pointer to ParaRacingRampUpParamSet object
275  ///
277  ) = 0;
278 
279  ///
280  /// create ParaTask object by default constructor
281  /// @return pointer to ParaTask object
282  ///
283  virtual ParaTask *createParaTask(
284  ) = 0;
285 
286  ///
287  /// create ParaParamSet object
288  /// @return pointer to ParaParamSet object
289  ///
291  ) = 0;
292 
293  ///
294  /// create ParaSolverState object by default constructor
295  /// @return pointer to ParaSolverState object
296  ///
298  ) = 0;
299 
300  ///
301  /// create ParaSolverTerminationState object by default constructor
302  /// @return pointer to ParaSolverTerminationState object
303  ///
305  ) = 0;
306 
307  ///
308  /// create ParaTimer object
309  /// @return pointer to ParaTimer object
310  ///
311  virtual ParaTimer *createParaTimer(
312  ) = 0;
313 
314  ///
315  /// create ParaInstance object by default constructor
316  /// @return pointer to ParaInstance object
317  ///
319  ) = 0;
320 
321  ///
322  /// create ParaSolution object by default constructor
323  /// @return pointer to ParaSolution object
324  ///
326  ) = 0;
327 
328  ///
329  /// create ParaDiffSubproblem object by default constructor
330  /// @return pointer to ParaDiffSubproblem object
331  ///
333  )
334  {
335  THROW_LOGICAL_ERROR1("*** createParaDiffSubproblem() is called in ParaComm class ***");
336  }
337 
338  ////////////////////////////////////////////////////////////////////////////////
339  /// Some action need to be taken for fault tolerant, when the functions return.
340  /// So, they rerun status value
341  ////////////////////////////////////////////////////////////////////////////////
342 
343  ///
344  /// broadcast function for standard ParaData types
345  /// @return always 0 (for future extensions)
346  ///
347  virtual int bcast(
348  void* buffer, ///< point to the head of sending message
349  int count, ///< the number of data in the message
350  const int datatypeId, ///< data type in the message
351  int root ///< root rank for broadcasting
352  ) = 0;
353 
354  ///
355  /// send function for standard ParaData types
356  /// @return always 0 (for future extensions)
357  ///
358  virtual int send(
359  void* bufer, ///< point to the head of sending message
360  int count, ///< the number of data in the message
361  const int datatypeId, ///< data type in the message
362  int dest, ///< destination to send the message
363  const int tag ///< tag of this message
364  ) = 0;
365 
366  ///
367  /// receive function for standard ParaData types
368  /// @return always 0 (for future extensions)
369  ///
370  virtual int receive(
371  void* bufer, ///< point to the head of receiving message
372  int count, ///< the number of data in the message
373  const int datatypeId, ///< data type in the message
374  int source, ///< source of the message coming from
375  const int tag ///< tag of the message
376  ) = 0;
377 
378  ///
379  /// wait function for a specific tag from a specific source coming from
380  /// @return always 0 (for future extensions)
381  ///
382  virtual void waitSpecTagFromSpecSource(
383  const int source, ///< source rank which the message should come from
384  const int tag, ///< tag which the message should wait
385  int *receivedTag ///< tag of the message which is arrived
386  ) = 0;
387 
388  //////////////////////////////////////////////////////////////////////////
389  /// No need to take action for fault tolerant, when the functions return.
390  /// So, they do not rerun status value
391  //////////////////////////////////////////////////////////////////////////
392 
393  ///
394  /// probe function which waits a new message
395  /// @return always true
396  ///
397  virtual bool probe(
398  int *source, ///< source rank of the message arrived
399  int *tag ///< tag of the message arrived
400  ) = 0;
401 
402  ///
403  /// iProbe function which checks if a new message is arrived or not
404  /// @return true when a new message exists
405  ///
406  virtual bool iProbe(
407  int *source, ///< source rank of the message arrived
408  int *tag ///< tag of the message arrived
409  ) = 0;
410 
411  ///
412  /// get Tag string for debugging
413  /// @return string which shows Tag
414  ///
415  virtual const char *getTagString(
416  int tag /// tag to be converted to string
417  ) = 0;
418 };
419 
420 }
421 
422 #endif // __PARA_COMM_H__
static const int ParaSHORT
Definition: paraComm.h:65
class ParaSolverState (ParaSolver state object for notification message)
static const int ParaCHAR
Definition: paraComm.h:64
virtual void lcInit(ParaParamSet *paraParamSet)=0
special initializer when this object is used in LoadCoordinator
virtual ParaSolverTerminationState * createParaSolverTerminationState()=0
create ParaSolverTerminationState object by default constructor
static const int TYPE_FIRST
standard transfer data types
Definition: paraComm.h:63
static ScipParaParamSet * paraParamSet
Definition: fscip.cpp:74
virtual bool probe(int *source, int *tag)=0
No need to take action for fault tolerant, when the functions return. So, they do not rerun status va...
virtual int bcast(void *buffer, int count, const int datatypeId, int root)=0
Some action need to be taken for fault tolerant, when the functions return. So, they rerun status val...
virtual ParaRacingRampUpParamSet * createParaRacingRampUpParamSet()=0
create ParaRacingRampUpParamSet object
virtual void unlockApp()=0
unlock UG application to synchronize with other threads
static const int ParaUNSIGNED_LONG
Definition: paraComm.h:73
static const int ParaLONG_LONG
Definition: paraComm.h:68
virtual void setToken(int rank, int *token)
set received token to this communicator
Definition: paraComm.h:221
virtual void lockApp(char const *f, int l)
lock UG application to synchronize with other threads (for debug)
Definition: paraComm.h:238
static const int NumMaxWorkers
Definition: paraComm.h:83
Base class of Calculation state in a ParaSolver.
static const int ParaBOOL
Definition: paraComm.h:78
static const int TYPE_LIST_SIZE
Definition: paraComm.h:81
Defines for UG Framework.
virtual ParaSolverState * createParaSolverState()=0
create ParaSolverState object by default constructor
virtual void setLocalRank(int inRank)
Definition: paraComm.h:166
virtual void abort()=0
abort function for this communicator (how to abort depends on which library used for communication) ...
virtual ~ParaComm()
destructor of ParaComm
Definition: paraComm.h:116
virtual bool waitToken(int rank)
wait token when UG runs with deterministic mode
Definition: paraComm.h:191
TaskId class.
Definition: paraTask.h:222
static const int TYPE_LAST
Definition: paraComm.h:80
static const int ParaUNSIGNED
Definition: paraComm.h:72
virtual void passToken(int rank)
pass token to from the rank to the next
Definition: paraComm.h:201
virtual int getRank()=0
get rank of this process or this thread depending on run-time environment
static const int ParaLONG
Definition: paraComm.h:67
static const int ParaLONG_DOUBLE
Definition: paraComm.h:77
static const int ParaDOUBLE
Definition: paraComm.h:76
virtual ParaInstance * createParaInstance()=0
create ParaInstance object by default constructor
static const int ParaSIGNED_CHAR
Definition: paraComm.h:69
virtual void lockApp()=0
lock UG application to synchronize with other threads
virtual bool waitTerminatedMessage()=0
function to wait Terminated message (This function is not used currently)
Parameter set for UG framework.
#define THROW_LOGICAL_ERROR1(msg1)
Definition: paraDef.h:52
class ParaSolverTerminationState (Solver termination state in a ParaSolver)
virtual int receive(void *bufer, int count, const int datatypeId, int source, const int tag)=0
receive function for standard ParaData types
virtual ParaSolution * createParaSolution()=0
create ParaSolution object by default constructor
static const int ParaUNSIGNED_CHAR
Definition: paraComm.h:70
class ParaParamSet
Definition: paraParamSet.h:850
virtual ParaDiffSubproblem * createParaDiffSubproblem()
create ParaDiffSubproblem object by default constructor
Definition: paraComm.h:332
ParaComm()
default constructor of ParaComm
Definition: paraComm.h:108
class for instance data
Definition: paraInstance.h:50
Class for the difference between instance and subproblem.
virtual ParaTask * createParaTask()=0
create ParaTask object by default constructor
static const int ParaBYTE
Definition: paraComm.h:79
Fundamental Tag definitions.
virtual bool passTermToken(int rank)
pass termination token from the rank to the next
Definition: paraComm.h:211
virtual bool iProbe(int *source, int *tag)=0
iProbe function which checks if a new message is arrived or not
virtual void unlockApp(char const *f, int l)
unlock UG application to synchronize with other threads (for debug)
Definition: paraComm.h:253
virtual int getNumOfMessagesWaitingToSend(int dest)=0
get size of the messageQueueTable
static const int ParaUNSIGNED_LONG_LONG
Definition: paraComm.h:74
virtual const char * getTagString(int tag)=0
get Tag string for debugging
static const int ParaFLOAT
Definition: paraComm.h:75
class for initial statistics collecting after racing
virtual void solverInit(ParaParamSet *paraParamSet)=0
special initializer when this object is used in Solver
virtual ParaCalculationState * createParaCalculationState()=0
transfer object factory
virtual int send(void *bufer, int count, const int datatypeId, int dest, const int tag)=0
send function for standard ParaData types
virtual void init(int argc, char **argv)=0
initializer of this object
virtual int getSize()=0
get number of UG processes or UG threads depending on run-time environment
virtual ParaTimer * createParaTimer()=0
create ParaTimer object
static const int ParaINT
Definition: paraComm.h:66
class ParaTimer
Definition: paraTimer.h:48
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
static const int ParaUNSIGNED_SHORT
Definition: paraComm.h:71
Base class of communicator object.
Definition: paraComm.h:101
class for solution
Definition: paraSolution.h:53
virtual void waitSpecTagFromSpecSource(const int source, const int tag, int *receivedTag)=0
wait function for a specific tag from a specific source coming from
virtual ParaParamSet * createParaParamSet()=0
create ParaParamSet object
class ParaTask
Definition: paraTask.h:541