Skip to content

Commit 4289cec

Browse files
authored
Fix: Plug memory leak in dav_subspace (#6532)
* Plug memory leak in dav_subspace destructor * Rename hphi and sphi to hpsi and spsi
1 parent bb0d003 commit 4289cec

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

source/source_hsolver/diago_dav_subspace.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ Diago_DavSubspace<T, Device>::Diago_DavSubspace(const std::vector<Real>& precond
5151
setmem_complex_op()(this->psi_in_iter, 0, this->nbase_x * this->dim);
5252

5353
// the product of H and psi in the reduced psi set
54-
resmem_complex_op()(this->hphi, this->nbase_x * this->dim, "DAV::hphi");
55-
setmem_complex_op()(this->hphi, 0, this->nbase_x * this->dim);
54+
resmem_complex_op()(this->hpsi, this->nbase_x * this->dim, "DAV::hpsi");
55+
setmem_complex_op()(this->hpsi, 0, this->nbase_x * this->dim);
5656

5757
// the product of S and psi in the reduced psi set
58-
resmem_complex_op()(this->sphi, this->nbase_x * this->dim, "DAV::sphi");
59-
setmem_complex_op()(this->sphi, 0, this->nbase_x * this->dim);
58+
resmem_complex_op()(this->spsi, this->nbase_x * this->dim, "DAV::spsi");
59+
setmem_complex_op()(this->spsi, 0, this->nbase_x * this->dim);
6060

6161
// Hamiltonian on the reduced psi set
6262
resmem_complex_op()(this->hcc, this->nbase_x * this->nbase_x, "DAV::hcc");
@@ -87,7 +87,8 @@ Diago_DavSubspace<T, Device>::~Diago_DavSubspace()
8787
{
8888
delmem_complex_op()(this->psi_in_iter);
8989

90-
delmem_complex_op()(this->hphi);
90+
delmem_complex_op()(this->hpsi);
91+
delmem_complex_op()(this->spsi);
9192
delmem_complex_op()(this->hcc);
9293
delmem_complex_op()(this->scc);
9394
delmem_complex_op()(this->vcc);
@@ -137,14 +138,14 @@ int Diago_DavSubspace<T, Device>::diag_once(const HPsiFunc& hpsi_func,
137138

138139
// compute h*psi_in_iter
139140
// NOTE: bands after the first n_band should yield zero
140-
// hphi[:, 0:nbase_x] = H * psi_in_iter[:, 0:nbase_x]
141-
hpsi_func(this->psi_in_iter, this->hphi, this->dim, this->notconv);
141+
// hpsi[:, 0:nbase_x] = H * psi_in_iter[:, 0:nbase_x]
142+
hpsi_func(this->psi_in_iter, this->hpsi, this->dim, this->notconv);
142143

143144
// compute s*psi_in_iter
144-
// sphi[:, 0:nbase_x] = S * psi_in_iter[:, 0:nbase_x]
145-
spsi_func(this->psi_in_iter, this->sphi, this->dim, this->notconv);
145+
// spsi[:, 0:nbase_x] = S * psi_in_iter[:, 0:nbase_x]
146+
spsi_func(this->psi_in_iter, this->spsi, this->dim, this->notconv);
146147

147-
this->cal_elem(this->dim, nbase, this->notconv, this->psi_in_iter, this->sphi, this->hphi, this->hcc, this->scc);
148+
this->cal_elem(this->dim, nbase, this->notconv, this->psi_in_iter, this->spsi, this->hpsi, this->hcc, this->scc);
148149

149150
this->diag_zhegvx(nbase, this->notconv, this->hcc, this->scc, this->nbase_x, &eigenvalue_iter, this->vcc);
150151

@@ -167,8 +168,8 @@ int Diago_DavSubspace<T, Device>::diag_once(const HPsiFunc& hpsi_func,
167168
nbase,
168169
this->notconv,
169170
this->psi_in_iter,
170-
this->hphi,
171-
this->sphi,
171+
this->hpsi,
172+
this->spsi,
172173
this->vcc,
173174
unconv.data(),
174175
&eigenvalue_iter);
@@ -177,8 +178,8 @@ int Diago_DavSubspace<T, Device>::diag_once(const HPsiFunc& hpsi_func,
177178
nbase,
178179
this->notconv,
179180
this->psi_in_iter,
180-
this->sphi,
181-
this->hphi,
181+
this->spsi,
182+
this->hpsi,
182183
this->hcc,
183184
this->scc);
184185

@@ -251,8 +252,8 @@ int Diago_DavSubspace<T, Device>::diag_once(const HPsiFunc& hpsi_func,
251252
nbase,
252253
eigenvalue_in_hsolver,
253254
this->psi_in_iter,
254-
this->hphi,
255-
this->sphi,
255+
this->hpsi,
256+
this->spsi,
256257
this->hcc,
257258
this->scc,
258259
this->vcc);
@@ -275,7 +276,7 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
275276
const int& nbase,
276277
const int& notconv,
277278
T* psi_iter,
278-
T* hphi,
279+
T* hpsi,
279280
T* spsi,
280281
T* vcc,
281282
const int* unconv,
@@ -303,7 +304,7 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
303304
notconv,
304305
nbase,
305306
this->one,
306-
hphi,
307+
hpsi,
307308
this->dim,
308309
vcc,
309310
this->nbase_x,
@@ -333,7 +334,7 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
333334
notconv,
334335
nbase,
335336
this->one,
336-
sphi,
337+
spsi,
337338
this->dim,
338339
vcc,
339340
this->nbase_x,
@@ -392,8 +393,8 @@ void Diago_DavSubspace<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
392393

393394
// update hpsi[:, nbase:nbase+notconv]
394395
// hpsi[:, nbase:nbase+notconv] = H * psi_iter[:, nbase:nbase+notconv]
395-
hpsi_func(psi_iter + nbase * dim, hphi + nbase * this->dim, this->dim, notconv);
396-
spsi_func(psi_iter + nbase * dim, sphi + nbase * this->dim, this->dim, notconv);
396+
hpsi_func(psi_iter + nbase * dim, hpsi + nbase * this->dim, this->dim, notconv);
397+
spsi_func(psi_iter + nbase * dim, spsi + nbase * this->dim, this->dim, notconv);
397398

398399
ModuleBase::timer::tick("Diago_DavSubspace", "cal_grad");
399400
return;
@@ -405,7 +406,7 @@ void Diago_DavSubspace<T, Device>::cal_elem(const int& dim,
405406
const int& notconv,
406407
const T* psi_iter,
407408
const T* spsi,
408-
const T* hphi,
409+
const T* hpsi,
409410
T* hcc,
410411
T* scc)
411412
{
@@ -424,7 +425,7 @@ void Diago_DavSubspace<T, Device>::cal_elem(const int& dim,
424425
this->one,
425426
psi_iter,
426427
this->dim,
427-
&hphi[nbase * this->dim],
428+
&hpsi[nbase * this->dim],
428429
this->dim,
429430
this->zero,
430431
&hcc[nbase * this->nbase_x],
@@ -659,8 +660,8 @@ void Diago_DavSubspace<T, Device>::refresh(const int& dim,
659660
const Real* eigenvalue_in_hsolver,
660661
// const psi::Psi<T, Device>& psi,
661662
T* psi_iter,
662-
T* hphi,
663-
T* sphi,
663+
T* hpsi,
664+
T* spsi,
664665
T* hcc,
665666
T* scc,
666667
T* vcc)
@@ -678,16 +679,16 @@ void Diago_DavSubspace<T, Device>::refresh(const int& dim,
678679
nband,
679680
nbase,
680681
this->one,
681-
this->hphi,
682+
this->hpsi,
682683
this->dim,
683684
this->vcc,
684685
this->nbase_x,
685686
this->zero,
686687
psi_iter + nband * this->dim,
687688
this->dim);
688689

689-
// update hphi
690-
syncmem_complex_op()(hphi, psi_iter + nband * this->dim, this->dim * nband);
690+
// update hpsi
691+
syncmem_complex_op()(hpsi, psi_iter + nband * this->dim, this->dim * nband);
691692

692693
#ifdef __DSP
693694
ModuleBase::gemm_op_mt<T, Device>()
@@ -700,16 +701,16 @@ void Diago_DavSubspace<T, Device>::refresh(const int& dim,
700701
nband,
701702
nbase,
702703
this->one,
703-
this->sphi,
704+
this->spsi,
704705
this->dim,
705706
this->vcc,
706707
this->nbase_x,
707708
this->zero,
708709
psi_iter + nband * this->dim,
709710
this->dim);
710711

711-
// update sphi
712-
syncmem_complex_op()(sphi, psi_iter + nband * this->dim, this->dim * nband);
712+
// update spsi
713+
syncmem_complex_op()(spsi, psi_iter + nband * this->dim, this->dim * nband);
713714

714715
nbase = nband;
715716

source/source_hsolver/diago_dav_subspace.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ class Diago_DavSubspace
8080
T* psi_in_iter = nullptr;
8181

8282
/// the product of H and psi in the reduced basis set
83-
T* hphi = nullptr;
83+
T* hpsi = nullptr;
8484

8585
/// the product of S and psi in the reduced basis set
86-
T* sphi = nullptr;
86+
T* spsi = nullptr;
8787

8888
/// Hamiltonian on the reduced basis
8989
T* hcc = nullptr;
@@ -108,7 +108,7 @@ class Diago_DavSubspace
108108
const int& nbase,
109109
const int& notconv,
110110
T* psi_iter,
111-
T* hphi,
111+
T* hpsi,
112112
T* spsi,
113113
T* vcc,
114114
const int* unconv,
@@ -118,8 +118,8 @@ class Diago_DavSubspace
118118
int& nbase,
119119
const int& notconv,
120120
const T* psi_iter,
121-
const T* sphi,
122-
const T* hphi,
121+
const T* spsi,
122+
const T* hpsi,
123123
T* hcc,
124124
T* scc);
125125

@@ -128,8 +128,8 @@ class Diago_DavSubspace
128128
int& nbase,
129129
const Real* eigenvalue,
130130
T* psi_iter,
131-
T* hphi,
132-
T* sphi,
131+
T* hpsi,
132+
T* spsi,
133133
T* hcc,
134134
T* scc,
135135
T* vcc);

0 commit comments

Comments
 (0)