-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVinciaDiagnostics.cc
128 lines (108 loc) · 4.33 KB
/
VinciaDiagnostics.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// VinciaDiagnstoics.cc is a part of the PYTHIA event generator.
// Copyright (C) 2024 Peter Skands, Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.
// Function definitions (not found in the header) for Vincia's
// diagnostics class.
#include "Pythia8/VinciaCommon.h"
#include "Pythia8/VinciaDiagnostics.h"
namespace Pythia8 {
using namespace VinciaConstants;
//==========================================================================
// Vincia diagnostics.
//--------------------------------------------------------------------------
// Define and increment a counter.
void VinciaDiagnostics::increment(string methodName, string variableName,
double inc) {
map<string, double> counter;
if (counters.find(methodName) != counters.end())
counter = counters[methodName];
else counters[methodName] = counter;
if (counter.find(variableName) != counter.end())
counters[methodName][variableName] += inc;
else
counters[methodName][variableName] = inc;
}
//--------------------------------------------------------------------------
// Called when "name" starts.
void VinciaDiagnostics::start(string name) {
// Measure number of calls.
++nStarts[name];
// If this is already running, this is a restart.
if (isRunning.find(name) != isRunning.end()) {
if (isRunning[name]) ++nRestarts[name];
else startTime[name] = clock();
} else {
// If not already running, start clock.
startTime[name] = clock();
isRunning[name] = true;
}
}
//--------------------------------------------------------------------------
// Called when "name" starts.
void VinciaDiagnostics::stop(string name, string counter, double inc) {
// Measure CPU runtime.
isRunning[name] = false;
clock_t stopTime = clock();
double runNow = 1000. * (double) (stopTime-startTime[name])/CLOCKS_PER_SEC;
if (runTime.find(name) == runTime.end()) {
hRunTime[name] = Hist("runTime in milliseconds",100,0.0,10.);
runTime[name] = runNow;
}
else {
runTime[name] += runNow;
}
hRunTime[name].fill(runNow);
if (counter != "") increment(name, counter, inc);
}
//--------------------------------------------------------------------------
// Print diagnostics.
void VinciaDiagnostics::print() {
cout<<"\n *------- VINCIA Diagnostics and Profiling -------------------"
"----------------------------------------------------------*\n";
double nEvent = max((double)infoPtr->nAccepted(),1.);
for (auto it = nStarts.begin(); it != nStarts.end(); ++it) {
string name = it->first;
cout<<" |\n"
<<" | Diagnostics for " << name<<endl;
cout<<" | total time = " << num2str(runTime[name]/nEvent,9)
<<"ms/Event nCalls/event = " << num2str(nStarts[name]/nEvent,9)
<<" failure rate = "
<< nRestarts[name]/max(1.,nStarts[name]) << endl;
// Produce tables with over- and underflow bins.
string fileName = name;
// Remove last 2 characters () from name
fileName.resize(fileName.size() - 2);
fileName += ".dat";
hRunTime[name].table(fileName, true);
// Also print counters associated with the same method.
if (counters.find(name) != counters.end()) {
for (auto jt = counters[name].begin(); jt != counters[name].end();
++jt) {
string variable = jt->first;
double rate = jt->second/nEvent;
cout<<" | "<<num2str(rate,9)<<" : "<<variable<<" / event"<<endl;
}
counters.erase(name);
}
}
// Print any counters not associated with profiled methods.
for (auto it = counters.begin(); it != counters.end(); ++it) {
string name = it->first;
cout<<" | \n"
<<" | Diagnostics for "<<name<<endl;
for (auto jt = counters[name].begin(); jt != counters[name].end();
++jt) {
string variable = jt->first;
double rate = jt->second/nEvent;
cout<<" | "<<num2str(rate,9)<<" : "<<variable<<" / event"<<endl;
}
}
cout<<" |\n"
<<" | See also the generated .runtime files for "
<<"histograms of run times per call.\n";
cout<<" |\n *------- End VINCIA Diagnostics and Profiling -----------"
"--------------------------------------------------------------*\n\n";
}
//==========================================================================
} // end namespace Pythia8