Skip to content

Commit 255e104

Browse files
authored
Sorting out the calculation logic of pexsi in hsolver-lcao (#5299)
1 parent 7cb7664 commit 255e104

File tree

2 files changed

+45
-47
lines changed

2 files changed

+45
-47
lines changed

source/module_hsolver/hsolver_lcao.cpp

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,50 @@ void HSolverLCAO<T, Device>::solve(hamilt::Hamilt<T>* pHamilt,
4343
ModuleBase::TITLE("HSolverLCAO", "solve");
4444
ModuleBase::timer::tick("HSolverLCAO", "solve");
4545

46-
#ifdef __PEXSI // other purification methods should follow this routine
47-
// Zhang Xiaoyang : Please modify Pesxi usage later
48-
if (this->method == "pexsi")
46+
if (this->method != "pexsi")
47+
{
48+
if (GlobalV::KPAR_LCAO > 1
49+
&& (this->method == "genelpa" || this->method == "elpa" || this->method == "scalapack_gvx"))
50+
{
51+
#ifdef __MPI
52+
this->parakSolve(pHamilt, psi, pes, GlobalV::KPAR_LCAO);
53+
#endif
54+
}
55+
else if (GlobalV::KPAR_LCAO == 1)
56+
{
57+
/// Loop over k points for solve Hamiltonian to eigenpairs(eigenvalues and eigenvectors).
58+
for (int ik = 0; ik < psi.get_nk(); ++ik)
59+
{
60+
/// update H(k) for each k point
61+
pHamilt->updateHk(ik);
62+
63+
/// find psi pointer for each k point
64+
psi.fix_k(ik);
65+
66+
/// solve eigenvector and eigenvalue for H(k)
67+
this->hamiltSolvePsiK(pHamilt, psi, &(pes->ekb(ik, 0)));
68+
}
69+
}
70+
else
71+
{
72+
ModuleBase::WARNING_QUIT("HSolverLCAO::solve",
73+
"This method and KPAR setting is not supported for lcao basis in ABACUS!");
74+
}
75+
76+
if (!skip_charge)
77+
{
78+
// used in scf calculation
79+
// calculate charge by eigenpairs(eigenvalues and eigenvectors)
80+
pes->psiToRho(psi);
81+
}
82+
else
83+
{
84+
// used in nscf calculation
85+
}
86+
}
87+
else if (this->method == "pexsi")
4988
{
89+
#ifdef __PEXSI // other purification methods should follow this routine
5090
DiagoPexsi<T> pe(ParaV);
5191
for (int ik = 0; ik < psi.get_nk(); ++ik)
5292
{
@@ -60,41 +100,7 @@ void HSolverLCAO<T, Device>::solve(hamilt::Hamilt<T>* pHamilt,
60100
pes->f_en.eband = pe.totalFreeEnergy;
61101
// maybe eferm could be dealt with in the future
62102
_pes->dmToRho(pe.DM, pe.EDM);
63-
ModuleBase::timer::tick("HSolverLCAO", "solve");
64-
return;
65-
}
66103
#endif
67-
68-
if (GlobalV::KPAR_LCAO > 1
69-
&& (this->method == "genelpa" || this->method == "elpa" || this->method == "scalapack_gvx"))
70-
{
71-
#ifdef __MPI
72-
this->parakSolve(pHamilt, psi, pes, GlobalV::KPAR_LCAO);
73-
#endif
74-
}
75-
else if (GlobalV::KPAR_LCAO == 1)
76-
{
77-
/// Loop over k points for solve Hamiltonian to eigenpairs(eigenvalues and eigenvectors).
78-
for (int ik = 0; ik < psi.get_nk(); ++ik)
79-
{
80-
/// update H(k) for each k point
81-
pHamilt->updateHk(ik);
82-
83-
/// find psi pointer for each k point
84-
psi.fix_k(ik);
85-
86-
/// solve eigenvector and eigenvalue for H(k)
87-
this->hamiltSolvePsiK(pHamilt, psi, &(pes->ekb(ik, 0)));
88-
}
89-
}
90-
91-
if (!skip_charge) // used in scf calculation
92-
{
93-
// calculate charge by eigenpairs(eigenvalues and eigenvectors)
94-
pes->psiToRho(psi);
95-
}
96-
else // used in nscf calculation
97-
{
98104
}
99105

100106
ModuleBase::timer::tick("HSolverLCAO", "solve");
@@ -114,7 +120,6 @@ void HSolverLCAO<T, Device>::hamiltSolvePsiK(hamilt::Hamilt<T>* hm, psi::Psi<T>&
114120
sa.diag(hm, psi, eigenvalue);
115121
#endif
116122
}
117-
118123
#ifdef __ELPA
119124
else if (this->method == "genelpa")
120125
{
@@ -127,7 +132,6 @@ void HSolverLCAO<T, Device>::hamiltSolvePsiK(hamilt::Hamilt<T>* hm, psi::Psi<T>&
127132
el.diag(hm, psi, eigenvalue);
128133
}
129134
#endif
130-
131135
#ifdef __CUDA
132136
else if (this->method == "cusolver")
133137
{
@@ -142,15 +146,13 @@ void HSolverLCAO<T, Device>::hamiltSolvePsiK(hamilt::Hamilt<T>* hm, psi::Psi<T>&
142146
}
143147
#endif
144148
#endif
145-
146149
#ifndef __MPI
147150
else if (this->method == "lapack") // only for single core
148151
{
149152
DiagoLapack<T> la;
150153
la.diag(hm, psi, eigenvalue);
151154
}
152155
#endif
153-
154156
else
155157
{
156158
ModuleBase::WARNING_QUIT("HSolverLCAO::solve", "This method is not supported for lcao basis in ABACUS!");

source/module_hsolver/hsolver_lcao.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@ class HSolverLCAO
1919
const bool skip_charge);
2020

2121
private:
22-
void hamiltSolvePsiK(hamilt::Hamilt<T>* hm, psi::Psi<T>& psi, double* eigenvalue);
22+
void hamiltSolvePsiK(hamilt::Hamilt<T>* hm, psi::Psi<T>& psi, double* eigenvalue); // for kpar_lcao == 1
2323

24-
void parakSolve(hamilt::Hamilt<T>* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, int kpar);
24+
void parakSolve(hamilt::Hamilt<T>* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, int kpar); // for kpar_lcao > 1
2525

2626
const Parallel_Orbitals* ParaV;
2727

2828
const std::string method;
29-
30-
// for cg_in_lcao
31-
using Real = typename GetTypeReal<T>::type;
32-
std::vector<Real> precondition_lcao;
3329
};
3430

3531
} // namespace hsolver

0 commit comments

Comments
 (0)