Scippy

UG

Ubiquity Generator framework

paraTimeLimitMonitorTh.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 paraTimeLimitMonitorTh.h
27  * @brief Time limit monitor thread class.
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_TIME_LIMIT_MONITOR_TH_H__
38 #define __PARA_TIME_LIMIT_MONITOR_TH_H__
39 
40 #include <algorithm>
41 #include "paraDef.h"
42 #ifdef _COMM_PTH
43 #include "paraCommPth.h"
44 #endif
45 #ifdef _COMM_CPP11
46 #include "paraCommCPP11.h"
47 #endif
48 
49 namespace UG
50 {
51 
52 ///
53 /// class ParaTimeLimitMonitorTh
54 ///
56 {
57 
58 protected:
59 
60 #ifdef _COMM_PTH
61  ParaCommPth *paraComm; ///< ParaCommunicator used
62 #endif
63 
64 #ifdef _COMM_CPP11
65  ParaCommCPP11 *paraComm; ///< ParaCommunicator used
66 #endif
67 
68  double hardTimeLimit; ///< hard time limit
69 
70 public:
71 
72  ///
73  /// default constructor
74  ///
76  )
77  : paraComm(0),
78  hardTimeLimit(0.0)
79  {
80  THROW_LOGICAL_ERROR1("Default constructor of ParaTimeLimitMonitor is called");
81  }
82 
83 
84  ///
85  /// constructor
86  ///
88 #ifdef _COMM_PTH
89  ParaCommPth *comm, ///< communicator used
90 #endif
91 #ifdef _COMM_CPP11
92  ParaCommCPP11 *comm, ///< communicator used
93 #endif
94  double timelimit
95  ) : paraComm(comm)
96  {
97  // hardTimeLimit = timelimit + std::min(60.0, 0.1 * timelimit); // set hard time limit + 60 seconds longer than time limit
98  hardTimeLimit = timelimit + 3; // set hard time limit + 60 seconds longer than time limit
99  }
100 
101  ///
102  /// destructor
103  ///
105  )
106  {
107  }
108 
109  ///
110  /// run this time limit monitor
111  ///
112  void run(
113  )
114  {
115 #ifdef _MSC_VER
116  _sleep(static_cast<unsigned int>(hardTimeLimit));
117 #else
118  sleep(static_cast<unsigned int>(hardTimeLimit));
119 #endif
121  paraComm->send( NULL, 0, ParaBYTE, 0, TagHardTimeLimit)
122  );
123  std::cout << "****** send TagHardTimeLimit message *****" << std::endl;
124  }
125 
126 };
127 
128 }
129 
130 #endif // __PARA_TIME_LIMIT_MONITOR_TH_H__
131 
static ScipParaCommTh * comm
Definition: fscip.cpp:73
ParaComm extension for Pthreads communication.
static const int TagHardTimeLimit
Definition: paraTagDef.h:61
Defines for UG Framework.
ParaTimeLimitMonitorTh(double timelimit)
constructor
void run()
run this time limit monitor
#define PARA_COMM_CALL(paracommcall)
Definition: paraComm.h:47
Communicator object for pthreads thread communications.
Definition: paraCommPth.h:705
#define THROW_LOGICAL_ERROR1(msg1)
Definition: paraDef.h:52
ParaTimeLimitMonitorTh()
default constructor
static const int ParaBYTE
Definition: paraComm.h:79
virtual ~ParaTimeLimitMonitorTh()
destructor
int send(void *bufer, int count, const int datatypeId, int dest, const int tag)
send function for standard ParaData types
ParaComm extension for C++11 thread communication.
class ParaTimeLimitMonitorTh
Communicator object for C++11 thread communications.
double hardTimeLimit
hard time limit