Skip to content

Commit

Permalink
fix mpi
Browse files Browse the repository at this point in the history
add input test

small fixes
  • Loading branch information
maki49 committed Jul 14, 2024
1 parent fe08bd1 commit da7b659
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion source/module_esolver/esolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ ESolver* init_esolver(Input& input, const Input_para& input_para, UnitCell& ucel
// they will be supported after the analytical gradient
// of LR-TDDFT is implemented.
// after_all_runners() is for output, it is not needed here.
std::cout << "Setting up the esolver for excited state..." << std::endl;
std::cout << "Setting up the esolver for excited states..." << std::endl;
// initialize the 2nd ESolver_LR at the temporary pointer
ModuleESolver::ESolver* p_esolver_lr = nullptr;
if (GlobalV::GAMMA_ONLY_LOCAL)
Expand Down
10 changes: 10 additions & 0 deletions source/module_io/test/read_input_ptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ TEST_F(InputParaTest, ParaRead)
EXPECT_DOUBLE_EQ(param.inp.alpha_trial, 0.02);
EXPECT_DOUBLE_EQ(param.inp.sccut, 4.0);
EXPECT_EQ(param.inp.sc_file, "sc.json");
EXPECT_EQ(param.inp.lr_nstates, 1);
EXPECT_EQ(param.inp.nocc, param.inp.nbands);
EXPECT_EQ(param.inp.nvirt, 1);
EXPECT_EQ(param.inp.xc_kernel, "LDA");
EXPECT_EQ(param.inp.lr_solver, "dav");
EXPECT_DOUBLE_EQ(param.inp.lr_thr, 1e-2);
EXPECT_FALSE(param.inp.out_wfc_lr);
EXPECT_EQ(param.inp.abs_wavelen_range.size(), 2);
EXPECT_DOUBLE_EQ(param.inp.abs_wavelen_range[0], 0.0);
EXPECT_DOUBLE_EQ(param.inp.abs_broadening, 0.01);
}

TEST_F(InputParaTest, Check)
Expand Down
11 changes: 11 additions & 0 deletions source/module_io/test_serial/read_input_item_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,4 +1637,15 @@ TEST_F(InputTest, Item_test)
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("NOTICE"));
}
{ // nocc
auto it = find_lable("nocc", readinput.input_lists);
param.input.nocc = 5;
param.input.nbands = 4;
param.input.nelec = 0.0;
it->second.reset_value(it->second, param);
EXPECT_EQ(param.input.nocc, 4);
param.input.nocc = 0;
it->second.reset_value(it->second, param);
EXPECT_EQ(param.input.nocc, 4);
}
}
46 changes: 31 additions & 15 deletions source/module_lr/esolver_lrtd_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,20 @@ LR::ESolver_LR<T, TR>::ESolver_LR(ModuleESolver::ESolver_KS_LCAO<T, TR>&& ks_sol
this->paraMat_.atom_begin_col = std::move(ks_sol.ParaV.atom_begin_col);
this->paraMat_.iat2iwt_ = ucell.get_iat2iwt();

LR_Util::setup_2d_division(this->paraC_, 1, this->nbasis, this->nbands, this->paraMat_.blacs_ctxt);

if (this->nbands == GlobalV::NBANDS) // move the ground state info
{
this->psi_ks = ks_sol.psi;
ks_sol.psi = nullptr;
//only need the eigenvalues. the 'elecstates' of excited states is different from ground state.
this->eig_ks = std::move(ks_sol.pelec->ekb);
}
LR_Util::setup_2d_division(this->paraC_, 1, this->nbasis, this->nbands
#ifdef __MPI
, this->paraMat_.blacs_ctxt
#endif
);
auto move_gs = [&, this]() -> void // move the ground state info
{
this->psi_ks = ks_sol.psi;
ks_sol.psi = nullptr;
//only need the eigenvalues. the 'elecstates' of excited states is different from ground state.
this->eig_ks = std::move(ks_sol.pelec->ekb);
};
#ifdef __MPI
if (this->nbands == GlobalV::NBANDS) { move_gs(); }
else // copy the part of ground state info according to paraC_
{
this->psi_ks = new psi::Psi<T>(this->kv.get_nks(), this->paraC_.get_col_size(), this->paraC_.get_row_size());
Expand All @@ -155,6 +160,9 @@ LR::ESolver_LR<T, TR>::ESolver_LR(ModuleESolver::ESolver_KS_LCAO<T, TR>&& ks_sol
this->eig_ks(ik, ib) = ks_sol.pelec->ekb(ik, start_band + ib);
}
}
#else
move_gs();
#endif

//grid integration
this->gt_ = std::move(ks_sol.GridT);
Expand Down Expand Up @@ -225,8 +233,8 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, Input& inp_tmp, UnitCel
this->set_dimension();
// setup 2d-block distribution for AO-matrix and KS wfc
LR_Util::setup_2d_division(this->paraMat_, 1, this->nbasis, this->nbasis);
this->paraMat_.set_desc_wfc_Eij(this->nbasis, this->nbands, paraMat_.get_row_size());
#ifdef __MPI
this->paraMat_.set_desc_wfc_Eij(this->nbasis, this->nbands, paraMat_.get_row_size());
int err = this->paraMat_.set_nloc_wfc_Eij(this->nbands, GlobalV::ofs_running, GlobalV::ofs_warning);
this->paraMat_.set_atomic_trace(ucell.get_iat2iwt(), ucell.nat, this->nbasis);
#else
Expand All @@ -242,7 +250,11 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, Input& inp_tmp, UnitCel
this->paraMat_.get_row_size());
this->read_ks_wfc();

LR_Util::setup_2d_division(this->paraC_, 1, this->nbasis, this->nbands, paraMat_.blacs_ctxt);
LR_Util::setup_2d_division(this->paraC_, 1, this->nbasis, this->nbands
#ifdef __MPI
, paraMat_.blacs_ctxt
#endif
);

//allocate 2-particle state and setup 2d division
this->pelec = new elecstate::ElecState();
Expand Down Expand Up @@ -335,17 +347,17 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, Input& inp_tmp, UnitCel
&GlobalC::ORB);
this->gint_->initialize_pvpR(ucell, &GlobalC::GridD);

// if EXX from scratch, init 2-center integral and calclate Cs, Vs
// if EXX from scratch, init 2-center integral and calculate Cs, Vs
#ifdef __EXX
if ((xc_kernel == "hf" || xc_kernel == "hse") && this->input.lr_solver != "spectrum")
{
this->exx_lri = std::make_shared<Exx_LRI<T>>(GlobalC::exx_info.info_ri);
this->exx_lri->init(MPI_COMM_WORLD, this->kv); // using GlobalC::ORB
this->exx_lri->cal_exx_ions();
}
else
// else
#endif
ModuleBase::Ylm::set_coefficients(); // set Ylm only for Gint
// ModuleBase::Ylm::set_coefficients() is deprecated
}
template <typename T, typename TR>
void LR::ESolver_LR<T, TR>::runner(int istep, UnitCell& cell)
Expand Down Expand Up @@ -402,7 +414,11 @@ template<typename T, typename TR>
void LR::ESolver_LR<T, TR>::setup_eigenvectors_X()
{
ModuleBase::TITLE("ESolver_LR", "setup_eigenvectors_X");
LR_Util::setup_2d_division(this->paraX_, 1, this->nvirt, this->nocc, this->paraC_.blacs_ctxt);//nvirt - row, nocc - col
LR_Util::setup_2d_division(this->paraX_, 1, this->nvirt, this->nocc
#ifdef __MPI
, this->paraC_.blacs_ctxt
#endif
);//nvirt - row, nocc - col
// if spectrum-only, read the LR-eigenstates from file and return
if (this->input.lr_solver == "spectrum")
{
Expand Down

0 comments on commit da7b659

Please sign in to comment.