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
45 class Scope
46 {
47 public:
48 Scope(const char* owner, const char* function) : owner_(owner), function_(function)
49 {
51 }
53 {
55 }
56 Scope(const Scope&) = delete;
57 Scope& operator=(const Scope&) = delete;
58
59 private:
60 const char* owner_;
61 const char* function_;
62 };
63
68 static void start(void);
69
77 static void finish(std::ofstream &ofs, const bool print_flag = true, const bool check_end = true);
78
83 static void enable(void)
84 {
85 disabled = false;
86 }
87
92 static void set_nvtx_enabled(bool b)
93 {
94 enable_nvtx_ = b;
95 }
96
101 static void disable(void)
102 {
103 disabled = true;
104 }
105
111 static void write_to_json(std::string file_name);
112
118 static void print_all(std::ofstream &ofs, const bool check_end);
119
126 static long double print_until_now(void);
127
128 private:
133 static bool disabled;
134
138 static bool enable_nvtx_;
139
144 static size_t n_now;
145
151 static double cpu_time(void);
152};
153
154} // namespace ModuleBase
155#endif
const char * function_
Definition timer.h:61
Scope(const char *owner, const char *function)
Definition timer.h:48
Scope(const Scope &)=delete
Scope & operator=(const Scope &)=delete
const char * owner_
Definition timer.h:60
~Scope()
Definition timer.h:52
Tracing computation time.
Definition timer.h:19
static bool enable_nvtx_
Member variable: NVTX range emission toggle (CUDA profiling only).
Definition timer.h:138
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:83
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:92
static size_t n_now
Member variable: the index of clocks.
Definition timer.h:144
static bool disabled
Member variable: if disabled , timer can't work.
Definition timer.h:133
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:101
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