Skip to content

Commit 8016b53

Browse files
authored
Merge pull request #523 from sunliang98/planewave
< build > add timer to module_pw
2 parents 283e9ca + 3e3e9bc commit 8016b53

18 files changed

+112
-33
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: 21 additions & 20 deletions
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.
@@ -48,14 +50,14 @@ void PW_Basis::distribution_method1()
4850
std::cout << "The first step done\n";
4951
std::cout << "tot_npw " << tot_npw << '\n';
5052
std::cout << "this->nstot " << this->nstot << '\n';
51-
for (int ix = 0; ix < nx; ++ix)
52-
{
53-
for (int iy = 0; iy < ny; ++iy)
54-
{
55-
std::cout << st_length2D[ix * ny + iy] << std::setw(4);
56-
}
57-
std::cout << '\n';
58-
}
53+
// for (int ix = 0; ix < nx; ++ix)
54+
// {
55+
// for (int iy = 0; iy < ny; ++iy)
56+
// {
57+
// std::cout << st_length2D[ix * ny + iy] << std::setw(4);
58+
// }
59+
// std::cout << '\n';
60+
// }
5961
// ------------------------------------------------------------
6062
#ifdef __MPI
6163
// Parallel line
@@ -90,9 +92,9 @@ void PW_Basis::distribution_method1()
9092

9193
// for test -----------------------------------------------------------------------------
9294
std::cout << "The 3-1 step done\n";
93-
std::cout << "st_i ";
94-
for (int is = 0; is < this->nstot; ++is) cout << st_i[is] << setw(4) ;
95-
std::cout << std::endl;
95+
// std::cout << "st_i ";
96+
// for (int is = 0; is < this->nstot; ++is) cout << st_i[is] << setw(4) ;
97+
// std::cout << std::endl;
9698
// --------------------------------------------------------------------------------------
9799

98100
this->get_istot2bigixy(st_i, st_j);
@@ -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

@@ -261,7 +263,6 @@ void PW_Basis::collect_st(
261263
temp_st_j[is] = y;
262264
temp_st_length[is] = static_cast<double>(st_length2D[index]);
263265
++is;
264-
std::cout << "is " << is << '\n';
265266
}
266267
}
267268
}
@@ -281,9 +282,9 @@ void PW_Basis::collect_st(
281282
st_i[istot] = temp_st_i[st_sorted_index[istot]];
282283
st_j[istot] = temp_st_j[st_sorted_index[istot]];
283284
}
284-
std::cout << "st_length ";
285-
for (int is = 0; is < this->nstot; ++is) std::cout << st_length[is] << std::setw(4);
286-
std::cout << "\n";
285+
// std::cout << "st_length ";
286+
// for (int is = 0; is < this->nstot; ++is) std::cout << st_length[is] << std::setw(4);
287+
// std::cout << "\n";
287288

288289
delete[] temp_st_i;
289290
delete[] temp_st_j;
@@ -348,10 +349,10 @@ void PW_Basis::divide_sticks(
348349
this->ixy2ip[st_i[is] * this->ny + st_j[is]] = ipmin;
349350
}
350351
// for test --------------------------------------------------------------------------
351-
for(int i = 0; i < this->poolnproc; ++i) std::cout<<this->nstnz_per[i]<<std::setw(4);
352-
std::cout<<"\n";
353-
for(int i = 0; i < this->poolnproc; ++i) std::cout<<nst_per[i]<<std::setw(4);
354-
std::cout<<"\n";
352+
// for(int i = 0; i < this->poolnproc; ++i) std::cout<<this->nstnz_per[i]<<std::setw(4);
353+
// std::cout<<"\n";
354+
// for(int i = 0; i < this->poolnproc; ++i) std::cout<<nst_per[i]<<std::setw(4);
355+
// std::cout<<"\n";
355356
// -----------------------------------------------------------------------------------
356357
for (int ip = 1; ip < poolnproc; ++ip)
357358
{

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.h

Lines changed: 6 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
#include "typeinfo"
45
#ifdef __MPI
56
#include "mpi.h"
@@ -15,6 +16,8 @@ namespace ModulePW
1516
template<typename T>
1617
void PW_Basis:: gatherp_scatters(complex<T> *in, complex<T> *out)
1718
{
19+
ModuleBase::timer::tick("PW_Basis", "gatherp_scatters");
20+
1821
if(this->poolnproc == 1) //In this case nst=nstot, nz = nplane,
1922
{
2023
for(int is = 0 ; is < this->nst ; ++is)
@@ -61,6 +64,7 @@ void PW_Basis:: gatherp_scatters(complex<T> *in, complex<T> *out)
6164
}
6265

6366
#endif
67+
ModuleBase::timer::tick("PW_Basis", "gatherp_scatters");
6468
return;
6569
}
6670

@@ -72,6 +76,7 @@ void PW_Basis:: gatherp_scatters(complex<T> *in, complex<T> *out)
7276
template<typename T>
7377
void PW_Basis:: gathers_scatterp(complex<T> *in, complex<T> *out)
7478
{
79+
ModuleBase::timer::tick("PW_Basis", "gatherp_scatterp");
7580

7681
if(this->poolnproc == 1) //In this case nrxx=nx*ny*nz, nst = nstot,
7782
{
@@ -121,6 +126,7 @@ void PW_Basis:: gathers_scatterp(complex<T> *in, complex<T> *out)
121126
}
122127

123128
#endif
129+
ModuleBase::timer::tick("PW_Basis", "gatherp_scatterp");
124130
return;
125131
}
126132

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
#include "pw_gatherscatter.h"
78

89
namespace ModulePW
@@ -15,6 +16,8 @@ namespace ModulePW
1516
//
1617
void PW_Basis:: real2recip(std::complex<double> * in, std::complex<double> * out)
1718
{
19+
ModuleBase::timer::tick("PW_Basis", "real2recip");
20+
1821
assert(this->gamma_only == false);
1922
for(int ir = 0 ; ir < this->nrxx ; ++ir)
2023
{
@@ -31,6 +34,7 @@ void PW_Basis:: real2recip(std::complex<double> * in, std::complex<double> * out
3134
out[ig] = this->ft.aux1[this->ig2isz[ig]];
3235
}
3336
return;
37+
ModuleBase::timer::tick("PW_Basis", "real2recip");
3438
}
3539

3640
//
@@ -40,6 +44,7 @@ void PW_Basis:: real2recip(std::complex<double> * in, std::complex<double> * out
4044
//
4145
void PW_Basis:: real2recip(double * in, std::complex<double> * out)
4246
{
47+
ModuleBase::timer::tick("PW_Basis", "real2recip_gamma_only");
4348
assert(this->gamma_only == true);
4449
// for(int ir = 0 ; ir < this->nrxx ; ++ir)
4550
// {
@@ -65,6 +70,7 @@ void PW_Basis:: real2recip(double * in, std::complex<double> * out)
6570
{
6671
out[ig] = this->ft.aux1[this->ig2isz[ig]];
6772
}
73+
ModuleBase::timer::tick("PW_Basis", "real2recip_gamma_only");
6874
return;
6975
}
7076

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

@@ -92,6 +99,7 @@ void PW_Basis:: recip2real(std::complex<double> * in, std::complex<double> * out
9299
{
93100
out[ir] = this->ft.aux1[ir] / double(this->bignxyz);
94101
}
102+
ModuleBase::timer::tick("PW_Basis", "recip2real");
95103

96104
return;
97105
}
@@ -103,6 +111,7 @@ void PW_Basis:: recip2real(std::complex<double> * in, std::complex<double> * out
103111
//
104112
void PW_Basis:: recip2real(std::complex<double> * in, double * out)
105113
{
114+
ModuleBase::timer::tick("PW_Basis", "recip2real_gamma_only");
106115
assert(this->gamma_only == true);
107116
ModuleBase::GlobalFunc::ZEROS(ft.aux1, this->nst * this->nz);
108117

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

source/module_pw/unittest/test1.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "../pw_basis.h"
22
#include "../../src_parallel/parallel_global.h"
33
#include "test_tool.h"
4+
#include "../../module_base/timer.h"
5+
#include "../../module_base/global_function.h"
46

57
int main(int argc,char **argv)
68
{
@@ -14,6 +16,8 @@ int main(int argc,char **argv)
1416
setupmpi(argc,argv,nproc, myrank);
1517
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
1618

19+
ModuleBase::timer::start();
20+
1721
int distribution_type = 1;
1822
ModulePW::PW_Basis pwtest;
1923

@@ -74,6 +78,7 @@ int main(int argc,char **argv)
7478
std::cout << "\n";
7579
}
7680
}
81+
if(rank_in_pool==0) ModuleBase::timer::finish(GlobalV::ofs_running, true);
7782

7883
// if (rank_in_pool == 0)
7984
// {

source/module_pw/unittest/test2-1.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "../pw_basis.h"
22
#include "../../src_parallel/parallel_global.h"
33
#include "test_tool.h"
4+
#include "../../module_base/timer.h"
5+
#include "../../module_base/global_function.h"
46

57
int main(int argc,char **argv)
68
{
@@ -14,6 +16,8 @@ int main(int argc,char **argv)
1416
setupmpi(argc,argv,nproc, myrank);
1517
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
1618

19+
ModuleBase::timer::start();
20+
1721
int distribution_type = 2;
1822
ModulePW::PW_Basis pwtest;
1923

@@ -74,6 +78,7 @@ int main(int argc,char **argv)
7478
std::cout << "\n";
7579
}
7680
}
81+
if(rank_in_pool==0) ModuleBase::timer::finish(GlobalV::ofs_running, true);
7782

7883
// if (rank_in_pool == 0)
7984
// {

source/module_pw/unittest/test2-2.cpp

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

1213
using namespace std;
1314
int main(int argc,char **argv)
@@ -33,6 +34,7 @@ int main(int argc,char **argv)
3334
setupmpi(argc,argv,nproc, myrank);
3435
divide_pools(nproc, myrank, nproc_in_pool, npool, mypool, rank_in_pool);
3536
//cout<<nproc<<" d "<<myrank<<" d "<<nproc_in_pool<<" "<<npool<<" "<<mypool<<" "<<rank_in_pool<<endl;
37+
ModuleBase::timer::start();
3638

3739
//init
3840
pwtest.initgrids(lat0,latvec,wfcecut);
@@ -55,10 +57,10 @@ int main(int argc,char **argv)
5557
GT = latvec.Inverse();
5658
G = GT.Transpose();
5759
GGT = G * GT;
58-
60+
complex<double> *tmp = NULL;
5961
if(myrank == 0)
6062
{
61-
complex<double> *tmp = new complex<double> [nx*ny*nz];
63+
tmp = new complex<double> [nx*ny*nz];
6264
for(int ix = 0 ; ix < nx ; ++ix)
6365
{
6466
for(int iy = 0 ; iy < ny ; ++iy)
@@ -80,7 +82,8 @@ int main(int argc,char **argv)
8082
}
8183
}
8284
fftw_plan pp = fftw_plan_dft_3d(nx,ny,nz,(fftw_complex *) tmp, (fftw_complex *) tmp, FFTW_BACKWARD, FFTW_ESTIMATE);
83-
fftw_execute(pp);
85+
fftw_execute(pp);
86+
fftw_destroy_plan(pp);
8487

8588
//output
8689
cout << "reference\n";
@@ -153,6 +156,11 @@ int main(int argc,char **argv)
153156
}
154157

155158

156-
MPI_Barrier(MPI_COMM_WORLD);
159+
MPI_Barrier(MPI_COMM_WORLD);
160+
if(rank_in_pool==0) ModuleBase::timer::finish(GlobalV::ofs_running, true);
161+
162+
delete [] rhog;
163+
delete [] rhor;
164+
if(tmp!=NULL) delete []tmp;
157165
return 0;
158166
}

0 commit comments

Comments
 (0)