From 516a31796ebb6ab218043f0cabefc12958be5e23 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Jun 2020 23:12:11 -0400 Subject: [PATCH] need to move destruction of base per-atom properties back to atom.cpp so we don't leak memory in read_restart and don't crash with replicate --- src/atom.cpp | 8 ++++ src/atom_vec.cpp | 97 +++++++++++++++++++++--------------------------- src/atom_vec.h | 4 -- 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 42ff9d4613..2a5d3c494e 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -243,6 +243,14 @@ Atom::~Atom() memory->destroy(next); memory->destroy(permute); + memory->destroy(tag); + memory->destroy(type); + memory->destroy(mask); + memory->destroy(image); + memory->destroy(x); + memory->destroy(v); + memory->destroy(f); + // delete peratom data struct for (int i = 0; i < nperatom; i++) diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index 5a86caa4fb..85afd46d32 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -33,8 +33,6 @@ using namespace MathConst; #define DELTA 16384 #define DELTA_BONUS 8192 -int AtomVec::num_atom_vecs = 0; - /* ---------------------------------------------------------------------- */ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp) @@ -52,11 +50,14 @@ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp) kokkosable = 0; nargcopy = 0; - argcopy = NULL; + argcopy = nullptr; - threads = NULL; + tag = nullptr; + type = mask = nullptr; + image = nullptr; + x = v = f = nullptr; - ++num_atom_vecs; + threads = nullptr; // peratom variables auto-included in corresponding child style fields string // these fields cannot be specified in the fields string @@ -97,48 +98,36 @@ AtomVec::~AtomVec() int datatype,cols; void *pdata; - --num_atom_vecs; - for (int i = 0; i < nargcopy; i++) delete [] argcopy[i]; delete [] argcopy; - if (num_atom_vecs == 0) { - memory->destroy(atom->tag); - memory->destroy(atom->type); - memory->destroy(atom->mask); - memory->destroy(atom->image); - memory->destroy(atom->x); - memory->destroy(atom->v); - memory->destroy(atom->f); - - for (int i = 0; i < ngrow; i++) { - pdata = mgrow.pdata[i]; - datatype = mgrow.datatype[i]; - cols = mgrow.cols[i]; - if (datatype == Atom::DOUBLE) { - if (cols == 0) - memory->destroy(*((double **) pdata)); - else if (cols > 0) - memory->destroy(*((double ***) pdata)); - else { - memory->destroy(*((double ***) pdata)); - } - } else if (datatype == Atom::INT) { - if (cols == 0) - memory->destroy(*((int **) pdata)); - else if (cols > 0) - memory->destroy(*((int ***) pdata)); - else { - memory->destroy(*((int ***) pdata)); - } - } else if (datatype == Atom::BIGINT) { - if (cols == 0) - memory->destroy(*((bigint **) pdata)); - else if (cols > 0) - memory->destroy(*((bigint ***) pdata)); - else { - memory->destroy(*((bigint ***) pdata)); - } + for (int i = 0; i < ngrow; i++) { + pdata = mgrow.pdata[i]; + datatype = mgrow.datatype[i]; + cols = mgrow.cols[i]; + if (datatype == Atom::DOUBLE) { + if (cols == 0) + memory->destroy(*((double **) pdata)); + else if (cols > 0) + memory->destroy(*((double ***) pdata)); + else { + memory->destroy(*((double ***) pdata)); + } + } else if (datatype == Atom::INT) { + if (cols == 0) + memory->destroy(*((int **) pdata)); + else if (cols > 0) + memory->destroy(*((int ***) pdata)); + else { + memory->destroy(*((int ***) pdata)); + } + } else if (datatype == Atom::BIGINT) { + if (cols == 0) + memory->destroy(*((bigint **) pdata)); + else if (cols > 0) + memory->destroy(*((bigint ***) pdata)); + else { + memory->destroy(*((bigint ***) pdata)); } } } @@ -194,7 +183,7 @@ void AtomVec::init() deform_groupbit = domain->deform_groupbit; h_rate = domain->h_rate; - if (lmp->kokkos != NULL && !kokkosable) + if (lmp->kokkos != nullptr && !kokkosable) error->all(FLERR,"KOKKOS package requires a kokkos enabled atom_style"); } @@ -2492,8 +2481,8 @@ void AtomVec::setup_fields() int AtomVec::process_fields(char *str, const char *default_str, Method *method) { - if (str == NULL) { - method->index = NULL; + if (str == nullptr) { + method->index = nullptr; return 0; } @@ -2572,13 +2561,13 @@ void AtomVec::create_method(int nfield, Method *method) void AtomVec::init_method(Method *method) { - method->pdata = NULL; - method->datatype = NULL; - method->cols = NULL; - method->maxcols = NULL; - method->collength = NULL; - method->plength = NULL; - method->index = NULL; + method->pdata = nullptr; + method->datatype = nullptr; + method->cols = nullptr; + method->maxcols = nullptr; + method->collength = nullptr; + method->plength = nullptr; + method->index = nullptr; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec.h b/src/atom_vec.h index 625307face..8ccf922c4b 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -209,10 +209,6 @@ class AtomVec : protected Pointers { bool *threads; - // counter for atom vec instances - - static int num_atom_vecs; - // local methods void grow_nmax();