HILA
Loading...
Searching...
No Matches
timing.h
1#ifndef TIMING_H
2#define TIMING_H
3
4#include "plumbing/defs.h"
5
6namespace hila {
7
8////////////////////////////////////////////////////////////////
9/// This file defines timer class and other timing related utilities
10
12 double time; // time accumulated in this timer (in sec)
13 int64_t count; // how many times this timer has been used (start - stop interval)
14};
15
16// clang-format off
17////////////////////////////////////////////////////////////////
18///
19/// Timers are used to time recurring events. Usage:
20///
21/// static timer loop_timer("Loop");
22///
23/// loop_timer.start();
24/// < timed section >
25/// loop_timer.stop();
26///
27/// All timer values are automatically reported on program exit (hila::finishrun calls
28/// report_timers())
29///
30/// Timer can be reset with
31/// loop_timer.reset();
32///
33/// Timer value can be inquired with
34/// timer_value tval = loop_timer.value();
35/// where timer_value is a struct defined below.
36///
37///
38/// Other time related functions:
39/// double hila::gettime(); - returns the time in seconds from program
40/// start void hila::timestamp("message"); - prints msg + current date+time +
41/// time from start
42///
43/// void hila::setup_timelimit(long seconds); - sets the cpu time limit (see
44/// time_to_finish())
45/// bool hila::time_to_finish(); - to be called periodically
46/// at a suitable spot in
47/// the program; returns true if the program
48/// should exit now.
49///
50/// Signal handling functions (for SIGUSR1):
51/// int hila::signal_status(); - returns the signal SIGUSR1 if set
52///
53////////////////////////////////////////////////////////////////
54// clang-format on
55
56
57class timer {
58 private:
59 double t_start, t_total;
60 int64_t count; // need more than 32 bits
61 std::string label;
62 bool is_on, is_error;
63
64 public:
65 // initialize timer to this timepoint
66 timer() {
67 init(nullptr);
68 }
69 timer(const char *tag) {
70 init(tag);
71 }
72
73 ~timer() {
74 remove();
75 }
76
77 void init(const char *tag);
78 void remove();
79 void reset();
80 double start();
81 double stop();
82 void error();
83 void report(bool print_not_timed = false);
84
85 timer_value value();
86};
87
88void report_timers();
89
90//////////////////////////////////////////////////////////////////
91// Prototypes
92//////////////////////////////////////////////////////////////////
93
94double gettime();
95void inittime();
96
97bool time_to_finish();
98void setup_timelimit(const std::string &timestr);
99void setup_timelimit(const double seconds);
100
101void timestamp(const char *msg);
102void timestamp(const std::string &msg);
103
104// signal handling
105void setup_signal_handler();
106int signal_status();
107
108
109} // namespace hila
110
111#endif /* timing */
This file defines all includes for HILA.
Implement hila::swap for gauge fields.
Definition array.h:981
void setup_timelimit(const double secs)
Setup time limit with seconds.
Definition timing.cpp:197
double gettime()
Definition timing.cpp:167
bool time_to_finish()
Definition timing.cpp:327
This file defines timer class and other timing related utilities.
Definition timing.h:11