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 <string>
4 
5 
6 namespace opencarp {
7 
8 
10 {
11  logger = f_open(filename, "w");
12 
13  const char* h1 = " ----- ----- ------- ----- ----- | ---- ----- --------- --------- --------- |";
14  const char* h2 = " mn it mx it avg it its ttits | ss ts st stps stpit |";
15 
16  if(logger == NULL)
17  log_msg(NULL, 3, 0,"%s error: Could not open file %s in %s. Turning off logging.\n",
18  __func__, filename);
19  else {
20  log_msg(logger, 0, 0, "%s", h1);
21  log_msg(logger, 0, 0, "%s", h2);
22  }
23 }
24 
25 void lin_solver_stats::log_stats(double tm, bool cflg)
26 {
27  if(!this->logger) return;
28 
29  // make sure this->solves is > 0
30  if(!this->solves) this->solves++;
31 
32  char itbuf[256];
33  char stbuf[64];
34 
35  // iterations in this period
36  float its = (this->tot-this->last_tot);
37 
38  // total solver time spent in this period
39  float tstm = this->slvtime-this->lastSlvtime;
40 
41  // solver time per solve
42  float stm = tstm/this->solves;
43 
44  // solver time per iteration
45  float itm = its?tstm/its:0.;
46 
47  if(!its)
48  this->min = 0;
49  this->totsolves += this->solves;
50 
51  snprintf(itbuf, sizeof itbuf, "%5d %5d %7.1f %6d %6d",
52  this->min, this->max, (float)(its/this->solves),
53  this->tot - this->last_tot, this->tot );
54  snprintf(stbuf, sizeof stbuf, "%4d %5d %9.4f %9.4f %9.4f",this->solves,this->totsolves,
55  (float)tstm,stm,itm);
56 
57  unsigned char flag = cflg? ECHO : 0;
58  log_msg(this->logger, 0, flag|FLUSH|NONL, "%9.3f %s | %s |\n", tm, itbuf, stbuf);
59 
60  this->min = INT_MAX;
61  this->max = 0;
62  this->last_tot = this->tot;
63  this->solves = 0;
64  this->lastSlvtime = this->slvtime;
65 }
66 
67 void lin_solver_stats::update_iter(const int curiter)
68 {
69  if (curiter > max) max = curiter;
70  if (curiter < min) min = curiter;
71  tot += curiter;
72  solves++;
73 }
74 
76 {
77  logger = f_open(filename, "w");
78 
79  const char* h1 = " ----- ----- | --------- --------- |";
80  const char* h2 = " cls ttcls | time tot time |";
81 
82  if(logger == NULL)
83  log_msg(NULL, 3, 0,"%s error: Could not open file %s in %s. Turning off logging.\n",
84  __func__, filename);
85  else {
86  log_msg(logger, 0, 0, "%s", h1);
87  log_msg(logger, 0, 0, "%s", h2);
88  }
89 }
90 
91 void generic_timing_stats::log_stats(double tm, bool cflg)
92 {
93  if(!this->logger) return;
94 
95  char cbuf[256];
96  char tbuf[256];
97 
98  // time spent in this period
99  float ctm = this->tot_time - this->last_tot_time;
100  this->tot_calls += this->calls;
101 
102  snprintf(cbuf, sizeof cbuf, "%5d %5d", this->calls, this->tot_calls);
103  snprintf(tbuf, sizeof tbuf, "%9.4f %9.4f", ctm, this->tot_time);
104 
105  unsigned char flag = cflg? ECHO : 0;
106  log_msg(this->logger, 0, flag|FLUSH|NONL, "%9.3f %s | %s |\n", tm, cbuf, tbuf);
107 
108  this->last_tot_time = this->tot_time;
109  this->calls = 0;
110 }
111 
112 
113 } // namespace opencarp
int totsolves
total # of solutions
Definition: timers.h:18
void log_stats(double tm, bool cflg)
Definition: timers.cc:91
#define FLUSH
Definition: basics.h:311
void init_logger(const char *filename)
Definition: timers.cc:9
FILE_SPEC logger
file in which to write stats
Definition: timers.h:21
int solves
#solutions performed
Definition: timers.h:17
#define ECHO
Definition: basics.h:308
void init_logger(const char *filename)
Definition: timers.cc:75
double lastSlvtime
total solver time
Definition: timers.h:20
int min
minimum #interations
Definition: timers.h:12
int last_tot
previous total #
Definition: timers.h:15
void log_stats(double tm, bool cflg)
Definition: timers.cc:25
void update_iter(const int curiter)
Definition: timers.cc:67
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:19
int max
maximum #iterations
Definition: timers.h:13
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
Definition: basics.cc:135