Skip to content

Commit 5a774bf

Browse files
authored
Fix: Fix Consts memory leak by directly removing custome consts (#5344)
* Fix #5343 by directly remove consts in diago_dav_subspace * Fix 1 * Fix 2
1 parent d7150d0 commit 5a774bf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

source/module_hsolver/diago_dav_subspace.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Diago_DavSubspace<T, Device>::Diago_DavSubspace(const std::vector<Real>& precond
2525
{
2626
this->device = base_device::get_device_type<Device>(this->ctx);
2727

28-
this->one = this->cs.one;
29-
this->zero = this->cs.zero;
30-
this->neg_one = this->cs.neg_one;
28+
this->one = &one_;
29+
this->zero = &zero_;
30+
this->neg_one = &neg_one_;
3131

3232
assert(david_ndim_in > 1);
3333
assert(david_ndim_in * nband_in < nbasis_in * this->diag_comm.nproc);
@@ -559,8 +559,8 @@ void Diago_DavSubspace<T, Device>::diag_zhegvx(const int& nbase,
559559
}
560560
else
561561
{
562-
std::vector<std::vector<T>> h_diag(nbase, std::vector<T>(nbase, cs.zero[0]));
563-
std::vector<std::vector<T>> s_diag(nbase, std::vector<T>(nbase, cs.zero[0]));
562+
std::vector<std::vector<T>> h_diag(nbase, std::vector<T>(nbase, *this->zero));
563+
std::vector<std::vector<T>> s_diag(nbase, std::vector<T>(nbase, *this->zero));
564564

565565
for (size_t i = 0; i < nbase; i++)
566566
{
@@ -589,10 +589,10 @@ void Diago_DavSubspace<T, Device>::diag_zhegvx(const int& nbase,
589589

590590
for (size_t j = nbase; j < this->nbase_x; j++)
591591
{
592-
hcc[i * this->nbase_x + j] = cs.zero[0];
593-
hcc[j * this->nbase_x + i] = cs.zero[0];
594-
scc[i * this->nbase_x + j] = cs.zero[0];
595-
scc[j * this->nbase_x + i] = cs.zero[0];
592+
hcc[i * this->nbase_x + j] = *this->zero;
593+
hcc[j * this->nbase_x + i] = *this->zero;
594+
scc[i * this->nbase_x + j] = *this->zero;
595+
scc[j * this->nbase_x + i] = *this->zero;
596596
}
597597
}
598598
}

source/module_hsolver/diago_dav_subspace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class Diago_DavSubspace
158158
using syncmem_h2d_op = base_device::memory::synchronize_memory_op<T, Device, base_device::DEVICE_CPU>;
159159
using syncmem_d2h_op = base_device::memory::synchronize_memory_op<T, base_device::DEVICE_CPU, Device>;
160160

161-
const_nums<T> cs;
162161
const T *one = nullptr, *zero = nullptr, *neg_one = nullptr;
162+
const T one_ = static_cast<T>(1.0), zero_ = static_cast<T>(0.0), neg_one_ = static_cast<T>(-1.0);
163163
};
164164

165165
} // namespace hsolver

0 commit comments

Comments
 (0)