Skip to content

Commit 079f791

Browse files
committed
Remove all GlobalV::ofs_running from RT-TDDFT core algorithms and pass it as an input parameter instead
1 parent dc54ffd commit 079f791

28 files changed

+437
-361
lines changed

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void ESolver_KS_LCAO_TDDFT<Device>::hamilt2density_single(UnitCell& ucell,
106106
this->Hk_laststep,
107107
this->Sk_laststep,
108108
this->pelec->ekb,
109+
GlobalV::ofs_running,
109110
td_htype,
110111
PARAM.inp.propagator,
111112
use_tensor,
@@ -127,6 +128,7 @@ void ESolver_KS_LCAO_TDDFT<Device>::hamilt2density_single(UnitCell& ucell,
127128
this->Hk_laststep,
128129
this->Sk_laststep,
129130
this->pelec->ekb,
131+
GlobalV::ofs_running,
130132
td_htype,
131133
PARAM.inp.propagator,
132134
use_tensor,

source/module_esolver/esolver_ks_lcao_tddft.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void gatherMatrix(const int myid, const int root_proc, const hamilt::MatrixBlock
4545
// Call the Cpxgemr2d function in ScaLAPACK to collect the matrix data
4646
Cpxgemr2d(nrows, ncols, mat_l.p, 1, 1, const_cast<int*>(desca), mat_g.p.get(), 1, 1, mat_g.desc.get(), ctxt);
4747
}
48-
4948
//------------------------ MPI gathering and distributing functions ------------------------//
5049

5150
template <typename Device = base_device::DEVICE_CPU>

source/module_hamilt_lcao/module_tddft/band_energy.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ void compute_ekb(const Parallel_Orbitals* pv,
2525
const int nlocal,
2626
const std::complex<double>* Htmp,
2727
const std::complex<double>* psi_k,
28-
double* ekb)
28+
double* ekb,
29+
std::ofstream& ofs_running)
2930
{
3031

3132
std::complex<double>* tmp1 = new std::complex<double>[pv->nloc_wfc];
@@ -76,10 +77,10 @@ void compute_ekb(const Parallel_Orbitals* pv,
7677

7778
if (PARAM.inp.td_print_eij > 0.0)
7879
{
79-
GlobalV::ofs_running
80+
ofs_running
8081
<< "------------------------------------------------------------------------------------------------"
8182
<< std::endl;
82-
GlobalV::ofs_running << " Eij:" << std::endl;
83+
ofs_running << " Eij:" << std::endl;
8384
for (int i = 0; i < pv->nrow_bands; i++)
8485
{
8586
for (int j = 0; j < pv->ncol_bands; j++)
@@ -98,12 +99,12 @@ void compute_ekb(const Parallel_Orbitals* pv,
9899
}
99100
if (aa > 0.0 || bb > 0.0)
100101
{
101-
GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl;
102+
ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl;
102103
}
103104
}
104105
}
105-
GlobalV::ofs_running << std::endl;
106-
GlobalV::ofs_running
106+
ofs_running << std::endl;
107+
ofs_running
107108
<< "------------------------------------------------------------------------------------------------"
108109
<< std::endl;
109110
}
@@ -156,7 +157,8 @@ void compute_ekb_tensor(const Parallel_Orbitals* pv,
156157
const int nlocal,
157158
const ct::Tensor& Htmp,
158159
const ct::Tensor& psi_k,
159-
ct::Tensor& ekb)
160+
ct::Tensor& ekb,
161+
std::ofstream& ofs_running)
160162
{
161163
// Create Tensor objects for temporary data
162164
ct::Tensor tmp1(ct::DataType::DT_COMPLEX_DOUBLE, ct::DeviceType::CpuDevice, ct::TensorShape({pv->nloc_wfc}));
@@ -209,10 +211,10 @@ void compute_ekb_tensor(const Parallel_Orbitals* pv,
209211

210212
if (PARAM.inp.td_print_eij >= 0.0)
211213
{
212-
GlobalV::ofs_running
214+
ofs_running
213215
<< "------------------------------------------------------------------------------------------------"
214216
<< std::endl;
215-
GlobalV::ofs_running << " Eij:" << std::endl;
217+
ofs_running << " Eij:" << std::endl;
216218
for (int i = 0; i < pv->nrow_bands; i++)
217219
{
218220
for (int j = 0; j < pv->ncol_bands; j++)
@@ -231,12 +233,12 @@ void compute_ekb_tensor(const Parallel_Orbitals* pv,
231233
}
232234
if (aa > 0.0 || bb > 0.0)
233235
{
234-
GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl;
236+
ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl;
235237
}
236238
}
237239
}
238-
GlobalV::ofs_running << std::endl;
239-
GlobalV::ofs_running
240+
ofs_running << std::endl;
241+
ofs_running
240242
<< "------------------------------------------------------------------------------------------------"
241243
<< std::endl;
242244
}
@@ -290,7 +292,8 @@ void compute_ekb_tensor_lapack(const Parallel_Orbitals* pv,
290292
const int nlocal,
291293
const ct::Tensor& Htmp,
292294
const ct::Tensor& psi_k,
293-
ct::Tensor& ekb)
295+
ct::Tensor& ekb,
296+
std::ofstream& ofs_running)
294297
{
295298
// ct_device_type = ct::DeviceType::CpuDevice or ct::DeviceType::GpuDevice
296299
ct::DeviceType ct_device_type = ct::DeviceTypeToEnum<Device>::value;
@@ -346,10 +349,10 @@ void compute_ekb_tensor_lapack(const Parallel_Orbitals* pv,
346349
{
347350
ct::Tensor Eij_cpu = Eij.to_device<ct::DEVICE_CPU>();
348351

349-
GlobalV::ofs_running
352+
ofs_running
350353
<< "------------------------------------------------------------------------------------------------"
351354
<< std::endl;
352-
GlobalV::ofs_running << " Eij:" << std::endl;
355+
ofs_running << " Eij:" << std::endl;
353356
for (int i = 0; i < nband; i++)
354357
{
355358
for (int j = 0; j < nband; j++)
@@ -368,12 +371,12 @@ void compute_ekb_tensor_lapack(const Parallel_Orbitals* pv,
368371
}
369372
if (aa > 0.0 || bb > 0.0)
370373
{
371-
GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl;
374+
ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << std::endl;
372375
}
373376
}
374377
}
375-
GlobalV::ofs_running << std::endl;
376-
GlobalV::ofs_running
378+
ofs_running << std::endl;
379+
ofs_running
377380
<< "------------------------------------------------------------------------------------------------"
378381
<< std::endl;
379382
}
@@ -406,15 +409,17 @@ template void compute_ekb_tensor_lapack<base_device::DEVICE_CPU>(const Parallel_
406409
const int nlocal,
407410
const ct::Tensor& Htmp,
408411
const ct::Tensor& psi_k,
409-
ct::Tensor& ekb);
412+
ct::Tensor& ekb,
413+
std::ofstream& ofs_running);
410414

411415
#if ((defined __CUDA) /* || (defined __ROCM) */)
412416
template void compute_ekb_tensor_lapack<base_device::DEVICE_GPU>(const Parallel_Orbitals* pv,
413417
const int nband,
414418
const int nlocal,
415419
const ct::Tensor& Htmp,
416420
const ct::Tensor& psi_k,
417-
ct::Tensor& ekb);
421+
ct::Tensor& ekb,
422+
std::ofstream& ofs_running);
418423
#endif // __CUDA
419424
#endif // __MPI
420425

source/module_hamilt_lcao/module_tddft/band_energy.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ void compute_ekb(const Parallel_Orbitals* pv,
2929
const int nlocal,
3030
const std::complex<double>* Htmp,
3131
const std::complex<double>* psi_k,
32-
double* ekb);
32+
double* ekb,
33+
std::ofstream& ofs_running);
3334

3435
void compute_ekb_tensor(const Parallel_Orbitals* pv,
3536
const int nband,
3637
const int nlocal,
3738
const ct::Tensor& Htmp,
3839
const ct::Tensor& psi_k,
39-
ct::Tensor& ekb);
40+
ct::Tensor& ekb,
41+
std::ofstream& ofs_running);
4042

4143
template <typename Device>
4244
void compute_ekb_tensor_lapack(const Parallel_Orbitals* pv,
4345
const int nband,
4446
const int nlocal,
4547
const ct::Tensor& Htmp,
4648
const ct::Tensor& psi_k,
47-
ct::Tensor& ekb);
49+
ct::Tensor& ekb,
50+
std::ofstream& ofs_running);
4851
#endif // __MPI
4952
} // namespace module_tddft
5053
#endif

source/module_hamilt_lcao/module_tddft/evolve_elec.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void Evolve_elec<Device>::solve_psi(const int& istep,
3131
std::complex<double>** Hk_laststep,
3232
std::complex<double>** Sk_laststep,
3333
ModuleBase::matrix& ekb,
34+
std::ofstream& ofs_running,
3435
const int htype,
3536
const int propagator,
3637
const bool use_tensor,
@@ -62,6 +63,7 @@ void Evolve_elec<Device>::solve_psi(const int& istep,
6263
&(ekb(ik, 0)),
6364
htype,
6465
propagator,
66+
ofs_running,
6567
print_matrix);
6668
}
6769
else if (htype == 1)
@@ -79,6 +81,7 @@ void Evolve_elec<Device>::solve_psi(const int& istep,
7981
&(ekb(ik, 0)),
8082
htype,
8183
propagator,
84+
ofs_running,
8285
print_matrix);
8386
// std::cout << "Print ekb: " << std::endl;
8487
// ekb.print(std::cout);
@@ -161,6 +164,7 @@ void Evolve_elec<Device>::solve_psi(const int& istep,
161164
ekb_tensor,
162165
htype,
163166
propagator,
167+
ofs_running,
164168
print_matrix,
165169
use_lapack);
166170

source/module_hamilt_lcao/module_tddft/evolve_elec.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ inline void print_tensor_data<std::complex<double>>(const ct::Tensor& tensor, co
9292
namespace module_tddft
9393
{
9494
#ifdef __MPI
95+
//------------------------ MPI gathering and distributing functions ------------------------//
9596
template <typename T>
9697
void gatherPsi(const int myid,
9798
const int root_proc,
@@ -133,13 +134,12 @@ void distributePsi(const Parallel_Orbitals& para_orb, T* psi_l, const ModuleESol
133134
// Call the Cpxgemr2d function in ScaLAPACK to distribute the matrix data
134135
Cpxgemr2d(nrows, ncols, psi_g.p.get(), 1, 1, psi_g.desc.get(), psi_l, 1, 1, const_cast<int*>(desc_psi), ctxt);
135136
}
137+
//------------------------ MPI gathering and distributing functions ------------------------//
136138
#endif // __MPI
137139

138140
template <typename Device = base_device::DEVICE_CPU>
139141
class Evolve_elec
140142
{
141-
142-
friend class ELEC_scf;
143143
friend class ModuleESolver::ESolver_KS_LCAO<std::complex<double>, double>;
144144

145145
// Template parameter is needed for the friend class declaration
@@ -161,6 +161,7 @@ class Evolve_elec
161161
std::complex<double>** Hk_laststep,
162162
std::complex<double>** Sk_laststep,
163163
ModuleBase::matrix& ekb,
164+
std::ofstream& ofs_running,
164165
const int htype,
165166
const int propagator,
166167
const bool use_tensor,

0 commit comments

Comments
 (0)