diff --git a/src/dihedral_hybrid.cpp b/src/dihedral_hybrid.cpp index 8088719491..48d879d435 100644 --- a/src/dihedral_hybrid.cpp +++ b/src/dihedral_hybrid.cpp @@ -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]; diff --git a/src/improper_hybrid.cpp b/src/improper_hybrid.cpp index a5781beba2..ed1a8075a9 100644 --- a/src/improper_hybrid.cpp +++ b/src/improper_hybrid.cpp @@ -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];