Skip to content

Commit 8edadcc

Browse files
committed
add timer to module_pw
1 parent e868f9c commit 8edadcc

File tree

10 files changed

+46
-6
lines changed

10 files changed

+46
-6
lines changed

source/module_base/timer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ void timer::print_all(std::ofstream &ofs)
146146
const std::string &name = timer_pool_order_A.first.second;
147147
const Timer_One &timer_one = timer_pool_order_A.second;
148148

149-
if(timer_one.cpu_second < small)
150-
continue;
149+
// if(timer_one.cpu_second < small)
150+
// continue;
151151

152152
ofs << " "
153153
// << std::setw(2) << timer_one.level

source/module_pw/pw_basis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "pw_basis.h"
22
#include "../module_base/mymath.h"
33
#include <iostream>
4+
#include "../module_base/memory.h"
5+
#include "../module_base/timer.h"
6+
#include "../module_base/global_function.h"
7+
48

59
namespace ModulePW
610
{

source/module_pw/pw_distributeg_method1.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../src_parallel/parallel_global.h"
44
#include "../module_base/global_function.h"
55
#include "iostream"
6+
#include "../module_base/timer.h"
67

78

89
namespace ModulePW
@@ -24,6 +25,7 @@ namespace ModulePW
2425
//
2526
void PW_Basis::distribution_method1()
2627
{
28+
ModuleBase::timer::tick("PW_Basis", "distributeg_method1");
2729

2830
// initial the variables needed by all proc.
2931
int tot_npw = 0; // total number of planewaves.
@@ -186,7 +188,7 @@ void PW_Basis::distribution_method1()
186188
// for test ----------------------------------------------
187189
if (poolrank==0) std::cout << "The fifth step done\n";
188190
// -------------------------------------------------------
189-
191+
ModuleBase::timer::tick("PW_Basis", "distributeg_method1");
190192
return;
191193
}
192194

source/module_pw/pw_distributeg_method2.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../src_parallel/parallel_global.h"
44
#include "../module_base/global_function.h"
55
#include "iostream"
6+
#include "../module_base/timer.h"
67

78

89
namespace ModulePW
@@ -23,6 +24,7 @@ namespace ModulePW
2324
//
2425
void PW_Basis::distribution_method2()
2526
{
27+
ModuleBase::timer::tick("PW_Basis", "distributeg_method2");
2628

2729
// initial the variables needed by all proc.
2830
int tot_npw = 0; // total number of planewaves.
@@ -135,7 +137,7 @@ void PW_Basis::distribution_method2()
135137
// for test ----------------------------------------------
136138
if (poolrank==0) std::cout << "The fifth step done\n";
137139
// -------------------------------------------------------
138-
140+
ModuleBase::timer::tick("PW_Basis", "distributeg_method1");
139141
return;
140142
}
141143

source/module_pw/pw_gatherscatter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "pw_basis.h"
22
#include "../module_base/global_function.h"
3+
#include "../module_base/timer.h"
34
#ifdef __MPI
45
#include "mpi.h"
56
#include "../src_parallel/parallel_global.h"
@@ -13,6 +14,8 @@ namespace ModulePW
1314
//
1415
void PW_Basis:: gatherp_scatters(complex<double> *in, complex<double> *out)
1516
{
17+
ModuleBase::timer::tick("PW_Basis", "gatherp_scatters");
18+
1619
if(this->poolnproc == 1) //In this case nst=nstot, nz = nplane,
1720
{
1821
for(int is = 0 ; is < this->nst ; ++is)

source/module_pw/pw_init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "./pw_basis.h"
22
#include "../module_base/constants.h"
3+
#include "../module_base/timer.h"
34

45
namespace ModulePW
56
{
@@ -14,6 +15,7 @@ void PW_Basis:: initgrids(
1415
double gridecut
1516
)
1617
{
18+
// ModuleBase::timer::start();
1719
//init latice
1820
this->lat0 = lat0_in;
1921
this->latvec = latvec_in;

source/module_pw/pw_transform.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "pw_basis.h"
44
#include <cassert>
55
#include "../module_base/global_function.h"
6+
#include "../module_base/timer.h"
67

78
namespace ModulePW
89
{
@@ -14,6 +15,8 @@ namespace ModulePW
1415
//
1516
void PW_Basis:: real2recip(std::complex<double> * in, std::complex<double> * out)
1617
{
18+
ModuleBase::timer::tick("PW_Basis", "real2recip");
19+
1720
assert(this->gamma_only == false);
1821
for(int ir = 0 ; ir < this->nrxx ; ++ir)
1922
{
@@ -30,6 +33,7 @@ void PW_Basis:: real2recip(std::complex<double> * in, std::complex<double> * out
3033
out[ig] = this->ft.aux1[this->ig2isz[ig]];
3134
}
3235
return;
36+
ModuleBase::timer::tick("PW_Basis", "real2recip");
3337
}
3438

3539
//
@@ -39,6 +43,7 @@ void PW_Basis:: real2recip(std::complex<double> * in, std::complex<double> * out
3943
//
4044
void PW_Basis:: real2recip(double * in, std::complex<double> * out)
4145
{
46+
ModuleBase::timer::tick("PW_Basis", "real2recip_gamma_only");
4247
assert(this->gamma_only == true);
4348
// for(int ir = 0 ; ir < this->nrxx ; ++ir)
4449
// {
@@ -64,6 +69,7 @@ void PW_Basis:: real2recip(double * in, std::complex<double> * out)
6469
{
6570
out[ig] = this->ft.aux1[this->ig2isz[ig]];
6671
}
72+
ModuleBase::timer::tick("PW_Basis", "real2recip_gamma_only");
6773
return;
6874
}
6975

@@ -74,6 +80,7 @@ void PW_Basis:: real2recip(double * in, std::complex<double> * out)
7480
//
7581
void PW_Basis:: recip2real(std::complex<double> * in, std::complex<double> * out)
7682
{
83+
ModuleBase::timer::tick("PW_Basis", "recip2real");
7784
assert(this->gamma_only == false);
7885
ModuleBase::GlobalFunc::ZEROS(ft.aux1, this->nst * this->nz);
7986

@@ -91,6 +98,7 @@ void PW_Basis:: recip2real(std::complex<double> * in, std::complex<double> * out
9198
{
9299
out[ir] = this->ft.aux1[ir] / double(this->bignxyz);
93100
}
101+
ModuleBase::timer::tick("PW_Basis", "recip2real");
94102

95103
return;
96104
}
@@ -102,6 +110,7 @@ void PW_Basis:: recip2real(std::complex<double> * in, std::complex<double> * out
102110
//
103111
void PW_Basis:: recip2real(std::complex<double> * in, double * out)
104112
{
113+
ModuleBase::timer::tick("PW_Basis", "recip2real_gamma_only");
105114
assert(this->gamma_only == true);
106115
ModuleBase::GlobalFunc::ZEROS(ft.aux1, this->nst * this->nz);
107116

@@ -129,6 +138,7 @@ void PW_Basis:: recip2real(std::complex<double> * in, double * out)
129138
out[ix*npy + ipy] = this->ft.r_rspace[ix*npy*2 + ipy] / double(this->bignxyz);
130139
}
131140
}
141+
ModuleBase::timer::tick("PW_Basis", "recip2real_gamma_only");
132142
return;
133143
}
134144

source/module_pw/unittest/test2.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <iostream>
99
#include <iomanip>
1010
#include "mpi.h"
11+
#include "../../module_base/timer.h"
12+
#include <fstream>
1113

1214
using namespace std;
1315
int main(int argc,char **argv)
@@ -33,7 +35,7 @@ int main(int argc,char **argv)
3335
setupmpi(argc,argv,nproc, myrank);
3436
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
3537
//cout<<nproc<<" d "<<myrank<<" d "<<nproc_in_pool<<" "<<npool<<" "<<mypool<<" "<<rank_in_pool<<endl;
36-
38+
ModuleBase::timer::start();
3739
//init
3840
pwtest.initgrids(lat0,latvec,wfcecut);
3941
//pwtest.initgrids(lat0,latvec,5,7,7);
@@ -152,7 +154,8 @@ int main(int argc,char **argv)
152154
}
153155
cout<<endl;
154156
}
155-
157+
// ofstream ofs("time.txt");
158+
ModuleBase::timer::finish(GlobalV::ofs_running, true);
156159

157160
MPI_Barrier(MPI_COMM_WORLD);
158161
delete [] rhog;

source/module_pw/unittest/test_t1.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "mpi.h"
1111
#include "time.h"
1212
#include <gperftools/profiler.h>
13+
#include "../../module_base/timer.h"
1314

1415
using namespace std;
1516
int main(int argc,char **argv)
@@ -39,6 +40,7 @@ int main(int argc,char **argv)
3940
// if(myrank==0) ProfilerStart("test0.prof");
4041
// if(myrank==1) ProfilerStart("test1.prof");
4142

43+
ModuleBase::timer::start();
4244
//init
4345
pwtest.initgrids(lat0,latvec,wfcecut);
4446
//pwtest.initgrids(lat0,latvec,5,7,7);
@@ -83,6 +85,8 @@ int main(int argc,char **argv)
8385

8486
cout<<"\n";
8587
cout<<"spend "<<fftduration<<"s\n";
88+
89+
if(rank_in_pool==0) ModuleBase::timer::finish(GlobalV::ofs_running, true);
8690

8791
if(tmp!=NULL) delete []tmp;
8892
// MPI_Barrier(MPI_COMM_WORLD);

source/module_pw/unittest/time.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
4+
5+
|CLASS_NAME---------|NAME---------------|TIME(Sec)-----|CALLS----|AVG------|PER%-------
6+
total 0.0386 1 0.039 1e+02%
7+
PW_Basis distributeg_method1 0.0007 1 0.0007 1.8%
8+
mymath heapsort 2.1e-06 1 2.1e-06 0.0055%
9+
PW_Basis real2recip 0 1 0 0%
10+
----------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)