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 start(const std::string &class_name_in, const std::string &name_in);
40 static void end(const std::string &class_name_in, const std::string &name_in);
41
46 static void start(void);
47
55 static void finish(std::ofstream &ofs, const bool print_flag = true, const bool check_end = true);
56
61 static void enable(void)
62 {
63 disabled = false;
64 }
65
70 static void set_nvtx_enabled(bool b)
71 {
72 enable_nvtx_ = b;
73 }
74
79 static void disable(void)
80 {
81 disabled = true;
82 }
83
89 static void write_to_json(std::string file_name);
90
96 static void print_all(std::ofstream &ofs, const bool check_end);
97
104 static long double print_until_now(void);
105
106 private:
111 static bool disabled;
112
116 static bool enable_nvtx_;
117
122 static size_t n_now;
123
129 static double cpu_time(void);
130};
131
132} // namespace ModuleBase
133#endif
Tracing computation time.
Definition timer.h:19
static bool enable_nvtx_
Member variable: NVTX range emission toggle (CUDA profiling only).
Definition timer.h:116
static std::map< std::string, std::map< std::string, Timer_One > > timer_pool
Definition timer.h:30
static void print_all(std::ofstream &ofs, const bool check_end)
Print all computational processes with during > 0.1 s.
Definition timer.cpp:267
static void finish(std::ofstream &ofs, const bool print_flag=true, const bool check_end=true)
Finish total time calculation and print computational processes with duration > 0....
Definition timer.cpp:33
static void enable(void)
Enable time computation.
Definition timer.h:61
static void set_nvtx_enabled(bool b)
Toggle NVTX range emission for CUDA profiling. Caller-injected; only consulted when built with __CUDA...
Definition timer.h:70
static size_t n_now
Member variable: the index of clocks.
Definition timer.h:122
static bool disabled
Member variable: if disabled , timer can't work.
Definition timer.h:111
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:151
static void write_to_json(std::string file_name)
Write all computational processes to json file.
Definition timer.cpp:160
static void start(void)
Start total time calculation.
Definition timer.cpp:44
static void end(const std::string &class_name_in, const std::string &name_in)
Definition timer.cpp:109
static void disable(void)
Disable time computation.
Definition timer.h:79
static double cpu_time(void)
Member function: calculate time.
Definition timer.cpp:51
Definition clebsch_gordan_coeff.cpp:8
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