From c960b9295cab16665c88d12a14ae40c131ca0a8a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 17 May 2018 04:27:08 -0400 Subject: [PATCH 1/3] fix cut-n-paste error in fix property/local docs correct issue reported in comment at https://github.com/lammps/lammps/pull/911 --- doc/src/compute_property_local.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/compute_property_local.txt b/doc/src/compute_property_local.txt index 39106a39c8..e4e6f1ef1e 100644 --- a/doc/src/compute_property_local.txt +++ b/doc/src/compute_property_local.txt @@ -19,8 +19,8 @@ one or more attributes may be appended :l patom1 patom2 ptype1 ptype2 batom1 batom2 btype aatom1 aatom2 aatom3 atype - datom1 datom2 datom3 dtype - iatom1 iatom2 iatom3 itype :pre + datom1 datom2 datom3 datom4 dtype + iatom1 iatom2 iatom3 iatom4 itype :pre natom1, natom2 = IDs of 2 atoms in each pair (within neighbor cutoff) ntype1, ntype2 = type of 2 atoms in each pair (within neighbor cutoff) From d10a470245c3cef9a0083e3d5855f58e7599bdc0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 18 May 2018 06:43:23 -0400 Subject: [PATCH 2/3] 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++) { From d5594350c4f57dae239ba5c3c00b1f831f3456e2 Mon Sep 17 00:00:00 2001 From: "Steven J. Plimpton" Date: Thu, 9 Aug 2018 08:50:11 -0600 Subject: [PATCH 3/3] change zero-size shrink box to original box --- doc/src/compute_property_local.txt | 14 +++++++------- src/balance.cpp | 31 +++++++++++++++++------------- src/rcb.cpp | 2 ++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/doc/src/compute_property_local.txt b/doc/src/compute_property_local.txt index e4e6f1ef1e..c4ad0afc95 100644 --- a/doc/src/compute_property_local.txt +++ b/doc/src/compute_property_local.txt @@ -2,7 +2,7 @@ :link(lws,http://lammps.sandia.gov) :link(ld,Manual.html) -:link(lc,Section_commands.html#comm) +:link(lc,Commands_all.html) :line @@ -48,10 +48,10 @@ compute 1 all property/local atype aatom2 :pre Define a computation that stores the specified attributes as local data so it can be accessed by other "output -commands"_Section_howto.html#howto_15. If the input attributes refer -to bond information, then the number of datums generated, aggregated -across all processors, equals the number of bonds in the system. -Ditto for pairs, angles, etc. +commands"_Howto_output.html. If the input attributes refer to bond +information, then the number of datums generated, aggregated across +all processors, equals the number of bonds in the system. Ditto for +pairs, angles, etc. If multiple attributes are specified then they must all generate the same amount of information, so that the resulting local array has the @@ -140,8 +140,8 @@ the array is the number of bonds, angles, etc. If a single input is specified, a local vector is produced. If two or more inputs are specified, a local array is produced where the number of columns = the number of inputs. The vector or array can be accessed by any command -that uses local values from a compute as input. See "this -section"_Section_howto.html#howto_15 for an overview of LAMMPS output +that uses local values from a compute as input. See the "Howto +output"_Howto_output.html doc page for an overview of LAMMPS output options. The vector or array values will be integers that correspond to the diff --git a/src/balance.cpp b/src/balance.cpp index ed44e3ee0e..2a953caf47 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -28,7 +28,6 @@ #include "rcb.h" #include "irregular.h" #include "domain.h" -#include "neighbor.h" #include "force.h" #include "update.h" #include "group.h" @@ -351,13 +350,13 @@ void Balance::command(int narg, char **arg) domain->set_local_box(); // move particles to new processors via irregular() + // set disable = 0, so weights migrate with atoms for imbfinal calculation if (domain->triclinic) domain->x2lamda(atom->nlocal); Irregular *irregular = new Irregular(lmp); if (wtflag) fixstore->disable = 0; if (style == BISECTION) irregular->migrate_atoms(1,1,rcb->sendproc); else irregular->migrate_atoms(1); - if (wtflag) fixstore->disable = 1; delete irregular; if (domain->triclinic) domain->lamda2x(atom->nlocal); @@ -378,9 +377,11 @@ void Balance::command(int narg, char **arg) } // imbfinal = final imbalance + // set disable = 1, so weights no longer migrate with atoms double maxfinal; double imbfinal = imbalance_factor(maxfinal); + if (wtflag) fixstore->disable = 1; // stats output @@ -541,6 +542,8 @@ void Balance::weight_storage(char *prefix) fixstore = (FixStore *) modify->fix[modify->nfix-1]; } else fixstore = (FixStore *) modify->fix[ifix]; + // do not carry weights with atoms during normal atom migration + fixstore->disable = 1; if (prefix) delete [] fixargs[0]; @@ -644,17 +647,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]); - } + // if shrink size in any dim is zero, use box size in that dim + + if (shrinklo[0] == shrinkhi[0]) { + shrinklo[0] = boxlo[0]; + shrinkhi[0] = boxhi[0]; + } + if (shrinklo[1] == shrinkhi[1]) { + shrinklo[1] = boxlo[1]; + shrinkhi[1] = boxhi[1]; + } + if (shrinklo[2] == shrinkhi[2]) { + shrinklo[2] = boxlo[2]; + shrinkhi[2] = boxhi[2]; } // invoke RCB diff --git a/src/rcb.cpp b/src/rcb.cpp index 4ea70ee914..13e27b6fbf 100644 --- a/src/rcb.cpp +++ b/src/rcb.cpp @@ -241,6 +241,8 @@ void RCB::compute(int dimension, int n, double **x, double *wt, // dim_select = selected cut dimension // valuehalf_select = valuehalf in that dimension // dotmark_select = dot markings in that dimension + // initialize largest = -1.0 to insure a cut in some dim is accepted + // e.g. if current recursed box is size 0 in all dims int dim_select = -1; double largest = -1.0;