ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1#ifndef TIMER_H
2#define TIMER_H
3
4#include <ctime>
5#include <fstream>
6#include <iomanip>
7#include <iostream>
8#include <map>
9#include <string>
10
11namespace ModuleBase
12{
18class timer
19{
20 public:
21 struct Timer_One
22 {
23 double cpu_start;
24 double cpu_second = 0.0;
25 size_t calls = 0;
26 size_t order = n_now++;
27 bool start_flag = true;
28 };
29
30 static std::map<std::string, std::map<std::string, Timer_One>> timer_pool;
31
39 static void tick(const std::string &class_name_in, const std::string &name_in);
40
45 static void start(void);
46
54 static void finish(std::ofstream &ofs, const bool print_flag = 1);
55
60 static void enable(void)
61 {
62 disabled = false;
63 }
64
69 static void disable(void)
70 {
71 disabled = true;
72 }
73
79 static void write_to_json(std::string file_name);
80
86 static void print_all(std::ofstream &ofs);
87
94 static long double print_until_now(void);
95
96 private:
101 static bool disabled;
102
107 static size_t n_now;
108
114 static double cpu_time(void);
115};
116
117} // namespace ModuleBase
118#endif
Tracing computation time.
Definition timer.h:19
static std::map< std::string, std::map< std::string, Timer_One > > timer_pool
Definition timer.h:30
static void enable(void)
Enable time computation.
Definition timer.h:60
static void finish(std::ofstream &ofs, const bool print_flag=1)
Finish total time calculation and print computational processes with duration > 0....
Definition timer.cpp:27
static void tick(const std::string &class_name_in, const std::string &name_in)
Use twice at a time: the first time, set start_flag to false; the second time, calculate the time dur...
Definition timer.cpp:57
static size_t n_now
Member variable: the index of clocks.
Definition timer.h:107
static bool disabled
Member variable: if disabled , timer can't work.
Definition timer.h:101
static long double print_until_now(void)
Stop total time calculation, print total time until now, and then start total time calculation again.
Definition timer.cpp:114
static void write_to_json(std::string file_name)
Write all computational processes to json file.
Definition timer.cpp:123
static void print_all(std::ofstream &ofs)
Print all computational processes with during > 0.1 s.
Definition timer.cpp:230
static void start(void)
Start total time calculation.
Definition timer.cpp:38
static void disable(void)
Disable time computation.
Definition timer.h:69
static double cpu_time(void)
Member function: calculate time.
Definition timer.cpp:44
Definition array_pool.h:6
Definition timer.h:22
double cpu_second
Definition timer.h:24
size_t calls
Definition timer.h:25
bool start_flag
Definition timer.h:27
size_t order
Definition timer.h:26
double cpu_start
Definition timer.h:23