Skip to content

Commit 6225505

Browse files
committed
optimize LR log
1 parent 33f5bad commit 6225505

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

source/module_base/global_file.cpp

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,18 @@ void ModuleBase::Global_File::make_dir_out(
153153
#endif
154154
}
155155

156-
std::stringstream ss,ss1;
157-
158-
// mohan add 2010-09-12
159-
if(out_alllog)
160-
{
161-
ss << "running_" << calculation << "_" << rank + 1;
162-
open_log(GlobalV::ofs_running, ss.str(), calculation, restart);
163-
#if defined(__CUDA) || defined(__ROCM)
164-
open_log(GlobalV::ofs_device, "device" + std::to_string(rank), calculation, restart);
165-
#endif
166-
}
167-
else
168-
{
169-
if(rank==0)
170-
{
171-
ss << "running_" << calculation;
172-
open_log(GlobalV::ofs_running, ss.str(), calculation, restart);
173-
#if defined(__CUDA) || defined(__ROCM)
174-
open_log(GlobalV::ofs_device, "device", calculation, restart);
175-
#endif
176-
}
177-
}
156+
auto open_running_log = [&](const std::string& keyword)
157+
{
158+
std::stringstream ss;
159+
ss << "running_" << keyword;
160+
if (out_alllog) { ss << "_" << rank + 1; }
161+
open_log(GlobalV::ofs_running, ss.str(), keyword, restart);
162+
#if defined(__CUDA) || defined(__ROCM)
163+
open_log(GlobalV::ofs_device, "device" + std::to_string(rank), calculation, restart);
164+
#endif
165+
};
166+
// if linear response solver only, open running_lr.log. else, open running_calculation.log
167+
if (out_alllog || rank == 0) { open_running_log(PARAM.inp.esolver_type == "lr" ? "lr" : calculation); }
178168

179169
if(rank==0)
180170
{
@@ -242,27 +232,18 @@ void ModuleBase::Global_File::close_all_log(const int rank, const bool out_alllo
242232
// NAME : ofs_build
243233
//----------------------------------------------------------
244234

245-
// mohan update 2011-01-13
246-
std::stringstream ss;
247-
if(out_alllog)
248-
{
249-
ss << "running_" << calculation << "_cpu" << rank << ".log";
250-
close_log(GlobalV::ofs_running,ss.str());
251-
#if defined(__CUDA) || defined(__ROCM)
252-
close_log(GlobalV::ofs_device, "device" + std::to_string(rank));
253-
#endif
254-
}
255-
else
256-
{
257-
if(rank==0)
258-
{
259-
ss << "running_" << calculation << ".log";
260-
close_log(GlobalV::ofs_running,ss.str());
261-
#if defined(__CUDA) || defined(__ROCM)
262-
close_log(GlobalV::ofs_device, "device");
263-
#endif
264-
}
265-
}
235+
auto close_running_log = [&](const std::string& keyword)
236+
{
237+
std::stringstream ss;
238+
ss << "running_" << keyword;
239+
if (out_alllog) { ss << "_" << rank + 1; }
240+
close_log(GlobalV::ofs_running, ss.str());
241+
#if defined(__CUDA) || defined(__ROCM)
242+
close_log(GlobalV::ofs_device, "device" + std::to_string(rank));
243+
#endif
244+
};
245+
// mohan update 2011-01-13
246+
if (out_alllog || rank == 0) { close_running_log(PARAM.inp.esolver_type == "lr" ? "lr" : calculation); }
266247

267248
if (rank==0)
268249
{

source/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ void LR::ESolver_LR<double>::move_exx_lri(std::shared_ptr<Exx_LRI<std::complex<d
4646
template<>void LR::ESolver_LR<double>::set_gint() { this->gint_ = &this->gint_g_;this->gint_g_.gridt = &this->gt_; }
4747
template<>void LR::ESolver_LR<std::complex<double>>::set_gint() { this->gint_ = &this->gint_k_; this->gint_k_.gridt = &this->gt_; }
4848

49-
inline double getreal(std::complex<double> x) { return x.real(); }
50-
inline double getreal(double x) { return x; }
51-
5249
inline void redirect_log(const bool& out_alllog)
5350
{
5451
GlobalV::ofs_running.close();
@@ -431,6 +428,7 @@ template <typename T, typename TR>
431428
void LR::ESolver_LR<T, TR>::runner(int istep, UnitCell& cell)
432429
{
433430
ModuleBase::TITLE("ESolver_LR", "runner");
431+
ModuleBase::timer::tick("ESolver_LR", "runner");
434432
//allocate 2-particle state and setup 2d division
435433
this->setup_eigenvectors_X();
436434
this->pelec->ekb.create(nspin, this->nstates);
@@ -494,6 +492,7 @@ void LR::ESolver_LR<T, TR>::runner(int istep, UnitCell& cell)
494492
for (int is = 0;is < nspin;++is) { read_states(spin_types[is], this->pelec->ekb.c + is * nstates, this->X[is].template data<T>(), nloc_per_band, nstates); }
495493
}
496494
}
495+
ModuleBase::timer::tick("ESolver_LR", "runner");
497496
return;
498497
}
499498

0 commit comments

Comments
 (0)