Merge release-5-0 into master
authorRoland Schulz <roland@utk.edu>
Thu, 31 Jul 2014 16:23:51 +0000 (12:23 -0400)
committerRoland Schulz <roland@utk.edu>
Thu, 31 Jul 2014 16:26:23 +0000 (12:26 -0400)
Change-Id: Ifc6c3180fe5803bc9a23a0be84be7c93ecb7f472

1  2 
src/gromacs/mdlib/nbnxn_search.c

index 0ee8b4d4d09303d14c4b06c927caf3ddc9227749,dc0b02013f645ed2f44acb66c6509f23e5350cb5..0826017bab62cad0285c13546270b01a9f8b85a8
   * the research papers on the package. Check out http://www.gromacs.org.
   */
  
 -#ifdef HAVE_CONFIG_H
 -#include <config.h>
 -#endif
 +#include "config.h"
  
  #include <math.h>
  #include <string.h>
  #include <assert.h>
  
 -#include "sysstuff.h"
 -#include "gromacs/utility/smalloc.h"
  #include "types/commrec.h"
  #include "macros.h"
  #include "gromacs/math/utilities.h"
 -#include "vec.h"
 -#include "pbc.h"
 +#include "gromacs/math/vec.h"
  #include "nbnxn_consts.h"
  /* nbnxn_internal.h included gromacs/simd/macros.h */
  #include "nbnxn_internal.h"
@@@ -55,9 -60,7 +55,9 @@@
  #include "nrnb.h"
  #include "ns.h"
  
 -#include "gromacs/fileio/gmxfio.h"
 +#include "gromacs/pbcutil/ishift.h"
 +#include "gromacs/pbcutil/pbc.h"
 +#include "gromacs/utility/smalloc.h"
  
  #ifdef NBNXN_SEARCH_BB_SIMD4
  /* Always use 4-wide SIMD for bounding box calculations */
@@@ -416,6 -419,12 +416,12 @@@ static real grid_atom_density(int n, rv
  {
      rvec size;
  
+     if (n == 0)
+     {
+         /* To avoid zero density we use a minimum of 1 atom */
+         n = 1;
+     }
      rvec_sub(corner1, corner0, size);
  
      return n/(size[XX]*size[YY]*size[ZZ]);
@@@ -436,6 -445,8 +442,8 @@@ static int set_grid_size_xy(const nbnxn
  
      if (n > grid->na_sc)
      {
+         assert(atom_density > 0);
          /* target cell length */
          if (grid->bSimple)
          {
@@@ -1371,13 -1382,14 +1379,13 @@@ static void sort_columns_supersub(cons
                                    int cxy_start, int cxy_end,
                                    int *sort_work)
  {
 -    int  cxy;
 -    int  cx, cy, cz = -1, c = -1, ncz;
 -    int  na, ash, na_c, ind, a;
 -    int  subdiv_z, sub_z, na_z, ash_z;
 -    int  subdiv_y, sub_y, na_y, ash_y;
 -    int  subdiv_x, sub_x, na_x, ash_x;
 +    int        cxy;
 +    int        cx, cy, cz = -1, c = -1, ncz;
 +    int        na, ash, na_c, ind, a;
 +    int        subdiv_z, sub_z, na_z, ash_z;
 +    int        subdiv_y, sub_y, na_y, ash_y;
 +    int        subdiv_x, sub_x, na_x, ash_x;
  
 -    /* cppcheck-suppress unassignedVariable */
      nbnxn_bb_t bb_work_array[2], *bb_work_aligned;
  
      bb_work_aligned = (nbnxn_bb_t *)(((size_t)(bb_work_array+1)) & (~((size_t)15)));
@@@ -1810,7 -1822,8 +1818,8 @@@ void nbnxn_put_on_grid(nbnxn_search_t n
          nbs->ePBC = ePBC;
          copy_mat(box, nbs->box);
  
-         if (atom_density >= 0)
+         /* Avoid zero density */
+         if (atom_density > 0)
          {
              grid->atom_density = atom_density;
          }
           * for the local atoms (dd_zone=0).
           */
          nbs->natoms_nonlocal = a1 - nmoved;
+         if (debug)
+         {
+             fprintf(debug, "natoms_local = %5d atom_density = %5.1f\n",
+                     nbs->natoms_local, grid->atom_density);
+         }
      }
      else
      {
          nbs->natoms_nonlocal = max(nbs->natoms_nonlocal, a1);
      }
  
+     /* We always use the home zone (grid[0]) for setting the cell size,
+      * since determining densities for non-local zones is difficult.
+      */
      nc_max_grid = set_grid_size_xy(nbs, grid,
                                     dd_zone, n-nmoved, corner0, corner1,
                                     nbs->grid[0].atom_density);