From d10a470245c3cef9a0083e3d5855f58e7599bdc0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 18 May 2018 06:43:23 -0400 Subject: [PATCH] second try to implement changes suggested in issue #888 In src/rcb.cpp:460 there is an if (smaller > largest). now if we have one particle you will see that lo[] = hi[] and because of this smaller == largest == 0 for all values of dim. This causes this particular part of the code to never be run. In particular the memcpy inside this if is never executed. This causes an unitialized memory access in line 472. Additionally, dim is initialized with -1 and thus the accesses in 484 and 485 are problematic. Additionally, valuehalf_select is never initialized either. closes #888 --- src/balance.cpp | 14 ++++++++++++++ src/rcb.cpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/balance.cpp b/src/balance.cpp index 86deb55b47..ed44e3ee0e 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -28,6 +28,7 @@ #include "rcb.h" #include "irregular.h" #include "domain.h" +#include "neighbor.h" #include "force.h" #include "update.h" #include "group.h" @@ -643,6 +644,19 @@ int *Balance::bisection(int sortflag) double *shrinklo = &shrinkall[0]; double *shrinkhi = &shrinkall[3]; + // ensure that that the box has at least some extent. + const double nproc_rt = domain->dimension == 3 ? + cbrt(static_cast(comm->nprocs)) : + sqrt(static_cast(comm->nprocs)); + const double min_extent = ceil(nproc_rt)*neighbor->skin; + for (int i = 0; i < domain->dimension; i++) { + if (shrinkall[3+i]-shrinkall[i] < min_extent) { + const double mid = 0.5*(shrinkall[3+i]+shrinkall[i]); + shrinkall[3+i] = std::min(mid + min_extent*0.5, boxhi[i]); + shrinkall[i] = std::max(mid - min_extent*0.5, boxlo[i]); + } + } + // invoke RCB // then invert() to create list of proc assignments for my atoms // NOTE: (3/2017) can remove undocumented "old" option at some point diff --git a/src/rcb.cpp b/src/rcb.cpp index 3027920310..4ea70ee914 100644 --- a/src/rcb.cpp +++ b/src/rcb.cpp @@ -243,7 +243,7 @@ void RCB::compute(int dimension, int n, double **x, double *wt, // dotmark_select = dot markings in that dimension int dim_select = -1; - double largest = 0.0; + double largest = -1.0; for (dim = 0; dim < dimension; dim++) {