Skip to content

Commit bb5349b

Browse files
committed
comment: modify comments for pw module
1 parent a9f30fe commit bb5349b

File tree

12 files changed

+224
-161
lines changed

12 files changed

+224
-161
lines changed

source/module_pw/fft.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ class FFT
2727

2828
FFT();
2929
~FFT();
30+
31+
// init parameters of fft
3032
void initfft(int nx_in, int bigny_in, int nz_in, int liy_in, int riy_in, int ns_in, int nplane_in,
3133
int nproc_in, bool gamma_only_in, bool mpifft_in = false);
32-
void setupFFT();
33-
void cleanFFT();
34+
35+
//init fftw_plans
36+
void setupFFT();
37+
38+
//destroy fftw_plans
39+
void cleanFFT();
3440

3541
void fftzfor(std::complex<double>* & in, std::complex<double>* & out);
3642
void fftzbac(std::complex<double>* & in, std::complex<double>* & out);
@@ -50,10 +56,12 @@ class FFT
5056
#endif
5157

5258
public:
53-
void initplan();
59+
//init fftw_plans
60+
void initplan();
5461
void initplan_mpi();
5562
#ifdef __MIX_PRECISION
56-
void initplanf();
63+
//init fftwf_plans
64+
void initplanf();
5765
void initplanf_mpi();
5866
#endif
5967

source/module_pw/pw_basis.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ PW_Basis:: ~PW_Basis()
5252
if(startr != NULL) delete[] startr;
5353
}
5454

55+
///
56+
/// distribute plane wave basis and real-space grids to different processors
57+
/// set up maps for fft and create arrays for MPI_Alltoall
58+
/// set up ffts
59+
///
5560
void PW_Basis::setuptransform()
5661
{
5762
this->distribute_r();
@@ -96,11 +101,11 @@ void PW_Basis::getstartgr()
96101
return;
97102
}
98103

99-
//
100-
// Collect planewaves on current core, and construct gg, gdirect, gcar according to ig2isz and is2ixy.
101-
// known: ig2isz, is2ixy
102-
// output: gg, gdirect, gcar
103-
//
104+
///
105+
/// Collect planewaves on current core, and construct gg, gdirect, gcar according to ig2isz and is2ixy.
106+
/// known: ig2isz, is2ixy
107+
/// output: gg, gdirect, gcar
108+
///
104109
void PW_Basis::collect_local_pw()
105110
{
106111
if(gg != NULL) delete[] gg;

source/module_pw/pw_basis.h

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ class PW_Basis
9393
//distribute real-space grids to different processors
9494
void distribute_r();
9595

96+
//prepare for MPI_Alltoall
9697
void getstartgr();
9798

98-
//distribute plane waves to different processors
99-
void distribution_method1(); // x varies fast
100-
void distribution_method2(); // sticks sorted according to ixy
101-
// void distribution_method3(); // y varies fast
10299

100+
101+
//prepare for transforms between real and reciprocal spaces
103102
void collect_local_pw();
104103

105104
// void collect_tot_pw(
@@ -120,38 +119,52 @@ class PW_Basis
120119
int distribution_type;
121120
int poolnproc;
122121
int poolrank;
123-
122+
//distribute plane waves to different processors
123+
124+
//method 1: first consider number of plane waves
125+
void distribution_method1();
126+
// Distribute sticks to cores in method 1.
127+
void divide_sticks_1(
128+
int* st_i, // x or x + nx (if x < 0) of stick.
129+
int* st_j, // y or y + ny (if y < 0) of stick.
130+
int* st_length, // the stick on (ix, iy) consists of st_length[ix*ny+iy] planewaves.
131+
int* npw_per // number of planewaves on each core.
132+
);
124133

125-
// for both distributeg_method1 and distributeg_method2
134+
//method 2: first consider number of sticks
135+
void distribution_method2();
136+
// Distribute sticks to cores in method 2.
137+
void divide_sticks_2();
138+
139+
//Count the total number of planewaves (tot_npw) and sticks (this->nstot) (in distributeg method1 and method2)
126140
void count_pw_st(
127141
int &tot_npw, // total number of planewaves.
128142
int* st_length2D, // the number of planewaves that belong to the stick located on (x, y).
129143
int* st_bottom2D // the z-coordinate of the bottom of stick on (x, y).
130144
);
145+
146+
//get ig2isz and is2ixy
131147
void get_ig2isz_is2ixy(
132148
int* st_bottom, // minimum z of stick, stored in 1d array with tot_nst elements.
133149
int* st_length // the stick on (x, y) consists of st_length[x*ny+y] planewaves.
134150
);
135-
// for distributeg_method1
151+
152+
//Collect the x, y indexs, length of the sticks (in distributeg method1)
136153
void collect_st(
137154
int* st_length2D, // the number of planewaves that belong to the stick located on (x, y), stored in 2d x-y plane.
138155
int* st_bottom2D, // the z-coordinate of the bottom of stick on (x, y), stored in 2d x-y plane.
139156
int* st_i, // x or x + nx (if x < 0) of stick.
140157
int* st_j, // y or y + ny (if y < 0) of stick.
141158
int* st_length // number of planewaves in stick, stored in 1d array with tot_nst elements.
142159
);
143-
void divide_sticks(
144-
int* st_i, // x or x + nx (if x < 0) of stick.
145-
int* st_j, // y or y + ny (if y < 0) of stick.
146-
int* st_length, // the stick on (x, y) consists of st_length[x*ny+y] planewaves.
147-
int* npw_per // number of planewaves on each core.
148-
);
160+
161+
//get istot2bigixy
149162
void get_istot2bigixy(
150163
int* st_i, // x or x + nx (if x < 0) of stick.
151164
int* st_j // y or y + ny (if y < 0) of stick.
152165
);
153-
// for distributeg_method2
154-
void divide_sticks2();
166+
167+
//Create the maps from ixy to (in method 2)
155168
void create_maps(
156169
int* st_length2D, // the number of planewaves that belong to the stick located on (x, y), stored in 2d x-y plane.
157170
int* npw_per // number of planewaves on each core.
@@ -179,16 +192,14 @@ class PW_Basis
179192
void recip2real(std::complex<float> * in, float *out); //in:(nz, ns) ; out(nplane,nx*ny)
180193
void recip2real(std::complex<float> * in, std::complex<float> * out); //in:(nz, ns) ; out(nplane,nx*ny)
181194
#endif
195+
//gather planes and scatter sticks of all processors
182196
template<typename T>
183-
void gatherp_scatters(std::complex<T> *in, std::complex<T> *out); //gather planes and scatter sticks of all processors
184-
template<typename T>
185-
void gathers_scatterp(std::complex<T> *in, std::complex<T> *out); //gather sticks of and scatter planes of all processors
186-
// void gathers_scatterp2(std::complex<double> *in, std::complex<double> *out); //gather sticks of and scatter planes of all processors
187-
// void gatherp_scatters2(std::complex<double> *in, std::complex<double> *out); //gather sticks of and scatter planes of all processors
188-
// void gatherp_scatters_gamma(std::complex<double> *in, std::complex<double> *out); //gather planes and scatter sticks of all processors, used when gamma_only
189-
// void gathers_scatterp_gamma(std::complex<double> *in, std::complex<double> *out); //gather sticks of and scatter planes of all processors, used when gamma only
197+
void gatherp_scatters(std::complex<T> *in, std::complex<T> *out);
190198

199+
//gather sticks of and scatter planes of all processors
200+
template<typename T>
201+
void gathers_scatterp(std::complex<T> *in, std::complex<T> *out);
191202
};
192203

193204
}
194-
#endif //PlaneWave class
205+
#endif //PlaneWave

source/module_pw/pw_basis_k.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ void PW_Basis_K::setupIndGk()
9999

100100
return;
101101
}
102+
103+
///
104+
/// distribute plane wave basis and real-space grids to different processors
105+
/// set up maps for fft and create arrays for MPI_Alltoall
106+
/// set up ffts
107+
///
102108
void PW_Basis_K::setuptransform()
103109
{
104110
this->distribute_r();

source/module_pw/pw_basis_k.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace ModulePW
88
///
99
/// Special pw_basis class.
1010
/// It includes different k-points
11-
/// plane waves: <r|g,k>=1/sqrt(V) * exp(i(k+g)r)
11+
/// plane waves: <r|g,k> = 1/sqrt(V) * exp(i(k+g)r)
12+
/// f(r) = 1/sqrt(V) * \sum_g{c(g)*exp(i(k+g)r)}
1213
///
1314
class PW_Basis_K : public PW_Basis
1415
{
@@ -17,6 +18,7 @@ class PW_Basis_K : public PW_Basis
1718
PW_Basis_K();
1819
~PW_Basis_K();
1920

21+
//init parameters of pw_basis_k class
2022
void initparameters(
2123
bool gamma_only_in,
2224
double ecut_in,
@@ -35,9 +37,15 @@ class PW_Basis_K : public PW_Basis
3537
double gk_ecut; //Energy cut off for (g+k)^2/2
3638

3739
public:
40+
//prepare for transforms between real and reciprocal spaces
3841
void setuptransform();
42+
43+
//create igl2isz_k map array for fft
3944
void setupIndGk();
45+
4046
int *igl2isz_k; //[npwk_max*nks] map (ig,ik) to (is,iz)
47+
48+
//create Direct coordinate, Cartesian coordinate, norm2 of plane waves in each processor
4149
void collect_local_pw();
4250

4351
public:
@@ -54,9 +62,13 @@ class PW_Basis_K : public PW_Basis
5462
#endif
5563

5664
public:
57-
//operator
65+
//operator:
66+
67+
//calculate g+k
5868
ModuleBase::Vector3<double> get_GPlusK_cartesian(const int ik, const int ig) const;
69+
//calculate g+k.x/y/z
5970
double get_GPlusK_cartesian_projection(const int ik, const int ig, const int axis) const;
71+
//calculate (g+k)^2
6072
double get_SquareGPlusK_cartesian(const int ik, const int ig) const;
6173
};
6274

source/module_pw/pw_distributeg.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace ModulePW
66
{
7-
//
8-
//distribute plane waves to different cores
9-
//Known: G, GT, GGT, nx, ny, nz, poolnproc, poolrank, ggecut
10-
//output: ig2isz[ig], istot2ixy[is], ixy2istot[ixy], is2ixy[is], ixy2ip[ixy], startnsz_per[ip], nstnz_per[ip], gg[ig], gcar[ig], gdirect[ig], nst, nstot
11-
//
7+
///
8+
/// distribute plane waves to different cores
9+
/// Known: G, GT, GGT, nx, ny, nz, poolnproc, poolrank, ggecut
10+
/// output: ig2isz[ig], istot2ixy[is], ixy2istot[ixy], is2ixy[is], ixy2ip[ixy], startnsz_per[ip], nstnz_per[ip], gg[ig], gcar[ig], gdirect[ig], nst, nstot
11+
///
1212
void PW_Basis::distribute_g()
1313
{
1414
if(this->distribution_type == 1)
@@ -26,13 +26,13 @@ void PW_Basis::distribute_g()
2626
return;
2727
}
2828

29-
//
30-
// (1) We count the total number of planewaves (tot_npw) and sticks (this->nstot) here.
31-
// Meanwhile, we record the number of planewaves on (x, y) in st_length2D, and store the smallest z-coordinate of each stick in st_bottom2D,
32-
// so that we can scan a much smaller area in step(2).
33-
// known: nx, ny, nz, ggecut, GGT
34-
// output: tot_npw, this->nstot, st_length2D, st_bottom2D
35-
//
29+
///
30+
/// (1) We count the total number of planewaves (tot_npw) and sticks (this->nstot) here.
31+
/// Meanwhile, we record the number of planewaves on (x, y) in st_length2D, and store the smallest z-coordinate of each stick in st_bottom2D,
32+
/// so that we can scan a much smaller area in step(2).
33+
/// known: nx, ny, nz, ggecut, GGT
34+
/// output: tot_npw, this->nstot, st_length2D, st_bottom2D
35+
///
3636
void PW_Basis::count_pw_st(
3737
int &tot_npw, // total number of planewaves.
3838
int* st_length2D, // the number of planewaves that belong to the stick located on (x, y).
@@ -96,14 +96,14 @@ void PW_Basis::count_pw_st(
9696
return;
9797
}
9898

99-
//
100-
// (5) Construct ig2isz, and is2ixy.
101-
// is2ixy contains the x-coordinate and y-coordinate of sticks on current core.
102-
// ig2isz contains the z-coordinate of planewaves on current core.
103-
// We will scan all the sticks and find the planewaves on them, then store the information into ig2isz and is2ixy.
104-
// known: this->nstot, st_bottom2D, st_length2D
105-
// output: ig2isz, is2ixy
106-
//
99+
///
100+
/// (5) Construct ig2isz, and is2ixy.
101+
/// is2ixy contains the x-coordinate and y-coordinate of sticks on current core.
102+
/// ig2isz contains the z-coordinate of planewaves on current core.
103+
/// We will scan all the sticks and find the planewaves on them, then store the information into ig2isz and is2ixy.
104+
/// known: this->nstot, st_bottom2D, st_length2D
105+
/// output: ig2isz, is2ixy
106+
///
107107
void PW_Basis::get_ig2isz_is2ixy(
108108
int* st_bottom2D, // minimum z of stick, stored in 1d array with this->nstot elements.
109109
int* st_length2D // the stick on (x, y) consists of st_length[x*ny+y] planewaves.

0 commit comments

Comments
 (0)