14 #if (MFEM_TIMER_TYPE == 0)
16 #elif (MFEM_TIMER_TYPE == 1)
17 #include <sys/times.h>
20 #elif (MFEM_TIMER_TYPE == 2)
22 #if (!defined(CLOCK_MONOTONIC) || !defined(CLOCK_PROCESS_CPUTIME_ID))
23 #error "CLOCK_MONOTONIC and CLOCK_PROCESS_CPUTIME_ID not defined in <time.h>"
25 #elif (MFEM_TIMER_TYPE == 3)
30 #error "Unknown MFEM_TIMER_TYPE"
42 #if (MFEM_TIMER_TYPE == 0)
43 std::clock_t user_time, start_utime;
44 #elif (MFEM_TIMER_TYPE == 1)
45 clock_t real_time, user_time, syst_time;
46 clock_t start_rtime, start_utime, start_stime;
48 inline void Current(clock_t *, clock_t *, clock_t *);
49 #elif (MFEM_TIMER_TYPE == 2)
50 struct timespec real_time, user_time;
51 struct timespec start_rtime, start_utime;
52 inline void GetRealTime(
struct timespec &tp);
53 inline void GetUserTime(
struct timespec &tp);
54 #elif (MFEM_TIMER_TYPE == 3)
55 LARGE_INTEGER frequency, real_time, start_rtime;
64 inline double Resolution();
65 inline double RealTime();
66 inline double UserTime();
67 inline double SystTime();
72 #if (MFEM_TIMER_TYPE == 0)
74 #elif (MFEM_TIMER_TYPE == 1)
75 my_CLK_TCK = sysconf(_SC_CLK_TCK);
76 real_time = user_time = syst_time = 0;
77 #elif (MFEM_TIMER_TYPE == 2)
78 real_time.tv_sec = user_time.tv_sec = 0;
79 real_time.tv_nsec = user_time.tv_nsec = 0;
80 #elif (MFEM_TIMER_TYPE == 3)
81 QueryPerformanceFrequency(&frequency);
82 real_time.QuadPart = 0;
87 #if (MFEM_TIMER_TYPE == 1)
88 inline void StopWatch::Current(clock_t *r, clock_t *u, clock_t *s)
93 *u = my_tms.tms_utime;
94 *s = my_tms.tms_stime;
96 #elif (MFEM_TIMER_TYPE == 2)
97 inline void StopWatch::GetRealTime(
struct timespec &tp)
99 clock_gettime(CLOCK_MONOTONIC, &tp);
102 inline void StopWatch::GetUserTime(
struct timespec &tp)
104 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
110 #if (MFEM_TIMER_TYPE == 0)
113 start_utime = std::clock();
114 #elif (MFEM_TIMER_TYPE == 1)
115 real_time = user_time = syst_time = 0;
117 Current(&start_rtime, &start_utime, &start_stime);
118 #elif (MFEM_TIMER_TYPE == 2)
119 real_time.tv_sec = user_time.tv_sec = 0;
120 real_time.tv_nsec = user_time.tv_nsec = 0;
123 GetRealTime(start_rtime);
124 GetUserTime(start_utime);
126 #elif (MFEM_TIMER_TYPE == 3)
127 real_time.QuadPart = 0;
129 QueryPerformanceCounter(&start_rtime);
136 #if (MFEM_TIMER_TYPE == 0)
137 start_utime = std::clock();
138 #elif (MFEM_TIMER_TYPE == 1)
139 Current(&start_rtime, &start_utime, &start_stime);
140 #elif (MFEM_TIMER_TYPE == 2)
141 GetRealTime(start_rtime);
142 GetUserTime(start_utime);
143 #elif (MFEM_TIMER_TYPE == 3)
144 QueryPerformanceCounter(&start_rtime);
151 if (!Running)
return;
152 #if (MFEM_TIMER_TYPE == 0)
153 user_time += ( std::clock() - start_utime );
154 #elif (MFEM_TIMER_TYPE == 1)
155 clock_t curr_rtime, curr_utime, curr_stime;
156 Current(&curr_rtime, &curr_utime, &curr_stime);
157 real_time += ( curr_rtime - start_rtime );
158 user_time += ( curr_utime - start_utime );
159 syst_time += ( curr_stime - start_stime );
160 #elif (MFEM_TIMER_TYPE == 2)
161 struct timespec curr_rtime, curr_utime;
162 GetRealTime(curr_rtime);
163 GetUserTime(curr_utime);
164 real_time.tv_sec += ( curr_rtime.tv_sec - start_rtime.tv_sec );
165 real_time.tv_nsec += ( curr_rtime.tv_nsec - start_rtime.tv_nsec );
166 user_time.tv_sec += ( curr_utime.tv_sec - start_utime.tv_sec );
167 user_time.tv_nsec += ( curr_utime.tv_nsec - start_utime.tv_nsec );
168 #elif (MFEM_TIMER_TYPE == 3)
169 LARGE_INTEGER curr_rtime;
170 QueryPerformanceCounter(&curr_rtime);
171 real_time.QuadPart += (curr_rtime.QuadPart - start_rtime.QuadPart);
178 #if (MFEM_TIMER_TYPE == 0)
179 return 1.0 / CLOCKS_PER_SEC;
180 #elif (MFEM_TIMER_TYPE == 1)
181 return 1.0 / my_CLK_TCK;
182 #elif (MFEM_TIMER_TYPE == 2)
187 clock_getres(CLOCK_MONOTONIC, &res);
188 return res.tv_sec + 1e-9*res.tv_nsec;
189 #elif (MFEM_TIMER_TYPE == 3)
190 return 1.0 / frequency.QuadPart;
196 #if (MFEM_TIMER_TYPE == 0)
198 #elif (MFEM_TIMER_TYPE == 1)
199 clock_t curr_rtime, curr_utime, curr_stime;
200 clock_t rtime = real_time;
203 Current(&curr_rtime, &curr_utime, &curr_stime);
204 rtime += (curr_rtime - start_rtime);
206 return (
double)(rtime) / my_CLK_TCK;
207 #elif (MFEM_TIMER_TYPE == 2)
210 struct timespec curr_rtime;
211 GetRealTime(curr_rtime);
212 return ((real_time.tv_sec + (curr_rtime.tv_sec - start_rtime.tv_sec)) +
213 1e-9*(real_time.tv_nsec +
214 (curr_rtime.tv_nsec - start_rtime.tv_nsec)));
218 return real_time.tv_sec + 1e-9*real_time.tv_nsec;
220 #elif (MFEM_TIMER_TYPE == 3)
221 LARGE_INTEGER curr_rtime, rtime = real_time;
224 QueryPerformanceCounter(&curr_rtime);
225 rtime.QuadPart += (curr_rtime.QuadPart - start_rtime.QuadPart);
227 return (
double)(rtime.QuadPart) / frequency.QuadPart;
233 #if (MFEM_TIMER_TYPE == 0)
234 std::clock_t utime = user_time;
236 utime += (std::clock() - start_utime);
237 return (
double)(utime) / CLOCKS_PER_SEC;
238 #elif (MFEM_TIMER_TYPE == 1)
239 clock_t curr_rtime, curr_utime, curr_stime;
240 clock_t utime = user_time;
243 Current(&curr_rtime, &curr_utime, &curr_stime);
244 utime += (curr_utime - start_utime);
246 return (
double)(utime) / my_CLK_TCK;
247 #elif (MFEM_TIMER_TYPE == 2)
250 struct timespec curr_utime;
251 GetUserTime(curr_utime);
252 return ((user_time.tv_sec + (curr_utime.tv_sec - start_utime.tv_sec)) +
253 1e-9*(user_time.tv_nsec +
254 (curr_utime.tv_nsec - start_utime.tv_nsec)));
258 return user_time.tv_sec + 1e-9*user_time.tv_nsec;
260 #elif (MFEM_TIMER_TYPE == 3)
267 #if (MFEM_TIMER_TYPE == 1)
268 clock_t curr_rtime, curr_utime, curr_stime;
269 clock_t stime = syst_time;
272 Current(&curr_rtime, &curr_utime, &curr_stime);
273 stime += (curr_stime - start_stime);
275 return (
double)(stime) / my_CLK_TCK;
286 M =
new internal::StopWatch;
306 return M->Resolution();
311 return M->RealTime();
316 return M->UserTime();
321 return M->SystTime();