Skip to content

Commit 17d9f1d

Browse files
authored
Refactor: clean Davidson code, remove deprecated overlap matrix scc related code (#6330)
* Remove scc calculation deprecated code of traditional Davidson algorithm. * Remove scc completely in traditional Davidson. * Fix test after removal of scc
1 parent 2861312 commit 17d9f1d

File tree

3 files changed

+8
-61
lines changed

3 files changed

+8
-61
lines changed

source/source_hsolver/diago_david.cpp

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ DiagoDavid<T, Device>::DiagoDavid(const Real* precondition_in,
7676
resmem_complex_op()(this->hcc, nbase_x * nbase_x, "DAV::hcc");
7777
setmem_complex_op()(this->hcc, 0, nbase_x * nbase_x);
7878

79-
// scc(nbase_x, nbase_x); // Overlap on the reduced basis
80-
// resmem_complex_op()(this->ctx, this->scc, nbase_x * nbase_x, "DAV::scc");
81-
// setmem_complex_op()(this->ctx, this->scc, 0, nbase_x * nbase_x);
82-
8379
// vcc(nbase_x, nbase_x); // Eigenvectors of hcc
8480
resmem_complex_op()(this->vcc, nbase_x * nbase_x, "DAV::vcc");
8581
setmem_complex_op()(this->vcc, 0, nbase_x * nbase_x);
@@ -106,7 +102,6 @@ DiagoDavid<T, Device>::~DiagoDavid()
106102
delmem_complex_op()(this->hpsi);
107103
delmem_complex_op()(this->spsi);
108104
delmem_complex_op()(this->hcc);
109-
// delmem_complex_op()(this->ctx, this->scc);
110105
delmem_complex_op()(this->vcc);
111106
delmem_complex_op()(this->lagrange_matrix);
112107
base_device::memory::delete_memory_op<Real, base_device::DEVICE_CPU>()(this->eigenvalue);
@@ -190,9 +185,9 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
190185
// slice index in this piece of code is in C manner. i.e. 0:id stands for [0,id)
191186
hpsi_func(basis, hpsi, dim, nband);
192187

193-
this->cal_elem(dim, nbase, nbase_x, this->notconv, this->hpsi, this->spsi, this->hcc, this->scc);
188+
this->cal_elem(dim, nbase, nbase_x, this->notconv, this->hpsi, this->spsi, this->hcc);
194189

195-
this->diag_zhegvx(nbase, nband, this->hcc, this->scc, nbase_x, this->eigenvalue, this->vcc);
190+
this->diag_zhegvx(nbase, nband, this->hcc, nbase_x, this->eigenvalue, this->vcc);
196191

197192
for (int m = 0; m < nband; m++)
198193
{
@@ -218,9 +213,9 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
218213
unconv.data(),
219214
this->eigenvalue);
220215

221-
this->cal_elem(dim, nbase, nbase_x, this->notconv, this->hpsi, this->spsi, this->hcc, this->scc);
216+
this->cal_elem(dim, nbase, nbase_x, this->notconv, this->hpsi, this->spsi, this->hcc);
222217

223-
this->diag_zhegvx(nbase, nband, this->hcc, this->scc, nbase_x, this->eigenvalue, this->vcc);
218+
this->diag_zhegvx(nbase, nband, this->hcc, nbase_x, this->eigenvalue, this->vcc);
224219

225220
// check convergence and update eigenvalues
226221
ModuleBase::timer::tick("DiagoDavid", "check_update");
@@ -282,7 +277,6 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
282277
this->hpsi,
283278
this->spsi,
284279
this->hcc,
285-
this->scc,
286280
this->vcc);
287281
ModuleBase::timer::tick("DiagoDavid", "last");
288282
}
@@ -536,8 +530,7 @@ void DiagoDavid<T, Device>::cal_elem(const int& dim,
536530
const int& notconv, // number of newly added basis vectors
537531
const T* hpsi,
538532
const T* spsi,
539-
T* hcc,
540-
T* scc)
533+
T* hcc)
541534
{
542535
if (test_david == 1) {
543536
ModuleBase::TITLE("DiagoDavid", "cal_elem");
@@ -562,28 +555,12 @@ void DiagoDavid<T, Device>::cal_elem(const int& dim,
562555
this->zero,
563556
hcc + nbase, // notconv * (nbase + notconv)
564557
nbase_x);
565-
// scc[nbase] = basis[nbase]' * spsi
566-
// gemm_op<T, Device>()(this->ctx,
567-
// 'C',
568-
// 'N',
569-
// notconv,
570-
// nbase + notconv,
571-
// dim,
572-
// this->one,
573-
// basis + dim*nbase, // dim * notconv
574-
// dim,
575-
// spsi, // dim * (nbase + notconv)
576-
// dim,
577-
// this->zero,
578-
// scc + nbase, // notconv * (nbase + notconv)
579-
// nbase_x);
580558

581559

582560
#ifdef __MPI
583561
if (diag_comm.nproc > 1)
584562
{
585563
ModuleBase::matrixTranspose_op<T, Device>()(nbase_x, nbase_x, hcc, hcc);
586-
// matrixTranspose_op<T, Device>()(this->ctx, nbase_x, nbase_x, scc, scc);
587564

588565
auto* swap = new T[notconv * nbase_x];
589566
syncmem_complex_op()(swap, hcc + nbase * nbase_x, notconv * nbase_x);
@@ -599,21 +576,13 @@ void DiagoDavid<T, Device>::cal_elem(const int& dim,
599576
else {
600577
MPI_Reduce(swap, hcc + nbase * nbase_x, notconv * nbase_x, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, diag_comm.comm);
601578
}
602-
// syncmem_complex_op()(this->ctx, this->ctx, swap, scc + nbase * nbase_x, notconv * nbase_x);
603-
if (base_device::get_current_precision(swap) == "single") {
604-
// MPI_Reduce(swap, scc + nbase * nbase_x, notconv * nbase_x, MPI_COMPLEX, MPI_SUM, 0, diag_comm.comm);
605-
}
606-
else {
607-
// MPI_Reduce(swap, scc + nbase * nbase_x, notconv * nbase_x, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, diag_comm.comm);
608-
}
579+
609580
}
610581
delete[] swap;
611582

612583
// Parallel_Reduce::reduce_complex_double_pool( hcc + nbase * nbase_x, notconv * nbase_x );
613-
// Parallel_Reduce::reduce_complex_double_pool( scc + nbase * nbase_x, notconv * nbase_x );
614584

615585
ModuleBase::matrixTranspose_op<T, Device>()(nbase_x, nbase_x, hcc, hcc);
616-
// matrixTranspose_op<T, Device>()(this->ctx, nbase_x, nbase_x, scc, scc);
617586
}
618587
#endif
619588

@@ -637,7 +606,6 @@ template <typename T, typename Device>
637606
void DiagoDavid<T, Device>::diag_zhegvx(const int& nbase,
638607
const int& nband,
639608
const T* hcc,
640-
const T* /*scc*/,
641609
const int& nbase_x,
642610
Real* eigenvalue, // in CPU
643611
T* vcc)
@@ -694,7 +662,6 @@ void DiagoDavid<T, Device>::refresh(const int& dim,
694662
T* hpsi,
695663
T* spsi,
696664
T* hcc,
697-
T* scc,
698665
T* vcc)
699666
{
700667
if (test_david == 1) {
@@ -763,42 +730,31 @@ void DiagoDavid<T, Device>::refresh(const int& dim,
763730

764731
setmem_complex_op()(hcc, 0, nbase_x * nbase_x);
765732

766-
// setmem_complex_op()(this->ctx, scc, 0, nbase_x * nbase_x);
767-
768733
if (this->device == base_device::GpuDevice)
769734
{
770735
#if defined(__CUDA) || defined(__ROCM)
771736
T* hcc_cpu = nullptr;
772-
// T* scc_cpu = nullptr;
773737
T* vcc_cpu = nullptr;
774738
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(hcc_cpu,
775739
nbase_x * nbase_x,
776740
"DAV::hcc");
777-
// base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(this->cpu_ctx,
778-
// scc_cpu,
779-
// nbase_x * nbase_x,
780-
// "DAV::scc");
781741
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(vcc_cpu,
782742
nbase_x * nbase_x,
783743
"DAV::vcc");
784744

785745
syncmem_d2h_op()(hcc_cpu, hcc, nbase_x * nbase_x);
786-
// syncmem_d2h_op()(this->cpu_ctx, this->ctx, scc_cpu, scc, nbase_x * nbase_x);
787746
syncmem_d2h_op()(vcc_cpu, vcc, nbase_x * nbase_x);
788747

789748
for (int i = 0; i < nbase; i++)
790749
{
791750
hcc_cpu[i * nbase_x + i] = eigenvalue_in[i];
792-
// scc_cpu[i * nbase_x + i] = this->one[0];
793751
vcc_cpu[i * nbase_x + i] = this->one[0];
794752
}
795753

796754
syncmem_h2d_op()(hcc, hcc_cpu, nbase_x * nbase_x);
797-
// syncmem_h2d_op()(this->ctx, this->cpu_ctx, scc, scc_cpu, nbase_x * nbase_x);
798755
syncmem_h2d_op()(vcc, vcc_cpu, nbase_x * nbase_x);
799756

800757
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(hcc_cpu);
801-
// base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(this->cpu_ctx, scc_cpu);
802758
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(vcc_cpu);
803759
#endif
804760
}
@@ -808,7 +764,6 @@ void DiagoDavid<T, Device>::refresh(const int& dim,
808764
{
809765
hcc[i * nbase_x + i] = eigenvalue_in[i];
810766
// sc(i, i) = this->one;
811-
// scc[i * nbase_x + i] = this->one[0];
812767
// vc(i, i) = this->one;
813768
vcc[i * nbase_x + i] = this->one[0];
814769
}

source/source_hsolver/diago_david.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DiagoDavid
6161
* @brief Destructor for the DiagoDavid class.
6262
*
6363
* This destructor releases the dynamically allocated memory used by the class members.
64-
* It deletes the basis, hpsi, spsi, hcc, scc, vcc, lagrange_matrix, and eigenvalue arrays.
64+
* It deletes the basis, hpsi, spsi, hcc, vcc, lagrange_matrix, and eigenvalue arrays.
6565
*
6666
*/
6767
~DiagoDavid();
@@ -170,8 +170,6 @@ class DiagoDavid
170170

171171
T* hcc = nullptr; /// Hamiltonian on the reduced basis
172172

173-
T* scc = nullptr; /// overlap on the reduced basis
174-
175173
T* vcc = nullptr; /// eigenvectors of hc
176174

177175
T* lagrange_matrix = nullptr;
@@ -228,16 +226,14 @@ class DiagoDavid
228226
* @param hpsi The output array for the Hamiltonian H times blockvector psi.
229227
* @param spsi The output array for the overlap matrix S times blockvector psi.
230228
* @param hcc Pointer to the array where the calculated Hamiltonian matrix elements will be stored.
231-
* @param scc Pointer to the array where the calculated overlap matrix elements will be stored.
232229
*/
233230
void cal_elem(const int& dim,
234231
int& nbase,
235232
const int nbase_x,
236233
const int& notconv,
237234
const T* hpsi,
238235
const T* spsi,
239-
T* hcc,
240-
T* scc);
236+
T* hcc);
241237

242238
/**
243239
* Refreshes the diagonalization solver by updating the basis and the reduced Hamiltonian.
@@ -252,7 +248,6 @@ class DiagoDavid
252248
* @param hpsi Pointer to the output array for the updated basis set.
253249
* @param spsi Pointer to the output array for the updated basis set (nband-th column).
254250
* @param hcc Pointer to the output array for the updated reduced Hamiltonian.
255-
* @param scc Pointer to the output array for the updated overlap matrix.
256251
* @param vcc Pointer to the output array for the updated eigenvector matrix.
257252
*
258253
*/
@@ -266,7 +261,6 @@ class DiagoDavid
266261
T* hpsi,
267262
T* spsi,
268263
T* hcc,
269-
T* scc,
270264
T* vcc);
271265

272266
/**
@@ -304,7 +298,6 @@ class DiagoDavid
304298
void diag_zhegvx(const int& nbase,
305299
const int& nband,
306300
const T* hcc,
307-
const T* scc,
308301
const int& nbase_x,
309302
Real* eigenvalue,
310303
T* vcc);

source/source_hsolver/test/hsolver_pw_sup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ DiagoDavid<T, Device>::~DiagoDavid() {
142142
delmem_complex_op()(this->hpsi);
143143
delmem_complex_op()(this->spsi);
144144
delmem_complex_op()(this->hcc);
145-
delmem_complex_op()(this->scc);
146145
delmem_complex_op()(this->vcc);
147146
delmem_complex_op()(this->lagrange_matrix);
148147
base_device::memory::delete_memory_op<Real, base_device::DEVICE_CPU>()(this->eigenvalue);

0 commit comments

Comments
 (0)