Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deallocate per-atom data less aggressively so replicate command keeps working #2180

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 43 additions & 35 deletions src/atom_vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ using namespace MathConst;
#define DELTA 16384
#define DELTA_BONUS 8192

int AtomVec::num_atom_vecs = 0;

/* ---------------------------------------------------------------------- */

AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp)
Expand All @@ -54,6 +56,8 @@ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp)

threads = NULL;

++num_atom_vecs;

// peratom variables auto-included in corresponding child style fields string
// these fields cannot be specified in the fields string

Expand Down Expand Up @@ -93,44 +97,48 @@ AtomVec::~AtomVec()
int datatype,cols;
void *pdata;

--num_atom_vecs;

for (int i = 0; i < nargcopy; i++) delete [] argcopy[i];
delete [] argcopy;

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));
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));
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/atom_vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class AtomVec : protected Pointers {

bool *threads;

// counter for atom vec instances

static int num_atom_vecs;

// local methods

void grow_nmax();
Expand Down