ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
memory_recorder.h
Go to the documentation of this file.
1#ifndef RECORD_MEMORY_H
2#define RECORD_MEMORY_H
3
4#include <fstream>
5#include <string>
6
7namespace ModuleBase
8{
9
17class Memory
18{
19 public:
20 Memory();
21 ~Memory();
22
33 static double record(const std::string &class_name,
34 const std::string &name,
35 const long &n,
36 const std::string &type,
37 const bool accumulate = false);
38
46 static void record(
47 const std::string &name_in,
48 const long &n_in,
49 const bool accumulate = false
50 );
51
52#if defined(__CUDA) || defined(__ROCM)
53
64 static double record_gpu(const std::string &class_name,
65 const std::string &name,
66 const long &n,
67 const std::string &type,
68 const bool accumulate = false);
69
77 static void record_gpu(
78 const std::string &name_in,
79 const size_t &n_in,
80 const bool accumulate = false
81 );
82
83#endif
84
85 static double &get_total(void)
86 {
87 return total;
88 }
89
92 static bool is_initialized(void)
93 {
94 return init_flag;
95 }
96
97 static void finish(std::ofstream &ofs);
98
104 static void print_all(std::ofstream &ofs);
105
106 static void print(const std::string& name, double size_mb);
107
116 static double calculate_mem(const long &n, const std::string &type);
117
118 private:
119 static double total;
120 static std::string *name;
121 static std::string *class_name;
122 static double *consume;
123 static int n_memory;
124 static int n_now;
125 static bool init_flag;
126
127#if defined(__CUDA) || defined(__ROCM)
128 static double total_gpu;
129 static std::string *name_gpu;
130 static std::string *class_name_gpu;
131 static double *consume_gpu;
132 static int n_now_gpu;
133 static bool init_flag_gpu;
134#endif
135
136 static int complex_matrix_memory; //(16 Byte)
137 static int double_memory; //(8 Byte)
138 static int int_memory; //(4 Byte)
139 static int bool_memory;
140 static int short_memory; //(2 Byte)
141 static int float_memory; //(4 Byte)
142};
143
144} // namespace ModuleBase
145
146#endif
static bool init_flag
Definition memory_recorder.h:125
static double & get_total(void)
Definition memory_recorder.h:85
static double total
Definition memory_recorder.h:119
static int n_now
Definition memory_recorder.h:124
static bool is_initialized(void)
Whether the record tables are currently allocated. record() allocates them on first use and finish() ...
Definition memory_recorder.h:92
static int bool_memory
Definition memory_recorder.h:139
static int float_memory
Definition memory_recorder.h:141
static int n_memory
Definition memory_recorder.h:123
static int short_memory
Definition memory_recorder.h:140
static void print(const std::string &name, double size_mb)
Definition memory_recorder.cpp:343
Memory()
Definition memory_recorder.cpp:44
~Memory()
Definition memory_recorder.cpp:48
static int complex_matrix_memory
Definition memory_recorder.h:136
static int double_memory
Definition memory_recorder.h:137
static std::string * name
Definition memory_recorder.h:120
static double calculate_mem(const long &n, const std::string &type)
Calculate memory requirements for various types of data.
Definition memory_recorder.cpp:52
static void print_all(std::ofstream &ofs)
Print memory consumed (> 1 MB) in a file.
Definition memory_recorder.cpp:373
static int int_memory
Definition memory_recorder.h:138
static void finish(std::ofstream &ofs)
Definition memory_recorder.cpp:351
static double record(const std::string &class_name, const std::string &name, const long &n, const std::string &type, const bool accumulate=false)
Record memory consumed during computation.
Definition memory_recorder.cpp:107
static std::string * class_name
Definition memory_recorder.h:121
static double * consume
Definition memory_recorder.h:122
Definition clebsch_gordan_coeff.cpp:8