From 050a2c441a680eb9d418a416671ddd122bee3d6a Mon Sep 17 00:00:00 2001 From: yang2022i <113529914+yang2022i@users.noreply.github.com> Date: Sun, 2 Jun 2024 09:58:06 +0800 Subject: [PATCH] Remove redundant function and modify comments in the PW module (#4271) --- source/module_basis/module_pw/pw_basis.h | 30 ++--- .../module_basis/module_pw/pw_distributeg.cpp | 56 ++++---- .../module_pw/pw_distributeg_method1.cpp | 125 ++++++++++-------- .../module_pw/pw_distributeg_method2.cpp | 82 ++++++------ .../module_basis/module_pw/pw_distributer.cpp | 14 +- 5 files changed, 169 insertions(+), 138 deletions(-) diff --git a/source/module_basis/module_pw/pw_basis.h b/source/module_basis/module_pw/pw_basis.h index a9e6cbc66a..6f95343b1a 100644 --- a/source/module_basis/module_pw/pw_basis.h +++ b/source/module_basis/module_pw/pw_basis.h @@ -15,9 +15,9 @@ namespace ModulePW { /** - * @brief A class which can convert a function of "r" to the corresponding linear + * @brief A class which can convert a function of "r" to the corresponding linear * superposition of plane waves (real space to reciprocal space) - * or convert a linear superposition of plane waves to the function + * or convert a linear superposition of plane waves to the function * of "r" (reciprocal to real). * @author qianrui, Sunliang on 2021-10-15 * @details @@ -25,13 +25,13 @@ namespace ModulePW * plane waves: =1/sqrt(V) * exp(igr) * f(r) = 1/sqrt(V) * \sum_g{c(g)*exp(igr)} * c(g) = \int f(r)*exp(-igr) dr - * USAGE: + * USAGE: * ModulePW::PW_Basis pwtest; * 0. init mpi for PW_Basis * pwtest.inimpi(nproc_in_pool,rank_in_pool,POOL_WORLD); * 1. setup FFT grids for PW_Basis * pwtest.initgrids(lat0,latvec,gridecut); - * pwtest.initgrids(lat0,latvec,N1,N2,N3); + * pwtest.initgrids(lat0,latvec,N1,N2,N3); * //double lat0: unit length, (unit: bohr) * //ModuleBase::Matrix3 latvec: lattice vector, (unit: lat0), e.g. ModuleBase::Matrix3 latvec(1, 1, 0, 0, 2, 0, 0, 0, 2); * //double gridecut: cutoff energy to generate FFT grids, (unit: Ry) @@ -42,13 +42,13 @@ namespace ModulePW * //double ggecut: cutoff kinetic energy for planewaves,(unit in Ry) G^2 < ggecut * //int dividemthd: method to divide planewaves to different cores * 3. Setup transforms from real space to reciprocal space or from reciprocal space to real space. - * pwtest.setuptransform(); + * pwtest.setuptransform(); * pwtest.recip2real(rhog,rhor); //rhog to rhor * pwtest.real2recip(rhor,rhog); //rhor to rhog * 4. Generate the wave vector for planewaves - * pwtest.collect_local_pw(); + * pwtest.collect_local_pw(); * //then we can use pwtest.gg, pwtest.gdirect, pwtest.gcar, (unit in lat0^-1 or lat0^-2) - * + * */ class PW_Basis { @@ -70,7 +70,7 @@ class PW_Basis //Init the grids for FFT virtual void initgrids( const double lat0_in, //unit length (unit in bohr) - const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors (unit in lat0) + const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors (unit in lat0) const double gridecut //unit in Ry, ecut to set up grids ); //Init the grids for FFT @@ -100,7 +100,7 @@ class PW_Basis #ifdef __MPI MPI_Comm pool_world; #endif - + int *ig2isz=nullptr; // map ig to (is, iz). int *istot2ixy=nullptr; // istot2ixy[is]: iy + ix * ny of is^th stick among all sticks. int *is2fftixy=nullptr, * d_is2fftixy = nullptr; // is2fftixy[is]: iy + ix * ny of is^th stick among sticks on current proc. @@ -115,9 +115,9 @@ class PW_Basis //real space int nrxx=0; //num. of real space grids - int *startz=nullptr; //startz[ip]: starting z plane in the ip-th proc. in current POOL_WORLD + int *startz=nullptr; //startz[ip]: starting z plane in the ip-th proc. in current POOL_WORLD int *numz=nullptr; //numz[ip]: num. of z planes in the ip-th proc. in current POOL_WORLD - int *numg=nullptr; //numg[ip] : nst_per[poolrank] * numz[ip] + int *numg=nullptr; //numg[ip] : nst_per[poolrank] * numz[ip] int *numr=nullptr; //numr[ip] : numz[poolrank] * nst_per[ip] int *startg=nullptr; // startg[ip] = numg[ip-1] + startg[ip-1] int *startr=nullptr; // startr[ip] = numr[ip-1] + startr[ip-1] @@ -157,7 +157,7 @@ class PW_Basis double *gg_uniq=nullptr; //[ngg] modulus (G^2) of G vectors of igg, each gg of igg is unique. //collect gg_uniq void collect_uniqgg(); - + public: bool gamma_only = false; ///< only half g are used. @@ -182,7 +182,7 @@ class PW_Basis protected: //distribute plane waves to different processors //method 1: first consider number of plane waves - void distribution_method1(); + void distribution_method1(); // Distribute sticks to cores in method 1. void divide_sticks_1( int* st_i, // x or x + fftnx (if x < 0) of stick. @@ -194,7 +194,7 @@ class PW_Basis void distribution_method2(); // Distribute sticks to cores in method 2. void divide_sticks_2(); - + //Count the total number of planewaves (tot_npw) and sticks (this->nstot) (in distributeg method1 and method2) void count_pw_st( int* st_length2D, // the number of planewaves that belong to the stick located on (x, y). @@ -295,4 +295,4 @@ class PW_Basis #endif // PWBASIS_H #include "pw_basis_sup.h" -#include "pw_basis_big.h" //temporary it will be removed \ No newline at end of file +#include "pw_basis_big.h" //temporary it will be removed diff --git a/source/module_basis/module_pw/pw_distributeg.cpp b/source/module_basis/module_pw/pw_distributeg.cpp index f72d4910b5..92b9e2fe3b 100644 --- a/source/module_basis/module_pw/pw_distributeg.cpp +++ b/source/module_basis/module_pw/pw_distributeg.cpp @@ -5,11 +5,11 @@ namespace ModulePW { -/// -/// distribute plane waves to different cores -/// Known: G, GT, GGT, fftnx, fftny, nz, poolnproc, poolrank, ggecut -/// output: ig2isz[ig], istot2ixy[is], is2fftixy[is], fftixy2ip[ixy], gg[ig], gcar[ig], gdirect[ig], nst, nstot -/// +/** + * @brief distribute plane waves to different cores + * @param in: G, GT, GGT, fftnx, fftny, nz, poolnproc, poolrank, ggecut + * @param out: ig2isz[ig], istot2ixy[is], is2fftixy[is], fftixy2ip[ixy], gg[ig], gcar[ig], gdirect[ig], nst, nstot + */ void PW_Basis::distribute_g() { ModuleBase::timer::tick(this->classname, "distributeg"); @@ -30,13 +30,16 @@ void PW_Basis::distribute_g() return; } -/// -/// (1) We count the total number of planewaves (tot_npw) and sticks (this->nstot) here. -/// 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, -/// so that we can scan a much smaller area in step(2). -/// known: fftnx, fftny, nz, ggecut, GGT -/// output: tot_npw, this->nstot, st_length2D, st_bottom2D, this->riy, this->liy -/// +/** + * @brief (1) We count the total number of planewaves (tot_npw) and sticks (this->nstot) here. + * + * 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, + * so that we can scan a much smaller area in step(2). + * + * @param in: fftnx, fftny, nz, ggecut, GGT + * @param out: tot_npw, this->nstot, st_length2D, st_bottom2D, this->riy, this->liy + */ + void PW_Basis::count_pw_st( int* st_length2D, // the number of planewaves that belong to the stick located on (x, y). int* st_bottom2D // the z-coordinate of the bottom of stick on (x, y). @@ -48,10 +51,10 @@ void PW_Basis::count_pw_st( // determine the scaning area along x-direct, if gamma-only && xprime, only positive axis is used. int ix_end = int(this->nx / 2) + 1; - int ix_start = -ix_end; + int ix_start = -ix_end; // determine the scaning area along y-direct, if gamma-only && !xprime, only positive axis is used. int iy_end = int(this->ny / 2) + 1; - int iy_start = -iy_end; + int iy_start = -iy_end; int iz_end = int(this->nz / 2) + 1; int iz_start = -iz_end; @@ -59,10 +62,10 @@ void PW_Basis::count_pw_st( if (this->full_pw) { ix_end = int(this->nx / 2); - ix_start = ix_end - this->nx + 1; + ix_start = ix_end - this->nx + 1; iy_end = int(this->ny / 2); - iy_start = iy_end - this->ny + 1; + iy_start = iy_end - this->ny + 1; iz_end = int(this->nz / 2); iz_start = iz_end - this->nz + 1; @@ -131,14 +134,17 @@ void PW_Basis::count_pw_st( return; } -/// -/// (5) Construct ig2isz, and is2fftixy. -/// is2fftixy contains the x-coordinate and y-coordinate of sticks on current core. -/// ig2isz contains the z-coordinate of planewaves on current core. -/// We will scan all the sticks and find the planewaves on them, then store the information into ig2isz and is2fftixy. -/// known: this->nstot, st_bottom2D, st_length2D -/// output: ig2isz, is2fftixy -/// +/** + * @brief (5) Construct ig2isz, and is2fftixy. + * + * is2fftixy contains the x-coordinate and y-coordinate of sticks on current core. + * ig2isz contains the z-coordinate of planewaves on current core. + * We will scan all the sticks and find the planewaves on them, then store the information into ig2isz and is2fftixy. + * + * @param in: this->nstot, st_bottom2D, st_length2D + * @param out: ig2isz, is2fftixy + */ + void PW_Basis::get_ig2isz_is2fftixy( int* st_bottom2D, // minimum z of stick, stored in 1d array with this->nstot elements. int* st_length2D // the stick on (x, y) consists of st_length[x*fftny+y] planewaves. @@ -160,7 +166,7 @@ void PW_Basis::get_ig2isz_is2fftixy( delete[] this->ig2isz; this->ig2isz = new int[this->npw]; // map ig to the z coordinate of this planewave. ModuleBase::GlobalFunc::ZEROS(this->ig2isz, this->npw); delete[] this->is2fftixy; this->is2fftixy = new int[this->nst]; // map is (index of sticks) to ixy (iy + ix * fftny). - for (int is = 0; is < this->nst; ++is) + for (int is = 0; is < this->nst; ++is) { this->is2fftixy[is] = -1; } diff --git a/source/module_basis/module_pw/pw_distributeg_method1.cpp b/source/module_basis/module_pw/pw_distributeg_method1.cpp index 254d934d98..fe95b3556b 100644 --- a/source/module_basis/module_pw/pw_distributeg_method1.cpp +++ b/source/module_basis/module_pw/pw_distributeg_method1.cpp @@ -5,21 +5,23 @@ namespace ModulePW { -/// -/// Distribute planewaves in reciprocal space to cores. -/// Firstly, divide the sphere in reciprocal space into sticks, which are vertical to x-y plane. -/// Secondly, distribute these sticks to coreors. -/// -/// Example -/// | ---- ixy increasing ---> | ---- ixy increasing ---> |... -/// index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1]-1, ... -/// |___________________________|______________________________|___ -/// ip 0 1 ... -/// npw approximate equal to npw approximate equal to... -/// -/// Known: G, GT, GGT, fftny, fftnx, nz, poolnproc, poolrank, ggecut -/// output: ig2isz[ig], istot2ixy[is], is2fftixy[is], fftixy2ip[ixy], startnsz_per[ip], nst_per[ip], nst -/// +/** + * @brief Distribute planewaves in reciprocal space to cores + * + * Firstly, divide the sphere in reciprocal space into sticks, which are vertical to x-y plane. + * Secondly, distribute these sticks to coreors. + * + * @example + * | ---- ixy increasing ---> | ---- ixy increasing ---> |... + * index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1]-1, ... + * |___________________________|______________________________|___ + * ip 0 1 ... + * npw approximate equal to npw approximate equal to... + * + * @param in: G, GT, GGT, fftny, fftnx, nz, poolnproc, poolrank, ggecut + * @param out: ig2isz[ig], istot2ixy[is], is2fftixy[is], fftixy2ip[ixy], startnsz_per[ip], nst_per[ip], nst + */ + void PW_Basis::distribution_method1() { // initial the variables needed by all process @@ -32,13 +34,17 @@ void PW_Basis::distribution_method1() this->fftixy2ip[ixy] = -1; // meaning this stick has not been distributed or there is no stick on (x, y). if (poolrank == 0) { - // (1) Count the total number of planewaves (tot_npw) and sticks (this->nstot). - - // Actually we will scan [(2 * ibox[0] + 1) * (2 * ibox[1] + 1)] points on x-y plane, - // but we define st_length2D with (fftny * fftnx) points here, because the diameter - // of the sphere should be shorter than the sides of the cube. - // calculate this->nstot and this->npwtot, liy, riy - this->count_pw_st(st_length2D, st_bottom2D); + /** + * @brief (1) Count the total number of planewaves (tot_npw) and sticks (this->nstot). + * + * @note the funcion here is defined in pw_distributeg.cpp + * Actually we will scan [(2 * ibox[0] + 1) * (2 * ibox[1] + 1)] points on x-y plane, + * but we define st_length2D with (fftny * fftnx) points here, because the diameter + * of the sphere should be shorter than the sides of the cube. + * calculate this->nstot and this->npwtot, liy, riy + */ + + this->count_pw_st(st_length2D, st_bottom2D); } #ifdef __MPI MPI_Bcast(&this->npwtot, 1, MPI_INT, 0, this->pool_world); @@ -57,7 +63,7 @@ void PW_Basis::distribution_method1() // (2) Collect the x, y indexs, and length of the sticks. int* st_i = new int[this->nstot]; // x or x + fftnx (if x < 0) of stick. int* st_j = new int[this->nstot]; // y or y + fftny (if y < 0) of stick. - int* st_length = new int[this->nstot]; // number of planewaves in stick. + int* st_length = new int[this->nstot]; // number of planewaves in stick. this->collect_st(st_length2D, st_bottom2D, st_i, st_j, st_length); // (3) Distribute the sticks to cores. @@ -103,7 +109,7 @@ void PW_Basis::distribution_method1() this->nst = this->nst_per[this->poolrank]; this->nstnz = this->nst * this->nz; - // (5) Construct ig2isz and is2fftixy. + // (5) Construct ig2isz and is2fftixy. this->get_ig2isz_is2fftixy(st_bottom2D, st_length2D); delete[] st_bottom2D; @@ -111,14 +117,17 @@ void PW_Basis::distribution_method1() return; } -/// -/// (2) Collect the x, y indexs, length of the sticks. -/// Firstly, we scan the area and construct temp_st_*. -/// Then, as we will distribute the longest sticks preferentially in Step(3), -/// we will sort temp_st_length from largest to smallest, and reaarange st_* to the same order. -/// known: tot_npw, this->nstot, st_length2D, st_bottom2D -/// output: st_i, st_j, st_length -/// +/** + * @brief (2) Collect the x, y indexs, length of the sticks. + * + * Firstly, we scan the area and construct temp_st_*. + * Then, as we will distribute the longest sticks preferentially in Step(3), + * we will sort temp_st_length from largest to smallest, and reaarange st_* to the same order. + * + * @param in: tot_npw, this->nstot, st_length2D, st_bottom2D + * @param out: st_i, st_j, st_length + */ + void PW_Basis::collect_st( int* st_length2D, // the number of planewaves that belong to the stick located on (x, y), stored in 2d x-y plane. int* st_bottom2D, // the z-coordinate of the bottom of stick on (x, y), stored in 2d x-y plane. @@ -136,15 +145,15 @@ void PW_Basis::collect_st( int is = 0; // index of stick. int ix_end = int(this->nx / 2) + 1; - int ix_start = -ix_end; + int ix_start = -ix_end; int iy_end = int(this->ny / 2) + 1; - int iy_start = -iy_end; + int iy_start = -iy_end; if (this->full_pw) { ix_end = int(this->nx / 2); - ix_start = ix_end - this->nx + 1; + ix_start = ix_end - this->nx + 1; iy_end = int(this->ny / 2); - iy_start = iy_end - this->ny + 1; + iy_start = iy_end - this->ny + 1; } if (this->gamma_only) @@ -165,6 +174,7 @@ void PW_Basis::collect_st( { for (int iy = iy_start; iy <= iy_end; ++iy) { + // we have shifted all sticks to the first quadrant in x-y plane before. // (ix, iy, iz) is the direct coordinates of planewaves. // x and y is the coordinates of shifted sticks in x-y plane. @@ -197,14 +207,14 @@ void PW_Basis::collect_st( { find_stick = true; } - + if (find_stick) { temp_st_i[is] = x; temp_st_j[is] = y; temp_st_length[is] = static_cast(st_length2D[index]); ++is; - } + } } } } @@ -236,14 +246,18 @@ void PW_Basis::collect_st( return; } -/// -/// (3-1) Distribute sticks to cores according to the number of plane waves. -/// We have rearranged sticks in the order of length decreasing, so that we will distribute the longest stick preferentially here. -/// For each stick, we find the core that contains the least planewaves firstly, and distribute the stick to it, -/// then update npw_per, this->fftixy2ip, and this->startnsz_per. -/// known: tot_npw, this->nstot, st_i, st_j, st_length -/// output: npw_per, nst_per, this->fftixy2ip, this->startnsz_per -/// + +/** + * @brief (3-1) Distribute sticks to cores according to the number of plane waves. + * + * We have rearranged sticks in the order of length decreasing, so that we will distribute the longest stick preferentially here. + * For each stick, we find the core that contains the least planewaves firstly, and distribute the stick to it, + * then update npw_per, this->fftixy2ip, and this->startnsz_per. + * + * @param in: tot_npw, this->nstot, st_i, st_j, st_length + * @param out: npw_per, nst_per, this->fftixy2ip, this->startnsz_per + */ + void PW_Basis::divide_sticks_1( int* st_i, // x or x + fftnx (if x < 0) of stick. int* st_j, // y or y + fftny (if y < 0) of stick. @@ -290,13 +304,16 @@ void PW_Basis::divide_sticks_1( return; } -/// -/// (3-2) Rearrange sticks in the order of the ip of core increasing, in each core, sticks are sorted in the order of ixy increasing. -/// (st_start + st_move) is the new index of sticks. -/// Then get istot2ixy (istot2ixy[is]: iy + ix * fftny of is^th stick among all sticks) on the first core -/// known: this->nstot, st_i, st_j, this->startnsz_per -/// output: istot2ixy -/// +/** + * @brief (3-2) Rearrange sticks in the order of the ip of core increasing, in each core, sticks are sorted in the order of ixy increasing. + * + * (st_start + st_move) is the new index of sticks. + * Then get istot2ixy (istot2ixy[is]: iy + ix * fftny of is^th stick among all sticks) on the first core + * + * @param in: this->nstot, st_i, st_j, this->startnsz_per + * @param out: istot2ixy + */ + void PW_Basis::get_istot2ixy( int* st_i, // x or x + fftnx (if x < 0) of stick. int* st_j // y or y + fftny (if y < 0) of stick. @@ -311,7 +328,7 @@ void PW_Basis::get_istot2ixy( { int ip = this->fftixy2ip[ixy]; if (ip != -1) - { + { this->istot2ixy[this->startnsz_per[ip] / this->nz + st_move[ip]] = (ixy / fftny)*ny + ixy % fftny; st_move[ip]++; } diff --git a/source/module_basis/module_pw/pw_distributeg_method2.cpp b/source/module_basis/module_pw/pw_distributeg_method2.cpp index 675858fc1f..9ba6e0aacc 100644 --- a/source/module_basis/module_pw/pw_distributeg_method2.cpp +++ b/source/module_basis/module_pw/pw_distributeg_method2.cpp @@ -5,20 +5,23 @@ namespace ModulePW { -/// -/// Distribute planewaves in reciprocal space to cores. -/// Firstly, divide the sphere in reciprocal space into sticks, which are vertical to x-y plane. -/// Secondly, distribute these sticks to coreors. -/// -/// Example -/// ---- ixy increasing ---> -/// index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1]-1, ... -/// |___________________________|______________________________|___ -/// ip 0 1 ... -/// nst_per[i] approxiamte equal to nst_per[j] -/// Known: G, GT, GGT, fftny, fftnx, nz, poolnproc, poolrank, ggecut -/// output: ig2isz[ig], istot2ixy[is], is2fftixy[is], fftixy2ip[ixy], startnsz_per[ip], nst_per[ip], nst -/// +/** + * @brief Distribute planewaves in reciprocal space to cores + * + * Firstly, divide the sphere in reciprocal space into sticks, which are vertical to x-y plane. + * Secondly, distribute these sticks to coreors. + * + * @example + * | ---- ixy increasing ---> | ---- ixy increasing ---> |... + * index of sticks 0, 1, 2, ..., nst_per[0]-1, nst_per[0], ..., nst_per[1]-1, ... + * |___________________________|______________________________|___ + * ip 0 1 ... + * npw approximate equal to npw approximate equal to... + * + * @param in: G, GT, GGT, fftny, fftnx, nz, poolnproc, poolrank, ggecut + * @param out: ig2isz[ig], istot2ixy[is], is2fftixy[is], fftixy2ip[ixy], startnsz_per[ip], nst_per[ip], nst + */ + void PW_Basis::distribution_method2() { @@ -32,12 +35,15 @@ void PW_Basis::distribution_method2() this->fftixy2ip[ixy] = -1; // meaning this stick has not been distributed or there is no stick on (x, y). if (poolrank == 0) { - // (1) Count the total number of planewaves (tot_npw) and sticks (this->nstot). - - // Actually we will scan [(2 * ibox[0] + 1) * (2 * ibox[1] + 1)] points on x-y plane, - // but we define st_length2D with (fftny * fftnx) points here, because we assume that the diameter - // of the sphere is shorter than the sides of the cube. - // calculate this->nstot and this->npwtot, liy, riy + /** + * @brief (1) Count the total number of planewaves (tot_npw) and sticks (this->nstot). + * + * @note the funcion here is defined in pw_distributeg.cpp + * Actually we will scan [(2 * ibox[0] + 1) * (2 * ibox[1] + 1)] points on x-y plane, + * but we define st_length2D with (fftny * fftnx) points here, because the diameter + * of the sphere should be shorter than the sides of the cube. + * calculate this->nstot and this->npwtot, liy, riy + */ this->count_pw_st(st_length2D, st_bottom2D); } #ifdef __MPI @@ -94,7 +100,7 @@ void PW_Basis::distribution_method2() this->nst = this->nst_per[this->poolrank]; this->nstnz = this->nst * this->nz; - // (5) Construct ig2isz and is2fftixy. + // (5) Construct ig2isz and is2fftixy. this->get_ig2isz_is2fftixy(st_bottom2D, st_length2D); delete[] st_bottom2D; @@ -102,33 +108,35 @@ void PW_Basis::distribution_method2() return; } -/// -/// (2) Devide the sticks to each core according to the number of sticks -/// Sticks are in the order of ixy increasing. -/// known: this->nstot, this->poolnproc -/// output: nst_per, this->startnsz_per -/// +/** + * @brief (2) Devide the sticks to each core according to the number of sticks + * Sticks are in the order of ixy increasing. + * @param in: this->nstot, this->poolnproc + * @param out: nst_per, this->startnsz_per + */ + void PW_Basis::divide_sticks_2() { ModuleBase::GlobalFunc::ZEROS(nst_per, this->poolnproc); - + int average_nst = this->nstot / this->poolnproc; int mods = this->nstot % this->poolnproc; - + this->startnsz_per[0] = 0; for (int ip = 0; ip < this->poolnproc; ++ip) { nst_per[ip] = average_nst; if (ip < mods) nst_per[ip]++; - if (ip >= 1) this->startnsz_per[ip] = this->startnsz_per[ip-1] + this->nst_per[ip-1] * this->nz; + if (ip >= 1) this->startnsz_per[ip] = this->startnsz_per[ip-1] + this->nst_per[ip-1] * this->nz; } } -// -// (3) Create the maps from ixy to ip, istot, and from istot to ixy, and construt npw_per simultaneously. -// known: st_length2D -// output: this->fftixy2ip, this->istot2ixy, npw_per -// +/** + * @brief (3) Create the maps from ixy to ip, istot, and from istot to ixy, and construt npw_per simultaneously. + * @param in: st_length2D + * @param out: this->fftixy2ip, this->istot2ixy, npw_per + */ + void PW_Basis::create_maps( int* st_length2D // the number of planewaves that belong to the stick located on (x, y), stored in 2d x-y plane. ) @@ -148,9 +156,9 @@ void PW_Basis::create_maps( if (ip < this->poolnproc - 1) { // all of sticks on current core are found, skip to next core - if (st_move * this->nz >= this->startnsz_per[ip + 1]) ip++; + if (st_move * this->nz >= this->startnsz_per[ip + 1]) ip++; } } } } -} \ No newline at end of file +} diff --git a/source/module_basis/module_pw/pw_distributer.cpp b/source/module_basis/module_pw/pw_distributer.cpp index cb83f9455c..b4a577c12b 100644 --- a/source/module_basis/module_pw/pw_distributer.cpp +++ b/source/module_basis/module_pw/pw_distributer.cpp @@ -3,11 +3,11 @@ namespace ModulePW { -/// -/// distribute real-space grids to different processors -/// Known: nx, ny, nz, poolnproc, poolrank -/// output: nrxx, startz, numz -/// +/** + * @brief distribute real-space grids to different processors + * @param in: nx, ny, nz, poolnproc, poolrank + * @param out: nrxx, startz, numz + */ void PW_Basis::distribute_r() { delete[] this->numz; this->numz = new int[this->poolnproc]; @@ -23,7 +23,7 @@ void PW_Basis::distribute_r() this->numz[ip] = npz; if(ip < modz) this->numz[ip]++; if(ip < this->poolnproc - 1) this->startz[ip+1] = this->startz[ip] + numz[ip]; - if(ip == this->poolrank) + if(ip == this->poolrank) { this->nplane = numz[ip]; this->startz_current = startz[ip]; @@ -33,4 +33,4 @@ void PW_Basis::distribute_r() return; } -} \ No newline at end of file +}