ARTS  2.4.0(git:4fb77825)
timings.h
Go to the documentation of this file.
1 
9 #ifndef timings_h
10 #define timings_h
11 
12 #include <iostream>
13 #include "arts.h"
14 #include "arts_omp.h"
15 
17 
24 class Timings {
25  public:
26  friend std::ostream &operator<<(std::ostream &os, const Timings &timer);
27 
29 
32  Timings() : running(), times(), stamps(), names() {
33  ntimers = 0;
34  nrunning = 0;
35  stamp = 0.0;
36  total_time = 0.0;
37  }
38 
40 
47  ntimers++;
48  running.push_back(false);
49  times.push_back(0.0);
50  names.push_back(name);
51  stamps.push_back(0.0);
52 
53  return (Index)ntimers - 1;
54  }
55 
57 
65 #ifdef OMP
66  return omp_get_wtime();
67 #else
68  return 0.0;
69 #endif
70  }
71 
73 
80  void mark(Index i) {
81  if (i < ntimers) {
82  // Stop timer if it is running and check if overall timer
83  // must be stopped.
84 
85  if (running[i]) {
86  Numeric t = get_time();
87  times[i] += t - stamps[i];
88  running[i] = false;
89 
90  nrunning--;
91  if (nrunning == 0) total_time += get_time() - stamp;
92 
93  } else // Continue timer if not running.
94  {
95  if (nrunning == 0) stamp = get_time();
96 
97  nrunning++;
98 
99  stamps[i] = get_time();
100  running[i] = true;
101  }
102  }
103  }
104 
105  private:
108  std::vector<bool> running;
109  std::vector<Numeric> times, stamps;
110  std::vector<String> names;
111 };
112 
113 #endif // timer_h
Timings::operator<<
friend std::ostream & operator<<(std::ostream &os, const Timings &timer)
Print timing results.
Definition: timings.cc:18
Timings::add_timer
Index add_timer(String name)
Add timer.
Definition: timings.h:46
Timings
Timings Class.
Definition: timings.h:24
ARTS::Var::timer
Timer timer(Workspace &ws) noexcept
Definition: autoarts.h:7064
Timings::names
std::vector< String > names
Definition: timings.h:110
Timings::get_time
Numeric get_time()
Get Wall Time.
Definition: timings.h:64
Timings::total_time
Numeric total_time
Definition: timings.h:107
Timings::ntimers
Index ntimers
Definition: timings.h:106
Timings::running
std::vector< bool > running
Definition: timings.h:108
Timings::stamps
std::vector< Numeric > stamps
Definition: timings.h:109
my_basic_string< char >
Timings::times
std::vector< Numeric > times
Definition: timings.h:109
Timings::Timings
Timings()
Simple Constructor.
Definition: timings.h:32
Timings::stamp
Numeric stamp
Definition: timings.h:107
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Timings::nrunning
Index nrunning
Definition: timings.h:106
arts_omp.h
Header file for helper functions for OpenMP.
Timings::mark
void mark(Index i)
Start/Stop Timings.
Definition: timings.h:80
arts.h
The global header file for ARTS.