Skip to content

Commit 1fb385c

Browse files
committed
make Pgrid a serial-or-parallel grid class
1 parent 712376b commit 1fb385c

File tree

19 files changed

+84
-93
lines changed

19 files changed

+84
-93
lines changed

source/module_elecstate/module_charge/charge_init.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
5353
{
5454
std::stringstream ssc;
5555
ssc << PARAM.globalv.global_readin_dir << "SPIN" << is + 1 << "_CHG.cube";
56-
if (ModuleIO::read_cube(
57-
#ifdef __MPI
58-
& (GlobalC::Pgrid),
59-
#endif
56+
if (ModuleIO::read_cube(GlobalC::Pgrid,
6057
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
6158
GlobalV::ofs_running,
6259
ssc.str(),
@@ -109,10 +106,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout,
109106
GlobalV::ofs_running << " try to read kinetic energy density from file : " << ssc.str()
110107
<< std::endl;
111108
// mohan update 2012-02-10, sunliang update 2023-03-09
112-
if (ModuleIO::read_cube(
113-
#ifdef __MPI
114-
& (GlobalC::Pgrid),
115-
#endif
109+
if (ModuleIO::read_cube(GlobalC::Pgrid,
116110
(PARAM.inp.esolver_type == "sdft" ? GlobalV::RANK_IN_STOGROUP : GlobalV::MY_RANK),
117111
GlobalV::ofs_running,
118112
ssc.str(),

source/module_esolver/esolver_fp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void ESolver_FP::after_scf(const int istep)
155155
this->pw_rhod->real2recip(this->pelec->charge->rho_save[is], this->pelec->charge->rhog_save[is]);
156156
}
157157
std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube";
158-
ModuleIO::write_cube(
158+
ModuleIO::write_cube(GlobalC::Pgrid,
159159
data,
160160
is,
161161
PARAM.inp.nspin,
@@ -171,7 +171,7 @@ void ESolver_FP::after_scf(const int istep)
171171
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
172172
{
173173
fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_TAU.cube";
174-
ModuleIO::write_cube(
174+
ModuleIO::write_cube(GlobalC::Pgrid,
175175
this->pelec->charge->kin_r_save[is],
176176
is,
177177
PARAM.inp.nspin,
@@ -211,7 +211,7 @@ void ESolver_FP::after_scf(const int istep)
211211
{
212212
std::string fn =PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube";
213213

214-
ModuleIO::write_cube(
214+
ModuleIO::write_cube(GlobalC::Pgrid,
215215
this->pelec->pot->get_effective_v(is),
216216
is,
217217
PARAM.inp.nspin,

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
10291029
data = this->pelec->charge->rho_save[is];
10301030
}
10311031
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
1032-
ModuleIO::write_cube(
1032+
ModuleIO::write_cube(GlobalC::Pgrid,
10331033
data,
10341034
is,
10351035
PARAM.inp.nspin,
@@ -1045,7 +1045,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(int& iter)
10451045
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
10461046
{
10471047
fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
1048-
ModuleIO::write_cube(
1048+
ModuleIO::write_cube(GlobalC::Pgrid,
10491049
this->pelec->charge->kin_r_save[is],
10501050
is,
10511051
PARAM.inp.nspin,

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void ESolver_KS_PW<T, Device>::before_scf(const int istep)
239239
{
240240
std::stringstream ss;
241241
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube";
242-
ModuleIO::write_cube(
242+
ModuleIO::write_cube(GlobalC::Pgrid,
243243
this->pelec->charge->rho[is],
244244
is,
245245
PARAM.inp.nspin,
@@ -260,7 +260,7 @@ void ESolver_KS_PW<T, Device>::before_scf(const int istep)
260260
{
261261
std::stringstream ss;
262262
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_POT_INI.cube";
263-
ModuleIO::write_cube(
263+
ModuleIO::write_cube(GlobalC::Pgrid,
264264
this->pelec->pot->get_effective_v(is),
265265
is,
266266
PARAM.inp.nspin,
@@ -468,7 +468,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(int& iter)
468468
data = this->pelec->charge->rho_save[is];
469469
}
470470
std::string fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_CHG.cube";
471-
ModuleIO::write_cube(
471+
ModuleIO::write_cube(GlobalC::Pgrid,
472472
data,
473473
is,
474474
PARAM.inp.nspin,
@@ -484,7 +484,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(int& iter)
484484
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
485485
{
486486
fn = PARAM.globalv.global_out_dir + "/tmp_SPIN" + std::to_string(is + 1) + "_TAU.cube";
487-
ModuleIO::write_cube(
487+
ModuleIO::write_cube(GlobalC::Pgrid,
488488
this->pelec->charge->kin_r_save[is],
489489
is,
490490
PARAM.inp.nspin,

source/module_esolver/lcao_before_scf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
227227
{
228228
std::stringstream ss;
229229
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_CHG_INI.cube";
230-
ModuleIO::write_cube(
230+
ModuleIO::write_cube(GlobalC::Pgrid,
231231
this->pelec->charge->rho[is],
232232
is,
233233
PARAM.inp.nspin,
@@ -248,7 +248,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
248248
{
249249
std::stringstream ss;
250250
ss << PARAM.globalv.global_out_dir << "SPIN" << is + 1 << "_POT_INI.cube";
251-
ModuleIO::write_cube(
251+
ModuleIO::write_cube(GlobalC::Pgrid,
252252
this->pelec->pot->get_effective_v(is),
253253
is,
254254
PARAM.inp.nspin,
@@ -297,7 +297,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
297297
for (int is = 0; is < nspin0; is++)
298298
{
299299
std::string fn = PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_CHG.cube";
300-
ModuleIO::write_cube(
300+
ModuleIO::write_cube(GlobalC::Pgrid,
301301
this->pelec->charge->rho[is],
302302
is,
303303
PARAM.inp.nspin,

source/module_esolver/lcao_nscf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void ESolver_KS_LCAO<TK, TR>::nscf() {
196196
{
197197
std::string fn = PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube";
198198

199-
ModuleIO::write_cube(
199+
ModuleIO::write_cube(GlobalC::Pgrid,
200200
this->pelec->pot->get_effective_v(is),
201201
is,
202202
PARAM.inp.nspin,

source/module_esolver/pw_nscf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void ESolver_KS_PW<T, Device>::nscf() {
165165
{
166166
std::string fn = PARAM.globalv.global_out_dir + "/SPIN" + std::to_string(is + 1) + "_POT.cube";
167167

168-
ModuleIO::write_cube(
168+
ModuleIO::write_cube(GlobalC::Pgrid,
169169
this->pelec->pot->get_effective_v(is),
170170
is,
171171
PARAM.inp.nspin,

source/module_hamilt_pw/hamilt_pwdft/parallel_grid.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ void Parallel_Grid::init(
3535
const int &bz_in)
3636
{
3737

38-
#ifndef __MPI
39-
return;
40-
#endif
41-
4238
ModuleBase::TITLE("Parallel_Grid","init");
4339

4440
this->ncx = ncx_in;
@@ -47,7 +43,7 @@ void Parallel_Grid::init(
4743
this->nczp = nczp_in;
4844
this->nrxx = nrxx_in;
4945
this->nbz = nbz_in;
50-
this->bz = bz_in;
46+
this->bz = bz_in;
5147

5248
if(nczp<0)
5349
{
@@ -60,7 +56,11 @@ void Parallel_Grid::init(
6056
assert(ncz > 0);
6157

6258
this->ncxy = ncx * ncy;
63-
this->ncxyz = ncxy * ncz;
59+
this->ncxyz = ncxy * ncz;
60+
61+
#ifndef __MPI
62+
return;
63+
#endif
6464

6565
// enable to call this function again liuyu 2023-03-10
6666
if(this->allocate)
@@ -323,7 +323,7 @@ void Parallel_Grid::zpiece_to_stogroup(double *zpiece, const int &iz, double *rh
323323
return;
324324

325325
}
326-
void Parallel_Grid::reduce_to_fullrho(double* rhotot, const double* const rhoin)
326+
void Parallel_Grid::reduce_to_fullrho(double* rhotot, const double* const rhoin)const
327327
{
328328
//ModuleBase::TITLE("Parallel_Grid","reduce_to_fullrho");
329329

@@ -393,10 +393,6 @@ void Parallel_Grid::init_final_scf(const int &ncx_in, const int &ncy_in, const i
393393
const int &nrxx_in, const int &nbz_in, const int &bz_in)
394394
{
395395

396-
#ifndef __MPI
397-
return;
398-
#endif
399-
400396
ModuleBase::TITLE("Parallel_Grid","init");
401397

402398
this->ncx = ncx_in;
@@ -405,7 +401,7 @@ const int &nrxx_in, const int &nbz_in, const int &bz_in)
405401
this->nczp = nczp_in;
406402
this->nrxx = nrxx_in;
407403
this->nbz = nbz_in;
408-
this->bz = bz_in;
404+
this->bz = bz_in;
409405

410406
if(nczp<0)
411407
{
@@ -418,7 +414,11 @@ const int &nrxx_in, const int &nbz_in, const int &bz_in)
418414
assert(ncz > 0);
419415

420416
this->ncxy = ncx * ncy;
421-
this->ncxyz = ncxy * ncz;
417+
this->ncxyz = ncxy * ncz;
418+
419+
#ifndef __MPI
420+
return;
421+
#endif
422422

423423
// (2)
424424
assert(allocate_final_scf==false);

source/module_hamilt_pw/hamilt_pwdft/parallel_grid.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ class Parallel_Grid
1111
friend class Efield;
1212
friend class Symmetry_rho;
1313

14-
Parallel_Grid();
15-
~Parallel_Grid();
14+
Parallel_Grid();
15+
Parallel_Grid(const int ncx_in, const int ncy_in, const int ncz_in, const int nczp_in, const int nrxx_in, const int nbz_in, const int bz_in)
16+
:ncx(ncx_in), ncy(ncy_in), ncz(ncz_in), nczp(nczp_in), nrxx(nrxx_in), nbz(nbz_in), bz(bz_in),
17+
ncxy(ncx_in* ncy_in), ncxyz(ncx_in* ncy_in* ncz_in)
18+
{
19+
assert(ncx > 0 && ncy > 0 && ncz > 0 && nczp >= 0 && nrxx > 0 && nbz > 0 && bz > 0);
20+
}
21+
~Parallel_Grid();
1622

1723
void init(const int &ncx, const int &ncy, const int &ncz,
1824
const int &nczp, const int &nrxx, const int &nbz, const int &bz);
@@ -24,7 +30,7 @@ class Parallel_Grid
2430
void zpiece_to_all(double *zpiece, const int &iz, double *rho) const;
2531
void zpiece_to_stogroup(double *zpiece, const int &iz, double *rho) const; //qainrui add for sto-dft 2021-7-21
2632

27-
void reduce_to_fullrho(double* rhotot, const double* constrhoin);
33+
void reduce_to_fullrho(double* rhotot, const double* constrhoin)const;
2834
#endif
2935

3036
private:
@@ -46,8 +52,8 @@ class Parallel_Grid
4652
int nbz;
4753
int bz;
4854

49-
bool allocate;
50-
bool allocate_final_scf; //LiuXh add 20180619
55+
bool allocate = false;
56+
bool allocate_final_scf = false; //LiuXh add 20180619
5157
};
5258

5359
#endif

source/module_io/cube_io.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
#define CUBE_IO_H
33
#include <string>
44
#include "module_cell/unitcell.h"
5-
#ifdef __MPI
6-
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
7-
#endif
5+
class Parallel_Grid;
86

97
namespace ModuleIO
108
{
119
bool read_cube(
12-
#ifdef __MPI
13-
const Parallel_Grid*const Pgrid,
14-
#endif
10+
const Parallel_Grid& pgrid,
1511
const int my_rank,
1612
std::ofstream& ofs_running,
1713
const std::string& fn,
@@ -22,7 +18,8 @@ bool read_cube(
2218
const int nat);
2319

2420
void write_cube(
25-
const double*const data,
21+
const Parallel_Grid& pgrid,
22+
const double* const data,
2623
const int is,
2724
const int nspin,
2825
const int iter,
@@ -42,20 +39,16 @@ void write_cube(
4239
// read file as order (ixy,iz) to data[iz*nxy+ixy]
4340
void read_cube_core_match(
4441
std::ifstream &ifs,
45-
#ifdef __MPI
46-
const Parallel_Grid*const Pgrid,
42+
const Parallel_Grid& pgrid,
4743
const bool flag_read_rank,
48-
#endif
4944
double*const data,
5045
const int nxy,
5146
const int nz);
5247

5348
void read_cube_core_mismatch(
5449
std::ifstream &ifs,
55-
#ifdef __MPI
56-
const Parallel_Grid*const Pgrid,
50+
const Parallel_Grid& pgrid,
5751
const bool flag_read_rank,
58-
#endif
5952
double*const data,
6053
const int nx,
6154
const int ny,
@@ -69,6 +62,7 @@ void read_cube_core_mismatch(
6962
// when serial:
7063
// write data[iz*nxy+ixy] to file as order (ixy,iz)
7164
void write_cube_core(
65+
const Parallel_Grid& pgrid,
7266
std::ofstream& ofs_cube,
7367
const double*const data,
7468
const int nxy,

0 commit comments

Comments
 (0)