Skip to content

Commit

Permalink
Remove init_basis_lcao from ESolver_LCAO to LCAO_domain (#4746)
Browse files Browse the repository at this point in the history
* Build: manually link MKL scalapack in absence

* add message output

* set message type for finding elpa

* Add scalapack setup for standard MKL config

* move init_basis_lcao from ESolver_LCAO to LCAO_domain namespace

* fix some remaining bugs

* fix bug when compiling with exx

---------

Co-authored-by: caic99 <[email protected]>
  • Loading branch information
mohanchen and caic99 authored Jul 21, 2024
1 parent b0872a7 commit d6d9636
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 86 deletions.
1 change: 1 addition & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ OBJS_LCAO=evolve_elec.o\
LCAO_set_zero.o\
LCAO_allocate.o\
LCAO_set_mat2d.o\
LCAO_init_basis.o\
center2_orb.o\
center2_orb-orb11.o\
center2_orb-orb21.o\
Expand Down
90 changes: 8 additions & 82 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
// 3) init LCAO basis
// reading the localized orbitals/projectors
// construct the interpolation tables.
this->init_basis_lcao(inp, ucell);
LCAO_domain::init_basis_lcao(this->ParaV,
inp.onsite_radius,
inp.lcao_ecut,
inp.lcao_dk,
inp.lcao_dr,
inp.lcao_rmax,
ucell,
two_center_bundle_);
//------------------init Basis_lcao----------------------

// 5) initialize density matrix
Expand Down Expand Up @@ -517,87 +524,6 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners()
ModuleBase::timer::tick("ESolver_KS_LCAO", "after_all_runners");
}

//------------------------------------------------------------------------------
//! the 9th function of ESolver_KS_LCAO: init_basis_lcao
//! mohan add 2024-05-11
//------------------------------------------------------------------------------
template <typename TK, typename TR>
void ESolver_KS_LCAO<TK, TR>::init_basis_lcao(const Input_para& inp, UnitCell& ucell)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "init_basis_lcao");

// autoset NB2D first
if (GlobalV::NB2D == 0)
{
if (GlobalV::NLOCAL > 0)
{
GlobalV::NB2D = (GlobalV::NSPIN == 4) ? 2 : 1;
}
if (GlobalV::NLOCAL > 500)
{
GlobalV::NB2D = 32;
}
if (GlobalV::NLOCAL > 1000)
{
GlobalV::NB2D = 64;
}
}

// * reading the localized orbitals/projectors
// * construct the interpolation tables.

two_center_bundle_.build_orb(ucell.ntype, ucell.orbital_fn);
two_center_bundle_.build_alpha(GlobalV::deepks_setorb, &ucell.descriptor_file);
two_center_bundle_.build_orb_onsite(PARAM.inp.onsite_radius);
// currently deepks only use one descriptor file, so cast bool to int is
// fine

// TODO Due to the omnipresence of GlobalC::ORB, we still have to rely
// on the old interface for now.
two_center_bundle_.to_LCAO_Orbitals(GlobalC::ORB, inp.lcao_ecut, inp.lcao_dk, inp.lcao_dr, inp.lcao_rmax);

ucell.infoNL.setupNonlocal(ucell.ntype, ucell.atoms, GlobalV::ofs_running, GlobalC::ORB);

two_center_bundle_.build_beta(ucell.ntype, ucell.infoNL.Beta);

int Lmax = 0;
#ifdef __EXX
Lmax = GlobalC::exx_info.info_ri.abfs_Lmax;
#endif

#ifdef USE_NEW_TWO_CENTER
two_center_bundle_.tabulate();
#else
two_center_bundle_.tabulate(inp.lcao_ecut, inp.lcao_dk, inp.lcao_dr, inp.lcao_rmax);
#endif

// setup_2d_division
#ifdef __MPI
// storage form of H and S matrices on each processor
// is determined in 'divide_HS_2d' subroutine

int try_nb = ParaV.init(GlobalV::NLOCAL, GlobalV::NLOCAL, GlobalV::NB2D, DIAG_WORLD);
try_nb += ParaV.set_nloc_wfc_Eij(GlobalV::NBANDS, GlobalV::ofs_running, GlobalV::ofs_warning);
if (try_nb != 0)
{
ParaV.set(GlobalV::NLOCAL, GlobalV::NLOCAL, 1, ParaV.blacs_ctxt);
try_nb = ParaV.set_nloc_wfc_Eij(GlobalV::NBANDS, GlobalV::ofs_running, GlobalV::ofs_warning);
}

// init blacs context for genelpa
ParaV.set_desc_wfc_Eij(GlobalV::NLOCAL, GlobalV::NBANDS, ParaV.nrow);

#else
ParaV.set_serial(GlobalV::NLOCAL, GlobalV::NLOCAL);
ParaV.nrow_bands = GlobalV::NLOCAL;
ParaV.ncol_bands = GlobalV::NBANDS;
// Zhang Xiaoyang enable the serial version of LCAO and recovered this function usage. 2024-07-06
#endif

ParaV.set_atomic_trace(GlobalC::ucell.get_iat2iwt(), GlobalC::ucell.nat, GlobalV::NLOCAL);

return;
}

//------------------------------------------------------------------------------
//! the 10th function of ESolver_KS_LCAO: iter_init
Expand Down
4 changes: 1 addition & 3 deletions source/module_esolver/esolver_ks_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
ModuleBase::matrix scs;
bool have_force = false;

void init_basis_lcao(const Input_para& inp, UnitCell& ucell);

//--------------common for all calculation, not only scf-------------
// set matrix and grid integral
void set_matrix_grid(Record_adj& ra);
Expand Down Expand Up @@ -129,4 +127,4 @@ class ESolver_KS_LCAO : public ESolver_KS<TK> {
friend class LR::ESolver_LR<std::complex<double>, double>;
};
} // namespace ModuleESolver
#endif
#endif
9 changes: 8 additions & 1 deletion source/module_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell&
}

// 4) read the local orbitals and construct the interpolation tables.
this->init_basis_lcao(inp, ucell);
LCAO_domain::init_basis_lcao(this->ParaV,
inp.onsite_radius,
inp.lcao_ecut,
inp.lcao_dk,
inp.lcao_dr,
inp.lcao_rmax,
ucell,
two_center_bundle_);

// 5) allocate H and S matrices according to computational resources
LCAO_domain::divide_HS_in_frag(GlobalV::GAMMA_ONLY_LOCAL, ParaV, kv.get_nks());
Expand Down
1 change: 1 addition & 0 deletions source/module_hamilt_lcao/hamilt_lcaodft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if(ENABLE_LCAO)
LCAO_set_zero.cpp
LCAO_allocate.cpp
LCAO_set_mat2d.cpp
LCAO_init_basis.cpp
record_adj.cpp
center2_orb.cpp
center2_orb-orb11.cpp
Expand Down
10 changes: 10 additions & 0 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
namespace LCAO_domain
{

void init_basis_lcao(Parallel_Orbitals& pv,
const double &onsite_radius,
const double &lcao_ecut,
const double &lcao_dk,
const double &lcao_dr,
const double &lcao_rmax,
UnitCell& ucell,
TwoCenterBundle& two_center_bundle);


void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,
ForceStressArrays& fsr, // mohan 2024-06-16
double* HlocR,
Expand Down
98 changes: 98 additions & 0 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_init_basis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "LCAO_domain.h"

/// once the GlobalC::exx_info has been deleted, this include can be gone
/// mohan note 2024-07-21
#ifdef __EXX
#include "module_hamilt_pw/hamilt_pwdft/global.h"
#endif

namespace LCAO_domain
{

void init_basis_lcao(Parallel_Orbitals& pv,
const double &onsite_radius,
const double &lcao_ecut,
const double &lcao_dk,
const double &lcao_dr,
const double &lcao_rmax,
UnitCell& ucell,
TwoCenterBundle& two_center_bundle)
{
ModuleBase::TITLE("ESolver_KS_LCAO", "init_basis_lcao");

const int nlocal = GlobalV::NLOCAL;

// autoset NB2D first
if (GlobalV::NB2D == 0)
{
if (nlocal > 0)
{
GlobalV::NB2D = (GlobalV::NSPIN == 4) ? 2 : 1;
}
if (nlocal > 500)
{
GlobalV::NB2D = 32;
}
if (nlocal > 1000)
{
GlobalV::NB2D = 64;
}
}

// * reading the localized orbitals/projectors
// * construct the interpolation tables.

two_center_bundle.build_orb(ucell.ntype, ucell.orbital_fn);
two_center_bundle.build_alpha(GlobalV::deepks_setorb, &ucell.descriptor_file);
two_center_bundle.build_orb_onsite(onsite_radius);
// currently deepks only use one descriptor file, so cast bool to int is
// fine

// TODO Due to the omnipresence of GlobalC::ORB, we still have to rely
// on the old interface for now.
two_center_bundle.to_LCAO_Orbitals(GlobalC::ORB, lcao_ecut, lcao_dk, lcao_dr, lcao_rmax);

ucell.infoNL.setupNonlocal(ucell.ntype, ucell.atoms, GlobalV::ofs_running, GlobalC::ORB);

two_center_bundle.build_beta(ucell.ntype, ucell.infoNL.Beta);

int Lmax = 0;
#ifdef __EXX
Lmax = GlobalC::exx_info.info_ri.abfs_Lmax;
#endif

#ifdef USE_NEW_TWO_CENTER
two_center_bundle.tabulate();
#else
two_center_bundle.tabulate(lcao_ecut, lcao_dk, lcao_dr, lcao_rmax);
#endif

// setup_2d_division
#ifdef __MPI
// storage form of H and S matrices on each processor
// is determined in 'divide_HS_2d' subroutine

int try_nb = pv.init(nlocal, nlocal, GlobalV::NB2D, DIAG_WORLD);
try_nb += pv.set_nloc_wfc_Eij(GlobalV::NBANDS, GlobalV::ofs_running, GlobalV::ofs_warning);
if (try_nb != 0)
{
pv.set(nlocal, nlocal, 1, pv.blacs_ctxt);
try_nb = pv.set_nloc_wfc_Eij(GlobalV::NBANDS, GlobalV::ofs_running, GlobalV::ofs_warning);
}

// init blacs context for genelpa
pv.set_desc_wfc_Eij(nlocal, GlobalV::NBANDS, pv.nrow);

#else
pv.set_serial(nlocal, nlocal);
pv.nrow_bands = nlocal;
pv.ncol_bands = GlobalV::NBANDS;
// Zhang Xiaoyang enable the serial version of LCAO and recovered this function usage. 2024-07-06
#endif

pv.set_atomic_trace(ucell.get_iat2iwt(), ucell.nat, nlocal);

return;
}

}
4 changes: 4 additions & 0 deletions source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
#include "module_base/timer.h"
#include "module_hamilt_lcao/module_dftu/dftu.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h"

#ifdef __DEEPKS
#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h"
#include "operator_lcao/deepks_lcao.h"
#endif

#ifdef __EXX
#include "module_ri/Exx_LRI_interface.h"
#include "operator_lcao/op_exx_lcao.h"
#endif

#ifdef __ELPA
#include "module_hsolver/diago_elpa.h"
#endif

#include "module_elecstate/potentials/H_TDDFT_pw.h"
#include "module_hamilt_general/module_xc/xc_functional.h"
#include "module_hamilt_lcao/module_hcontainer/hcontainer_funcs.h"
Expand Down

0 comments on commit d6d9636

Please sign in to comment.