MADNESS 0.10.1
timing_utilities.h
Go to the documentation of this file.
1//
2// Created by Florian Bischoff on 5/15/21.
3//
4
5#ifndef MADNESS_TIMING_UTILITIES_H
6#define MADNESS_TIMING_UTILITIES_H
7
8namespace madness {
9struct timer {
11 double ttt=0.0, sss=0.0; // duration
12 bool do_print = true;
13 bool is_running=false;
14
16 world.gop.fence();
17 resume();
18 }
19
20 void resume() {
21 if (is_running) print("timer was already running!");
22 world.gop.fence();
23 ttt-=wall_time();
24 sss-=cpu_time();
25 is_running=true;
26 }
27
28 double interrupt() {
29 world.gop.fence();
30 ttt+=wall_time();
31 sss+=cpu_time();
32 is_running=false;
33 return sss;
34 }
35
36 void print(const std::string msg) const {
37 if (world.rank() == 0 and do_print) {
38 std::stringstream ss;
39 ss << "timer:" << std::setw(30) << msg << std::setw(8) << std::setprecision(2)
40 << std::fixed << sss << "s " << ttt <<"s";
41 std::cout << ss.str() << std::endl;
42 }
43 }
44
45 double tag(const std::string msg) {
46 world.gop.fence();
47 interrupt();
48 print(msg);
49 double cpu=sss;
50 ttt=0.0;
51 sss=0.0;
52 resume();
53 return cpu;
54 }
55
56 double end(const std::string msg) {
57 return tag(msg);
58// world.gop.fence();
59// double tt1 = wall_time() - ttt;
60// double ss1 = cpu_time() - sss;
61// if (world.rank() == 0 and do_print) printf("timer: %20.20s %8.2fs %8.2fs\n", msg.c_str(), ss1, tt1);
62 }
63};
64}
65
66#endif //MADNESS_TIMING_UTILITIES_H
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:161
A parallel world class.
Definition world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:318
WorldGopInterface & gop
Global operations.
Definition world.h:205
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
static double cpu_time()
Returns the cpu time in seconds relative to an arbitrary origin.
Definition timers.h:127
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
Definition timing_utilities.h:9
bool is_running
Definition timing_utilities.h:13
double sss
Definition timing_utilities.h:11
World & world
Definition timing_utilities.h:10
double tag(const std::string msg)
Definition timing_utilities.h:45
double interrupt()
Definition timing_utilities.h:28
double ttt
Definition timing_utilities.h:11
timer(World &world, bool do_print=true)
Definition timing_utilities.h:15
void print(const std::string msg) const
Definition timing_utilities.h:36
void resume()
Definition timing_utilities.h:20
bool do_print
Definition timing_utilities.h:12
double end(const std::string msg)
Definition timing_utilities.h:56