Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions source/source_basis/module_pw/pw_basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ class PW_Basis
const bool xprime_in = true
);

//Serial basis assembly: the plain production sequence (initgrids ->
//initparameters -> default FFT mode -> setuptransform -> collect_local_pw)
//without any parallel/device context (no initmpi, default distribution).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Please state that the advertised no-initmpi use requires PW sources compiled without __MPI. Both initgrids overloads otherwise reach MPI_Allreduce with a fresh object's MPI_COMM_NULL; the migrated DFPT fixture avoids this by recompiling those sources with __MPI disabled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 883b21d: both init_serial declarations (PW_Basis and
PW_Basis_K) now carry the requirement explicitly -- the no-initmpi use
requires the PW sources compiled without __MPI, because with __MPI the
initgrids overloads reduce over the object communicator, which is
MPI_COMM_NULL on a fresh basis that never called initmpi. The note also
points at the working pattern: the DFPT serial test targets compile the
PW sources with __MPI disabled (abacus_disable_feature_definitions),
which is exactly why the migrated fixture is safe. Comment-only change;
abacus_basic_para rebuilt clean (make rc=0).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 883b21de7: both declarations now document the non-__MPI build requirement and identify the DFPT serial targets as the supported example. Confirmed by static review.

//NOTE: this no-initmpi use requires the PW sources to be compiled
//without __MPI -- with __MPI the initgrids overloads reduce over this
//object's communicator, which is MPI_COMM_NULL on a fresh basis that
//never called initmpi. The reusable form of the setup chain for serial
//utilities and unit tests (compiled with __MPI disabled, like the DFPT
//serial test targets); the parallel production path stays in
//setup_pwrho.
void init_serial(
const double lat0_in, //unit length (unit in bohr)
const ModuleBase::Matrix3 latvec_in, // Unitcell lattice vectors (unit in lat0)
const double gridecut //unit in Ry, ecut to set up grids
);

//Set parameters about full planewave, only used in OFDFT for now.
void setfullpw(
const bool inpt_full_pw = false,
Expand Down
16 changes: 16 additions & 0 deletions source/source_basis/module_pw/pw_basis_k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,20 @@ double* PW_Basis_K::get_gk2_data() const
return this->d_gk2;
}

void PW_Basis_K::init_serial(const double lat0_in,
const ModuleBase::Matrix3 latvec_in,
const int nx_in,
const int ny_in,
const int nz_in,
const double ecut_in,
const int nk_in,
const ModuleBase::Vector3<double>* kvec_d)
{
initgrids(lat0_in, latvec_in, nx_in, ny_in, nz_in);
initparameters(false, ecut_in, nk_in, kvec_d);
this->fft_bundle.initfftmode(0);
setuptransform();
collect_local_pw();
}

} // namespace ModulePW
21 changes: 21 additions & 0 deletions source/source_basis/module_pw/pw_basis_k.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ class PW_Basis_K : public PW_Basis
const bool xprime_in = true
);

//Serial basis assembly on a given FFT box (usually the rho grid's
//nx/ny/nz so the two bases share the box): initgrids -> initparameters
//with the k list -> default FFT mode -> setuptransform ->
//collect_local_pw, without any parallel/device context. NOTE: this
//no-initmpi use requires the PW sources to be compiled without __MPI
//-- with __MPI the initgrids overloads reduce over this object's
//communicator, which is MPI_COMM_NULL on a fresh basis that never
//called initmpi. The reusable form of the setup chain for serial
//utilities and unit tests (compiled with __MPI disabled, like the
//DFPT serial test targets); the parallel production path stays in
//setup_pwwfc.
void init_serial(
const double lat0_in,
const ModuleBase::Matrix3 latvec_in,
const int nx_in,
const int ny_in,
const int nz_in,
const double ecut_in,
const int nk_in,
const ModuleBase::Vector3<double>* kvec_d);

public:
int nks=0;//number of k points in this pool
ModuleBase::Vector3<double> *kvec_d=nullptr; // Direct coordinates of k points
Expand Down
15 changes: 14 additions & 1 deletion source/source_basis/module_pw/pw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,26 @@ void PW_Basis:: initparameters(

this->ggecut = pwecut_in / this->tpiba2;
//ggecut should be no larger than gridecut
if(this->ggecut > this->gridecut_lat)
if(this->ggecut > this->gridecut_lat)
{
this->ggecut = this->gridecut_lat;
}
this->distribution_type = distribution_type_in;
}

void PW_Basis:: init_serial(
const double lat0_in,
const ModuleBase::Matrix3 latvec_in,
const double gridecut
)
{
initgrids(lat0_in, latvec_in, gridecut);
initparameters(false, gridecut);
this->fft_bundle.initfftmode(0);
setuptransform();
collect_local_pw();
}

// Set parameters about full planewave, used only in OFDFT for now. sunliang added 2022-08-30
void PW_Basis::setfullpw(
const bool inpt_full_pw,
Expand Down
16 changes: 5 additions & 11 deletions source/source_pw/module_dfpt/test_serial/dfpt_serial_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,12 @@ void DFPTSerialBase::SetupBases(const ModuleBase::Vector3<double>& k_d,
int nbands)
{
G_ = ucell_.G;
pw_rho_.initgrids(lat0_, latvec_, rho_mult_ * ecutwfc_);
pw_rho_.initparameters(false, rho_mult_ * ecutwfc_);
pw_rho_.fft_bundle.initfftmode(0);
pw_rho_.setuptransform();
pw_rho_.collect_local_pw();

// the serial assembly chains live in the PW_Basis / PW_Basis_K
// sources (init_serial); this fixture only supplies the geometry
// and the (k, q) data
pw_rho_.init_serial(lat0_, latvec_, rho_mult_ * ecutwfc_);
const ModuleBase::Vector3<double> klist[1] = {k_d};
pw_wfc_.initgrids(lat0_, latvec_, pw_rho_.nx, pw_rho_.ny, pw_rho_.nz);
pw_wfc_.initparameters(false, ecutwfc_, 1, klist);
pw_wfc_.fft_bundle.initfftmode(0);
pw_wfc_.setuptransform();
pw_wfc_.collect_local_pw();
pw_wfc_.init_serial(lat0_, latvec_, pw_rho_.nx, pw_rho_.ny, pw_rho_.nz, ecutwfc_, 1, klist);

qlist_.nkstot = 1;
qlist_.kvec_d.clear();
Expand Down
Loading