diff --git a/source/module_esolver/esolver_ks_lcaopw.cpp b/source/module_esolver/esolver_ks_lcaopw.cpp index 1060a80d29..8533d7170d 100644 --- a/source/module_esolver/esolver_ks_lcaopw.cpp +++ b/source/module_esolver/esolver_ks_lcaopw.cpp @@ -139,15 +139,15 @@ namespace ModuleESolver // It is not a good choice to overload another solve function here, this will spoil the concept of // multiple inheritance and polymorphism. But for now, we just do it in this way. // In the future, there will be a series of class ESolver_KS_LCAO_PW, HSolver_LCAO_PW and so on. - std::weak_ptr> psig = this->p_wf_init->get_psig(); + auto psig = this->p_wf_init->get_psig(); - if (psig.expired()) + if (/*psig.expired()*/ psig == nullptr) { ModuleBase::WARNING_QUIT("ESolver_KS_PW::hamilt2density_single", "psig lifetime is expired"); } hsolver::HSolverLIP hsolver_lip_obj(this->pw_wfc); - hsolver_lip_obj.solve(this->p_hamilt, this->kspw_psi[0], this->pelec, psig.lock().get()[0], skip_charge,ucell.tpiba,ucell.nat); + hsolver_lip_obj.solve(this->p_hamilt, this->kspw_psi[0], this->pelec, psig[0], skip_charge, ucell.tpiba, ucell.nat); // add exx #ifdef __EXX diff --git a/source/module_esolver/esolver_ks_pw.h b/source/module_esolver/esolver_ks_pw.h index 3ad3aeb09c..4c5618f7ae 100644 --- a/source/module_esolver/esolver_ks_pw.h +++ b/source/module_esolver/esolver_ks_pw.h @@ -52,7 +52,7 @@ class ESolver_KS_PW : public ESolver_KS //! hide the psi in ESolver_KS for tmp use psi::Psi, base_device::DEVICE_CPU>* psi = nullptr; - // psi_initializer controller + // PsiInitializer controller psi::PSIInit* p_wf_init = nullptr; Device* ctx = {}; diff --git a/source/module_io/read_input_item_postprocess.cpp b/source/module_io/read_input_item_postprocess.cpp index 1087e24d95..d914d4c619 100644 --- a/source/module_io/read_input_item_postprocess.cpp +++ b/source/module_io/read_input_item_postprocess.cpp @@ -196,7 +196,7 @@ void ReadInput::item_postprocess() In the future lcao_in_pw will have its own ESolver. - 2023/12/22 use new psi_initializer to expand numerical + 2023/12/22 use new PsiInitializer to expand numerical atomic orbitals, ykhuang */ if (para.input.towannier90 && para.input.basis_type == "lcao_in_pw") diff --git a/source/module_io/read_input_item_system.cpp b/source/module_io/read_input_item_system.cpp index 7398dc2e6a..7cf382f64f 100644 --- a/source/module_io/read_input_item_system.cpp +++ b/source/module_io/read_input_item_system.cpp @@ -502,7 +502,7 @@ void ReadInput::item_system() } { Input_Item item("psi_initializer"); - item.annotation = "whether to use psi_initializer"; + item.annotation = "whether to use PsiInitializer"; item.reset_value = [](const Input_Item& item, Parameter& para) { if (para.input.basis_type == "lcao_in_pw") { diff --git a/source/module_io/to_wannier90_lcao_in_pw.cpp b/source/module_io/to_wannier90_lcao_in_pw.cpp index bf6bac22f6..bd51c493d3 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.cpp +++ b/source/module_io/to_wannier90_lcao_in_pw.cpp @@ -44,7 +44,7 @@ void toWannier90_LCAO_IN_PW::calculate( Structure_Factor* sf_ptr = const_cast(&sf); ModulePW::PW_Basis_K* wfcpw_ptr = const_cast(wfcpw); - this->psi_init_ = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init_ = new PsiInitializerNAO, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init_->initialize(sf_ptr, wfcpw_ptr, &ucell, &(GlobalC::Pkpoints), 1, nullptr, GlobalV::MY_RANK); #else @@ -218,8 +218,8 @@ void toWannier90_LCAO_IN_PW::nao_G_expansion( { int npwx = wfcpw->npwk_max; this->psi_init_->proj_ao_onkG(ik); - std::weak_ptr>> psig = this->psi_init_->share_psig(); - if(psig.expired()) { ModuleBase::WARNING_QUIT("toWannier90_LCAO_IN_PW::nao_G_expansion", "psig is expired"); + auto psig = this->psi_init_->share_psig(); + if(/*psig.expired()*/ psig == nullptr) { ModuleBase::WARNING_QUIT("toWannier90_LCAO_IN_PW::nao_G_expansion", "psig is expired"); } int nbands = PARAM.globalv.nlocal; int nbasis = npwx*PARAM.globalv.npol; @@ -227,7 +227,7 @@ void toWannier90_LCAO_IN_PW::nao_G_expansion( { for (int ig = 0; ig < nbasis; ig++) { - psi(ib, ig) = psig.lock().get()[0](ik, ib, ig); + psi(ib, ig) = psig[0](ik, ib, ig); } } } diff --git a/source/module_io/to_wannier90_lcao_in_pw.h b/source/module_io/to_wannier90_lcao_in_pw.h index 26fe2abb92..19d3a3f8c1 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.h +++ b/source/module_io/to_wannier90_lcao_in_pw.h @@ -70,7 +70,7 @@ class toWannier90_LCAO_IN_PW : public toWannier90_PW protected: const Parallel_Orbitals* ParaV; /// @brief psi initializer for expanding nao in planewave basis - psi_initializer, base_device::DEVICE_CPU>* psi_init_; + PsiInitializer, base_device::DEVICE_CPU>* psi_init_; /// @brief get Bloch function from LCAO wavefunction /// @param psi_in diff --git a/source/module_psi/psi_init.cpp b/source/module_psi/psi_init.cpp index fdd08958ba..cde7db1ce3 100644 --- a/source/module_psi/psi_init.cpp +++ b/source/module_psi/psi_init.cpp @@ -25,6 +25,35 @@ PSIInit::PSIInit(const std::string& init_wfc_in, this->basis_type = basis_type_in; this->use_psiinitializer = use_psiinitializer_in; this->pw_wfc = pw_wfc_in; + + if (PARAM.inp.psi_initializer == true) + { + this->init_psi_method = "new"; + } + else + { + if (PARAM.inp.init_wfc == "file" || PARAM.inp.device == "gpu" || PARAM.inp.esolver_type == "sdft") + { + this->init_psi_method = "old"; // old method; + } + else + { + this->init_psi_method = "new"; // new method; + } + } +} + +template +PSIInit::~PSIInit() +{ + if (this->init_psi_method == "new") + { + { + this->psi_init->deallocate_psig(); + // delete this->psi_init; + // this->psi_init = nullptr; + } + } } template @@ -37,53 +66,56 @@ void PSIInit::prepare_init(Structure_Factor* p_sf, #endif pseudopot_cell_vnl* p_ppcell) { - if (!this->use_psiinitializer) + if (this->init_psi_method == "old") { return; } - // under restriction of C++11, std::unique_ptr can not be allocate via std::make_unique - // use new instead, but will cause asymmetric allocation and deallocation, in literal aspect - ModuleBase::timer::tick("PSIInit", "prepare_init"); - if ((this->init_wfc.substr(0, 6) == "atomic") && (p_ucell->natomwfc == 0)) - { - this->psi_init = std::unique_ptr>(new psi_initializer_random()); - } - else if (this->init_wfc == "atomic") - { - this->psi_init = std::unique_ptr>(new psi_initializer_atomic()); - } - else if (this->init_wfc == "random") - { - this->psi_init = std::unique_ptr>(new psi_initializer_random()); - } - else if (this->init_wfc == "nao") - { - this->psi_init = std::unique_ptr>(new psi_initializer_nao()); - } - else if (this->init_wfc == "atomic+random") - { - this->psi_init = std::unique_ptr>(new psi_initializer_atomic_random()); - } - else if (this->init_wfc == "nao+random") - { - this->psi_init = std::unique_ptr>(new psi_initializer_nao_random()); - } else { - ModuleBase::WARNING_QUIT("PSIInit::prepare_init", "for new psi initializer, init_wfc type not supported"); - } + // under restriction of C++11, std::unique_ptr can not be allocate via std::make_unique + // use new instead, but will cause asymmetric allocation and deallocation, in literal aspect + ModuleBase::timer::tick("PSIInit", "prepare_init"); + if ((this->init_wfc.substr(0, 6) == "atomic") && (p_ucell->natomwfc == 0)) + { + this->psi_init = std::unique_ptr>(new PsiInitializerRandom()); + } + else if (this->init_wfc == "atomic") + { + this->psi_init = std::unique_ptr>(new PsiInitializerAtomic()); + } + else if (this->init_wfc == "random") + { + this->psi_init = std::unique_ptr>(new PsiInitializerRandom()); + } + else if (this->init_wfc == "nao") + { + this->psi_init = std::unique_ptr>(new PsiInitializerNAO()); + } + else if (this->init_wfc == "atomic+random") + { + this->psi_init = std::unique_ptr>(new PsiInitializerAtomicRandom()); + } + else if (this->init_wfc == "nao+random") + { + this->psi_init = std::unique_ptr>(new PsiInitializerNAORandom()); + } + else + { + ModuleBase::WARNING_QUIT("PSIInit::prepare_init", "for new psi initializer, init_wfc type not supported"); + } - //! function polymorphism is moved from constructor to function initialize. - //! Two slightly different implementation are for MPI and serial case, respectively. + //! function polymorphism is moved from constructor to function initialize. + //! Two slightly different implementation are for MPI and serial case, respectively. #ifdef __MPI - this->psi_init->initialize(p_sf, pw_wfc, p_ucell, p_parak, random_seed, p_ppcell, rank); + this->psi_init->initialize(p_sf, pw_wfc, p_ucell, p_parak, random_seed, p_ppcell, rank); #else - this->psi_init->initialize(p_sf, pw_wfc, p_ucell, random_seed, p_ppcell); + this->psi_init->initialize(p_sf, pw_wfc, p_ucell, random_seed, p_ppcell); #endif - // always new->initialize->tabulate->allocate->proj_ao_onkG - this->psi_init->tabulate(); - ModuleBase::timer::tick("PSIInit", "prepare_init"); + // always new->initialize->tabulate->allocate->proj_ao_onkG + this->psi_init->tabulate(); + ModuleBase::timer::tick("PSIInit", "prepare_init"); + } } template @@ -108,9 +140,9 @@ void PSIInit::allocate_psi(Psi>*& psi, // the basis (representation) with operator (hamiltonian) and solver (diagonalization). // This feature requires feasible Linear Algebra library in-built in ABACUS, which // is not ready yet. - if (this->use_psiinitializer) // new method + if (this->init_psi_method == "new") // new method { - // psi_initializer drag initialization of pw wavefunction out of HSolver, make psi + // PsiInitializer drag initialization of pw wavefunction out of HSolver, make psi // initialization decoupled with HSolver (diagonalization) procedure. // However, due to EXX is hard to maintain, we still use the old method for EXX. // LCAOINPW in version >= 3.5.0 uses this new method. @@ -137,27 +169,31 @@ void PSIInit::allocate_psi(Psi>*& psi, template void PSIInit::make_table(const int nks, Structure_Factor* p_sf, pseudopot_cell_vnl* p_ppcell) { - if (this->use_psiinitializer) + if (this->init_psi_method == "new") { } // do not need to do anything because the interpolate table is unchanged else // old initialization method, used in EXX calculation { this->wf_old.init_after_vc(nks); // reallocate wanf2, the planewave expansion of lcao - this->wf_old.init_at_1(p_sf, &p_ppcell->tab_at); // re-calculate tab_at, the overlap matrix between atomic pswfc and jlq + this->wf_old.init_at_1( + p_sf, + &p_ppcell->tab_at); // re-calculate tab_at, the overlap matrix between atomic pswfc and jlq } } +// in the following function, the psi on Device will be initialized with the CPU psi template -void PSIInit::initialize_psi(Psi>* psi, - psi::Psi* kspw_psi, - hamilt::Hamilt* p_hamilt, - const pseudopot_cell_vnl& nlpp, - std::ofstream& ofs_running, - const bool is_already_initpsi) +void PSIInit::initialize_psi( + Psi>* psi, // the one always on CPU + psi::Psi* kspw_psi, // the one may be on GPU. In CPU case, it is the same as psi + hamilt::Hamilt* p_hamilt, + const pseudopot_cell_vnl& nlpp, + std::ofstream& ofs_running, + const bool is_already_initpsi) { ModuleBase::timer::tick("PSIInit", "initialize_psi"); - if (PARAM.inp.psi_initializer) + if (this->init_psi_method == "new") { // if psig is not allocated before, allocate it if (!this->psi_init->psig_use_count()) @@ -169,7 +205,8 @@ void PSIInit::initialize_psi(Psi>* psi, // like (1, nbands, npwx), in which npwx is the maximal npw of all kpoints for (int ik = 0; ik < this->pw_wfc->nks; ik++) { - //! Fix the wavefunction to initialize at given kpoint + //! Fix the wavefunction to initialize at given kpoint. + // This will fix the kpoint for CPU case. For GPU, we should additionally call fix_k for kspw_psi psi->fix_k(ik); //! Update Hamiltonian from other kpoint to the given one @@ -179,20 +216,20 @@ void PSIInit::initialize_psi(Psi>* psi, //! and G is wavevector of the peroiodic part of the Bloch function this->psi_init->proj_ao_onkG(ik); - //! psi_initializer manages memory of psig with shared pointer, + //! PsiInitializer manages memory of psig with shared pointer, //! its access to use is shared here via weak pointer - //! therefore once the psi_initializer is destructed, psig will be destructed, too + //! therefore once the PsiInitializer is destructed, psig will be destructed, too //! this way, we can avoid memory leak and undefined behavior - std::weak_ptr> psig = this->psi_init->share_psig(); - - if (psig.expired()) + // std::weak_ptr> psig = this->psi_init->share_psig(); + psi::Psi* psig_ = this->psi_init->share_psig(); + if (/*psig.expired()*/ psig_ == nullptr) { ModuleBase::WARNING_QUIT("PSIInit::initialize_psi", "psig lifetime is expired"); } //! to use psig, we need to lock it to get a shared pointer version, //! then switch kpoint of psig to the given one - auto psig_ = psig.lock(); + // auto psig_ = psig.lock(); // CHANGE LOG: if not lcaoinpw, the psig will only be used in psi-initialization // so we can only allocate memory for one kpoint with the maximal number of pw // over all kpoints, then the memory space will be always enough. Then for each @@ -210,6 +247,7 @@ void PSIInit::initialize_psi(Psi>* psi, if (((this->ks_solver == "cg") || (this->ks_solver == "lapack")) && (this->basis_type == "pw")) { // the following function is only run serially, to be improved + // For GPU: this psig_ should be on GPU before calling the following function hsolver::DiagoIterAssist::diagH_subspace_init(p_hamilt, psig_->get_pointer(), psig_->get_nbands(), @@ -218,6 +256,7 @@ void PSIInit::initialize_psi(Psi>* psi, etatom.data()); continue; } + // do nothing in LCAO_IN_PW case because psig is used to do transformation instead of initialization else if ((this->ks_solver == "lapack") && (this->basis_type == "lcao_in_pw")) { if (ik == 0) @@ -239,6 +278,8 @@ void PSIInit::initialize_psi(Psi>* psi, } // for the Davidson method, we just copy the wavefunction (partially) + // For GPU: although this is simply the copy operation, if GPU present, this should be a data sending + // operation for (int iband = 0; iband < kspw_psi->get_nbands(); iband++) { for (int ibasis = 0; ibasis < kspw_psi->get_nbasis(); ibasis++) @@ -248,7 +289,8 @@ void PSIInit::initialize_psi(Psi>* psi, } } // end k-point loop - if (this->basis_type != "lcao_in_pw") + if (this->basis_type + != "lcao_in_pw") // if not LCAO_IN_PW case, we can release the memory of psig after initailization is done. { this->psi_init->deallocate_psig(); } diff --git a/source/module_psi/psi_init.h b/source/module_psi/psi_init.h index df0ec83446..54f6fd6a92 100644 --- a/source/module_psi/psi_init.h +++ b/source/module_psi/psi_init.h @@ -17,7 +17,7 @@ class PSIInit const std::string& basis_type_in, const bool& use_psiinitializer_in, ModulePW::PW_Basis_K* pw_wfc_in); - ~PSIInit(){}; + ~PSIInit(); // prepare the wavefunction initialization void prepare_init(Structure_Factor* p_sf, //< structure factor @@ -41,7 +41,7 @@ class PSIInit // make interpolate table void make_table(const int nks, Structure_Factor* p_sf, pseudopot_cell_vnl* p_ppcell); - //------------------------ only for psi_initializer -------------------- + //------------------------ only for PsiInitializer -------------------- /** * @brief initialize the wavefunction * @@ -58,27 +58,27 @@ class PSIInit const bool is_already_initpsi); /** - * @brief get the psi_initializer + * @brief get the PsiInitializer * - * @return psi_initializer* + * @return PsiInitializer* */ - std::weak_ptr> get_psig() const + psi::Psi* get_psig() const { return this->psi_init->share_psig(); } //---------------------------------------------------------------------- private: - // psi_initializer* psi_init = nullptr; + // PsiInitializer* psi_init = nullptr; // change to use smart pointer to manage the memory, and avoid memory leak // while the std::make_unique() is not supported till C++14, // so use the new and std::unique_ptr to manage the memory, but this makes new-delete not symmetric - std::unique_ptr> psi_init; + std::unique_ptr> psi_init; //! temporary: wave functions, this one may be deleted in future wavefunc wf_old; - // whether to use psi_initializer + // whether to usePsiInitializer bool use_psiinitializer = false; // wavefunction initialization type @@ -94,6 +94,8 @@ class PSIInit ModulePW::PW_Basis_K* pw_wfc = nullptr; Device* ctx = {}; + + std::string init_psi_method = "old"; }; } // namespace psi diff --git a/source/module_psi/psi_initializer.cpp b/source/module_psi/psi_initializer.cpp index ba1734e223..e65f78e0bb 100644 --- a/source/module_psi/psi_initializer.cpp +++ b/source/module_psi/psi_initializer.cpp @@ -12,9 +12,18 @@ #endif template -psi::Psi>* psi_initializer::allocate(const bool only_psig) +PsiInitializer::PsiInitializer() { - ModuleBase::timer::tick("psi_initializer", "allocate"); + // the following line will simultaneously run by CPU and GPU + // For CPU, this->device will get value base_device::CpuDevice + // For GPU, this->device will get value base_device::GpuDevice + this->device = base_device::get_device_type(this->ctx); +} + +template +psi::Psi>* PsiInitializer::allocate(const bool only_psig) +{ + ModuleBase::timer::tick("PsiInitializer", "allocate"); /* WARNING: when basis_type = "pw", the variable PARAM.globalv.nlocal will also be set, in this case, it is set to 9 = 1 + 3 + 5, which is the maximal number of orbitals spd, I don't think it is reasonable @@ -82,13 +91,17 @@ psi::Psi>* psi_initializer::allocate(const bool // std::cout << " MEMORY FOR PSI PER PROCESSOR (MB) : " << double(memory_cost_psi)/1024.0/1024.0 << std::endl; ModuleBase::Memory::record("Psi_PW", memory_cost_psi); } - // psi_initializer also works for basis transformation tasks. In this case, psig needs to allocate memory for + // PsiInitializer also works for basis transformation tasks. In this case, psig needs to allocate memory for // each kpoint, otherwise, for initializing pw wavefunction, only one kpoint's space is enough. const int nks_psig = (PARAM.inp.basis_type == "pw")? 1 : nks_psi; - this->psig_ = std::make_shared>(nks_psig, - nbands_actual, - nbasis_actual, - this->pw_wfc_->npwk); + // this->psig_ = std::make_shared>(nks_psig, + // nbands_actual, + // nbasis_actual, + // this->pw_wfc_->npwk); + this->d_psig_ = new psi::Psi(nks_psig, + nbands_actual, + nbasis_actual, + this->pw_wfc_->npwk); // psig can be directly allocate on GPU double memory_cost_psig = nks_psig * nbands_actual * this->pw_wfc_->npwk_max * PARAM.globalv.npol * sizeof(T); @@ -111,14 +124,14 @@ psi::Psi>* psi_initializer::allocate(const bool << "npwk_max = " << this->pw_wfc_->npwk_max << "\n" << "npol = " << PARAM.globalv.npol << "\n"; ModuleBase::Memory::record("psigPW", memory_cost_psig); - ModuleBase::timer::tick("psi_initializer", "allocate"); + ModuleBase::timer::tick("PsiInitializer", "allocate"); return psi_out; } template -void psi_initializer::random_t(T* psi, const int iw_start, const int iw_end, const int ik) +void PsiInitializer::random_t(T* psi, const int iw_start, const int iw_end, const int ik) { - ModuleBase::timer::tick("psi_initializer", "random_t"); + ModuleBase::timer::tick("PsiInitializer", "random_t"); assert(iw_start >= 0); const int ng = this->pw_wfc_->npwk[ik]; @@ -213,14 +226,14 @@ void psi_initializer::random_t(T* psi, const int iw_start, const int } } } - ModuleBase::timer::tick("psi_initializer_random", "random_t"); + ModuleBase::timer::tick("PsiInitializer", "random_t"); } #ifdef __MPI template -void psi_initializer::stick_to_pool(Real* stick, const int& ir, Real* out) const +void PsiInitializer::stick_to_pool(Real* stick, const int& ir, Real* out) const { - ModuleBase::timer::tick("psi_initializer", "stick_to_pool"); + ModuleBase::timer::tick("PsiInitializer", "stick_to_pool"); MPI_Status ierror; const int is = this->ixy2is_[ir]; const int ip = this->pw_wfc_->fftixy2ip[ir]; @@ -245,7 +258,7 @@ void psi_initializer::stick_to_pool(Real* stick, const int& ir, Real* } else { - ModuleBase::WARNING_QUIT("psi_initializer", "stick_to_pool: Real type not supported"); + ModuleBase::WARNING_QUIT("PsiInitializer", "stick_to_pool: Real type not supported"); } for(int iz=0; iz::stick_to_pool(Real* stick, const int& ir, Real* } else { - ModuleBase::WARNING_QUIT("psi_initializer", "stick_to_pool: Real type not supported"); + ModuleBase::WARNING_QUIT("PsiInitializer", "stick_to_pool: Real type not supported"); } } return; - ModuleBase::timer::tick("psi_initializer", "stick_to_pool"); + ModuleBase::timer::tick("PsiInitializer", "stick_to_pool"); } #endif // explicit instantiation -template class psi_initializer, base_device::DEVICE_CPU>; -template class psi_initializer, base_device::DEVICE_CPU>; +template class PsiInitializer, base_device::DEVICE_CPU>; +template class PsiInitializer, base_device::DEVICE_CPU>; // gamma point calculation -template class psi_initializer; -template class psi_initializer; +template class PsiInitializer; +template class PsiInitializer; #if ((defined __CUDA) || (defined __ROCM)) -template class psi_initializer, base_device::DEVICE_GPU>; -template class psi_initializer, base_device::DEVICE_GPU>; +template class PsiInitializer, base_device::DEVICE_GPU>; +template class PsiInitializer, base_device::DEVICE_GPU>; // gamma point calculation -template class psi_initializer; -template class psi_initializer; +template class PsiInitializer; +template class PsiInitializer; #endif diff --git a/source/module_psi/psi_initializer.h b/source/module_psi/psi_initializer.h index ec1efd605e..b6549ff7e7 100644 --- a/source/module_psi/psi_initializer.h +++ b/source/module_psi/psi_initializer.h @@ -41,7 +41,7 @@ A practical example would be in ESolver_KS_PW, because polymorphism is achieved pointer, while a raw pointer is risky, therefore std::unique_ptr is a better choice. 1. new a std::unique_ptr> with specific derived class -2. initialize() to link psi_initializer with external data and methods +2. initialize() to link PsiInitializer with external data and methods 3. allocate() to allocate memory for psi 4. tabulate() to calculate the interpolate table 5. proj_ao_onkG() to calculate projection of atomic radial function onto planewave basis @@ -50,22 +50,28 @@ choice. In summary: new->initialize->allocate->tabulate->proj_ao_onkG->share_psig - REPRESENTATION TRANSFORM -There is also another way to use psi_initializer, say the representation transform. +There is also another way to use PsiInitializer, say the representation transform. For this kind of use, see module_io/to_wannier90_lcao_in_pw, use allocate(true) instead of allocate() to only allocate memory for psig, then use share_psig() to get value. + +- SPECIAL TOPIC: GPU +Psi initialization operation is a good candidate for GPU acceleration, because the PW components +are highly independent, the threading is easy to implement. The most highly-computational-demanding +parts are two, the first is the building of interpolation table and the second is based on +the interpolation table, calculate the value for each |G>. */ template -class psi_initializer +class PsiInitializer { private: using Real = typename GetTypeReal::type; public: // technical notes: // Polymorphism is used to implement different methods, and achieved by pointers and virtual functions - psi_initializer() {}; - virtual ~psi_initializer() {}; + PsiInitializer(); + virtual ~PsiInitializer() {}; #ifdef __MPI // MPI additional implementation - /// @brief initialize the psi_initializer with external data and methods + /// @brief initialize the PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -81,7 +87,7 @@ class psi_initializer const int& ir, //< ir Real* out) const; //< out #else - /// @brief serial version of initialize function, link psi_initializer with external data and methods + /// @brief serial version of initialize function, link PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -99,9 +105,16 @@ class psi_initializer const int iw_start, //< iw_start, starting band index const int iw_end, //< iw_end, ending band index const int ik) //< ik, kpoint index - { ModuleBase::WARNING_QUIT("psi_initializer::random", "Polymorphism error"); } + { + ModuleBase::WARNING_QUIT("PsiInitializer::random", + "Polymorphism error: this function should not be called"); + } /// @brief CENTRAL FUNCTION: allocate interpolate table recording overlap integral between radial function and Spherical Bessel function - virtual void allocate_table() { ModuleBase::WARNING_QUIT("psi_initializer::create_ovlp_table", "Polymorphism error"); } + virtual void allocate_table() + { + ModuleBase::WARNING_QUIT("PsiInitializer::create_ovlp_table", + "Polymorphism error: this function should not be called"); + } /// @brief CENTRAL FUNCTION: calculate the interpolate table virtual void tabulate() = 0; /// @brief CENTRAL FUNCTION: calculate projection of atomic radial function onto planewave basis BASED ON THE OVERLAP TABLE @@ -121,8 +134,13 @@ class psi_initializer // because unique_ptr is not copyable or used as rvlaue, use shared_ptr instead // but to avoid ownership issue, use weak_ptr to share the pointer // therefore there is no really getter to get directly the shared_ptr. - std::weak_ptr> share_psig() { return this->psig_; } - int psig_use_count() { return this->psig_.use_count(); } + // std::weak_ptr> share_psig() { return this->psig_; } + psi::Psi* share_psig() { return this->d_psig_; } + int psig_use_count() const + { + // return this->psig_.use_count(); + return static_cast(this->d_psig_ != nullptr); + } void set_ucell(UnitCell* p_ucell_in) { this->p_ucell_ = p_ucell_in; } void set_pspot_nl(pseudopot_cell_vnl* p_pspot_nl_in) { this->p_pspot_nl_ = p_pspot_nl_in; } @@ -134,7 +152,12 @@ class psi_initializer void set_mem_saver(const int mem_saver_in) { this->mem_saver_ = mem_saver_in; } void set_method(std::string method_in) { this->method_ = method_in; } void set_nbands_complem(int nbands_in) { this->nbands_complem_ = nbands_in; } - void deallocate_psig() { this->psig_.reset(); } + void deallocate_psig() + { + // this->psig_.reset(); + delete this->d_psig_; + this->d_psig_ = nullptr; + } // tool methods // the following function is for compatibility concern, in ESolver_KS_PW the FPTYPE // now support double, float, std::complex and std::complex @@ -158,7 +181,7 @@ class psi_initializer // getgpluskcar... ModulePW::PW_Basis_K* pw_wfc_ = nullptr; // interface to UnitCell. UnitCell should be singleton and keep const for most cases. Due to - // many data are needed to read by psi_initializer, get a pointer to UnitCell instead of + // many data are needed to read by PsiInitializer, get a pointer to UnitCell instead of // importing all information one-by-one in parameter list. UnitCell* p_ucell_ = nullptr; #ifdef __MPI @@ -173,7 +196,12 @@ class psi_initializer std::vector ixy2is_; // refactored psig, in old version it is of datatype Psi*, use std::shared_ptr to // avoid memory leak - std::shared_ptr> psig_; + // std::shared_ptr> psig_; + + Device* ctx = {}; // device information carrier. The ctx can have type DEVICE_CPU or DEVICE_GPU + base_device::DEVICE_CPU* cpu_ctx = {}; + base_device::AbacusDevice_t device = {}; + psi::Psi* d_psig_ = nullptr; // is it possible to directly operate data on GPU? private: int mem_saver_ = 0; std::string method_ = "none"; diff --git a/source/module_psi/psi_initializer_atomic.cpp b/source/module_psi/psi_initializer_atomic.cpp index 0538483cad..e7f6c32fd5 100644 --- a/source/module_psi/psi_initializer_atomic.cpp +++ b/source/module_psi/psi_initializer_atomic.cpp @@ -25,7 +25,7 @@ void normalize(int n_rgrid, std::vector& pswfcr, double* rab) } template -void psi_initializer_atomic::allocate_table() +void PsiInitializerAtomic::allocate_table() { // find correct dimension for ovlp_flzjlq int dim1 = this->p_ucell_->ntype; @@ -36,7 +36,7 @@ void psi_initializer_atomic::allocate_table() } if (dim2 == 0) { - ModuleBase::WARNING_QUIT("psi_initializer_atomic::allocate_table", "there is not ANY pseudo atomic orbital read in present system, recommand other methods, quit."); + ModuleBase::WARNING_QUIT("PsiInitializerAtomic::allocate_table", "there is not ANY pseudo atomic orbital read in present system, recommand other methods, quit."); } int dim3 = PARAM.globalv.nqx; // allocate memory for ovlp_flzjlq @@ -46,7 +46,7 @@ void psi_initializer_atomic::allocate_table() #ifdef __MPI template -void psi_initializer_atomic::initialize(Structure_Factor* sf, //< structure factor +void PsiInitializerAtomic::initialize(Structure_Factor* sf, //< structure factor ModulePW::PW_Basis_K* pw_wfc, //< planewave basis UnitCell* p_ucell, //< unit cell Parallel_Kpoints* p_parakpts, //< parallel kpoints @@ -54,10 +54,10 @@ void psi_initializer_atomic::initialize(Structure_Factor* sf, pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - ModuleBase::timer::tick("psi_initializer_atomic", "initialize"); + ModuleBase::timer::tick("PsiInitializerAtomic", "initialize"); if(p_pspot_nl == nullptr) { - ModuleBase::WARNING_QUIT("psi_initializer_atomic::initialize", + ModuleBase::WARNING_QUIT("PsiInitializerAtomic::initialize", "pseudopot_cell_vnl object cannot be nullptr for atomic, quit."); } // import @@ -73,20 +73,20 @@ void psi_initializer_atomic::initialize(Structure_Factor* sf, this->ixy2is_.clear(); this->ixy2is_.resize(this->pw_wfc_->fftnxy); this->pw_wfc_->getfftixy2is(this->ixy2is_.data()); - ModuleBase::timer::tick("psi_initializer_atomic", "initialize_only_once"); + ModuleBase::timer::tick("PsiInitializerAtomic", "initialize_only_once"); } #else template -void psi_initializer_atomic::initialize(Structure_Factor* sf, //< structure factor +void PsiInitializerAtomic::initialize(Structure_Factor* sf, //< structure factor ModulePW::PW_Basis_K* pw_wfc, //< planewave basis UnitCell* p_ucell, //< unit cell const int& random_seed, //< random seed pseudopot_cell_vnl* p_pspot_nl) { - ModuleBase::timer::tick("psi_initializer_atomic", "initialize"); + ModuleBase::timer::tick("PsiInitializerAtomic", "initialize"); if(p_pspot_nl == nullptr) { - ModuleBase::WARNING_QUIT("psi_initializer_atomic::initialize", + ModuleBase::WARNING_QUIT("PsiInitializerAtomic::initialize", "pseudopot_cell_vnl object cannot be nullptr for atomic, quit."); } // import @@ -101,14 +101,14 @@ void psi_initializer_atomic::initialize(Structure_Factor* sf, this->ixy2is_.clear(); this->ixy2is_.resize(this->pw_wfc_->fftnxy); this->pw_wfc_->getfftixy2is(this->ixy2is_.data()); - ModuleBase::timer::tick("psi_initializer_atomic", "initialize_only_once"); + ModuleBase::timer::tick("PsiInitializerAtomic", "initialize_only_once"); } #endif template -void psi_initializer_atomic::tabulate() +void PsiInitializerAtomic::tabulate() { - ModuleBase::timer::tick("psi_initializer_atomic", "cal_ovlp_pswfcjlq"); + ModuleBase::timer::tick("PsiInitializerAtomic", "cal_ovlp_pswfcjlq"); int maxn_rgrid = 0; std::vector qgrid(PARAM.globalv.nqx); for (int iq = 0; iq < PARAM.globalv.nqx; iq++) @@ -150,7 +150,7 @@ void psi_initializer_atomic::tabulate() } } } - ModuleBase::timer::tick("psi_initializer_atomic", "cal_ovlp_pswfcjlq"); + ModuleBase::timer::tick("PsiInitializerAtomic", "cal_ovlp_pswfcjlq"); } std::complex phase_factor(double arg, int mode) @@ -162,11 +162,11 @@ std::complex phase_factor(double arg, int mode) } template -void psi_initializer_atomic::proj_ao_onkG(const int ik) +void PsiInitializerAtomic::proj_ao_onkG(const int ik) { - ModuleBase::timer::tick("psi_initializer_atomic", "proj_ao_onkG"); - const int ik_psig = (this->psig_->get_nk() == 1) ? 0 : ik; - this->psig_->fix_k(ik_psig); + ModuleBase::timer::tick("PsiInitializerAtomic", "proj_ao_onkG"); + const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik; + this->d_psig_->fix_k(ik_psig); //this->print_status(psi); const int npw = this->pw_wfc_->npwk[ik]; int lmax = this->p_ucell_->lmax_ppwf; @@ -247,7 +247,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) } for(int ig = 0; ig < npw; ig++) { - (*(this->psig_))(index, + (*(this->d_psig_))(index, ig + this->pw_wfc_->npwk_max*is ) = this->template cast_to_T( lphase * cg_coeffs[is] * sk[ig] * aux[ig] * ovlp_pswfcjlg[ig] @@ -258,7 +258,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) { for(int ig=0; ig < npw; ig++) { - (*(this->psig_))(index, + (*(this->d_psig_))(index, ig + this->pw_wfc_->npwk_max*is ) = this->template cast_to_T( std::complex(0.0, 0.0) @@ -300,6 +300,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) break; } } + #pragma omp parallel for for(int ig=0;ig and , a and b seem not necessarily to be equal */ @@ -324,7 +325,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) if(index+2*l+1 > this->p_ucell_->natomwfc) { std::cout<<__FILE__<<__LINE__<<" "<p_ucell_->natomwfc<::proj_ao_onkG()","error: too many wfcs"); + //ModuleBase::WARNING_QUIT("PsiInitializerAtomic::proj_ao_onkG()","error: too many wfcs"); } for(int ig = 0;ig::proj_ao_onkG(const int ik) fdw = phase_factor(0.5*alpha, -1)*aux[ig]; //build the orthogonal wfc //first rotation with angle (alpha + ModuleBase::PI) around (OX) - (*(this->psig_))(index, ig) = + (*(this->d_psig_))(index, ig) = this->template cast_to_T(phase_factor(0.5*gamma, 0)*fup); - (*(this->psig_))(index, ig+this->pw_wfc_->npwk_max) = + (*(this->d_psig_))(index, ig+this->pw_wfc_->npwk_max) = this->template cast_to_T(phase_factor(-0.5*gamma, 0)*fdw); //second rotation with angle gamma around(OZ) fup = phase_factor(0.5*(alpha + ModuleBase::PI), 1)*aux[ig]; fdw = phase_factor(0.5*(alpha + ModuleBase::PI), -1)*aux[ig]; - (*(this->psig_))(index+2*l+1, ig) = + (*(this->d_psig_))(index+2*l+1, ig) = this->template cast_to_T(phase_factor(0.5*gamma, 0)*fup); - (*(this->psig_))(index+2*l+1, ig+this->pw_wfc_->npwk_max) = + (*(this->d_psig_))(index+2*l+1, ig+this->pw_wfc_->npwk_max) = this->template cast_to_T(phase_factor(-0.5*gamma, 0)*fdw); } index++; @@ -370,7 +371,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) if(index+2*l+1 > this->p_ucell_->natomwfc) { std::cout<<__FILE__<<__LINE__<<" "<p_ucell_->natomwfc<::proj_ao_onkG()","error: too many wfcs"); + //ModuleBase::WARNING_QUIT("PsiInitializerAtomic::proj_ao_onkG()","error: too many wfcs"); } for(int ig = 0;ig::proj_ao_onkG(const int ik) fdown = ModuleBase::IMAG_UNIT * sin(0.5* alpha) * aux[ig]; //build the orthogonal wfc //first rotation with angle(alpha+ModuleBase::PI) around(OX) - (*(this->psig_))(index, ig) = + (*(this->d_psig_))(index, ig) = this->template cast_to_T( (cos(0.5*gamman) + ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fup ); - (*(this->psig_))(index, ig+ this->pw_wfc_->npwk_max) = + (*(this->d_psig_))(index, ig+ this->pw_wfc_->npwk_max) = this->template cast_to_T( (cos(0.5*gamman) - ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fdown ); //second rotation with angle gamma around(OZ) fup = cos(0.5 * (alpha + ModuleBase::PI)) * aux[ig]; fdown = ModuleBase::IMAG_UNIT * sin(0.5 * (alpha + ModuleBase::PI)) * aux[ig]; - (*(this->psig_))(index+2*l+1, ig) = + (*(this->d_psig_))(index+2*l+1, ig) = this->template cast_to_T( (cos(0.5*gamman) + ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fup ); - (*(this->psig_))(index+2*l+1, ig+ this->pw_wfc_->npwk_max) = + (*(this->d_psig_))(index+2*l+1, ig+ this->pw_wfc_->npwk_max) = this->template cast_to_T( (cos(0.5*gamman) - ModuleBase::IMAG_UNIT * sin(0.5*gamman)) * fdown ); @@ -416,7 +417,7 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) const int lm = l * l + m; for (int ig = 0; ig < npw; ig++) { - (*(this->psig_))(index, ig) = + (*(this->d_psig_))(index, ig) = this->template cast_to_T( lphase * sk [ig] * ylm(lm, ig) * ovlp_pswfcjlg[ig] ); @@ -432,20 +433,20 @@ void psi_initializer_atomic::proj_ao_onkG(const int ik) /* complement the rest of bands if there are */ if(this->nbands_complem() > 0) { - this->random_t(this->psig_->get_pointer(), index, this->psig_->get_nbands(), ik); + this->random_t(this->d_psig_->get_pointer(), index, this->d_psig_->get_nbands(), ik); } - ModuleBase::timer::tick("psi_initializer_atomic", "proj_ao_onkG"); + ModuleBase::timer::tick("PsiInitializerAtomic", "proj_ao_onkG"); } -template class psi_initializer_atomic, base_device::DEVICE_CPU>; -template class psi_initializer_atomic, base_device::DEVICE_CPU>; +template class PsiInitializerAtomic, base_device::DEVICE_CPU>; +template class PsiInitializerAtomic, base_device::DEVICE_CPU>; // gamma point calculation -template class psi_initializer_atomic; -template class psi_initializer_atomic; +template class PsiInitializerAtomic; +template class PsiInitializerAtomic; #if ((defined __CUDA) || (defined __ROCM)) -template class psi_initializer_atomic, base_device::DEVICE_GPU>; -template class psi_initializer_atomic, base_device::DEVICE_GPU>; +template class PsiInitializerAtomic, base_device::DEVICE_GPU>; +template class PsiInitializerAtomic, base_device::DEVICE_GPU>; // gamma point calculation -template class psi_initializer_atomic; -template class psi_initializer_atomic; +template class PsiInitializerAtomic; +template class PsiInitializerAtomic; #endif diff --git a/source/module_psi/psi_initializer_atomic.h b/source/module_psi/psi_initializer_atomic.h index 0bb13b604b..0818e12dcc 100644 --- a/source/module_psi/psi_initializer_atomic.h +++ b/source/module_psi/psi_initializer_atomic.h @@ -7,16 +7,16 @@ Psi (planewave based wavefunction) initializer: atomic */ template -class psi_initializer_atomic : public psi_initializer +class PsiInitializerAtomic : public PsiInitializer { private: using Real = typename GetTypeReal::type; public: - psi_initializer_atomic() {this->set_method("atomic");} - ~psi_initializer_atomic() {}; + PsiInitializerAtomic() {this->set_method("atomic");} + ~PsiInitializerAtomic() {}; #ifdef __MPI // MPI additional implementation - /// @brief initialize the psi_initializer with external data and methods + /// @brief initialize the PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -25,7 +25,7 @@ class psi_initializer_atomic : public psi_initializer pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential const int& = 0) override; //< MPI rank #else - /// @brief serial version of initialize function, link psi_initializer with external data and methods + /// @brief serial version of initialize function, link PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell diff --git a/source/module_psi/psi_initializer_atomic_random.cpp b/source/module_psi/psi_initializer_atomic_random.cpp index b502e95d72..abd3d8a045 100644 --- a/source/module_psi/psi_initializer_atomic_random.cpp +++ b/source/module_psi/psi_initializer_atomic_random.cpp @@ -2,7 +2,7 @@ #ifdef __MPI template -void psi_initializer_atomic_random::initialize(Structure_Factor* sf, //< structure factor +void PsiInitializerAtomicRandom::initialize(Structure_Factor* sf, //< structure factor ModulePW::PW_Basis_K* pw_wfc, //< planewave basis UnitCell* p_ucell, //< unit cell Parallel_Kpoints* p_parakpts, //< parallel kpoints @@ -10,48 +10,50 @@ void psi_initializer_atomic_random::initialize(Structure_Factor* sf, pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - psi_initializer_atomic::initialize(sf, pw_wfc, p_ucell, p_parakpts, random_seed, p_pspot_nl, rank); + PsiInitializerAtomic::initialize(sf, pw_wfc, p_ucell, p_parakpts, random_seed, p_pspot_nl, rank); } #else template -void psi_initializer_atomic_random::initialize(Structure_Factor* sf, //< structure factor +void PsiInitializerAtomicRandom::initialize(Structure_Factor* sf, //< structure factor ModulePW::PW_Basis_K* pw_wfc, //< planewave basis UnitCell* p_ucell, //< unit cell const int& random_seed, //< random seed pseudopot_cell_vnl* p_pspot_nl) { - psi_initializer_atomic::initialize(sf, pw_wfc, p_ucell, random_seed, p_pspot_nl); + PsiInitializerAtomic::initialize(sf, pw_wfc, p_ucell, random_seed, p_pspot_nl); } #endif template -void psi_initializer_atomic_random::proj_ao_onkG(const int ik) +void PsiInitializerAtomicRandom::proj_ao_onkG(const int ik) { double rm = this->random_mix(); - const int ik_psig = (this->psig_->get_nk() == 1) ? 0 : ik; - this->psig_->fix_k(ik_psig); - psi_initializer_atomic::proj_ao_onkG(ik); - psi::Psi psi_random(1, this->psig_->get_nbands(), this->psig_->get_nbasis(), nullptr); + const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik; + this->d_psig_->fix_k(ik_psig); + PsiInitializerAtomic::proj_ao_onkG(ik); + psi::Psi psi_random(1, this->d_psig_->get_nbands(), this->d_psig_->get_nbasis(), nullptr); psi_random.fix_k(0); this->random_t(psi_random.get_pointer(), 0, psi_random.get_nbands(), ik); - for(int iband = 0; iband < this->psig_->get_nbands(); iband++) + + #pragma omp parallel for collapse(2) + for(int iband = 0; iband < this->d_psig_->get_nbands(); iband++) { - for(int ibasis = 0; ibasis < this->psig_->get_nbasis(); ibasis++) + for(int ibasis = 0; ibasis < this->d_psig_->get_nbasis(); ibasis++) { - (*(this->psig_))(iband, ibasis) = ((Real)(1-rm))*(*(this->psig_))(iband, ibasis) + ((Real)rm)*psi_random(iband, ibasis); + (*(this->d_psig_))(iband, ibasis) = ((Real)(1-rm))*(*(this->d_psig_))(iband, ibasis) + ((Real)rm)*psi_random(iband, ibasis); } } } -template class psi_initializer_atomic_random, base_device::DEVICE_CPU>; -template class psi_initializer_atomic_random, base_device::DEVICE_CPU>; +template class PsiInitializerAtomicRandom, base_device::DEVICE_CPU>; +template class PsiInitializerAtomicRandom, base_device::DEVICE_CPU>; // gamma point calculation -template class psi_initializer_atomic_random; -template class psi_initializer_atomic_random; +template class PsiInitializerAtomicRandom; +template class PsiInitializerAtomicRandom; #if ((defined __CUDA) || (defined __ROCM)) -template class psi_initializer_atomic_random, base_device::DEVICE_GPU>; -template class psi_initializer_atomic_random, base_device::DEVICE_GPU>; +template class PsiInitializerAtomicRandom, base_device::DEVICE_GPU>; +template class PsiInitializerAtomicRandom, base_device::DEVICE_GPU>; // gamma point calculation -template class psi_initializer_atomic_random; -template class psi_initializer_atomic_random; +template class PsiInitializerAtomicRandom; +template class PsiInitializerAtomicRandom; #endif diff --git a/source/module_psi/psi_initializer_atomic_random.h b/source/module_psi/psi_initializer_atomic_random.h index 88b2bcfb93..4d2c60e755 100644 --- a/source/module_psi/psi_initializer_atomic_random.h +++ b/source/module_psi/psi_initializer_atomic_random.h @@ -1,6 +1,6 @@ #ifndef PSI_INITIALIZER_ATOMIC_RANDOM_H #define PSI_INITIALIZER_ATOMIC_RANDOM_H -#include "psi_initializer_atomic.h" +#include "module_psi/psi_initializer_atomic.h" #include "module_hamilt_pw/hamilt_pwdft/VNL_in_pw.h" #include "module_cell/parallel_kpoints.h" @@ -8,16 +8,16 @@ Psi (planewave based wavefunction) initializer: atomic+random */ template -class psi_initializer_atomic_random : public psi_initializer_atomic +class PsiInitializerAtomicRandom : public PsiInitializerAtomic { private: using Real = typename GetTypeReal::type; public: - psi_initializer_atomic_random() {this->set_method("atomic+random"); this->set_random_mix(0.05);} - ~psi_initializer_atomic_random() {}; + PsiInitializerAtomicRandom() {this->set_method("atomic+random"); this->set_random_mix(0.05);} + ~PsiInitializerAtomicRandom() {}; #ifdef __MPI // MPI additional implementation - /// @brief initialize the psi_initializer with external data and methods + /// @brief initialize the PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -26,7 +26,7 @@ class psi_initializer_atomic_random : public psi_initializer_atomic pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential const int& = 0) override; //< MPI rank #else - /// @brief serial version of initialize function, link psi_initializer with external data and methods + /// @brief serial version of initialize function, link PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -35,7 +35,7 @@ class psi_initializer_atomic_random : public psi_initializer_atomic #endif virtual void proj_ao_onkG(const int ik) override; - virtual void tabulate() override {psi_initializer_atomic::tabulate();}; + virtual void tabulate() override {PsiInitializerAtomic::tabulate();}; private: }; diff --git a/source/module_psi/psi_initializer_nao.cpp b/source/module_psi/psi_initializer_nao.cpp index c2b0f83c04..9a894bdbcc 100644 --- a/source/module_psi/psi_initializer_nao.cpp +++ b/source/module_psi/psi_initializer_nao.cpp @@ -29,7 +29,7 @@ I don't know why some variables are distributed while others not... for example We need not only read and import, but also distribute here */ -// free function, not needed to be a member of psi_initializer_nao +// free function, not needed to be a member of PsiInitializerNAO void normalize(const std::vector& r, std::vector& flz) { std::vector flz2r2(r.size()); @@ -43,9 +43,9 @@ void normalize(const std::vector& r, std::vector& flz) } template -void psi_initializer_nao::read_external_orbs(std::string* orbital_files, const int& rank) +void PsiInitializerNAO::read_external_orbs(std::string* orbital_files, const int& rank) { - ModuleBase::timer::tick("psi_initializer_nao", "read_external_orbs"); + ModuleBase::timer::tick("PsiInitializerNAO", "read_external_orbs"); this->orbital_files_.resize(this->p_ucell_->ntype); this->nr_.resize(this->p_ucell_->ntype); @@ -75,14 +75,14 @@ void psi_initializer_nao::read_external_orbs(std::string* orbital_fil #endif if (!is_open) { - GlobalV::ofs_warning << "psi_initializer_nao::read_orbital_files: cannot open orbital file: " + GlobalV::ofs_warning << "PsiInitializerNAO::read_orbital_files: cannot open orbital file: " << this->orbital_files_[it] << std::endl; - ModuleBase::WARNING_QUIT("psi_initializer_nao::read_orbital_files", + ModuleBase::WARNING_QUIT("PsiInitializerNAO::read_orbital_files", "cannot open orbital file."); } else { - GlobalV::ofs_running << "psi_initializer_nao::read_orbital_files: reading orbital file: " + GlobalV::ofs_running << "PsiInitializerNAO::read_orbital_files: reading orbital file: " << this->orbital_files_[it] << std::endl; } std::string elem; // garbage value, will discard @@ -119,11 +119,11 @@ void psi_initializer_nao::read_external_orbs(std::string* orbital_fil std::copy(radials[ichi].begin(), radials[ichi].end(), this->chi_[it][ichi].begin()); } } - ModuleBase::timer::tick("psi_initializer_nao", "read_external_orbs"); + ModuleBase::timer::tick("PsiInitializerNAO", "read_external_orbs"); } template -void psi_initializer_nao::allocate_table() +void PsiInitializerNAO::allocate_table() { // find correct dimension for ovlp_flzjlq int ntype = this->p_ucell_->ntype; @@ -142,7 +142,7 @@ void psi_initializer_nao::allocate_table() } if (nzeta_max == 0) { - ModuleBase::WARNING_QUIT("psi_initializer_nao::psi_initializer_nao", + ModuleBase::WARNING_QUIT("PsiInitializerNAO::allocate_table", "there is not ANY numerical atomic orbital read in present system, quit."); } // allocate a map (it, l, izeta) -> i, should allocate memory of ntype * lmax * nzeta_max @@ -151,7 +151,7 @@ void psi_initializer_nao::allocate_table() #ifdef __MPI template -void psi_initializer_nao::initialize(Structure_Factor* sf, +void PsiInitializerNAO::initialize(Structure_Factor* sf, ModulePW::PW_Basis_K* pw_wfc, UnitCell* p_ucell, Parallel_Kpoints* p_parakpts, @@ -159,7 +159,7 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - ModuleBase::timer::tick("psi_initializer_nao", "initialize_mpi"); + ModuleBase::timer::tick("PsiInitializerNAO", "initialize_mpi"); // import this->sf_ = sf; @@ -177,17 +177,17 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, this->ixy2is_.clear(); this->ixy2is_.resize(this->pw_wfc_->fftnxy); this->pw_wfc_->getfftixy2is(this->ixy2is_.data()); - ModuleBase::timer::tick("psi_initializer_nao", "initialize_mpi"); + ModuleBase::timer::tick("PsiInitializerNAO", "initialize_mpi"); } #else template -void psi_initializer_nao::initialize(Structure_Factor* sf, +void PsiInitializerNAO::initialize(Structure_Factor* sf, ModulePW::PW_Basis_K* pw_wfc, UnitCell* p_ucell, const int& random_seed, pseudopot_cell_vnl* p_pspot_nl) { - ModuleBase::timer::tick("psi_initializer_nao", "initialize_serial"); + ModuleBase::timer::tick("PsiInitializerNAO", "initialize_serial"); // import this->sf_ = sf; @@ -204,14 +204,14 @@ void psi_initializer_nao::initialize(Structure_Factor* sf, this->ixy2is_.clear(); this->ixy2is_.resize(this->pw_wfc_->fftnxy); this->pw_wfc_->getfftixy2is(this->ixy2is_.data()); - ModuleBase::timer::tick("psi_initializer_nao", "initialize_serial"); + ModuleBase::timer::tick("PsiInitializerNAO", "initialize_serial"); } #endif template -void psi_initializer_nao::tabulate() +void PsiInitializerNAO::tabulate() { - ModuleBase::timer::tick("psi_initializer_nao", "tabulate"); + ModuleBase::timer::tick("PsiInitializerNAO", "tabulate"); // a uniformed qgrid std::vector qgrid(PARAM.globalv.nqx); @@ -258,16 +258,16 @@ void psi_initializer_nao::tabulate() } } } - ModuleBase::timer::tick("psi_initializer_nao", "tabulate"); + ModuleBase::timer::tick("PsiInitializerNAO", "tabulate"); } template -void psi_initializer_nao::proj_ao_onkG(const int ik) +void PsiInitializerNAO::proj_ao_onkG(const int ik) { - ModuleBase::timer::tick("psi_initializer_nao", "initialize"); + ModuleBase::timer::tick("PsiInitializerNAO", "initialize"); assert(ik >= 0); - const int ik_psig = (this->psig_->get_nk() == 1) ? 0 : ik; - this->psig_->fix_k(ik_psig); + const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik; + this->d_psig_->fix_k(ik_psig); const int npw = this->pw_wfc_->npwk[ik]; const int total_lm = (this->p_ucell_->lmax + 1) * (this->p_ucell_->lmax + 1); ModuleBase::matrix ylm(total_lm, npw); @@ -348,17 +348,17 @@ void psi_initializer_nao::proj_ao_onkG(const int ik) fdown = ModuleBase::IMAG_UNIT * sin(0.5 * alpha) * aux[ig]; // build the orthogonal wfc // first rotation with angle (alpha + ModuleBase::PI) around (OX) - (*(this->psig_))(ibasis, ig) = this->template cast_to_T( + (*(this->d_psig_))(ibasis, ig) = this->template cast_to_T( (cos(0.5 * gamma) + ModuleBase::IMAG_UNIT * sin(0.5 * gamma)) * fup); - (*(this->psig_))(ibasis, ig + this->pw_wfc_->npwk_max) + (*(this->d_psig_))(ibasis, ig + this->pw_wfc_->npwk_max) = this->template cast_to_T( (cos(0.5 * gamma) - ModuleBase::IMAG_UNIT * sin(0.5 * gamma)) * fdown); // second rotation with angle gamma around(OZ) fup = cos(0.5 * (alpha + ModuleBase::PI)) * aux[ig]; fdown = ModuleBase::IMAG_UNIT * sin(0.5 * (alpha + ModuleBase::PI)) * aux[ig]; - (*(this->psig_))(ibasis + 2 * L + 1, ig) = this->template cast_to_T( + (*(this->d_psig_))(ibasis + 2 * L + 1, ig) = this->template cast_to_T( (cos(0.5 * gamma) + ModuleBase::IMAG_UNIT * sin(0.5 * gamma)) * fup); - (*(this->psig_))(ibasis + 2 * L + 1, ig + this->pw_wfc_->npwk_max) + (*(this->d_psig_))(ibasis + 2 * L + 1, ig + this->pw_wfc_->npwk_max) = this->template cast_to_T( (cos(0.5 * gamma) - ModuleBase::IMAG_UNIT * sin(0.5 * gamma)) * fdown); } @@ -377,7 +377,7 @@ void psi_initializer_nao::proj_ao_onkG(const int ik) #pragma omp parallel for for (int ig = 0; ig < npw; ig++) { - (*(this->psig_))(ibasis, ig) + (*(this->d_psig_))(ibasis, ig) = this->template cast_to_T(lphase * sk[ig] * ylm(lm, ig) * Jlfq[ig]); } ++ibasis; @@ -392,20 +392,20 @@ void psi_initializer_nao::proj_ao_onkG(const int ik) /* complement the rest of bands if there are */ if (this->nbands_complem() > 0) { - this->random_t(this->psig_->get_pointer(), ibasis, this->psig_->get_nbands(), ik); + this->random_t(this->d_psig_->get_pointer(), ibasis, this->d_psig_->get_nbands(), ik); } - ModuleBase::timer::tick("psi_initializer_nao", "initialize"); + ModuleBase::timer::tick("PsiInitializerNAO", "initialize"); } -template class psi_initializer_nao, base_device::DEVICE_CPU>; -template class psi_initializer_nao, base_device::DEVICE_CPU>; +template class PsiInitializerNAO, base_device::DEVICE_CPU>; +template class PsiInitializerNAO, base_device::DEVICE_CPU>; // gamma point calculation -template class psi_initializer_nao; -template class psi_initializer_nao; +template class PsiInitializerNAO; +template class PsiInitializerNAO; #if ((defined __CUDA) || (defined __ROCM)) -template class psi_initializer_nao, base_device::DEVICE_GPU>; -template class psi_initializer_nao, base_device::DEVICE_GPU>; +template class PsiInitializerNAO, base_device::DEVICE_GPU>; +template class PsiInitializerNAO, base_device::DEVICE_GPU>; // gamma point calculation -template class psi_initializer_nao; -template class psi_initializer_nao; +template class PsiInitializerNAO; +template class PsiInitializerNAO; #endif diff --git a/source/module_psi/psi_initializer_nao.h b/source/module_psi/psi_initializer_nao.h index b7643d38d7..f9b625c4af 100644 --- a/source/module_psi/psi_initializer_nao.h +++ b/source/module_psi/psi_initializer_nao.h @@ -8,18 +8,18 @@ Psi (planewave based wavefunction) initializer: numerical atomic orbital method */ template -class psi_initializer_nao : public psi_initializer +class PsiInitializerNAO : public PsiInitializer { private: using Real = typename GetTypeReal::type; public: - psi_initializer_nao() {this->set_method("nao");}; - ~psi_initializer_nao() {}; + PsiInitializerNAO() {this->set_method("nao");}; + ~PsiInitializerNAO() {}; virtual void proj_ao_onkG(const int ik) override; #ifdef __MPI // MPI additional implementation - /// @brief initialize the psi_initializer with external data and methods + /// @brief initialize the PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -28,7 +28,7 @@ class psi_initializer_nao : public psi_initializer pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential const int& = 0) override; //< MPI rank #else - /// @brief serial version of initialize function, link psi_initializer with external data and methods + /// @brief serial version of initialize function, link PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell diff --git a/source/module_psi/psi_initializer_nao_random.cpp b/source/module_psi/psi_initializer_nao_random.cpp index 15f376fcd5..8a6418cfc6 100644 --- a/source/module_psi/psi_initializer_nao_random.cpp +++ b/source/module_psi/psi_initializer_nao_random.cpp @@ -1,8 +1,9 @@ #include "psi_initializer_nao_random.h" +#include "module_base/timer.h" #ifdef __MPI template -void psi_initializer_nao_random::initialize(Structure_Factor* sf, +void PsiInitializerNAORandom::initialize(Structure_Factor* sf, ModulePW::PW_Basis_K* pw_wfc, UnitCell* p_ucell, Parallel_Kpoints* p_parakpts, @@ -10,48 +11,50 @@ void psi_initializer_nao_random::initialize(Structure_Factor* sf, pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - psi_initializer_nao::initialize(sf, pw_wfc, p_ucell, p_parakpts, random_seed, p_pspot_nl, rank); + PsiInitializerNAO::initialize(sf, pw_wfc, p_ucell, p_parakpts, random_seed, p_pspot_nl, rank); } #else template -void psi_initializer_nao_random::initialize(Structure_Factor* sf, +void PsiInitializerNAORandom::initialize(Structure_Factor* sf, ModulePW::PW_Basis_K* pw_wfc, UnitCell* p_ucell, const int& random_seed, pseudopot_cell_vnl* p_pspot_nl) { - psi_initializer_nao::initialize(sf, pw_wfc, p_ucell, random_seed, p_pspot_nl); + PsiInitializerNAO::initialize(sf, pw_wfc, p_ucell, random_seed, p_pspot_nl); } #endif template -void psi_initializer_nao_random::proj_ao_onkG(const int ik) +void PsiInitializerNAORandom::proj_ao_onkG(const int ik) { + ModuleBase::timer::tick("PsiInitializerNAORandom", "proj_ao_onkG"); double rm = this->random_mix(); - const int ik_psig = (this->psig_->get_nk() == 1) ? 0 : ik; - this->psig_->fix_k(ik_psig); - psi_initializer_nao::proj_ao_onkG(ik); - psi::Psi psi_random(1, this->psig_->get_nbands(), this->psig_->get_nbasis(), nullptr); + const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik; + this->d_psig_->fix_k(ik_psig); + PsiInitializerNAO::proj_ao_onkG(ik); + psi::Psi psi_random(1, this->d_psig_->get_nbands(), this->d_psig_->get_nbasis(), nullptr); psi_random.fix_k(0); this->random_t(psi_random.get_pointer(), 0, psi_random.get_nbands(), ik); - for(int iband = 0; iband < this->psig_->get_nbands(); iband++) + for(int iband = 0; iband < this->d_psig_->get_nbands(); iband++) { - for(int ibasis = 0; ibasis < this->psig_->get_nbasis(); ibasis++) + for(int ibasis = 0; ibasis < this->d_psig_->get_nbasis(); ibasis++) { - (*(this->psig_))(iband, ibasis) = ((Real)(1-rm))*(*(this->psig_))(iband, ibasis) + ((Real)rm)*psi_random(iband, ibasis); + (*(this->d_psig_))(iband, ibasis) = ((Real)(1-rm))*(*(this->d_psig_))(iband, ibasis) + ((Real)rm)*psi_random(iband, ibasis); } } + ModuleBase::timer::tick("PsiInitializerNAORandom", "proj_ao_onkG"); } -template class psi_initializer_nao_random, base_device::DEVICE_CPU>; -template class psi_initializer_nao_random, base_device::DEVICE_CPU>; +template class PsiInitializerNAORandom, base_device::DEVICE_CPU>; +template class PsiInitializerNAORandom, base_device::DEVICE_CPU>; // gamma point calculation -template class psi_initializer_nao_random; -template class psi_initializer_nao_random; +template class PsiInitializerNAORandom; +template class PsiInitializerNAORandom; #if ((defined __CUDA) || (defined __ROCM)) -template class psi_initializer_nao_random, base_device::DEVICE_GPU>; -template class psi_initializer_nao_random, base_device::DEVICE_GPU>; +template class PsiInitializerNAORandom, base_device::DEVICE_GPU>; +template class PsiInitializerNAORandom, base_device::DEVICE_GPU>; // gamma point calculation -template class psi_initializer_nao_random; -template class psi_initializer_nao_random; +template class PsiInitializerNAORandom; +template class PsiInitializerNAORandom; #endif \ No newline at end of file diff --git a/source/module_psi/psi_initializer_nao_random.h b/source/module_psi/psi_initializer_nao_random.h index 8fd6edb4c6..e54b238da1 100644 --- a/source/module_psi/psi_initializer_nao_random.h +++ b/source/module_psi/psi_initializer_nao_random.h @@ -8,16 +8,16 @@ Psi (planewave based wavefunction) initializer: numerical atomic orbital + random method */ template -class psi_initializer_nao_random : public psi_initializer_nao +class PsiInitializerNAORandom : public PsiInitializerNAO { private: using Real = typename GetTypeReal::type; public: - psi_initializer_nao_random() {this->set_method("nao+random"); this->set_random_mix(0.05);}; - ~psi_initializer_nao_random() {}; + PsiInitializerNAORandom() {this->set_method("nao+random"); this->set_random_mix(0.05);}; + ~PsiInitializerNAORandom() {}; #ifdef __MPI // MPI additional implementation - /// @brief initialize the psi_initializer with external data and methods + /// @brief initialize the PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -26,7 +26,7 @@ class psi_initializer_nao_random : public psi_initializer_nao pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential const int& = 0) override; //< MPI rank #else - /// @brief serial version of initialize function, link psi_initializer with external data and methods + /// @brief serial version of initialize function, link PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -35,6 +35,6 @@ class psi_initializer_nao_random : public psi_initializer_nao #endif virtual void proj_ao_onkG(const int ik) override; - virtual void tabulate() override {psi_initializer_nao::tabulate();}; + virtual void tabulate() override {PsiInitializerNAO::tabulate();}; }; #endif \ No newline at end of file diff --git a/source/module_psi/psi_initializer_random.cpp b/source/module_psi/psi_initializer_random.cpp index fcabca18fc..f46a7b4f11 100644 --- a/source/module_psi/psi_initializer_random.cpp +++ b/source/module_psi/psi_initializer_random.cpp @@ -9,7 +9,7 @@ #ifdef __MPI template -void psi_initializer_random::initialize(Structure_Factor* sf, +void PsiInitializerRandom::initialize(Structure_Factor* sf, ModulePW::PW_Basis_K* pw_wfc, UnitCell* p_ucell, Parallel_Kpoints* p_parakpts, @@ -28,7 +28,7 @@ void psi_initializer_random::initialize(Structure_Factor* sf, } #else template -void psi_initializer_random::initialize(Structure_Factor* sf, +void PsiInitializerRandom::initialize(Structure_Factor* sf, ModulePW::PW_Basis_K* pw_wfc, UnitCell* p_ucell, const int& random_seed, @@ -45,35 +45,35 @@ void psi_initializer_random::initialize(Structure_Factor* sf, #endif template -void psi_initializer_random::random(T* psi, +void PsiInitializerRandom::random(T* psi, const int iw_start, const int iw_end, const int ik) { - ModuleBase::timer::tick("psi_initializer_random", "random"); + ModuleBase::timer::tick("PsiInitializerRandom", "random"); this->random_t(psi, iw_start, iw_end, ik); - ModuleBase::timer::tick("psi_initializer_random", "random"); + ModuleBase::timer::tick("PsiInitializerRandom", "random"); } template -void psi_initializer_random::proj_ao_onkG(const int ik) +void PsiInitializerRandom::proj_ao_onkG(const int ik) { - ModuleBase::timer::tick("psi_initializer_random", "initialize"); - const int ik_psig = (this->psig_->get_nk() == 1) ? 0 : ik; - this->psig_->fix_k(ik_psig); - this->random(this->psig_->get_pointer(), 0, this->psig_->get_nbands(), ik); - ModuleBase::timer::tick("psi_initializer_random", "initialize"); + ModuleBase::timer::tick("PsiInitializerRandom", "initialize"); + const int ik_psig = (this->d_psig_->get_nk() == 1) ? 0 : ik; + this->d_psig_->fix_k(ik_psig); + this->random(this->d_psig_->get_pointer(), 0, this->d_psig_->get_nbands(), ik); + ModuleBase::timer::tick("PsiInitializerRandom", "initialize"); } -template class psi_initializer_random, base_device::DEVICE_CPU>; -template class psi_initializer_random, base_device::DEVICE_CPU>; +template class PsiInitializerRandom, base_device::DEVICE_CPU>; +template class PsiInitializerRandom, base_device::DEVICE_CPU>; // gamma point calculation -template class psi_initializer_random; -template class psi_initializer_random; +template class PsiInitializerRandom; +template class PsiInitializerRandom; #if ((defined __CUDA) || (defined __ROCM)) -template class psi_initializer_random, base_device::DEVICE_GPU>; -template class psi_initializer_random, base_device::DEVICE_GPU>; +template class PsiInitializerRandom, base_device::DEVICE_GPU>; +template class PsiInitializerRandom, base_device::DEVICE_GPU>; // gamma point calculation -template class psi_initializer_random; -template class psi_initializer_random; +template class PsiInitializerRandom; +template class PsiInitializerRandom; #endif \ No newline at end of file diff --git a/source/module_psi/psi_initializer_random.h b/source/module_psi/psi_initializer_random.h index 39707a303c..e107cf68b3 100644 --- a/source/module_psi/psi_initializer_random.h +++ b/source/module_psi/psi_initializer_random.h @@ -8,13 +8,13 @@ Psi (planewave based wavefunction) initializer: random method */ template -class psi_initializer_random : public psi_initializer +class PsiInitializerRandom : public PsiInitializer { private: using Real = typename GetTypeReal::type; public: - psi_initializer_random() {this->set_method("random");}; - ~psi_initializer_random() {}; + PsiInitializerRandom() {this->set_method("random");}; + ~PsiInitializerRandom() {}; /// @brief write random number to psi in certain range specified by ik, iw_start, iw_end void random(T* psi, //< psi const int iw_start, //< iw_start, starting band index of present kpoint @@ -25,7 +25,7 @@ class psi_initializer_random : public psi_initializer /// @return initialized planewave wavefunction (psi::Psi>*) virtual void proj_ao_onkG(const int ik) override; #ifdef __MPI // MPI additional implementation - /// @brief initialize the psi_initializer with external data and methods + /// @brief initialize the PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell @@ -34,7 +34,7 @@ class psi_initializer_random : public psi_initializer pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential const int& = 0) override; //< MPI rank #else - /// @brief serial version of initialize function, link psi_initializer with external data and methods + /// @brief serial version of initialize function, link PsiInitializer with external data and methods virtual void initialize(Structure_Factor*, //< structure factor ModulePW::PW_Basis_K*, //< planewave basis UnitCell*, //< unit cell diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index bad2bfcca0..08be55b457 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -15,8 +15,8 @@ psi initializer unit test ========================= - Tested functions: - - psi_initializer_random::psi_initializer_random - - constructor of psi_initializer_random + - PsiInitializerRandom::psi_initializer_random + - constructor of PsiInitializerRandom - psi_initializer_atomic::psi_initializer_atomic - constructor of psi_initializer_atomic - psi_initializer_atomic_random::psi_initializer_atomic_random @@ -27,7 +27,7 @@ psi initializer unit test - constructor of psi_initializer_nao_random - psi_initializer::cast_to_T (psi_initializer specialized as random) - function cast std::complex to float, double, std::complex, std::complex - - psi_initializer_random::allocate + - PsiInitializerRandom::allocate - allocate wavefunctions with random-specific method - psi_initializer_atomic::allocate - allocate wavefunctions with atomic-specific method @@ -37,7 +37,7 @@ psi initializer unit test - allocate wavefunctions with nao-specific method - psi_initializer_nao_random::allocate - allocate wavefunctions with nao-specific method - - psi_initializer_random::proj_ao_onkG + - PsiInitializerRandom::proj_ao_onkG - calculate wavefunction initial guess (before diagonalization) by randomly generating numbers - psi_initializer_atomic::proj_ao_onkG - calculate wavefunction initial guess (before diagonalization) with atomic pseudo wavefunctions @@ -100,7 +100,7 @@ class PsiIntializerUnitTest : public ::testing::Test { #endif int random_seed = 1; - psi_initializer, base_device::DEVICE_CPU>* psi_init; + PsiInitializer, base_device::DEVICE_CPU>* psi_init; private: protected: @@ -278,32 +278,32 @@ class PsiIntializerUnitTest : public ::testing::Test { }; TEST_F(PsiIntializerUnitTest, ConstructorRandom) { - this->psi_init = new psi_initializer_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAORandom, base_device::DEVICE_CPU>(); EXPECT_EQ("random", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorAtomic) { - this->psi_init = new psi_initializer_atomic, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomic, base_device::DEVICE_CPU>(); EXPECT_EQ("atomic", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorAtomicRandom) { - this->psi_init = new psi_initializer_atomic_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomicRandom, base_device::DEVICE_CPU>(); EXPECT_EQ("atomic+random", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorNao) { - this->psi_init = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAO, base_device::DEVICE_CPU>(); EXPECT_EQ("nao", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, ConstructorNaoRandom) { - this->psi_init = new psi_initializer_nao_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAORandom, base_device::DEVICE_CPU>(); EXPECT_EQ("nao+random", this->psi_init->method()); } TEST_F(PsiIntializerUnitTest, CastToT) { - this->psi_init = new psi_initializer_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerRandom, base_device::DEVICE_CPU>(); std::complex cd = {1.0, 2.0}; std::complex cf = {1.0, 2.0}; double d = 1.0; @@ -316,7 +316,7 @@ TEST_F(PsiIntializerUnitTest, CastToT) { TEST_F(PsiIntializerUnitTest, AllocateRandom) { PARAM.input.init_wfc = "random"; - this->psi_init = new psi_initializer_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerRandom, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -338,7 +338,8 @@ TEST_F(PsiIntializerUnitTest, AllocateRandom) { EXPECT_EQ(1, psi->get_nk()); EXPECT_EQ(1, psi->get_nbands()); EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_init->share_psig().lock(); + // auto psig = this->psi_init->share_psig().lock(); + auto psig = this->psi_init->share_psig(); EXPECT_EQ(1, psig->get_nk()); EXPECT_EQ(1, psig->get_nbands()); EXPECT_EQ(1, psig->get_nbasis()); @@ -347,7 +348,7 @@ TEST_F(PsiIntializerUnitTest, AllocateRandom) { TEST_F(PsiIntializerUnitTest, AllocateAtomic) { PARAM.input.init_wfc = "atomic"; - this->psi_init = new psi_initializer_atomic, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomic, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -369,7 +370,8 @@ TEST_F(PsiIntializerUnitTest, AllocateAtomic) { EXPECT_EQ(1, psi->get_nk()); EXPECT_EQ(1, psi->get_nbands()); EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_init->share_psig().lock(); + // auto psig = this->psi_init->share_psig().lock(); + auto psig = this->psi_init->share_psig(); EXPECT_EQ(1, psig->get_nk()); EXPECT_EQ(4, psig->get_nbands()); EXPECT_EQ(1, psig->get_nbasis()); @@ -378,7 +380,7 @@ TEST_F(PsiIntializerUnitTest, AllocateAtomic) { TEST_F(PsiIntializerUnitTest, AllocateAtomicRandom) { PARAM.input.init_wfc = "atomic+random"; - this->psi_init = new psi_initializer_atomic_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomicRandom, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -400,7 +402,8 @@ TEST_F(PsiIntializerUnitTest, AllocateAtomicRandom) { EXPECT_EQ(1, psi->get_nk()); EXPECT_EQ(1, psi->get_nbands()); EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_init->share_psig().lock(); + // auto psig = this->psi_init->share_psig().lock(); + auto psig = this->psi_init->share_psig(); EXPECT_EQ(1, psig->get_nk()); EXPECT_EQ(4, psig->get_nbands()); EXPECT_EQ(1, psig->get_nbasis()); @@ -409,7 +412,7 @@ TEST_F(PsiIntializerUnitTest, AllocateAtomicRandom) { TEST_F(PsiIntializerUnitTest, AllocateNao) { PARAM.input.init_wfc = "nao"; - this->psi_init = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAO, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -431,7 +434,8 @@ TEST_F(PsiIntializerUnitTest, AllocateNao) { EXPECT_EQ(1, psi->get_nk()); EXPECT_EQ(1, psi->get_nbands()); EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_init->share_psig().lock(); + // auto psig = this->psi_init->share_psig().lock(); + auto psig = this->psi_init->share_psig(); EXPECT_EQ(1, psig->get_nk()); EXPECT_EQ(13, psig->get_nbands()); EXPECT_EQ(1, psig->get_nbasis()); @@ -440,7 +444,7 @@ TEST_F(PsiIntializerUnitTest, AllocateNao) { TEST_F(PsiIntializerUnitTest, AllocateNaoRandom) { PARAM.input.init_wfc = "nao+random"; - this->psi_init = new psi_initializer_nao_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAORandom, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -462,7 +466,8 @@ TEST_F(PsiIntializerUnitTest, AllocateNaoRandom) { EXPECT_EQ(1, psi->get_nk()); EXPECT_EQ(1, psi->get_nbands()); EXPECT_EQ(1, psi->get_nbasis()); - auto psig = this->psi_init->share_psig().lock(); + // auto psig = this->psi_init->share_psig().lock(); + auto psig = this->psi_init->share_psig(); EXPECT_EQ(1, psig->get_nk()); EXPECT_EQ(13, psig->get_nbands()); EXPECT_EQ(1, psig->get_nbasis()); @@ -471,7 +476,7 @@ TEST_F(PsiIntializerUnitTest, AllocateNaoRandom) { TEST_F(PsiIntializerUnitTest, CalPsigRandom) { PARAM.input.init_wfc = "random"; - this->psi_init = new psi_initializer_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerRandom, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -496,7 +501,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigRandom) { TEST_F(PsiIntializerUnitTest, CalPsigAtomic) { PARAM.input.init_wfc = "atomic"; - this->psi_init = new psi_initializer_atomic, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomic, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -525,7 +530,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSoc) { PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = false; this->p_ucell->natomwfc *= 2; - this->psi_init = new psi_initializer_atomic, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomic, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -558,7 +563,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { PARAM.sys.npol = 2; this->p_ucell->atoms[0].ncpp.has_so = true; this->p_ucell->natomwfc *= 2; - this->psi_init = new psi_initializer_atomic, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomic, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -587,7 +592,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { TEST_F(PsiIntializerUnitTest, CalPsigAtomicRandom) { PARAM.input.init_wfc = "atomic+random"; - this->psi_init = new psi_initializer_atomic_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerAtomicRandom, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -612,7 +617,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicRandom) { TEST_F(PsiIntializerUnitTest, CalPsigNao) { PARAM.input.init_wfc = "nao"; - this->psi_init = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAO, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -637,7 +642,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNao) { TEST_F(PsiIntializerUnitTest, CalPsigNaoRandom) { PARAM.input.init_wfc = "nao+random"; - this->psi_init = new psi_initializer_nao_random, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAORandom, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -667,7 +672,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSoc) { this->p_ucell->atoms[0].ncpp.has_so = false; PARAM.sys.domag = false; PARAM.sys.domag_z = false; - this->psi_init = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAO, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -697,7 +702,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSo) { this->p_ucell->atoms[0].ncpp.has_so = true; PARAM.sys.domag = false; PARAM.sys.domag_z = false; - this->psi_init = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAO, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, @@ -727,7 +732,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSoDOMAG) { this->p_ucell->atoms[0].ncpp.has_so = true; PARAM.sys.domag = true; PARAM.sys.domag_z = false; - this->psi_init = new psi_initializer_nao, base_device::DEVICE_CPU>(); + this->psi_init = new PsiInitializerNAO, base_device::DEVICE_CPU>(); #ifdef __MPI this->psi_init->initialize(this->p_sf, this->p_pw_wfc, diff --git a/source/module_ri/exx_lip.hpp b/source/module_ri/exx_lip.hpp index 94689f5167..5ab81a49c4 100644 --- a/source/module_ri/exx_lip.hpp +++ b/source/module_ri/exx_lip.hpp @@ -216,7 +216,7 @@ void Exx_Lip::phi_cal(k_package* kq_pack, const int ikq) for (int iw = 0; iw < PARAM.globalv.nlocal; ++iw) { // this->wfc_basis->recip2real(&kq_pack->wf_ptr->wanf2[ikq](iw,0), porter.data(), ikq); - this->wfc_basis->recip2real(&(kq_pack->wf_ptr->get_psig().lock()->operator()(ikq, iw, 0)), porter.data(), ikq); + this->wfc_basis->recip2real(&(kq_pack->wf_ptr->get_psig()->operator()(ikq, iw, 0)), porter.data(), ikq); int ir = 0; for (int ix = 0; ix < this->rho_basis->nx; ++ix) {