From a02ab6eaa10a80a5c4e4889c8f332bc839b3855e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Sep 2022 15:32:25 -0400 Subject: [PATCH] avoid memory corruption when using mliap unified with ghostneigh_flag == 1 --- src/ML-IAP/mliap_unified.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ML-IAP/mliap_unified.cpp b/src/ML-IAP/mliap_unified.cpp index fef32a5293..8c2955d559 100644 --- a/src/ML-IAP/mliap_unified.cpp +++ b/src/ML-IAP/mliap_unified.cpp @@ -245,14 +245,18 @@ MLIAPBuildUnified_t LAMMPS_NS::build_unified(char *unified_fname, MLIAPData *dat void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij) { double e_total = 0; - for (int ii = 0; ii < data->nlistatoms; ii++) data->eatoms[ii] = 0; + const auto nlistatoms = data->nlistatoms; + for (int ii = 0; ii < nlistatoms; ii++) data->eatoms[ii] = 0; for (int ii = 0; ii < data->npairs; ii++) { int i = data->pair_i[ii]; double e = 0.5 * eij[ii]; - data->eatoms[i] += e; - e_total += e; + // TODO: the if avoids memory corruption with ghostneigh_flag = 1, + if (i < nlistatoms) { + data->eatoms[i] += e; + e_total += e; + } } data->energy = e_total; }