From 62255056be7d3b0ef001e3524caa6b98125e6105 Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Fri, 8 Nov 2024 01:47:51 +0800 Subject: [PATCH] optimize LR log --- source/module_base/global_file.cpp | 67 +++++++++----------------- source/module_lr/esolver_lrtd_lcao.cpp | 5 +- 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/source/module_base/global_file.cpp b/source/module_base/global_file.cpp index b912996f4e..c23563ce2c 100644 --- a/source/module_base/global_file.cpp +++ b/source/module_base/global_file.cpp @@ -153,28 +153,18 @@ void ModuleBase::Global_File::make_dir_out( #endif } - std::stringstream ss,ss1; - - // mohan add 2010-09-12 - if(out_alllog) - { - ss << "running_" << calculation << "_" << rank + 1; - open_log(GlobalV::ofs_running, ss.str(), calculation, restart); - #if defined(__CUDA) || defined(__ROCM) - open_log(GlobalV::ofs_device, "device" + std::to_string(rank), calculation, restart); - #endif - } - else - { - if(rank==0) - { - ss << "running_" << calculation; - open_log(GlobalV::ofs_running, ss.str(), calculation, restart); - #if defined(__CUDA) || defined(__ROCM) - open_log(GlobalV::ofs_device, "device", calculation, restart); - #endif - } - } + auto open_running_log = [&](const std::string& keyword) + { + std::stringstream ss; + ss << "running_" << keyword; + if (out_alllog) { ss << "_" << rank + 1; } + open_log(GlobalV::ofs_running, ss.str(), keyword, restart); +#if defined(__CUDA) || defined(__ROCM) + open_log(GlobalV::ofs_device, "device" + std::to_string(rank), calculation, restart); +#endif + }; + // if linear response solver only, open running_lr.log. else, open running_calculation.log + if (out_alllog || rank == 0) { open_running_log(PARAM.inp.esolver_type == "lr" ? "lr" : calculation); } if(rank==0) { @@ -242,27 +232,18 @@ void ModuleBase::Global_File::close_all_log(const int rank, const bool out_alllo // NAME : ofs_build //---------------------------------------------------------- - // mohan update 2011-01-13 - std::stringstream ss; - if(out_alllog) - { - ss << "running_" << calculation << "_cpu" << rank << ".log"; - close_log(GlobalV::ofs_running,ss.str()); - #if defined(__CUDA) || defined(__ROCM) - close_log(GlobalV::ofs_device, "device" + std::to_string(rank)); - #endif - } - else - { - if(rank==0) - { - ss << "running_" << calculation << ".log"; - close_log(GlobalV::ofs_running,ss.str()); - #if defined(__CUDA) || defined(__ROCM) - close_log(GlobalV::ofs_device, "device"); - #endif - } - } + auto close_running_log = [&](const std::string& keyword) + { + std::stringstream ss; + ss << "running_" << keyword; + if (out_alllog) { ss << "_" << rank + 1; } + close_log(GlobalV::ofs_running, ss.str()); +#if defined(__CUDA) || defined(__ROCM) + close_log(GlobalV::ofs_device, "device" + std::to_string(rank)); +#endif + }; + // mohan update 2011-01-13 + if (out_alllog || rank == 0) { close_running_log(PARAM.inp.esolver_type == "lr" ? "lr" : calculation); } if (rank==0) { diff --git a/source/module_lr/esolver_lrtd_lcao.cpp b/source/module_lr/esolver_lrtd_lcao.cpp index 5f696d7aa1..06fc98124c 100644 --- a/source/module_lr/esolver_lrtd_lcao.cpp +++ b/source/module_lr/esolver_lrtd_lcao.cpp @@ -46,9 +46,6 @@ void LR::ESolver_LR::move_exx_lri(std::shared_ptrvoid LR::ESolver_LR::set_gint() { this->gint_ = &this->gint_g_;this->gint_g_.gridt = &this->gt_; } template<>void LR::ESolver_LR>::set_gint() { this->gint_ = &this->gint_k_; this->gint_k_.gridt = &this->gt_; } -inline double getreal(std::complex x) { return x.real(); } -inline double getreal(double x) { return x; } - inline void redirect_log(const bool& out_alllog) { GlobalV::ofs_running.close(); @@ -431,6 +428,7 @@ template void LR::ESolver_LR::runner(int istep, UnitCell& cell) { ModuleBase::TITLE("ESolver_LR", "runner"); + ModuleBase::timer::tick("ESolver_LR", "runner"); //allocate 2-particle state and setup 2d division this->setup_eigenvectors_X(); this->pelec->ekb.create(nspin, this->nstates); @@ -494,6 +492,7 @@ void LR::ESolver_LR::runner(int istep, UnitCell& cell) for (int is = 0;is < nspin;++is) { read_states(spin_types[is], this->pelec->ekb.c + is * nstates, this->X[is].template data(), nloc_per_band, nstates); } } } + ModuleBase::timer::tick("ESolver_LR", "runner"); return; }