14#if (MFEM_TIMER_TYPE == 0)
16#elif (MFEM_TIMER_TYPE == 1)
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)
29#elif (MFEM_TIMER_TYPE == 4)
31#include <mach/mach_time.h>
32#elif (MFEM_TIMER_TYPE == 5)
34#elif (MFEM_TIMER_TYPE == 6)
37#error "Unknown MFEM_TIMER_TYPE"
49#if (MFEM_TIMER_TYPE == 0)
50 std::clock_t user_time, start_utime;
51#elif (MFEM_TIMER_TYPE == 1)
52 clock_t real_time, user_time, syst_time;
53 clock_t start_rtime, start_utime, start_stime;
55 inline void Current(clock_t *, clock_t *, clock_t *);
56#elif (MFEM_TIMER_TYPE == 2)
57 struct timespec real_time, user_time;
58 struct timespec start_rtime, start_utime;
59 inline void GetRealTime(
struct timespec &tp);
60 inline void GetUserTime(
struct timespec &tp);
61#elif (MFEM_TIMER_TYPE == 3)
62 LARGE_INTEGER frequency, real_time, start_rtime;
63#elif (MFEM_TIMER_TYPE == 4)
64 std::clock_t user_time, start_utime;
65 mach_timebase_info_data_t ratio;
66 uint64_t real_time, start_rtime;
67#elif (MFEM_TIMER_TYPE == 5)
68 struct timeval real_time, start_rtime;
69#elif (MFEM_TIMER_TYPE == 6)
70 double real_time, start_rtime;
79 inline double Resolution();
80 inline double RealTime();
81 inline double UserTime();
82 inline double SystTime();
87#if (MFEM_TIMER_TYPE == 0)
89#elif (MFEM_TIMER_TYPE == 1)
90 my_CLK_TCK = sysconf(_SC_CLK_TCK);
91 real_time = user_time = syst_time = 0;
92#elif (MFEM_TIMER_TYPE == 2)
93 real_time.tv_sec = user_time.tv_sec = 0;
94 real_time.tv_nsec = user_time.tv_nsec = 0;
95#elif (MFEM_TIMER_TYPE == 3)
96 QueryPerformanceFrequency(&frequency);
97 real_time.QuadPart = 0;
98#elif (MFEM_TIMER_TYPE == 4)
101 mach_timebase_info(&ratio);
102#elif (MFEM_TIMER_TYPE == 5)
103 real_time.tv_sec = 0;
104 real_time.tv_usec = 0;
105#elif (MFEM_TIMER_TYPE == 6)
111#if (MFEM_TIMER_TYPE == 1)
112inline void StopWatch::Current(clock_t *r, clock_t *
u, clock_t *
s)
117 *
u = my_tms.tms_utime;
118 *
s = my_tms.tms_stime;
120#elif (MFEM_TIMER_TYPE == 2)
121inline void StopWatch::GetRealTime(
struct timespec &tp)
123 clock_gettime(CLOCK_MONOTONIC, &tp);
126inline void StopWatch::GetUserTime(
struct timespec &tp)
128 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
132inline void StopWatch::Clear()
134#if (MFEM_TIMER_TYPE == 0)
138 start_utime = std::clock();
140#elif (MFEM_TIMER_TYPE == 1)
141 real_time = user_time = syst_time = 0;
144 Current(&start_rtime, &start_utime, &start_stime);
146#elif (MFEM_TIMER_TYPE == 2)
147 real_time.tv_sec = user_time.tv_sec = 0;
148 real_time.tv_nsec = user_time.tv_nsec = 0;
151 GetRealTime(start_rtime);
152 GetUserTime(start_utime);
154#elif (MFEM_TIMER_TYPE == 3)
155 real_time.QuadPart = 0;
158 QueryPerformanceCounter(&start_rtime);
160#elif (MFEM_TIMER_TYPE == 4)
165 start_utime = std::clock();
166 start_rtime = mach_absolute_time();
168#elif (MFEM_TIMER_TYPE == 5)
169 real_time.tv_sec = 0;
170 real_time.tv_usec = 0;
173 gettimeofday(&start_rtime, NULL);
175#elif (MFEM_TIMER_TYPE == 6)
179 start_rtime = MPI_Wtime();
184inline void StopWatch::Start()
186 if (Running) {
return; }
187#if (MFEM_TIMER_TYPE == 0)
188 start_utime = std::clock();
189#elif (MFEM_TIMER_TYPE == 1)
190 Current(&start_rtime, &start_utime, &start_stime);
191#elif (MFEM_TIMER_TYPE == 2)
192 GetRealTime(start_rtime);
193 GetUserTime(start_utime);
194#elif (MFEM_TIMER_TYPE == 3)
195 QueryPerformanceCounter(&start_rtime);
196#elif (MFEM_TIMER_TYPE == 4)
197 start_utime = std::clock();
198 start_rtime = mach_absolute_time();
199#elif (MFEM_TIMER_TYPE == 5)
200 gettimeofday(&start_rtime, NULL);
201#elif (MFEM_TIMER_TYPE == 6)
202 start_rtime = MPI_Wtime();
207inline void StopWatch::Stop()
209 if (!Running) {
return; }
210#if (MFEM_TIMER_TYPE == 0)
211 user_time += ( std::clock() - start_utime );
212#elif (MFEM_TIMER_TYPE == 1)
213 clock_t curr_rtime, curr_utime, curr_stime;
214 Current(&curr_rtime, &curr_utime, &curr_stime);
215 real_time += ( curr_rtime - start_rtime );
216 user_time += ( curr_utime - start_utime );
217 syst_time += ( curr_stime - start_stime );
218#elif (MFEM_TIMER_TYPE == 2)
219 struct timespec curr_rtime, curr_utime;
220 GetRealTime(curr_rtime);
221 GetUserTime(curr_utime);
222 real_time.tv_sec += ( curr_rtime.tv_sec - start_rtime.tv_sec );
223 real_time.tv_nsec += ( curr_rtime.tv_nsec - start_rtime.tv_nsec );
224 user_time.tv_sec += ( curr_utime.tv_sec - start_utime.tv_sec );
225 user_time.tv_nsec += ( curr_utime.tv_nsec - start_utime.tv_nsec );
226#elif (MFEM_TIMER_TYPE == 3)
227 LARGE_INTEGER curr_rtime;
228 QueryPerformanceCounter(&curr_rtime);
229 real_time.QuadPart += (curr_rtime.QuadPart - start_rtime.QuadPart);
230#elif (MFEM_TIMER_TYPE == 4)
231 user_time += ( std::clock() - start_utime );
232 real_time += (mach_absolute_time() - start_rtime);
233#elif (MFEM_TIMER_TYPE == 5)
234 struct timeval curr_rtime;
235 gettimeofday(&curr_rtime, NULL);
236 real_time.tv_sec += ( curr_rtime.tv_sec - start_rtime.tv_sec );
237 real_time.tv_usec += ( curr_rtime.tv_usec - start_rtime.tv_usec );
238#elif (MFEM_TIMER_TYPE == 6)
239 real_time += (MPI_Wtime() - start_rtime);
244inline double StopWatch::Resolution()
246#if (MFEM_TIMER_TYPE == 0)
247 return 1.0 / CLOCKS_PER_SEC;
248#elif (MFEM_TIMER_TYPE == 1)
249 return 1.0 / my_CLK_TCK;
250#elif (MFEM_TIMER_TYPE == 2)
255 clock_getres(CLOCK_MONOTONIC, &res);
256 return res.tv_sec + 1e-9*res.tv_nsec;
257#elif (MFEM_TIMER_TYPE == 3)
258 return 1.0 / frequency.QuadPart;
259#elif (MFEM_TIMER_TYPE == 4)
260 return 1.0 / CLOCKS_PER_SEC;
262#elif (MFEM_TIMER_TYPE == 5)
264#elif (MFEM_TIMER_TYPE == 6)
269inline double StopWatch::RealTime()
271#if (MFEM_TIMER_TYPE == 0)
273#elif (MFEM_TIMER_TYPE == 1)
274 clock_t curr_rtime, curr_utime, curr_stime;
275 clock_t rtime = real_time;
278 Current(&curr_rtime, &curr_utime, &curr_stime);
279 rtime += (curr_rtime - start_rtime);
281 return (
double)(rtime) / my_CLK_TCK;
282#elif (MFEM_TIMER_TYPE == 2)
285 struct timespec curr_rtime;
286 GetRealTime(curr_rtime);
287 return ((real_time.tv_sec + (curr_rtime.tv_sec - start_rtime.tv_sec)) +
288 1e-9*(real_time.tv_nsec +
289 (curr_rtime.tv_nsec - start_rtime.tv_nsec)));
293 return real_time.tv_sec + 1e-9*real_time.tv_nsec;
295#elif (MFEM_TIMER_TYPE == 3)
296 LARGE_INTEGER curr_rtime, rtime = real_time;
299 QueryPerformanceCounter(&curr_rtime);
300 rtime.QuadPart += (curr_rtime.QuadPart - start_rtime.QuadPart);
302 return (
double)(rtime.QuadPart) / frequency.QuadPart;
303#elif (MFEM_TIMER_TYPE == 4)
304 uint64_t rtime = real_time;
307 rtime += (mach_absolute_time() - start_rtime);
309 return 1e-9*rtime*ratio.numer/ratio.denom;
310#elif (MFEM_TIMER_TYPE == 5)
313 struct timeval curr_rtime;
314 gettimeofday(&curr_rtime, NULL);
315 real_time.tv_sec += ( curr_rtime.tv_sec - start_rtime.tv_sec );
316 real_time.tv_usec += ( curr_rtime.tv_usec - start_rtime.tv_usec );
317 return ((real_time.tv_sec + (curr_rtime.tv_sec - start_rtime.tv_sec)) +
318 1e-6*(real_time.tv_usec +
319 (curr_rtime.tv_usec - start_rtime.tv_usec)));
323 return real_time.tv_sec + 1e-6*real_time.tv_usec;
325#elif (MFEM_TIMER_TYPE == 6)
326 double rtime = real_time;
329 rtime += (MPI_Wtime() - start_rtime);
335inline double StopWatch::UserTime()
337#if (MFEM_TIMER_TYPE == 0)
338 std::clock_t utime = user_time;
341 utime += (std::clock() - start_utime);
343 return (
double)(utime) / CLOCKS_PER_SEC;
344#elif (MFEM_TIMER_TYPE == 1)
345 clock_t curr_rtime, curr_utime, curr_stime;
346 clock_t utime = user_time;
349 Current(&curr_rtime, &curr_utime, &curr_stime);
350 utime += (curr_utime - start_utime);
352 return (
double)(utime) / my_CLK_TCK;
353#elif (MFEM_TIMER_TYPE == 2)
356 struct timespec curr_utime;
357 GetUserTime(curr_utime);
358 return ((user_time.tv_sec + (curr_utime.tv_sec - start_utime.tv_sec)) +
359 1e-9*(user_time.tv_nsec +
360 (curr_utime.tv_nsec - start_utime.tv_nsec)));
364 return user_time.tv_sec + 1e-9*user_time.tv_nsec;
366#elif (MFEM_TIMER_TYPE == 3)
368#elif (MFEM_TIMER_TYPE == 4)
369 std::clock_t utime = user_time;
372 utime += (std::clock() - start_utime);
374 return (
double)(utime) / CLOCKS_PER_SEC;
375#elif (MFEM_TIMER_TYPE == 5)
377#elif (MFEM_TIMER_TYPE == 6)
382inline double StopWatch::SystTime()
384#if (MFEM_TIMER_TYPE == 1)
385 clock_t curr_rtime, curr_utime, curr_stime;
386 clock_t stime = syst_time;
389 Current(&curr_rtime, &curr_utime, &curr_stime);
390 stime += (curr_stime - start_stime);
392 return (
double)(stime) / my_CLK_TCK;
404 : M(new internal::
StopWatch(*(sw.M))) { }
429 return M->Resolution();
434 return M->RealTime();
439 return M->UserTime();
444 return M->SystTime();
double SystTime()
Return the number of system seconds elapsed since the stopwatch was started.
double RealTime()
Return the number of real seconds elapsed since the stopwatch was started.
~StopWatch()
Default destructor.
void Start()
Start the stopwatch. The elapsed time is not cleared.
void Restart()
Clears and restarts the stopwatch. Equivalent to Clear() followed by Start().
StopWatch()
Creates a new (stopped) StopWatch object.
double UserTime()
Return the number of user seconds elapsed since the stopwatch was started.
double Resolution()
Return the time resolution available to the stopwatch.
void Stop()
Stop the stopwatch.
void Clear()
Clear the elapsed time on the stopwatch and restart it if it's running.
real_t u(const Vector &xvec)
double toc()
End timing and return the time from tic() to toc() in seconds.
void tic()
Start the tic_toc timer.