Paramotopy
parallel parameter homotopy through bertini
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
timing.cpp
Go to the documentation of this file.
1 #include "timing.hpp"
2 
3 
4 
5 void timer::press_start(const std::string timer_name){
6 
7  timer::create_timer(timer_name);
8  this->active_timers[timer_name].t1 = std::chrono::high_resolution_clock::now();
9  return;
10 }
11 
12 void timer::add_time(const std::string timer_name){
13 
14  if (timer::create_timer(timer_name)){
15  std::cerr << "tried to add time to a counter which didn't exist!" << std::endl;
16  exit(909);
17  }
18 
19  this->active_timers[timer_name].elapsed_time += std::chrono::duration_cast<std::chrono::milliseconds>(
20  std::chrono::high_resolution_clock::now() - this->active_timers[timer_name].t1);
21  this->active_timers[timer_name].num_calls_timed++;
22 
23  return;
24 }
25 //aa
26 void timer::add_time(const std::string timer_name, const int num_incrementations){
27 
28  if (timer::create_timer(timer_name)){
29  std::cerr << "tried to add time to a counter which didn't exist!" << std::endl;
30  exit(910);
31  }
32 
33  this->active_timers[timer_name].elapsed_time += std::chrono::duration_cast<std::chrono::milliseconds>(
34  std::chrono::high_resolution_clock::now() - this->active_timers[timer_name].t1);
35  this->active_timers[timer_name].num_calls_timed += num_incrementations;
36 
37  return;
38 }
39 
40 
41 bool timer::create_timer(const std::string timer_name){
42 
43  if (this->active_timers.find( timer_name ) == this->active_timers.end()) {
44  this->active_timers[timer_name] = timer_data(); //instantiate.
45  return true;
46  }
47  else{
48  return false;
49  }
50 
51 }
52 
53 
54 
55 
56 
57 bool timer::write_timing_data(const boost::filesystem::path folder_to_write_to, const int myid){
58 
59  boost::filesystem::path file_to_write_to = folder_to_write_to;
60 
61 
62 
63  std::stringstream converter;
64  converter << myid;
65 
66  if (myid==0) {
67  file_to_write_to /= "master";
68  }
69  else{
70  file_to_write_to /= "slave";
71  }
72  file_to_write_to += "timing";
73 
74 
75  if (myid==0) {
76  }
77  else{
78  file_to_write_to += converter.str();
79  }
80 
81  std::ofstream fout(file_to_write_to.c_str());
82  if (!fout.is_open()) {
83  std::cerr << "failed to open " << file_to_write_to.string() << " to write timing data" << std::endl;
84  return false;
85  }
86 
87 
88 
89  std::map< std::string, timer_data >::iterator iter;
90  fout << myid << std::endl;
91 
92  timer::add_time("total");
93 
94  for (iter = this->active_timers.begin(); iter != this->active_timers.end(); iter++) {
95  fout << iter->first << ": " << iter->second.elapsed_time.count() << " " << iter->second.num_calls_timed << std::endl;
96  }
97 
98  fout.close();
99  return true;
100 }
101 
102 
103 
std::map< std::string, timer_data > active_timers
Definition: timing.hpp:124
bool create_timer(const std::string timer_name)
Definition: timing.cpp:41
void add_time(const std::string timer_name)
Definition: timing.cpp:12
Small class, with no methods, for holding timing data.
Definition: timing.hpp:36
bool write_timing_data(const boost::filesystem::path folder_to_write_to, const int myid)
Definition: timing.cpp:57
void press_start(const std::string timer_name)
Definition: timing.cpp:5