From a7f4bbffcfc60fdf25a25e2c9f6c039622aa58dd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 26 Aug 2021 07:10:47 -0400 Subject: [PATCH] avoid segfault when trying to apply (strict) pbc or convert to/from fractional coordinates on an MPI rank without atoms --- src/OPENMP/domain_omp.cpp | 10 +++++++--- src/domain.cpp | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/OPENMP/domain_omp.cpp b/src/OPENMP/domain_omp.cpp index 94a0b094a7..dffb58e2da 100644 --- a/src/OPENMP/domain_omp.cpp +++ b/src/OPENMP/domain_omp.cpp @@ -37,6 +37,9 @@ typedef struct { double x,y,z; } dbl3_t; void DomainOMP::pbc() { + const int nlocal = atom->nlocal; + if (!nlocal) return; + dbl3_t * _noalias const x = (dbl3_t *)&atom->x[0][0]; dbl3_t * _noalias const v = (dbl3_t *)&atom->v[0][0]; const double * _noalias const lo = (triclinic == 0) ? boxlo : boxlo_lamda; @@ -44,7 +47,6 @@ void DomainOMP::pbc() const double * _noalias const period = (triclinic == 0) ? prd : prd_lamda; const int * _noalias const mask = atom->mask; imageint * _noalias const image = atom->image; - const int nlocal = atom->nlocal; #if defined(_OPENMP) #pragma omp parallel for LMP_DEFAULT_NONE schedule(static) @@ -141,8 +143,9 @@ void DomainOMP::pbc() void DomainOMP::lamda2x(int n) { - dbl3_t * _noalias const x = (dbl3_t *)&atom->x[0][0]; const int num = n; + if (!n) return; + dbl3_t * _noalias const x = (dbl3_t *)&atom->x[0][0]; #if defined(_OPENMP) #pragma omp parallel for LMP_DEFAULT_NONE schedule(static) @@ -161,8 +164,9 @@ void DomainOMP::lamda2x(int n) void DomainOMP::x2lamda(int n) { - dbl3_t * _noalias const x = (dbl3_t *)&atom->x[0][0]; const int num = n; + if (!n) return; + dbl3_t * _noalias const x = (dbl3_t *)&atom->x[0][0]; #if defined(_OPENMP) #pragma omp parallel for LMP_DEFAULT_NONE schedule(static) diff --git a/src/domain.cpp b/src/domain.cpp index 7df82fbfb3..958c3f09db 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -528,10 +528,11 @@ void Domain::reset_box() void Domain::pbc() { + int nlocal = atom->nlocal; + if (!nlocal) return; int i; imageint idim,otherdims; double *lo,*hi,*period; - int nlocal = atom->nlocal; double **x = atom->x; double **v = atom->v; int *mask = atom->mask;