ExaDG
Toggle main menu visibility
Loading...
Searching...
No Matches
include
exadg
postprocessor
spectral_analysis
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 EXADG_POSTPROCESSOR_SPECTRAL_ANALYSIS_TIMER_H_
23
#define EXADG_POSTPROCESSOR_SPECTRAL_ANALYSIS_TIMER_H_
24
25
namespace
dealspectrum
26
{
30
class
DealSpectrumTimer
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
50
public
:
54
DealSpectrumTimer
()
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
112
printTimings
()
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
/* EXADG_POSTPROCESSOR_SPECTRAL_ANALYSIS_TIMER_H_ */
dealspectrum::DealSpectrumTimer::start
void start(std::string label)
Definition
timer.h:64
dealspectrum::DealSpectrumTimer::DealSpectrumTimer
DealSpectrumTimer()
Definition
timer.h:54
dealspectrum::DealSpectrumTimer::printTimings
void printTimings()
Definition
timer.h:112
dealspectrum::DealSpectrumTimer::append
void append(std::string label)
Definition
timer.h:95
dealspectrum::DealSpectrumTimer::stop
void stop(std::string label)
Definition
timer.h:78
Generated by
1.17.0