From 822c7c5ca11984fcfd26b02e8f66067f5b61ff30 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 11 May 2020 10:57:27 -0400 Subject: [PATCH] elimitate nthreads member, change threads from int to bool and determine number of threads dynamically this fixes #2081 --- src/atom_vec.cpp | 44 ++++++++++++++++++++++---------------------- src/atom_vec.h | 3 +-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index e7962ca038..5a29347e56 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -53,7 +53,6 @@ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp) argcopy = NULL; threads = NULL; - nthreads = comm->nthreads; // peratom variables auto-included in corresponding child style fields string // these fields cannot be specified in the fields string @@ -193,6 +192,7 @@ void AtomVec::grow(int n) { int datatype,cols,maxcols; void *pdata; + int nthreads = comm->nthreads; if (n == 0) grow_nmax(); else nmax = n; @@ -214,30 +214,30 @@ void AtomVec::grow(int n) cols = mgrow.cols[i]; if (datatype == DOUBLE) { if (cols == 0) - memory->grow(*((double **) pdata),nmax*threads[i],"atom:dvec"); + memory->grow(*((double **) pdata),nmax*(threads[i]?nthreads:1),"atom:dvec"); else if (cols > 0) - memory->grow(*((double ***) pdata),nmax*threads[i],cols,"atom:darray"); + memory->grow(*((double ***) pdata),nmax*(threads[i]?nthreads:1),cols,"atom:darray"); else { maxcols = *(mgrow.maxcols[i]); - memory->grow(*((double ***) pdata),nmax*threads[i],maxcols,"atom:darray"); + memory->grow(*((double ***) pdata),nmax*(threads[i]?nthreads:1),maxcols,"atom:darray"); } } else if (datatype == INT) { if (cols == 0) - memory->grow(*((int **) pdata),nmax*threads[i],"atom:ivec"); + memory->grow(*((int **) pdata),nmax*(threads[i]?nthreads:1),"atom:ivec"); else if (cols > 0) - memory->grow(*((int ***) pdata),nmax*threads[i],cols,"atom:iarray"); + memory->grow(*((int ***) pdata),nmax*(threads[i]?nthreads:1),cols,"atom:iarray"); else { maxcols = *(mgrow.maxcols[i]); - memory->grow(*((int ***) pdata),nmax*threads[i],maxcols,"atom:iarray"); + memory->grow(*((int ***) pdata),nmax*(threads[i]?nthreads:1),maxcols,"atom:iarray"); } } else if (datatype == BIGINT) { if (cols == 0) - memory->grow(*((bigint **) pdata),nmax*threads[i],"atom:bvec"); + memory->grow(*((bigint **) pdata),nmax*(threads[i]?nthreads:1),"atom:bvec"); else if (cols > 0) - memory->grow(*((bigint ***) pdata),nmax*threads[i],cols,"atom:barray"); + memory->grow(*((bigint ***) pdata),nmax*(threads[i]?nthreads:1),cols,"atom:barray"); else { maxcols = *(mgrow.maxcols[i]); - memory->grow(*((int ***) pdata),nmax*threads[i],maxcols,"atom:barray"); + memory->grow(*((int ***) pdata),nmax*(threads[i]?nthreads:1),maxcols,"atom:barray"); } } } @@ -2281,6 +2281,7 @@ bigint AtomVec::memory_usage() { int datatype,cols,index,maxcols; void *pdata; + int nthreads = comm->nthreads; bigint bytes = 0; @@ -2299,30 +2300,30 @@ bigint AtomVec::memory_usage() index = mgrow.index[i]; if (datatype == DOUBLE) { if (cols == 0) { - bytes += memory->usage(*((double **) pdata),nmax*threads[i]); + bytes += memory->usage(*((double **) pdata),nmax*(threads[i]?nthreads:1)); } else if (cols > 0) { - bytes += memory->usage(*((double ***) pdata),nmax*threads[i],cols); + bytes += memory->usage(*((double ***) pdata),nmax*(threads[i]?nthreads:1),cols); } else { maxcols = *(mgrow.maxcols[i]); - bytes += memory->usage(*((double ***) pdata),nmax*threads[i],maxcols); + bytes += memory->usage(*((double ***) pdata),nmax*(threads[i]?nthreads:1),maxcols); } } else if (datatype == INT) { if (cols == 0) { - bytes += memory->usage(*((int **) pdata),nmax*threads[i]); + bytes += memory->usage(*((int **) pdata),nmax*(threads[i]?nthreads:1)); } else if (cols > 0) { - bytes += memory->usage(*((int ***) pdata),nmax*threads[i],cols); + bytes += memory->usage(*((int ***) pdata),nmax*(threads[i]?nthreads:1),cols); } else { maxcols = *(mgrow.maxcols[i]); - bytes += memory->usage(*((int ***) pdata),nmax*threads[i],maxcols); + bytes += memory->usage(*((int ***) pdata),nmax*(threads[i]?nthreads:1),maxcols); } } else if (datatype == BIGINT) { if (cols == 0) { - bytes += memory->usage(*((bigint **) pdata),nmax*threads[i]); + bytes += memory->usage(*((bigint **) pdata),nmax*(threads[i]?nthreads:1)); } else if (cols > 0) { - bytes += memory->usage(*((bigint ***) pdata),nmax*threads[i],cols); + bytes += memory->usage(*((bigint ***) pdata),nmax*(threads[i]?nthreads:1),cols); } else { maxcols = *(mgrow.maxcols[i]); - bytes += memory->usage(*((bigint ***) pdata),nmax*threads[i],maxcols); + bytes += memory->usage(*((bigint ***) pdata),nmax*(threads[i]?nthreads:1),maxcols); } } } @@ -2383,11 +2384,10 @@ void AtomVec::setup_fields() // create threads data struct for grow and memory_usage to use - threads = new int[ngrow]; + threads = new bool[ngrow]; for (int i = 0; i < ngrow; i++) { Atom::PerAtom *field = &atom->peratom[mgrow.index[i]]; - if (field->threadflag) threads[i] = nthreads; - else threads[i] = 1; + threads[i] = (field->threadflag) ? true : false; } // set style-specific sizes diff --git a/src/atom_vec.h b/src/atom_vec.h index 148e2d4785..46a241becb 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -207,8 +207,7 @@ class AtomVec : protected Pointers { // thread info for fields that are duplicated over threads // used by fields in grow() and memory_usage() - int nthreads; - int *threads; + bool *threads; // union data struct for packing 32-bit and 64-bit ints into double bufs // this avoids aliasing issues by having 2 pointers (double,int)