Skip to content

Commit 954c358

Browse files
authored
Fix: timer not closed in TDDFT code (#5172)
* Fix a simple timer bug in TDDFT * Fix timer TD_Velocity::initialize_current_term * Fix timer ModuleIO::write_current
1 parent e32341a commit 954c358

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

source/module_hamilt_lcao/module_tddft/evolve_elec.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ void Evolve_elec::solve_psi(const int& istep,
3636
int propagator,
3737
const int& nks)
3838
{
39-
ModuleBase::TITLE("Evolve_elec", "eveolve_psi");
40-
ModuleBase::timer::tick("Evolve_elec", "evolve_psi");
39+
ModuleBase::TITLE("Evolve_elec", "solve_psi");
40+
ModuleBase::timer::tick("Evolve_elec", "solve_psi");
4141

4242
for (int ik = 0; ik < nks; ik++)
4343
{
@@ -82,7 +82,7 @@ void Evolve_elec::solve_psi(const int& istep,
8282
ModuleBase::timer::tick("Efficience", "evolve_k");
8383
} // end k
8484

85-
ModuleBase::timer::tick("Evolve_elec", "evolve_psi");
85+
ModuleBase::timer::tick("Evolve_elec", "solve_psi");
8686
return;
8787
}
8888
} // namespace module_tddft

source/module_hamilt_lcao/module_tddft/td_velocity.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "td_velocity.h"
22

3-
#include "module_parameter/parameter.h"
43
#include "module_elecstate/potentials/H_TDDFT_pw.h"
4+
#include "module_parameter/parameter.h"
55

66
bool TD_Velocity::tddft_velocity = false;
77
bool TD_Velocity::out_mat_R = false;
@@ -61,7 +61,7 @@ void TD_Velocity::output_cart_At(const std::string& out_dir)
6161
// divide by 2.0 to get the atomic unit
6262
for (int i = 0; i < 3; i++)
6363
{
64-
ofs << std::scientific << std::setprecision(4) << std::setw(15) << cart_At[i] ;
64+
ofs << std::scientific << std::setprecision(4) << std::setw(15) << cart_At[i];
6565
}
6666
ofs << std::endl;
6767
ofs.close();
@@ -79,7 +79,7 @@ void TD_Velocity::cal_cart_At(const ModuleBase::Vector3<double>& At)
7979
else
8080
{
8181
// transfrom into atomic unit
82-
this->cart_At = At/2.0;
82+
this->cart_At = At / 2.0;
8383
}
8484
// output the vector potential if needed
8585
if (out_vecpot == true)
@@ -171,7 +171,8 @@ void TD_Velocity::initialize_current_term(const hamilt::HContainer<std::complex<
171171
{
172172
this->current_term[dir]->allocate(nullptr, true);
173173
}
174-
ModuleBase::timer::tick("TDEkinetic", "initialize_HR_tmp");
174+
175+
ModuleBase::timer::tick("TD_Velocity", "initialize_current_term");
175176
}
176177

177178
void TD_Velocity::destroy_HS_R_td_sparse(void)

source/module_io/td_current_io.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "td_current_io.h"
22

3-
#include "module_parameter/parameter.h"
43
#include "module_base/global_function.h"
54
#include "module_base/global_variable.h"
65
#include "module_base/libm/libm.h"
@@ -11,9 +10,10 @@
1110
#include "module_elecstate/module_dm/cal_dm_psi.h"
1211
#include "module_elecstate/potentials/H_TDDFT_pw.h"
1312
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"
14-
#include "module_hamilt_lcao/module_tddft/td_velocity.h"
1513
#include "module_hamilt_lcao/module_tddft/td_current.h"
14+
#include "module_hamilt_lcao/module_tddft/td_velocity.h"
1615
#include "module_hamilt_pw/hamilt_pwdft/global.h"
16+
#include "module_parameter/parameter.h"
1717

1818
#ifdef __LCAO
1919

@@ -138,7 +138,7 @@ void ModuleIO::write_current(const int istep,
138138
cal_current->calculate_grad_term();
139139
for (int dir = 0; dir < 3; dir++)
140140
{
141-
current_term[dir]=cal_current->get_current_term_pointer(dir);
141+
current_term[dir] = cal_current->get_current_term_pointer(dir);
142142
}
143143
}
144144
else
@@ -149,11 +149,10 @@ void ModuleIO::write_current(const int istep,
149149
}
150150
for (int dir = 0; dir < 3; dir++)
151151
{
152-
current_term[dir]=TD_Velocity::td_vel_op->get_current_term_pointer(dir);
152+
current_term[dir] = TD_Velocity::td_vel_op->get_current_term_pointer(dir);
153153
}
154154
}
155155

156-
157156
// construct a DensityMatrix object
158157
// Since the function cal_dm_psi do not suport DMR in complex type, I replace it with two DMR in double type. Should
159158
// be refactored in the future.
@@ -224,12 +223,17 @@ void ModuleIO::write_current(const int istep,
224223
// std::cout<< "iat1: " << iat1 << " iat2: " << iat2 << " Rx: " << Rx << " Ry: " << Ry << " Rz:
225224
// " << Rz << std::endl;
226225
// get BaseMatrix
227-
hamilt::BaseMatrix<double>* tmp_matrix_real = DM_real.get_DMR_pointer(is)->find_matrix(iat1, iat2, Rx, Ry, Rz);
228-
hamilt::BaseMatrix<double>* tmp_matrix_imag = DM_imag.get_DMR_pointer(is)->find_matrix(iat1, iat2, Rx, Ry, Rz);
226+
hamilt::BaseMatrix<double>* tmp_matrix_real
227+
= DM_real.get_DMR_pointer(is)->find_matrix(iat1, iat2, Rx, Ry, Rz);
228+
hamilt::BaseMatrix<double>* tmp_matrix_imag
229+
= DM_imag.get_DMR_pointer(is)->find_matrix(iat1, iat2, Rx, Ry, Rz);
229230
// refactor
230-
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvx = current_term[0]->find_matrix(iat1, iat2, Rx, Ry, Rz);
231-
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvy = current_term[1]->find_matrix(iat1, iat2, Rx, Ry, Rz);
232-
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvz = current_term[2]->find_matrix(iat1, iat2, Rx, Ry, Rz);
231+
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvx
232+
= current_term[0]->find_matrix(iat1, iat2, Rx, Ry, Rz);
233+
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvy
234+
= current_term[1]->find_matrix(iat1, iat2, Rx, Ry, Rz);
235+
hamilt::BaseMatrix<std::complex<double>>* tmp_m_rvz
236+
= current_term[2]->find_matrix(iat1, iat2, Rx, Ry, Rz);
233237
if (tmp_matrix_real == nullptr)
234238
{
235239
continue;
@@ -254,16 +258,16 @@ void ModuleIO::write_current(const int istep,
254258
rvy = tmp_m_rvy->get_value(mu, nu);
255259
rvz = tmp_m_rvz->get_value(mu, nu);
256260
}
257-
local_current_ik[0] -= dm2d1_real * rvx.real() - dm2d1_imag * rvx.imag();
261+
local_current_ik[0] -= dm2d1_real * rvx.real() - dm2d1_imag * rvx.imag();
258262
local_current_ik[1] -= dm2d1_real * rvy.real() - dm2d1_imag * rvy.imag();
259263
local_current_ik[2] -= dm2d1_real * rvz.real() - dm2d1_imag * rvz.imag();
260-
264+
261265
++local_total_irr;
262266
++irr;
263267
} // end kk
264-
} // end jj
265-
} // end cb
266-
} // end iat
268+
} // end jj
269+
} // end cb
270+
} // end iat
267271
#ifdef _OPENMP
268272
#pragma omp critical(cal_current_k_reduce)
269273
{
@@ -293,9 +297,8 @@ void ModuleIO::write_current(const int istep,
293297
fout.close();
294298
}
295299
// write end
296-
ModuleBase::timer::tick("ModuleIO", "write_current");
297300
} // end nks
298-
} // end is
301+
} // end is
299302
if (GlobalV::MY_RANK == 0)
300303
{
301304
std::string filename = PARAM.globalv.global_out_dir + "current_total.dat";
@@ -306,10 +309,12 @@ void ModuleIO::write_current(const int istep,
306309
fout << istep << " " << current_total[0] << " " << current_total[1] << " " << current_total[2] << std::endl;
307310
fout.close();
308311
}
309-
if(!TD_Velocity::tddft_velocity)
312+
if (!TD_Velocity::tddft_velocity)
310313
{
311314
delete cal_current;
312315
}
316+
317+
ModuleBase::timer::tick("ModuleIO", "write_current");
313318
return;
314319
}
315320
#endif //__LCAO

0 commit comments

Comments
 (0)