Skip to content

Commit 77a1a21

Browse files
committed
fix bug of timer in functions
1 parent dabeecd commit 77a1a21

File tree

14 files changed

+23
-24
lines changed

14 files changed

+23
-24
lines changed

source/source_base/test/timer_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ TEST_F(TimerTest, PrintAll)
110110
// call print_all
111111
ofs.open("tmp");
112112
testing::internal::CaptureStdout();
113-
ModuleBase::timer::print_all(ofs);
113+
ModuleBase::timer::print_all(ofs, true);
114114
output = testing::internal::GetCapturedStdout();
115115
ofs.close();
116116

source/source_base/timer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ bool timer::disabled = false;
3030
size_t timer::n_now = 0;
3131
std::map<std::string,std::map<std::string,timer::Timer_One>> timer::timer_pool;
3232

33-
void timer::finish(std::ofstream &ofs,const bool print_flag)
33+
void timer::finish(std::ofstream &ofs, const bool print_flag, const bool check_end)
3434
{
3535
timer::end("","total");
3636
if(print_flag)
37-
{ print_all( ofs ); }
37+
{ print_all( ofs, check_end ); }
3838
}
3939

4040
//----------------------------------------------------------
@@ -43,7 +43,8 @@ void timer::finish(std::ofstream &ofs,const bool print_flag)
4343
void timer::start()
4444
{
4545
// first init ,then we can use tick
46-
timer::start("","total");
46+
if(timer_pool[""]["total"].start_flag)
47+
{ timer::start("","total"); }
4748
}
4849

4950
double timer::cpu_time()
@@ -262,7 +263,7 @@ void timer::write_to_json(std::string file_name)
262263
ofs.close();
263264
}
264265

265-
void timer::print_all(std::ofstream &ofs)
266+
void timer::print_all(std::ofstream &ofs, const bool check_end)
266267
{
267268
constexpr double small = 0.1; // cpu = 10^6
268269
// if want to print > 1s , set small = 10^6
@@ -275,7 +276,7 @@ void timer::print_all(std::ofstream &ofs)
275276
{
276277
const std::string name = timer_pool_B.first;
277278
const Timer_One &timer_one = timer_pool_B.second;
278-
if(!timer_one.start_flag)
279+
if(check_end && !timer_one.start_flag)
279280
{ throw std::runtime_error("timer::print_all " + class_name + "::" + name); }
280281
if(timer_pool_order.size() < timer_one.order+1)
281282
{

source/source_base/timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class timer
5252
* @param ofs The output file for print out timings
5353
* @param print_flag Print timings or not
5454
*/
55-
static void finish(std::ofstream &ofs, const bool print_flag = 1);
55+
static void finish(std::ofstream &ofs, const bool print_flag = true, const bool check_end = true);
5656

5757
/**
5858
* @brief Enable time computation
@@ -84,7 +84,7 @@ class timer
8484
*
8585
* @param ofs The output file for print out timings
8686
*/
87-
static void print_all(std::ofstream &ofs);
87+
static void print_all(std::ofstream &ofs, const bool check_end);
8888

8989
/**
9090
* @brief Stop total time calculation, print total time until now,

source/source_base/tool_quit.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ void QUIT(int ret)
4646
{
4747

4848
#ifdef __NORMAL
49-
5049
#else
51-
ModuleBase::timer::finish(GlobalV::ofs_running , !GlobalV::MY_RANK);
52-
50+
ModuleBase::timer::finish(GlobalV::ofs_running , !GlobalV::MY_RANK, false);
5351
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK);
54-
5552
std::cout<<" See output information in : "<<PARAM.globalv.global_out_dir<<std::endl;
5653
#endif
5754

source/source_estate/module_charge/charge_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void Charge::set_rho_core(const UnitCell& ucell,
369369
// The term was present in previous versions of the code but it shouldn't
370370
delete [] rhocg;
371371
delete [] vg;
372-
ModuleBase::timer::start("Charge","set_rho_core");
372+
ModuleBase::timer::end("Charge","set_rho_core");
373373
return;
374374
} // end subroutine set_rhoc
375375

source/source_hsolver/diago_dav_subspace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int Diago_DavSubspace<T, Device>::diag_once(const HPsiFunc& hpsi_func,
260260
this->scc,
261261
this->vcc);
262262

263-
ModuleBase::timer::start("Diago_DavSubspace", "last");
263+
ModuleBase::timer::end("Diago_DavSubspace", "last");
264264
}
265265
}
266266

source/source_io/module_ctrl/ctrl_runner_lcao.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void ctrl_runner_lcao(UnitCell& ucell, // unitcell
127127
);
128128
}
129129

130+
ModuleBase::timer::end("ModuleIO", "ctrl_runner_lcao");
130131
}
131132

132133

source/source_lcao/FORCE_STRESS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
795795
}
796796
} // end of stress calculation
797797

798-
ModuleBase::timer::start("Force_Stress_LCAO", "getForceStress");
798+
ModuleBase::timer::end("Force_Stress_LCAO", "getForceStress");
799799
return;
800800
}
801801

source/source_lcao/center2_orb.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,4 @@ void Center2_Orb::cal_ST_Phi12_R(const int& job,
332332
}
333333

334334
ModuleBase::timer::end("Center2_Orb", "cal_ST_Phi12_R");
335-
336-
return;
337335
}

source/source_lcao/module_operator_lcao/operator_lcao.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ void OperatorLCAO<TK, TR>::init(const int ik_in) {
236236
= this->hr_done;
237237
}
238238
// call init() function of next node
239+
ModuleBase::timer::end("OperatorLCAO", "init");
239240
this->next_op->init(ik_in);
241+
ModuleBase::timer::start("OperatorLCAO", "init");
240242
} else { // it is the last node, update HK with the current total HR
241243
OperatorLCAO<TK, TR>::contributeHk(ik_in);
242244
}

0 commit comments

Comments
 (0)