Skip to content

Commit

Permalink
plug memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
akohlmey committed Aug 2, 2024
1 parent 0367f3e commit 1096da2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ML-POD/pair_pod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ PairPOD::PairPOD(LAMMPS *lmp) : Pair(lmp), fastpodptr(nullptr)
abfx = nullptr;
abfy = nullptr;
abfz = nullptr;
abftm = nullptr;
sumU = nullptr;
forcecoeff = nullptr;
Centroids = nullptr;
Expand All @@ -88,6 +89,7 @@ PairPOD::PairPOD(LAMMPS *lmp) : Pair(lmp), fastpodptr(nullptr)
pdd = nullptr;
coefficients = nullptr;
pn3 = nullptr;
pq3 = nullptr;
pc3 = nullptr;
pa4 = nullptr;
pb4 = nullptr;
Expand Down Expand Up @@ -124,6 +126,7 @@ PairPOD::~PairPOD()
memory->destroy(abfx);
memory->destroy(abfy);
memory->destroy(abfz);
memory->destroy(abftm);
memory->destroy(sumU);
memory->destroy(forcecoeff);
memory->destroy(Centroids);
Expand All @@ -135,6 +138,7 @@ PairPOD::~PairPOD()
memory->destroy(pdd);
memory->destroy(coefficients);
memory->destroy(pn3);
memory->destroy(pq3);
memory->destroy(pc3);
memory->destroy(pa4);
memory->destroy(pb4);
Expand Down Expand Up @@ -568,14 +572,18 @@ void PairPOD::copy_data_from_pod_class()
besselparams[1] = fastpodptr->besselparams[1];
besselparams[2] = fastpodptr->besselparams[2];

memory->destroy(abftm);
memory->create(abftm, 4*K3, "abftm");
memory->destroy(elemindex);
memory->create(elemindex, nelements*nelements, "elemindex");
for (int i=0; i<nelements*nelements; i++) elemindex[i] = fastpodptr->elemindex[i];

memory->destroy(Phi);
memory->create(Phi, ns * ns, "pair_pod:Phi");
for (int i=0; i<ns*ns; i++)
Phi[i] = fastpodptr->Phi[i];

memory->destroy(coefficients);
memory->create(coefficients, nCoeffPerElement * nelements, "pair_pod:coefficients");
for (int i=0; i<nCoeffPerElement * nelements; i++)
coefficients[i] = fastpodptr->coeff[i];
Expand All @@ -590,11 +598,17 @@ void PairPOD::copy_data_from_pod_class()
Centroids[i] = fastpodptr->Centroids[i];
}

memory->destroy(pn3);
memory->create(pn3, nabf3+1, "pn3"); // array stores the number of monomials for each degree
memory->destroy(pq3);
memory->create(pq3, K3*2, "pq3"); // array needed for the recursive computation of the angular basis functions
memory->destroy(pc3);
memory->create(pc3, K3, "pc3"); // array needed for the computation of the three-body descriptors
memory->destroy(pa4);
memory->create(pa4, nabf4+1, "pa4"); // this array is a subset of the array {0, 1, 4, 10, 19, 29, 47, 74, 89, 119, 155, 209, 230, 275, 335, 425, 533, 561, 624, 714, 849, 949, 1129, 1345}
memory->destroy(pb4);
memory->create(pb4, Q4*3, "pb4"); // array stores the indices of the monomials needed for the computation of the angular basis functions
memory->destroy(pc4);
memory->create(pc4, Q4, "pc4"); // array of monomial coefficients needed for the computation of the four-body descriptors
for (int i=0; i<nabf3+1; i++) pn3[i] = fastpodptr->pn3[i];
for (int i=0; i<K3; i++) pc3[i] = fastpodptr->pc3[i];
Expand Down

0 comments on commit 1096da2

Please sign in to comment.