openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
timers.cc
Go to the documentation of this file.
1 #include "timers.h"
2 
3 #include <cstddef>
4 #include <cstdio>
5 #include <string>
6 #include "basics.h"
7 
8 namespace opencarp
9 {
10 
12 {
13  logger = f_open(filename, "w");
14 
15  const char* h1 = " ----- ----- ------- ----- ----- | ---- ----- --------- --------- --------- |";
16  const char* h2 = " mn it mx it avg it its ttits | ss ts st stps stpit |";
17 
18  if (logger == NULL)
19  log_msg(NULL, 3, 0, "%s error: Could not open file %s in %s. Turning off logging.\n",
20  __func__, filename);
21  else {
22  log_msg(logger, 0, 0, "%s", h1);
23  log_msg(logger, 0, 0, "%s", h2);
24  }
25 }
26 
27 void lin_solver_stats::log_stats(double tm, bool cflg)
28 {
29  if (!this->logger) return;
30 
31  // make sure this->solves is > 0
32  if (!this->solves) this->solves++;
33 
34  char itbuf[256];
35  char stbuf[64];
36 
37  // iterations in this period
38  float its = (this->tot - this->last_tot);
39 
40  // total solver time spent in this period
41  float tstm = this->slvtime - this->lastSlvtime;
42 
43  // solver time per solve
44  float stm = tstm / this->solves;
45 
46  // solver time per iteration
47  float itm = its ? tstm / its : 0.;
48 
49  if (!its)
50  this->min = 0;
51  this->totsolves += this->solves;
52 
53  snprintf(itbuf, sizeof itbuf, "%5d %5d %7.1f %6d %6d",
54  this->min, this->max, (float)(its / this->solves),
55  this->tot - this->last_tot, this->tot);
56  snprintf(stbuf, sizeof stbuf, "%4d %5d %9.4f %9.4f %9.4f", this->solves, this->totsolves,
57  (float)tstm, stm, itm);
58 
59  unsigned char flag = cflg ? ECHO : 0;
60  log_msg(this->logger, 0, flag | FLUSH | NONL, "%9.3f %s | %s |\n", tm, itbuf, stbuf);
61 
62  this->min = INT_MAX;
63  this->max = 0;
64  this->last_tot = this->tot;
65  this->solves = 0;
66  this->lastSlvtime = this->slvtime;
67 }
68 
69 void lin_solver_stats::update_iter(const int curiter)
70 {
71  if (curiter > max) max = curiter;
72  if (curiter < min) min = curiter;
73  tot += curiter;
74  solves++;
75 }
76 
78 {
79  logger = f_open(filename, "w");
80 
81  const char* h1 = " ----- ----- | --------- --------- |";
82  const char* h2 = " cls ttcls | time tot time |";
83 
84  if (logger == NULL)
85  log_msg(NULL, 3, 0, "%s error: Could not open file %s in %s. Turning off logging.\n",
86  __func__, filename);
87  else {
88  log_msg(logger, 0, 0, "%s", h1);
89  log_msg(logger, 0, 0, "%s", h2);
90  }
91 }
92 
93 void generic_timing_stats::log_stats(double tm, bool cflg)
94 {
95  if (!this->logger) return;
96 
97  char cbuf[256];
98  char tbuf[256];
99 
100  // time spent in this period
101  float ctm = this->tot_time - this->last_tot_time;
102  this->tot_calls += this->calls;
103 
104  snprintf(cbuf, sizeof cbuf, "%5d %5d", this->calls, this->tot_calls);
105  snprintf(tbuf, sizeof tbuf, "%9.4f %9.4f", ctm, this->tot_time);
106 
107  unsigned char flag = cflg ? ECHO : 0;
108  log_msg(this->logger, 0, flag | FLUSH | NONL, "%9.3f %s | %s |\n", tm, cbuf, tbuf);
109 
110  this->last_tot_time = this->tot_time;
111  this->calls = 0;
112 }
113 
115 {
116  logger = f_open(filename, "w");
117 
118  const char* h1 = " CycFIM (Step A) ------ ------ --------- --------- | Idiff (Step B) ------ | Repol. times (Step D)";
119  const char* h2 = " mn AT mx AT its ttits time tttime | time tttime | time tttime";
120 
121  if (logger == NULL)
122  log_msg(NULL, 3, 0, "%s error: Could not open file %s in %s. Turning off logging.\n",
123  __func__, filename);
124  else {
125  log_msg(logger, 0, 0, "%s", h1);
126  log_msg(logger, 0, 0, "%s", h2);
127  }
128 }
129 
130 void eikonal_solver_stats::log_stats(double time, bool cflg)
131 {
132  if (!this->logger) return;
133 
134  char abuf[256];
135  char bbuf[256];
136  char dbuf[256];
137 
138  // iterations in this period
139  float its = (this->tot - this->last_tot);
140 
141  // total solver time spent in this period
142  float tstm_A = this->slvtime_A - this->lastSlvtime_A;
143  float tstm_B = this->slvtime_B - this->lastSlvtime_B;
144  float tstm_D = this->slvtime_D - this->lastSlvtime_D;
145 
146  this->totsolves += this->solves;
147 
148  snprintf(abuf, sizeof abuf, "%7.2f %7.2f %6d %6d %10.4f %10.4f", this->minAT, this->maxAT, this->tot - this->last_tot, this->tot, tstm_A, this->slvtime_A);
149  snprintf(bbuf, sizeof bbuf, "%10.4f %10.4f", tstm_B, this->slvtime_B);
150  snprintf(dbuf, sizeof dbuf, "%10.4f %10.4f", tstm_D, this->slvtime_D);
151 
152  unsigned char flag = cflg ? ECHO : 0;
153  log_msg(this->logger, 0, flag | FLUSH | NONL, "%9.3f %s | %s | %s\n", time, abuf, bbuf, dbuf);
154 
155  this->lastSlvtime_A = this->slvtime_A;
156  this->lastSlvtime_B = this->slvtime_B;
157  this->lastSlvtime_D = this->slvtime_D;
158  this->last_tot = this->tot;
159  this->solves = 0;
160 }
161 
162 void eikonal_solver_stats::update_iter(const int curiter)
163 {
164  tot += curiter;
165  solves++;
166 }
167 
168 void eikonal_solver_stats::update_cli(double time, bool cflg)
169 {
170  char buf[256];
171 
172  // total solver time spent in this period
173  float tstm_A = this->slvtime_A - this->lastSlvtime_A;
174  float tstm_B = this->slvtime_B - this->lastSlvtime_B;
175  float tstm_D = this->slvtime_D - this->lastSlvtime_D;
176 
177  snprintf(buf, sizeof buf, "EIK_CYC %d", this->cycle);
178  log_msg(NULL, 0, ECHO | FLUSH, "%.2f\t----\t%.1f\t%15s", time, tstm_A+tstm_B+tstm_D, buf);
179 
180  if (param_globals::output_level > 1) {
181  const char* end_out = "----\t----- \t----\t-------\t-------";
182  log_msg(NULL, 0, ECHO | FLUSH, "minAT:\t%.2f -> %.2f", last_minAT, minAT);
183  log_msg(NULL, 0, ECHO | FLUSH, "maxAT:\t%.2f -> %.2f", last_maxAT, maxAT);
184  log_msg(NULL, 0, ECHO | FLUSH, "active list: %7i \tbc applied: %3s", this->activeList, this->bc_status ? "yes" : "no");
185  log_msg(NULL, 0, ECHO | FLUSH, "%s", end_out);
186  }
187 
188  this->cycle++;
189  this->bc_status = false;
190  this->last_minAT = this->minAT;
191  this->last_maxAT = this->maxAT;
192 }
193 
194 } // namespace opencarp
int totsolves
total # of solutions
Definition: timers.h:20
void log_stats(double tm, bool cflg)
Definition: timers.cc:93
#define FLUSH
Definition: basics.h:311
void init_logger(const char *filename)
Definition: timers.cc:11
FILE_SPEC logger
file in which to write stats
Definition: timers.h:23
int solves
#solutions performed
Definition: timers.h:19
#define ECHO
Definition: basics.h:308
void init_logger(const char *filename)
Definition: timers.cc:77
void update_cli(double time, bool cflg)
Definition: timers.cc:168
void log_stats(double time, bool cflg)
Definition: timers.cc:130
double lastSlvtime
total solver time
Definition: timers.h:22
void init_logger(const char *filename)
Definition: timers.cc:114
void update_iter(const int curiter)
Definition: timers.cc:162
int min
minimum #interations
Definition: timers.h:14
int last_tot
previous total #
Definition: timers.h:17
void log_stats(double tm, bool cflg)
Definition: timers.cc:27
void update_iter(const int curiter)
Definition: timers.cc:69
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
Definition: basics.cc:72
#define NONL
Definition: basics.h:312
double slvtime
total solver time
Definition: timers.h:21
int max
maximum #iterations
Definition: timers.h:15
Basic utility structs and functions, mostly IO related.
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
Definition: basics.cc:135