ExaDG
Loading...
Searching...
No Matches
timer.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef DEAL_SPECTRUM_TIMER
23#define DEAL_SPECTRUM_TIMER
24
25namespace dealspectrum
26{
31{
37 class Instance
38 {
39 public:
40 // ... timing instance has been started
41 bool started;
42 // ... current timing
43 clock_t time;
44 // ... temporal timing
45 clock_t temp;
46 // ... how often has this been timed
47 int count;
48 };
49
50public:
55 {
56 }
57
63 void
64 start(std::string label)
65 {
66 if(not m.count(label))
67 m[label] = Instance();
68 m[label].temp = clock();
69 m[label].started = true;
70 }
71
77 void
78 stop(std::string label)
79 {
80 if(m.count(label) and m[label].started)
81 {
82 auto & t = m[label];
83 t.time = clock() - m[label].temp;
84 t.started = false;
85 t.count++;
86 }
87 }
88
94 void
95 append(std::string label)
96 {
97 if(m.count(label) and m[label].started)
98 {
99 auto & t = m[label];
100 t.time += (clock() - t.temp);
101 t.started = false;
102 t.count++;
103 }
104 }
105
111 void
113 {
114 double sum_total = 0;
115 double sum_latency = 0;
116 printf("\n\ndeal.spectrum timing statistics in seconds:\n");
117 printf("===============================================================\n");
118 printf(" #nr ave sum\n");
119 printf("===============================================================\n");
120 for(auto const & i : m)
121 {
122 printf(" %-18s %4d %18.12f %18.12f\n",
123 i.first.c_str(),
124 i.second.count,
125 ((double)i.second.time) / CLOCKS_PER_SEC / i.second.count,
126 ((double)i.second.time) / CLOCKS_PER_SEC);
127 sum_total += ((double)i.second.time) / CLOCKS_PER_SEC;
128 sum_latency += ((double)i.second.time) / CLOCKS_PER_SEC / i.second.count;
129 }
130 printf("===============================================================\n");
131 printf(" %18.12f %18.12f\n", sum_latency, sum_total);
132 printf("===============================================================\n");
133 printf("\n\n");
134 }
135
136 // map containing timing instances
137 std::map<std::string, Instance> m;
138};
139
140} // namespace dealspectrum
141
142#endif
Definition timer.h:31
void start(std::string label)
Definition timer.h:64
DealSpectrumTimer()
Definition timer.h:54
void printTimings()
Definition timer.h:112
void append(std::string label)
Definition timer.h:95
void stop(std::string label)
Definition timer.h:78