Skip to content

Commit db5120e

Browse files
author
abacus_fixer
committed
feat(dfpt): add TITLE and timer instrumentation to module_dfpt
Add ModuleBase::TITLE and ModuleBase::timer::start/end calls to 111 functions across 10 C++ source files under source/source_pw/module_dfpt, following the ABACUS convention used in module_pwdft. TITLE+start are placed at function entry, timer::end before each return path; WARNING_QUIT stubs get TITLE+start only (exit() never returns). Empty ctors/dtors and one-line getters/setters are skipped. Verified by: make -j 30 (module_dfpt + abacus_basic_para, 0 errors).
1 parent fa95038 commit db5120e

10 files changed

Lines changed: 447 additions & 34 deletions

File tree

source/source_pw/module_dfpt/dfpt_hamilt_shift.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "dfpt_pert.h"
1212
#include "source_base/constants.h"
1313
#include "source_base/global_function.h"
14+
#include "source_base/timer.h"
15+
#include "source_base/tool_title.h"
1416
#include "source_basis/module_pw/pw_basis.h"
1517
#include "source_basis/module_pw/pw_basis_k.h"
1618
#include "source_cell/unitcell.h"
@@ -68,6 +70,8 @@ DFPT_HamiltShift::~DFPT_HamiltShift()
6870

6971
void DFPT_HamiltShift::set_context(const ModuleBase::Vector3<double>& q_cart, int k_idx)
7072
{
73+
ModuleBase::TITLE("DFPT_HamiltShift", "set_context");
74+
ModuleBase::timer::start("DFPT_HamiltShift", "set_context");
7175
kq_.init(pw_wfc_, pw_rho_, q_cart, k_idx);
7276
ik_cache_ = k_idx;
7377
const int npw = kq_.get_npwk();
@@ -99,23 +103,33 @@ void DFPT_HamiltShift::set_context(const ModuleBase::Vector3<double>& q_cart, in
99103

100104
x_recip_.assign(pw_rho_->npw, std::complex<double>(0.0, 0.0));
101105
x_r_.assign(nrxx_, std::complex<double>(0.0, 0.0));
106+
ModuleBase::timer::end("DFPT_HamiltShift", "set_context");
102107
}
103108

104109
void DFPT_HamiltShift::set_shift(double shift)
105110
{
111+
ModuleBase::TITLE("DFPT_HamiltShift", "set_shift");
112+
ModuleBase::timer::start("DFPT_HamiltShift", "set_shift");
106113
shift_ = shift;
114+
ModuleBase::timer::end("DFPT_HamiltShift", "set_shift");
107115
}
108116

109117
int DFPT_HamiltShift::dimension() const
110118
{
119+
ModuleBase::TITLE("DFPT_HamiltShift", "dimension");
120+
ModuleBase::timer::start("DFPT_HamiltShift", "dimension");
121+
ModuleBase::timer::end("DFPT_HamiltShift", "dimension");
111122
return kq_.get_npwk();
112123
}
113124

114125
void DFPT_HamiltShift::apply(const std::complex<double>* x, std::complex<double>* y) const
115126
{
127+
ModuleBase::TITLE("DFPT_HamiltShift", "apply");
128+
ModuleBase::timer::start("DFPT_HamiltShift", "apply");
116129
const int npw = kq_.get_npwk();
117130
if (npw <= 0 || x == nullptr || y == nullptr)
118131
{
132+
ModuleBase::timer::end("DFPT_HamiltShift", "apply");
119133
return;
120134
}
121135
// kinetic part minus the eigenvalue shift
@@ -184,10 +198,13 @@ void DFPT_HamiltShift::apply(const std::complex<double>* x, std::complex<double>
184198
}
185199
}
186200
}
201+
ModuleBase::timer::end("DFPT_HamiltShift", "apply");
187202
}
188203

189204
double DFPT_HamiltShift::debug_t_vnl(const std::vector<std::complex<double>>& x) const
190205
{
206+
ModuleBase::TITLE("DFPT_HamiltShift", "debug_t_vnl");
207+
ModuleBase::timer::start("DFPT_HamiltShift", "debug_t_vnl");
191208
const int npw = kq_.get_npwk();
192209
double ekin = 0.0;
193210
for (int igl = 0; igl < npw; ++igl)
@@ -229,11 +246,14 @@ double DFPT_HamiltShift::debug_t_vnl(const std::vector<std::complex<double>>& x)
229246
vnl += std::real(std::conj(becp_[mu]) * dbecp_[mu]);
230247
}
231248
}
249+
ModuleBase::timer::end("DFPT_HamiltShift", "debug_t_vnl");
232250
return ekin + vnl;
233251
}
234252

235253
double DFPT_HamiltShift::debug_v_wfc(const std::vector<std::complex<double>>& x) const
236254
{
255+
ModuleBase::TITLE("DFPT_HamiltShift", "debug_v_wfc");
256+
ModuleBase::timer::start("DFPT_HamiltShift", "debug_v_wfc");
237257
const int npw = kq_.get_npwk();
238258
std::vector<std::complex<double>> ur(nrxx_, std::complex<double>(0.0, 0.0));
239259
pw_wfc_->recip2real(x.data(), ur.data(), ik_cache_);
@@ -249,6 +269,7 @@ double DFPT_HamiltShift::debug_v_wfc(const std::vector<std::complex<double>>& x)
249269
{
250270
dot += std::conj(x[igl]) * xg[igl];
251271
}
272+
ModuleBase::timer::end("DFPT_HamiltShift", "debug_v_wfc");
252273
return dot.real();
253274
}
254275

source/source_pw/module_dfpt/dfpt_kq_basis.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
// ============================================================
2-
// This code is added by Mohan Chen on 2026-05-18.
3-
// This code is currently in design phase and has not been
4-
// put into production yet.
5-
// It may change in the future.
6-
// Please use this code with caution.
7-
// Only developers who know
8-
// what they are doing should use this code.
9-
// ============================================================
10-
111
#include "dfpt_kq_basis.h"
122

133
#include "source_base/global_function.h"
4+
#include "source_base/timer.h"
5+
#include "source_base/tool_title.h"
146
#include "source_basis/module_pw/pw_basis.h"
157
#include "source_basis/module_pw/pw_basis_k.h"
168

@@ -32,6 +24,8 @@ void DFPT_KQ_Basis::init(const ModulePW::PW_Basis_K* pw_wfc,
3224
const ModuleBase::Vector3<double>& q_cart,
3325
int ik)
3426
{
27+
ModuleBase::TITLE("DFPT_KQ_Basis", "init");
28+
ModuleBase::timer::start("DFPT_KQ_Basis", "init");
3529
pw_wfc_ = pw_wfc;
3630
npwk_ = 0;
3731
ig_rho_.clear();
@@ -40,6 +34,7 @@ void DFPT_KQ_Basis::init(const ModulePW::PW_Basis_K* pw_wfc,
4034

4135
if (pw_wfc_ == nullptr || pw_rho == nullptr)
4236
{
37+
ModuleBase::timer::end("DFPT_KQ_Basis", "init");
4338
return;
4439
}
4540

@@ -142,16 +137,20 @@ void DFPT_KQ_Basis::init(const ModulePW::PW_Basis_K* pw_wfc,
142137
try_push(ix, iy, iz, pw_rho->G, ig);
143138
}
144139
npwk_ = static_cast<int>(gcar_.size());
140+
ModuleBase::timer::end("DFPT_KQ_Basis", "init");
145141
}
146142

147143
void DFPT_KQ_Basis::clear()
148144
{
145+
ModuleBase::TITLE("DFPT_KQ_Basis", "clear");
146+
ModuleBase::timer::start("DFPT_KQ_Basis", "clear");
149147
pw_wfc_ = nullptr;
150148
kplusq_c_ = ModuleBase::Vector3<double>();
151149
npwk_ = 0;
152150
ig_rho_.clear();
153151
gk2_.clear();
154152
gcar_.clear();
153+
ModuleBase::timer::end("DFPT_KQ_Basis", "clear");
155154
}
156155

157156
} // namespace ModuleDFPT

source/source_pw/module_dfpt/dfpt_metal.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
// ============================================================
2-
// This code is added by Mohan Chen on 2026-05-18.
3-
// This code is currently in the design phase and has not been
4-
// put into production yet. It may change in the future.
5-
// Please use this code with caution. Only developers who know
6-
// what they are doing should use this code.
7-
// ============================================================
8-
91
#include "dfpt_metal.h"
102

3+
#include "source_base/timer.h"
114
#include "source_base/tool_quit.h"
5+
#include "source_base/tool_title.h"
126

137
namespace ModuleDFPT
148
{
@@ -23,12 +17,17 @@ DFPT_Metal::~DFPT_Metal()
2317

2418
void DFPT_Metal::init(double sigma, const std::string& smearing_type)
2519
{
20+
ModuleBase::TITLE("DFPT_Metal", "init");
21+
ModuleBase::timer::start("DFPT_Metal", "init");
2622
sigma_ = sigma;
2723
smearing_type_ = smearing_type;
24+
ModuleBase::timer::end("DFPT_Metal", "init");
2825
}
2926

3027
void DFPT_Metal::dfdeps(const ModuleBase::matrix& eig, double efermi, ModuleBase::matrix& dfdeps)
3128
{
29+
ModuleBase::TITLE("DFPT_Metal", "dfdeps");
30+
ModuleBase::timer::start("DFPT_Metal", "dfdeps");
3231
// C4 interface reservation: the metallic DFPT branch (smearing
3332
// derivatives, Fermi-level shift dmu and the occupation-response part of
3433
// the first-order density) is intentionally NOT implemented in this
@@ -47,6 +46,8 @@ void DFPT_Metal::compute_dmu(int q_idx,
4746
const ModuleBase::matrix& dfdeps,
4847
DFPT_PW_Data& data)
4948
{
49+
ModuleBase::TITLE("DFPT_Metal", "compute_dmu");
50+
ModuleBase::timer::start("DFPT_Metal", "compute_dmu");
5051
(void)q_idx;
5152
(void)psi;
5253
(void)wg;
@@ -62,6 +63,8 @@ void DFPT_Metal::compute_drho_metal(int q_idx,
6263
double dmu,
6364
DFPT_PW_Data& data)
6465
{
66+
ModuleBase::TITLE("DFPT_Metal", "compute_drho_metal");
67+
ModuleBase::timer::start("DFPT_Metal", "compute_drho_metal");
6568
(void)q_idx;
6669
(void)psi;
6770
(void)wg;
@@ -73,15 +76,21 @@ void DFPT_Metal::compute_drho_metal(int q_idx,
7376

7477
double DFPT_Metal::fd_dfdeps(double e, double efermi)
7578
{
79+
ModuleBase::TITLE("DFPT_Metal", "fd_dfdeps");
80+
ModuleBase::timer::start("DFPT_Metal", "fd_dfdeps");
7681
(void)e;
7782
(void)efermi;
83+
ModuleBase::timer::end("DFPT_Metal", "fd_dfdeps");
7884
return 0.0;
7985
}
8086

8187
double DFPT_Metal::gauss_dfdeps(double e, double efermi)
8288
{
89+
ModuleBase::TITLE("DFPT_Metal", "gauss_dfdeps");
90+
ModuleBase::timer::start("DFPT_Metal", "gauss_dfdeps");
8391
(void)e;
8492
(void)efermi;
93+
ModuleBase::timer::end("DFPT_Metal", "gauss_dfdeps");
8594
return 0.0;
8695
}
8796

0 commit comments

Comments
 (0)