avoid uninitialized data access for hybrid styles with OPENMP

This commit is contained in:
Axel Kohlmeyer
2021-08-02 15:22:21 -04:00
parent 50e8d7c36b
commit 45858be1b6
2 changed files with 32 additions and 0 deletions

View File

@ -33,7 +33,11 @@ using namespace LAMMPS_NS;
DihedralHybrid::DihedralHybrid(LAMMPS *lmp) : Dihedral(lmp)
{
writedata = 0;
nstyles = 0;
ndihedrallist = nullptr;
dihedrallist = nullptr;
maxdihedral = nullptr;
}
/* ---------------------------------------------------------------------- */
@ -108,6 +112,18 @@ void DihedralHybrid::compute(int eflag, int vflag)
ev_init(eflag,vflag);
// need to clear per-thread storage here, when using multiple threads
// with thread-enabled substyles to avoid uninitlialized data access.
const int nthreads = comm->nthreads;
if (comm->nthreads > 1) {
const bigint nall = atom->nlocal + atom->nghost;
if (eflag_atom)
memset(&eatom[0],0,nall*nthreads*sizeof(double));
if (vflag_atom)
memset(&vatom[0][0],0,6*nall*nthreads*sizeof(double));
}
for (m = 0; m < nstyles; m++) {
neighbor->ndihedrallist = ndihedrallist[m];
neighbor->dihedrallist = dihedrallist[m];

View File

@ -32,7 +32,11 @@ using namespace LAMMPS_NS;
ImproperHybrid::ImproperHybrid(LAMMPS *lmp) : Improper(lmp)
{
writedata = 0;
nstyles = 0;
nimproperlist = nullptr;
improperlist = nullptr;
maximproper = nullptr;
}
/* ---------------------------------------------------------------------- */
@ -107,6 +111,18 @@ void ImproperHybrid::compute(int eflag, int vflag)
ev_init(eflag,vflag);
// need to clear per-thread storage here, when using multiple threads
// with thread-enabled substyles to avoid uninitlialized data access.
const int nthreads = comm->nthreads;
if (comm->nthreads > 1) {
const bigint nall = atom->nlocal + atom->nghost;
if (eflag_atom)
memset(&eatom[0],0,nall*nthreads*sizeof(double));
if (vflag_atom)
memset(&vatom[0][0],0,6*nall*nthreads*sizeof(double));
}
for (m = 0; m < nstyles; m++) {
neighbor->nimproperlist = nimproperlist[m];
neighbor->improperlist = improperlist[m];