Scippy

UG

Ubiquity Generator framework

paraSysTimer.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 paraSysTimer.h
27  * @brief System timer.
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_SYS_TIMER_H__
38 #define __PARA_SYS_TIMER_H__
39 
40 //-------------------
41 // include files
42 //-------------------
43 #include <cstdlib>
44 #include "paraTimer.h"
45 
46 #ifdef __APPLE__
47 #define BSD
48 #endif /* Mac OSX */
49 
50 #ifdef __sun
51 #define BSD
52 #endif /* SUN_OS */
53 
54 #ifdef SUN_OS
55 #define BSD
56 #endif /* SUN_OS */
57 
58 #ifdef SOLARIS
59 #define SYSV
60 #endif /* SOLARIS */
61 
62 #ifdef linux
63 #define SYSV
64 #endif /* linux */
65 
66 #ifdef __linux__
67 #define SYSV
68 #endif /* linux */
69 
70 #ifdef __CYGWIN__
71 #define SYSV
72 #endif /* linux */
73 
74 #ifdef BlueGene
75 #define BSD
76 #endif
77 
78 #if !(defined _MSC_VER || defined SYSV || defined BSD )
79 #error cannot detect timer type!
80 #endif
81 
82 #ifdef BSD
83 #include <sys/time.h>
84 #include <sys/resource.h>
85 #endif /* BSD */
86 
87 #ifdef _MSC_VER
88 #include <sys/types.h>
89 #include <sys/timeb.h>
90 #include <time.h>
91 #include <windows.h>
92 #endif /* _MSC_VER */
93 
94 #ifdef SYSV
95 #include <sys/types.h>
96 #include <sys/times.h>
97 #include <sys/param.h>
98 #define TICKS HZ
99 #endif /* SYSV */
100 
101 namespace UG
102 {
103 
104 ///
105 /// Class ParaSysTimer
106 ///
107 class ParaSysTimer : public ParaTimer {
108 
109 public:
110 
111  ///
112  /// default constructor
113  ///
115  )
116  {
117  }
118 
119  ///
120  /// destructor
121  ///
123  )
124  {
125  }
126 
127  ///
128  /// initialize timer
129  ///
130  void init(
131  ParaComm* paraComm ///< communicator used
132  )
133  {
134  start();
135  }
136 
137  ///
138  /// get elapsed time
139  /// @return elapsed time
140  ///
142  )
143  {
144  return getRTimeInterval();
145  }
146 
147  ///
148  /// start timer
149  ///
150  void start(
151  void
152  );
153 
154  ///
155  /// stop timer
156  ///
157  void stop(
158  void
159  );
160 
161  ///
162  /// get start time
163  /// @return start time
164  ///
165  double getStartTime(
166  void
167  );
168 
169  ///
170  /// get elapsed time from start time
171  /// @return elapsed time
172  ///
173  double getRTimeInterval(
174  void
175  );
176 
177  ///
178  /// get real time between start timne and stop time
179  /// @return real time
180  ///
181  double getRTime(
182  void
183  );
184 
185  ///
186  /// get user time between start timne and stop time
187  /// @return user time
188  ///
189  double getUTime(
190  void
191  );
192 
193  ///
194  /// get system time between start timne and stop time
195  /// @return system time
196  ///
197  double getSTime(
198  void
199  );
200 
201 private:
202 
203 #ifdef BSD
204  struct timeval stTvTimeStart, stTvTimeStop;
205  struct rusage stRuStart, stRuStop;
206 # endif /* BSD */
207 
208 #ifdef _MSC_VER
209  struct _timeb timebStart, timebStop;
210  FILETIME ftCreationTime, ftExitTime,
211  ftKernelTimeStart, ftUserTimeStart,
212  ftKernelTimeStop, ftUserTimeStop;
213  HANDLE hCurrentProcess;
214 # endif /* _MSC_VER */
215 
216 # ifdef SYSV
217  long lTimeStart, lTimeStop;
218  struct tms stTmsStart, stTmsStop;
219 /* long times(); */
220 # endif /* SYSV */
221 
222 };
223 
224 }
225 
226 #endif // __PARA_SYS_TIMER_H__
ParaSysTimer()
default constructor
Definition: paraSysTimer.h:114
~ParaSysTimer()
destructor
Definition: paraSysTimer.h:122
double getRTimeInterval(void)
get elapsed time from start time
double getElapsedTime()
get elapsed time
Definition: paraSysTimer.h:141
Base class for Timer.
double getSTime(void)
get system time between start timne and stop time
void init(ParaComm *paraComm)
initialize timer
Definition: paraSysTimer.h:130
void stop(void)
stop timer
Class ParaSysTimer.
Definition: paraSysTimer.h:107
void start(void)
start timer
double getStartTime(void)
get start time
double getUTime(void)
get user time between start timne and stop time
class ParaTimer
Definition: paraTimer.h:48
Base class of communicator object.
Definition: paraComm.h:101
double getRTime(void)
get real time between start timne and stop time