From 48a08c5648b69ae3ef27242fd977a999a517832f Mon Sep 17 00:00:00 2001 From: dyzheng Date: Mon, 13 Dec 2021 11:56:21 +0800 Subject: [PATCH] < fix > time with openmp is incorrect, time output format is not consistant for running file and screen < range >timer.cpp ELEC_scf.cpp --- source/module_base/timer.cpp | 3 ++- source/src_lcao/ELEC_scf.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/source/module_base/timer.cpp b/source/module_base/timer.cpp index 22ac495546..cf29c267be 100644 --- a/source/module_base/timer.cpp +++ b/source/module_base/timer.cpp @@ -149,12 +149,13 @@ void timer::print_all(std::ofstream &ofs) if(timer_one.cpu_second < small) continue; + ofs << std::resetiosflags(std::ios::scientific); ofs << " " // << std::setw(2) << timer_one.level << std::setw(2) << " " << std::setw(20) << class_name << std::setw(20) << name - << std::setw(15) << timer_one.cpu_second + << std::setw(15) << std::setprecision(5) << timer_one.cpu_second << std::setw(10) << timer_one.calls << std::setw(10) << std::setprecision(2) << timer_one.cpu_second/timer_one.calls << std::setw(10) << timer_one.cpu_second / timer_pool_order[0].second.cpu_second * 100 << "%" << std::endl; diff --git a/source/src_lcao/ELEC_scf.cpp b/source/src_lcao/ELEC_scf.cpp index 4eee0ad897..b878c6cf4f 100644 --- a/source/src_lcao/ELEC_scf.cpp +++ b/source/src_lcao/ELEC_scf.cpp @@ -81,16 +81,16 @@ void ELEC_scf::scf(const int &istep) { Print_Info::print_scf(istep, iter); - //time_t time_start, time_finish; - clock_t clock_start; - std::string ufile = "CHANGE"; Update_input UI; UI.init(ufile); if(INPUT.dft_plus_u) GlobalC::dftu.iter_dftu = iter; - //time_start= std::time(NULL); - clock_start = std::clock(); +#ifdef __MPI + auto clock_start = MPI_Wtime(); +#else + auto clock_start = std::chrono::system_clock::now(); +#endif conv_elec = false;//mohan add 2008-05-25 // mohan add 2010-07-16 @@ -454,7 +454,11 @@ void ELEC_scf::scf(const int &istep) } //time_finish=std::time(NULL); - double duration = (double)(clock() - clock_start) / CLOCKS_PER_SEC; +#ifdef __MPI + double duration = (double)(MPI_Wtime() - clock_start); +#else + double duration = (double)(std::chrono::system_clock::now() - clock_start) / CLOCKS_PER_SEC; +#endif //double duration_time = difftime(time_finish, time_start); //std::cout<<"Time_clock\t"<<"Time_time"<