22 #ifndef RAJA_Timer_HPP
23 #define RAJA_Timer_HPP
25 #include "RAJA/config.hpp"
27 #if defined(RAJA_USE_CALIPER)
28 #include <caliper/Annotation.h>
33 #if defined(__bgq__) && (!defined(_LIBCPP_VERSION))
53 using ElapsedType = double;
56 using TimeType = timeval;
57 using DurationType = std::chrono::duration<ElapsedType>;
60 BGQTimer() : tstart(), tstop(), telapsed(0) {}
62 void start() { gettimeofday(&tstart, 0); }
66 gettimeofday(&tstop, 0);
67 auto start = std::chrono::seconds(tstart.tv_sec) +
68 std::chrono::microseconds(tstart.tv_usec);
69 auto stop = std::chrono::seconds(tstop.tv_sec) +
70 std::chrono::microseconds(tstop.tv_usec);
71 telapsed += DurationType(stop - start).count();
74 ElapsedType elapsed()
const {
return telapsed; }
76 void reset() { telapsed = 0; }
84 using TimerBase = BGQTimer;
88 #elif defined(RAJA_USE_CHRONO)
106 using ElapsedType = double;
109 using ClockType = std::chrono::steady_clock;
110 using TimeType = ClockType::time_point;
111 using DurationType = std::chrono::duration<ElapsedType>;
114 ChronoTimer() : tstart(ClockType::now()), tstop(ClockType::now()), telapsed(0)
117 void start() { tstart = ClockType::now(); }
121 tstop = ClockType::now();
123 std::chrono::duration_cast<DurationType>(tstop - tstart).count();
126 ElapsedType elapsed()
const {
return telapsed; }
128 void reset() { telapsed = 0; }
133 ElapsedType telapsed;
136 using TimerBase = ChronoTimer;
140 #elif defined(RAJA_USE_GETTIME)
158 using ElapsedType = double;
161 using TimeType = timespec;
164 GettimeTimer() : telapsed(0), stime_elapsed(0), nstime_elapsed(0) { ; }
166 void start() { clock_gettime(CLOCK_MONOTONIC, &tstart); }
170 clock_gettime(CLOCK_MONOTONIC, &tstop);
174 ElapsedType elapsed()
const {
return (stime_elapsed + nstime_elapsed); }
187 ElapsedType stime_elapsed;
188 ElapsedType nstime_elapsed;
192 stime_elapsed +=
static_cast<ElapsedType
>(tstop.tv_sec - tstart.tv_sec);
194 static_cast<ElapsedType
>(tstop.tv_nsec - tstart.tv_nsec) / 1000000000.0;
198 using TimerBase = GettimeTimer;
201 #elif defined(RAJA_USE_CLOCK)
220 using ElapsedType = double;
223 using TimeType = clock_t;
226 ClockTimer() : telapsed(0) { ; }
228 void start() { tstart = clock(); }
236 ElapsedType elapsed()
const
238 return static_cast<ElapsedType
>(telapsed) / CLOCKS_PER_SEC;
241 void reset() { telapsed = 0; }
246 long double telapsed;
248 void set_elapsed() { telapsed += (tstop - tstart); }
251 using TimerBase = ClockTimer;
256 #error RAJA_TIMER is undefined!
266 using TimerBase::start;
267 using TimerBase::stop;
269 #if defined(RAJA_USE_CALIPER)
270 void start(
const char* name) { cali::Annotation(name).begin(); }
272 void stop(
const char* name) { cali::Annotation(name).end(); }
Definition: Timer.hpp:264
void start(const char *)
Definition: Timer.hpp:274
void stop(const char *)
Definition: Timer.hpp:276
Definition: AlignedRangeIndexSetBuilders.cpp:35