99namespace 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//
2626void 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;
0 commit comments