Skip to content

Commit a9f30fe

Browse files
committed
1. update annotations about distributeg_method1 and distributeg_method2.
2. correct the heapsort in collect_st in distributeg_method1.cpp. 3. delete the distributeg_method3.cpp. 4. update collect_local_pw in pw_basis.cpp.
1 parent 477a829 commit a9f30fe

File tree

6 files changed

+51
-617
lines changed

6 files changed

+51
-617
lines changed

source/module_pw/pw_basis.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ void PW_Basis::getstartgr()
9898

9999
//
100100
// Collect planewaves on current core, and construct gg, gdirect, gcar according to 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 the sticks on current core and find the planewaves on them, then store the information into corresponding arrays.
104101
// known: ig2isz, is2ixy
105102
// output: gg, gdirect, gcar
106103
//
@@ -114,34 +111,24 @@ void PW_Basis::collect_local_pw()
114111
this->gcar = new ModuleBase::Vector3<double>[this->npw];
115112

116113
ModuleBase::Vector3<double> f;
117-
int pw_filled = 0; // how many current core's planewaves have been found.
118-
for (int is = 0; is < this->nst; ++is)
114+
for(int ig = 0 ; ig < this-> npw ; ++ig)
119115
{
120-
int ix = this->is2ixy[is] / this->ny;
121-
int iy = this->is2ixy[is] % this->ny;
116+
int isz = this->ig2isz[ig];
117+
int iz = isz % this->nz;
118+
int is = isz / this->nz;
119+
int ixy = this->is2ixy[is];
120+
int ix = ixy / this->ny;
121+
int iy = ixy % this->ny;
122122
if (ix >= int(this->nx/2) + 1) ix -= this->nx;
123123
if (iy >= int(this->bigny/2) + 1) iy -= this->bigny;
124-
for (int ig = pw_filled; ig < this->npw; ++ig)
125-
{
126-
if (this->ig2isz[ig] < (is + 1) * this->nz) // meaning this pw belongs to is^th sticks.
127-
{
128-
int iz = this->ig2isz[ig] % this->nz;
129-
if (iz >= int(this->nz/2) + 1) iz -= this->nz;
130-
f.x = ix;
131-
f.y = iy;
132-
f.z = iz;
133-
this->gg[pw_filled] = f * (this->GGT * f);
134-
this->gdirect[pw_filled] = f;
135-
this->gcar[pw_filled] = f * this->G;
136-
pw_filled++;
137-
}
138-
else
139-
{
140-
break;
141-
}
142-
}
124+
if (iz >= int(this->nz/2) + 1) iz -= this->nz;
125+
f.x = ix;
126+
f.y = iy;
127+
f.z = iz;
128+
this->gg[ig] = f * (this->GGT * f);
129+
this->gdirect[ig] = f;
130+
this->gcar[ig] = f * this->G;
143131
}
144-
assert(pw_filled == this->npw);
145132
return;
146133
}
147134

source/module_pw/pw_basis.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class PW_Basis
6161
// on all proc.
6262
int *ig2isz; // map ig to (is, iz).
6363
int *istot2bigixy; // istot2bigixy[is]: iy + ix * bigny of is^th stick among all sticks.
64-
int *ixy2istot; //useless // ixy2istot[ix + iy * nx]: is of stick on (ix, iy) among all sticks.
65-
int *is2ixy; // is2ixy[is]: ix + iy * bignx of is^th stick among sticks on current proc.
66-
int *ixy2ip; // useless// ixy2ip[ix + iy * nx]: ip of proc which contains stick on (ix, iy).
64+
int *ixy2istot; //useless // ixy2istot[iy + ix * ny]: is of stick on (ix, iy) among all sticks.
65+
int *is2ixy; // is2ixy[is]: iy + ix * bigny of is^th stick among sticks on current proc.
66+
int *ixy2ip; // useless// ixy2ip[iy + ix * ny]: ip of proc which contains stick on (ix, iy).
6767
int nst; //num. of sticks in current proc.
6868
int nstnz; // nst * nz
6969
int nstot; //num. of sticks in total.
@@ -156,28 +156,6 @@ class PW_Basis
156156
int* st_length2D, // the number of planewaves that belong to the stick located on (x, y), stored in 2d x-y plane.
157157
int* npw_per // number of planewaves on each core.
158158
);
159-
// for distributeg_method3
160-
// void divide_sticks2(
161-
// const int tot_npw, // total number of planewaves.
162-
// int* st_i, // x or x + nx (if x < 0) of stick.
163-
// int* st_j, // y or y + ny (if y < 0) of stick.
164-
// int* st_length, // the stick on (x, y) consists of st_length[x*ny+y] planewaves.
165-
// int* npw_per, // number of planewaves on each core.
166-
// int* nst_per, // number of sticks on each core.
167-
// int* is2ip // ip of core containing is^th stick, map is to ip.
168-
// );
169-
// void get_istot2ixy2(
170-
// int* st_i, // x or x + nx (if x < 0) of stick.
171-
// int* st_j, // y or y + ny (if y < 0) of stick.
172-
// int* is2ip // ip of core containing is^th stick, map is to ip.
173-
// );
174-
// void get_ig2isz_is2ixy2(
175-
// int* st_i, // x or x + nx (if x < 0) of stick.
176-
// int* st_j, // y or y + ny (if y < 0) of stick.
177-
// int* st_bottom, // minimum z of stick, stored in 1d array with tot_nst elements.
178-
// int* st_length, // the stick on (x, y) consists of st_length[x*ny+y] planewaves.
179-
// int* is2ip // ip of core containing is^th stick, map is to ip.
180-
// );
181159

182160
//===============================================
183161
// FFT

source/module_pw/pw_distributeg.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ void PW_Basis::count_pw_st(
4141
{
4242
int ibox[3] = {0, 0, 0}; // an auxiliary vector, determine the boundary of the scanning area.
4343
ibox[0] = int(this->nx / 2) + 1; // scan x from -ibox[0] to ibox[0].
44-
ibox[1] = int(this->ny / 2) + 1; // scan y from -ibox[1] to ibox[1].
44+
ibox[1] = int(this->ny / 2) + 1; // scan y from -ibox[1] to ibox[1], if not gamma-only.
4545
ibox[2] = int(this->nz / 2) + 1; // scan z from -ibox[2] to ibox[2].
4646

4747
ModuleBase::Vector3<double> f;
4848

49-
int iy_start = -ibox[1]; // determine the scaning area along x-direct, if gamma-only, only positive axis is used.
49+
int iy_start = -ibox[1]; // determine the scaning area along y-direct, if gamma-only, only positive axis is used.
5050
int iy_end = ibox[1];
5151
if (this->gamma_only)
5252
{
@@ -69,7 +69,7 @@ void PW_Basis::count_pw_st(
6969
if (y < 0) y += this->ny;
7070
int index = x * this->ny + y;
7171

72-
int length = 0; // number of planewave in stick (x, y).
72+
int length = 0; // number of planewave on stick (x, y).
7373
for (int iz = -ibox[2]; iz <= ibox[2]; ++iz)
7474
{
7575
f.x = ix;
@@ -113,14 +113,14 @@ void PW_Basis::get_ig2isz_is2ixy(
113113
{
114114
this->ig2isz = new int[1]; // map ig to the z coordinate of this planewave.
115115
this->ig2isz[0] = 0;
116-
this->is2ixy = new int[1]; // map is (index of sticks) to ixy (ix + iy * nx).
116+
this->is2ixy = new int[1]; // map is (index of sticks) to ixy (iy + ix * ny).
117117
this->is2ixy[0] = -1;
118118
return;
119119
}
120120

121121
this->ig2isz = new int[this->npw]; // map ig to the z coordinate of this planewave.
122122
ModuleBase::GlobalFunc::ZEROS(this->ig2isz, this->npw);
123-
this->is2ixy = new int[this->nst]; // map is (index of sticks) to ixy (ix + iy * nx).
123+
this->is2ixy = new int[this->nst]; // map is (index of sticks) to ixy (iy + ix * ny).
124124
for (int is = 0; is < this->nst; ++is)
125125
{
126126
this->is2ixy[is] = -1;

source/module_pw/pw_distributeg_method1.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@
99
namespace ModulePW
1010
{
1111
//
12-
// Distribute planewaves in reciprocal space to coreors.
12+
// Distribute planewaves in reciprocal space to cores.
1313
// Firstly, divide the sphere in reciprocal space into sticks, which are vertical to x-y plane.
14+
// Secondly, distribute these sticks to coreors.
1415
//
1516
// Example
16-
// | ---- ixy increasing ---> | ---- ixy increasing ---> |...
17-
// index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1], ...
18-
// |___________________________|____________________________|___
17+
// | ---- ixy increasing ---> | ---- ixy increasing ---> |...
18+
// index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1]-1, ...
19+
// |___________________________|______________________________|___
1920
// ip 0 1 ...
2021
// npw approximate equal to npw approximate equal to...
2122
//
22-
// Secondly, distribute these sticks to coreors.
2323
//Known: G, GT, GGT, ny, nx, nz, poolnproc, poolrank, ggecut
2424
//output: ig2isz[ig], istot2bigixy[is], ixy2istot[nxy], is2ixy[is], ixy2ip[ixy], startnsz_per[ip], nst_per[ip], nst
2525
//
2626
void PW_Basis::distribution_method1()
2727
{
2828
ModuleBase::timer::tick("PW_Basis", "distributeg_method1");
2929

30-
// initial the variables needed by all proc.
30+
// initial the variables needed by all process
3131
int tot_npw = 0; // total number of planewaves.
3232
this->nstot = 0; // total number of sticks.
3333
int *st_bottom2D = NULL; // st_bottom2D[ixy], minimum z of stick on (x, y).
@@ -38,10 +38,10 @@ void PW_Basis::distribution_method1()
3838
// (1) Count the total number of planewaves (tot_npw) and sticks (this->nstot).
3939

4040
// Actually we will scan [(2 * ibox[0] + 1) * (2 * ibox[1] + 1)] points on x-y plane,
41-
// but we define st_length2D with (ny * nx) points here, because we assume that the diameter
42-
// of the sphere is shorter than the sides of the cube.
43-
st_length2D = new int[nxy]; // the number of planewaves that belong to the stick located on (x, y).
44-
st_bottom2D = new int[nxy]; // the z-coordinate of the bottom of stick on (x, y).
41+
// but we define st_length2D with (ny * nx) points here, because the diameter
42+
// of the sphere should be shorter than the sides of the cube.
43+
st_length2D = new int[nxy];
44+
st_bottom2D = new int[nxy];
4545
ModuleBase::GlobalFunc::ZEROS(st_length2D, this->nxy);
4646
ModuleBase::GlobalFunc::ZEROS(st_bottom2D, this->nxy);
4747

@@ -62,7 +62,7 @@ void PW_Basis::distribution_method1()
6262
#ifdef __MPI
6363
// Parallel line
6464

65-
// (2) Collect the x, y indexs, length, bottom of the sticks.
65+
// (2) Collect the x, y indexs, and length of the sticks.
6666
int* st_i = new int[this->nstot]; // x or x + nx (if x < 0) of stick.
6767
int* st_j = new int[this->nstot]; // y or y + ny (if y < 0) of stick.
6868
int* st_length = new int[this->nstot]; // number of planewaves in stick.
@@ -73,7 +73,7 @@ void PW_Basis::distribution_method1()
7373
// std::cout << "\nThe second step done\n";
7474
// ------------------------------------------------------------
7575

76-
// (3) Distribute sticks to cores.
76+
// (3) Distribute the sticks to cores.
7777
int *npw_per = new int[this->poolnproc]; // number of planewaves on each core.
7878
this->nstnz_per = new int[this->poolnproc]; // nz * nst(number of sticks) on each core.
7979
this->startnsz_per = new int[this->poolnproc];
@@ -82,7 +82,7 @@ void PW_Basis::distribution_method1()
8282
ModuleBase::GlobalFunc::ZEROS(this->nstnz_per, poolnproc);
8383
ModuleBase::GlobalFunc::ZEROS(startnsz_per, poolnproc);
8484

85-
this->ixy2ip = new int[this->nxy]; // ip of core which contains stick on (x, y).
85+
this->ixy2ip = new int[this->nxy]; // ip of core which contains the stick on (x, y).
8686
for (int ixy = 0; ixy < this->nxy; ++ixy)
8787
{
8888
this->ixy2ip[ixy] = -1; // meaning this stick has not been distributed or there is no stick on (x, y).
@@ -104,7 +104,7 @@ void PW_Basis::distribution_method1()
104104
// std::cout << "The 3-2 step done\n";
105105
// --------------------------------------------------------------------------------------
106106

107-
// (4) Send npw_per, nst[poolrank], st_* to all cores.
107+
// (4) Send npw_per[ip], nst_per[ip] to all cores.
108108
this->npw = npw_per[0];
109109
this->nst = nst_per[0];
110110

@@ -127,7 +127,7 @@ void PW_Basis::distribution_method1()
127127

128128
this->ixy2istot = new int[nxy];
129129
this->istot2bigixy = new int[this->nstot];
130-
this->ixy2ip = new int[nxy]; // ip of core which contains stick on (x, y).
130+
this->ixy2ip = new int[nxy];
131131
int st_move = 0;
132132
for (int ixy = 0; ixy < nxy; ++ixy)
133133
{
@@ -140,8 +140,8 @@ void PW_Basis::distribution_method1()
140140
}
141141
else
142142
{
143-
ixy2istot[ixy] = -1;
144-
ixy2ip[ixy] = -1;
143+
ixy2istot[ixy] = -1;
144+
ixy2ip[ixy] = -1;
145145
}
146146
}
147147
#endif
@@ -205,7 +205,7 @@ void PW_Basis::collect_st(
205205
int* st_bottom2D, // the z-coordinate of the bottom of stick on (x, y), stored in 2d x-y plane.
206206
int* st_i, // x or x + nx (if x < 0) of stick.
207207
int* st_j, // y or y + ny (if y < 0) of stick.
208-
int* st_length // number of planewaves in stick, stored in 1d array with this->nstot elements.
208+
int* st_length // number of planewaves in stick, stored in 1d array with this->nstot elements.
209209
)
210210
{
211211
int *temp_st_i = new int[this->nstot]; // x or x + nx (if x < 0) of stick.
@@ -215,7 +215,7 @@ void PW_Basis::collect_st(
215215

216216
int ibox[3] = {0, 0, 0}; // an auxiliary vector, determine the boundary of the scanning area.
217217
ibox[0] = int(this->nx / 2) + 1; // scan x from -ibox[0] to ibox[0].
218-
ibox[1] = int(this->ny / 2) + 1; // scan y from -ibox[1] to ibox[1].
218+
ibox[1] = int(this->ny / 2) + 1; // scan y from -ibox[1] to ibox[1], if not gamma-only.
219219
ibox[2] = int(this->nz / 2) + 1; // scan z from -ibox[2] to ibox[2].
220220

221221
ModuleBase::Vector3<double> f;
@@ -274,13 +274,15 @@ void PW_Basis::collect_st(
274274

275275
int *st_sorted_index = new int[this->nstot]; // indexs in the order of length increasing.
276276
st_sorted_index[0] = 0;
277-
ModuleBase::heapsort(this->nstot, temp_st_length, st_sorted_index); // sort st_* in the order of length decreasing.
277+
ModuleBase::heapsort(this->nstot, temp_st_length, st_sorted_index); // sort st_* in the order of length increasing.
278278

279+
int index = 0; // indexs in the order of length decreasing.
279280
for (int istot = 0; istot < this->nstot; ++istot)
280281
{
281-
st_length[istot] = static_cast<int>(temp_st_length[istot]);
282-
st_i[istot] = temp_st_i[st_sorted_index[istot]];
283-
st_j[istot] = temp_st_j[st_sorted_index[istot]];
282+
index = (this->nstot - 1) - istot;
283+
st_length[index] = static_cast<int>(temp_st_length[istot]);
284+
st_i[index] = temp_st_i[st_sorted_index[istot]];
285+
st_j[index] = temp_st_j[st_sorted_index[istot]];
284286
}
285287
// std::cout << "st_length ";
286288
// for (int is = 0; is < this->nstot; ++is) std::cout << st_length[is] << std::setw(4);
@@ -343,7 +345,7 @@ void PW_Basis::divide_sticks(
343345
// }
344346
}
345347
}
346-
nst_per[ipmin]++;
348+
this->nst_per[ipmin]++;
347349
this->nstnz_per[ipmin] += this->nz;
348350
npw_per[ipmin] += st_length[is];
349351
this->ixy2ip[st_i[is] * this->ny + st_j[is]] = ipmin;

source/module_pw/pw_distributeg_method2.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
namespace ModulePW
1010
{
1111
//
12-
// Distribute planewaves in reciprocal space to coreors.
12+
// Distribute planewaves in reciprocal space to cores.
1313
// Firstly, divide the sphere in reciprocal space into sticks, which are vertical to x-y plane.
1414
// Secondly, distribute these sticks to coreors.
1515
//
1616
// Example
1717
// ---- ixy increasing --->
18-
// index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1], ...
19-
// |___________________________|____________________________|___
18+
// index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1]-1, ...
19+
// |___________________________|______________________________|___
2020
// ip 0 1 ...
2121
//
2222
//Known: G, GT, GGT, ny, nx, nz, poolnproc, poolrank, ggecut
@@ -29,7 +29,6 @@ void PW_Basis::distribution_method2()
2929
// initial the variables needed by all proc.
3030
int tot_npw = 0; // total number of planewaves.
3131
this->nstot = 0; // total number of sticks.
32-
// int st_start = 0; // index of the first stick on current proc.
3332
int *st_bottom2D = NULL; // st_bottom2D[ixy], minimum z of stick on (x, y).
3433
int *st_length2D = NULL; // st_length2D[ixy], number of planewaves in stick on (x, y).
3534

0 commit comments

Comments
 (0)