Skip to content

Commit 370e67c

Browse files
linpeizePeizeLin
andauthored
Refactor: split timer::tick() to timer::start() and timer::end() (#7020)
* 1. Refactor: split timer::tick() to timer::start() and timer::end() 2. fix bug of timer in ORB_gaunt_table::Calc_Gaunt_CH() * fix bug of timer in functions * fix timer in many functions * fix check in timer::finish() when WARNING_QUIT * fix timer in functions * update timer_test.cpp * update timer_test * fix timer in RPA * fix timer in functions * fix timer in functions * change to CRLF --------- Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent d1b4fc2 commit 370e67c

301 files changed

Lines changed: 1599 additions & 1560 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/source_base/inverse_matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void Inverse_Matrix_Complex::init(const int &dim_in)
5656

5757
void Inverse_Matrix_Complex::using_zheev( const ModuleBase::ComplexMatrix &Sin, ModuleBase::ComplexMatrix &Sout)
5858
{
59-
ModuleBase::timer::tick("Inverse","using_zheev");
59+
ModuleBase::timer::start("Inverse","using_zheev");
6060
this->A = Sin;
6161

6262
LapackConnector::zheev('V', 'U', dim, this->A, dim, e, work2, lwork, rwork, &info);
@@ -70,7 +70,7 @@ void Inverse_Matrix_Complex::using_zheev( const ModuleBase::ComplexMatrix &Sin,
7070
}
7171

7272
Sout = this->A * this->EA;
73-
ModuleBase::timer::tick("Inverse","using_zheev");
73+
ModuleBase::timer::end("Inverse","using_zheev");
7474
return;
7575
}
7676

source/source_base/math_polyint.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void PolyInt::Polynomial_Interpolation
1515
const double &x // input value
1616
)
1717
{
18-
ModuleBase::timer::tick("PolyInt","Poly_Interpo_1");
18+
ModuleBase::timer::start("PolyInt","Poly_Interpo_1");
1919
assert(table_interval>0.0);
2020
const double position = x / table_interval;
2121
const int iq = static_cast<int>(position);
@@ -36,7 +36,7 @@ void PolyInt::Polynomial_Interpolation
3636
table(dim1, dim2, iq+2) * x1 * x0 * x3 / 2.0 +
3737
table(dim1, dim2, iq+3) * x1 * x2 * x0 / 6.0 ;
3838

39-
ModuleBase::timer::tick("PolyInt","Poly_Interpo_1");
39+
ModuleBase::timer::end("PolyInt","Poly_Interpo_1");
4040
return;
4141
}
4242

@@ -50,7 +50,7 @@ double PolyInt::Polynomial_Interpolation
5050
const double &x // input value
5151
)
5252
{
53-
// ModuleBase::timer::tick("PolyInt","Poly_Interpo_2");
53+
// ModuleBase::timer::start("PolyInt","Poly_Interpo_2");
5454
assert(table_interval>0.0);
5555
const double position = x / table_interval;
5656
const int iq = static_cast<int>(position);
@@ -77,7 +77,7 @@ double PolyInt::Polynomial_Interpolation
7777
table(dim1, dim2, iq+2) * x1 * x0 * x3 / 2.0 +
7878
table(dim1, dim2, iq+3) * x1 * x2 * x0 / 6.0 ;
7979

80-
// ModuleBase::timer::tick("PolyInt","Poly_Interpo_2");
80+
// ModuleBase::timer::end("PolyInt","Poly_Interpo_2");
8181
return y;
8282
}
8383

@@ -92,7 +92,7 @@ double PolyInt::Polynomial_Interpolation // pengfei Li 2018-3-23
9292
const double &x // input value
9393
)
9494
{
95-
// ModuleBase::timer::tick("PolyInt","Poly_Interpo_3");
95+
// ModuleBase::timer::start("PolyInt","Poly_Interpo_3");
9696
assert(table_interval>0.0);
9797
const double position = x / table_interval;
9898
const int iq = static_cast<int>(position);
@@ -114,7 +114,7 @@ double PolyInt::Polynomial_Interpolation // pengfei Li 2018-3-23
114114
table(dim1, dim2, dim3, iq+2) * x1 * x0 * x3 / 2.0 +
115115
table(dim1, dim2, dim3, iq+3) * x1 * x2 * x0 / 6.0 ;
116116

117-
// ModuleBase::timer::tick("PolyInt","Poly_Interpo_3");
117+
// ModuleBase::timer::end("PolyInt","Poly_Interpo_3");
118118
return y;
119119
}
120120

@@ -168,7 +168,7 @@ double PolyInt::Polynomial_Interpolation_xy
168168
{
169169
return ypoint[0];
170170
}
171-
// ModuleBase::timer::tick("PolyInt","Poly_Inter_xy");
171+
// ModuleBase::timer::start("PolyInt","Poly_Inter_xy");
172172

173173
for (int ik = 0; ik < table_length; ik++)
174174
{
@@ -226,12 +226,12 @@ double PolyInt::Polynomial_Interpolation_xy
226226
part5 = dx1 * dx2 * dx3 * dx4 * dx6 / (-x15) / (-x25) / (-x35) / (-x45) / x56 * ypoint[position+4];
227227
part6 = dx1 * dx2 * dx3 * dx4 * dx5 / (-x16) / (-x26) / (-x36) / (-x46) / (-x56) * ypoint[position+5];
228228

229-
// ModuleBase::timer::tick("PolyInt","Poly_Inter_xy");
229+
// ModuleBase::timer::end("PolyInt","Poly_Inter_xy");
230230
return part1 + part2 + part3 + part4 + part5 + part6;
231231
}
232232
else
233233
{
234-
// ModuleBase::timer::tick("PolyInt","Poly_Inter_xy");
234+
// ModuleBase::timer::start("PolyInt","Poly_Inter_xy");
235235
return ypoint[position];
236236
}
237237
}

source/source_base/math_ylmreal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void YlmReal::rlylm
2828
double* rly // output
2929
)
3030
{
31-
ModuleBase::timer::tick("YlmReal","rlylm");
31+
ModuleBase::timer::start("YlmReal","rlylm");
3232

3333
assert(lmax >= 0);
3434

@@ -236,7 +236,7 @@ void YlmReal::rlylm
236236
}
237237
}
238238

239-
ModuleBase::timer::tick("YlmReal","rlylm");
239+
ModuleBase::timer::end("YlmReal","rlylm");
240240
return;
241241
}
242242

source/source_base/mathzone_add1.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void Mathzone_Add1::SplineD2 // modified by pengfei 13-8-8 add second derivative
6161
double* y2
6262
)
6363
{
64-
ModuleBase::timer::tick("Mathzone_Add1","SplineD2");
64+
ModuleBase::timer::start("Mathzone_Add1","SplineD2");
6565

6666
double dx1, dx2, dy1, dy2, p, qn, sig, un;
6767
double * u = nullptr;
@@ -122,7 +122,7 @@ void Mathzone_Add1::SplineD2 // modified by pengfei 13-8-8 add second derivative
122122

123123
delete[] u;
124124

125-
ModuleBase::timer::tick("Mathzone_Add1","SplineD2");
125+
ModuleBase::timer::end("Mathzone_Add1","SplineD2");
126126
}
127127

128128
// Peize Lin add openmp 2019-12-13
@@ -138,7 +138,7 @@ void Mathzone_Add1::Cubic_Spline_Interpolation
138138
double * const dy
139139
)
140140
{
141-
ModuleBase::timer::tick("Mathzone","cubic_spline");
141+
ModuleBase::timer::start("Mathzone","cubic_spline");
142142

143143
#ifdef _OPENMP
144144
#pragma omp parallel for schedule(static)
@@ -175,7 +175,7 @@ void Mathzone_Add1::Cubic_Spline_Interpolation
175175
//ddy[m] = ddy_tmp;
176176
}
177177

178-
ModuleBase::timer::tick("Mathzone","cubic_spline");
178+
ModuleBase::timer::end("Mathzone","cubic_spline");
179179
}
180180

181181
/// Interpolation for Numerical Orbitals
@@ -270,7 +270,7 @@ void Mathzone_Add1::Uni_Deriv_Phi
270270
double *phind
271271
)
272272
{
273-
ModuleBase::timer::tick("Mathzone_Add1", "Uni_Deriv_Phi");
273+
ModuleBase::timer::start("Mathzone_Add1", "Uni_Deriv_Phi");
274274
int FFT_NR = 2*mesh-1; // FFT_NR = 16019
275275
// std::cout << "\n mesh=" << mesh << ", radf[8010]=" << radf[8010] << ", radf[8009]=" << radf[8009] ;
276276
// mesh=8010, radf[8010]=4.396478951532926e-01, radf[8009]=0.000000000000000e+00
@@ -409,7 +409,7 @@ void Mathzone_Add1::Uni_Deriv_Phi
409409
delete [] fft_ndphik;
410410
delete [] fft_ndphir;
411411

412-
ModuleBase::timer::tick("Mathzone_Add1", "Uni_Deriv_Phi");
412+
ModuleBase::timer::end("Mathzone_Add1", "Uni_Deriv_Phi");
413413
}
414414

415415
}

source/source_base/module_mixing/broyden_mixing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ template <class FPTYPE>
105105
void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double(FPTYPE*, FPTYPE*)> inner_product)
106106
{
107107
ModuleBase::TITLE("Broyden_Mixing", "Simplified_Broyden_mixing");
108-
ModuleBase::timer::tick("Broyden_Mixing", "tem_cal_coef");
108+
ModuleBase::timer::start("Broyden_Mixing", "tem_cal_coef");
109109

110110
if (address != &mdata && address != nullptr)
111111
{
@@ -198,6 +198,6 @@ void Broyden_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double
198198
{
199199
dFnext[i] = FP_F[i];
200200
}
201-
ModuleBase::timer::tick("Broyden_Mixing", "tem_cal_coef");
201+
ModuleBase::timer::end("Broyden_Mixing", "tem_cal_coef");
202202
};
203203
} // namespace Base_Mixing

source/source_base/module_mixing/pulay_mixing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ template <class FPTYPE>
9898
void Pulay_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double(FPTYPE*, FPTYPE*)> inner_product)
9999
{
100100
ModuleBase::TITLE("Charge_Mixing", "Pulay_mixing");
101-
ModuleBase::timer::tick("Charge", "Pulay_mixing");
101+
ModuleBase::timer::start("Charge", "Pulay_mixing");
102102
if (address != &mdata && address != nullptr)
103103
ModuleBase::WARNING_QUIT(
104104
"Pulay_mixing",
@@ -177,6 +177,6 @@ void Pulay_Mixing::tem_cal_coef(const Mixing_Data& mdata, std::function<double(F
177177
coef[0] = 1.0;
178178
}
179179

180-
ModuleBase::timer::tick("Charge", "Pulay_mixing");
180+
ModuleBase::timer::end("Charge", "Pulay_mixing");
181181
};
182182
} // namespace Base_Mixing

source/source_base/mymath.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void heapAjust(double *r, int *ind, int s, int m)
3535

3636
void heapsort(const int n, double *r, int *ind)
3737
{
38-
ModuleBase::timer::tick("mymath", "heapsort");
38+
ModuleBase::timer::start("mymath", "heapsort");
3939
int i = 0, ic = 0;
4040
double rc = 0.0;
4141

@@ -62,7 +62,7 @@ void heapsort(const int n, double *r, int *ind)
6262
ind[i] = ic;
6363
heapAjust(r, ind, 0, i - 1);
6464
}
65-
ModuleBase::timer::tick("mymath", "heapsort");
65+
ModuleBase::timer::end("mymath", "heapsort");
6666
return;
6767
}
6868

source/source_base/para_gemm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void PGemmCN<T, Device>::set_dimension(
146146
template <typename T, typename Device>
147147
void PGemmCN<T, Device>::multiply(const T alpha, const T* A, const T* B, const T beta, T* C)
148148
{
149-
ModuleBase::timer::tick("PGemmCN", "multiply");
149+
ModuleBase::timer::start("PGemmCN", "multiply");
150150
#ifdef __MPI
151151
if (this->col_nproc > 1)
152152
{
@@ -164,7 +164,7 @@ void PGemmCN<T, Device>::multiply(const T alpha, const T* A, const T* B, const T
164164
{
165165
multiply_single(alpha, A, B, beta, C);
166166
}
167-
ModuleBase::timer::tick("PGemmCN", "multiply");
167+
ModuleBase::timer::end("PGemmCN", "multiply");
168168
}
169169

170170
template <typename T, typename Device>

source/source_base/test/timer_test.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class TimerTest : public testing::Test
5050

5151
TEST_F(TimerTest, Tick)
5252
{
53-
ModuleBase::timer::tick("wavefunc","evc");
53+
ModuleBase::timer::start("wavefunc","evc");
5454
// after 1st call of tick, start_flag becomes false
5555
EXPECT_FALSE(ModuleBase::timer::timer_pool["wavefunc"]["evc"].start_flag);
5656
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
5757
// then we can have time elapsed in cpu_second
58-
ModuleBase::timer::tick("wavefunc","evc");
58+
ModuleBase::timer::end("wavefunc","evc");
5959
EXPECT_GT(ModuleBase::timer::timer_pool["wavefunc"]["evc"].cpu_second,0.0001);
6060
}
6161

@@ -65,14 +65,15 @@ TEST_F(TimerTest, Start)
6565
ModuleBase::timer::start();
6666
// start() called tick() once
6767
EXPECT_FALSE(ModuleBase::timer::timer_pool[""]["total"].start_flag);
68+
ModuleBase::timer::end("","total");
6869
}
6970

7071

7172
TEST_F(TimerTest, write_to_json)
7273
{
73-
ModuleBase::timer::tick("wavefunc","evc");
74+
ModuleBase::timer::start("wavefunc","evc");
7475
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
75-
ModuleBase::timer::tick("wavefunc","evc");
76+
ModuleBase::timer::end("wavefunc","evc");
7677
ModuleBase::timer::write_to_json("tmp.json");
7778

7879
// check if tmp.json exists
@@ -103,14 +104,14 @@ TEST_F(TimerTest, write_to_json)
103104

104105
TEST_F(TimerTest, PrintAll)
105106
{
106-
ModuleBase::timer::tick("wavefunc","evc");
107+
ModuleBase::timer::start("wavefunc","evc");
107108
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
108-
ModuleBase::timer::tick("wavefunc","evc");
109+
ModuleBase::timer::end("wavefunc","evc");
109110

110111
// call print_all
111112
ofs.open("tmp");
112113
testing::internal::CaptureStdout();
113-
ModuleBase::timer::print_all(ofs);
114+
ModuleBase::timer::print_all(ofs, true);
114115
output = testing::internal::GetCapturedStdout();
115116
ofs.close();
116117

@@ -147,15 +148,15 @@ TEST_F(TimerTest, PrintAll)
147148
TEST_F(TimerTest, PrintUntilNow)
148149
{
149150
long double time = ModuleBase::timer::print_until_now();
150-
EXPECT_TRUE(time>0.0);
151+
EXPECT_GE(time, 0.0);
151152
}
152153

153154

154155
TEST_F(TimerTest, Finish)
155156
{
156-
ModuleBase::timer::tick("wavefunc","evc");
157+
ModuleBase::timer::start("wavefunc","evc");
157158
std::this_thread::sleep_for(std::chrono::microseconds(T_Elapse)); // 0.1 ms
158-
ModuleBase::timer::tick("wavefunc","evc");
159+
ModuleBase::timer::end("wavefunc","evc");
159160

160161
// call print_all
161162
ofs.open("tmp");

0 commit comments

Comments
 (0)