Commit c9c2ae6c authored by Steve Plimpton's avatar Steve Plimpton
Browse files

new neighbor list changes

parent 0252347d
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -5,12 +5,6 @@
#         sh Make.sh Makefile.shlib
#         sh Make.sh Makefile.list

# turn off enforced customizations
GREP_OPTIONS=
# enforce using portable C locale
LC_ALL=C
export LC_ALL GREP_OPTIONS

# function to create one style_*.h file
# must whack *.d files that depend on style_*.h file,
# else Make will not recreate them
@@ -59,8 +53,9 @@ style () {
# called by "make machine"
# col 1 = string to search for
# col 2 = search in *.h files starting with this name
# col 3 = prefix of style file
# col 4 
# col 3 = name of style file
# col 4 = file that includes the style file
# col 5 = optional 2nd file that includes the style file

if (test $1 = "style") then

@@ -69,7 +64,7 @@ if (test $1 = "style") then
  style BODY_CLASS      body_       body       atom_vec_body
  style BOND_CLASS      bond_       bond       force
  style COMMAND_CLASS   ""          command    input
  style COMPUTE_CLASS   compute_    compute    modify    modify_cuda
  style COMPUTE_CLASS   compute_    compute    modify
  style DIHEDRAL_CLASS  dihedral_   dihedral   force
  style DUMP_CLASS      dump_       dump       output    write_dump
  style FIX_CLASS       fix_        fix        modify
@@ -77,6 +72,10 @@ if (test $1 = "style") then
  style INTEGRATE_CLASS ""          integrate  update
  style KSPACE_CLASS    ""          kspace     force
  style MINIMIZE_CLASS  min_        minimize   update
  style NBIN_CLASS      nbin_       nbin       neighbor
  style NPAIR_CLASS     npair_      npair      neighbor
  style NSTENCIL_CLASS  nstencil_   nstencil   neighbor
  style NTOPO_CLASS     ntopo_      ntopo      neighbor
  style PAIR_CLASS      pair_       pair       force
  style READER_CLASS    reader_     reader     read_dump
  style REGION_CLASS    region_     region     domain
+33 −0
Original line number Diff line number Diff line
@@ -13,6 +13,39 @@ style_kspace.h
style_minimize.h
style_pair.h
style_region.h
style_neigh_bin.h
style_neigh_pair.h
style_neigh_stencil.h
# deleted on 30 Aug 2016
accelerator_intel.h
neigh_bond.cpp
neigh_bond.h
neigh_derive.cpp
neigh_derive.h
neigh_full.cpp
neigh_full.h
neigh_gran.cpp
neigh_gran.h
neigh_half_bin.cpp
neigh_half_bin.h
neigh_half_multi.cpp
neigh_half_multi.h
neigh_half_nsq.cpp
neigh_half_nsq.h
neigh_respa.cpp
neigh_respa.h
neigh_shardlow.cpp
neigh_shardlow.h
neigh_stencil.cpp
neigh_half_bin_intel.cpp
neighbor_omp.h
neigh_derive_omp.cpp
neigh_full_omp.cpp
neigh_gran_omp.cpp
neigh_half_bin_omp.cpp
neigh_half_multi_omp.cpp
neigh_half_nsq_omp.cpp
neigh_respa_omp.cpp
# deleted on 31 May 2016
fix_ave_spatial_sphere.cpp
fix_ave_spatial_sphere.h
+57 −184
Original line number Diff line number Diff line
@@ -16,195 +16,38 @@
   James Larentzos and Timothy I. Mattox (Engility Corporation)
------------------------------------------------------------------------- */

#include "npair_half_bin_newton_ssa.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "atom.h"
#include "atom_vec.h"
#include "molecule.h"
#include "domain.h"
#include "group.h"
#include "memory.h"
#include "my_page.h"
#include "error.h"
#include "update.h"

using namespace LAMMPS_NS;

/* ----------------------------------------------------------------------
   routines to create a stencil = list of bin offsets
   stencil = bins whose closest corner to central bin is within cutoff
   sx,sy,sz = bin bounds = furthest the stencil could possibly extend
   3d creates xyz stencil, 2d creates xy stencil
   for half list with newton on:
     stencil is bins to the "upper right" of central bin
     stencil does not include self
------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------- */

void Neighbor::stencil_half_bin_2d_ssa(NeighList *list,
                                   int sx, int sy, int sz)
{
  int i,j;
  int *stencil = list->stencil;
  int nstencil = 0;

  for (j = 0; j <= sy; j++)
    for (i = -sx; i <= sx; i++)
      if (j > 0 || (j == 0 && i > 0))
        if (bin_distance(i,j,0) < cutneighmaxsq)
          stencil[nstencil++] = j*mbinx + i;

  list->nstencil = nstencil;

  // Now include additional bins for AIR ghosts only
  for (j = -sy; j <= 0; j++)
    for (i = -sx; i <= sx; i++) {
      if (j == 0 && i > 0) continue;
      if (bin_distance(i,j,0) < cutneighmaxsq)
        stencil[nstencil++] = j*mbinx + i;
    }
// allocate space for static class variable
// prototype for non-class function

  while (nstencil < list->maxstencil) {
    stencil[nstencil++] = INT_MAX;
  }
}

/* ---------------------------------------------------------------------- */

void Neighbor::stencil_half_bin_3d_ssa(NeighList *list,
                                   int sx, int sy, int sz)
{
  int i,j,k;
  int *stencil = list->stencil;
  int nstencil = 0;

  for (k = 0; k <= sz; k++)
    for (j = -sy; j <= sy; j++)
      for (i = -sx; i <= sx; i++)
        if (k > 0 || j > 0 || (j == 0 && i > 0))
          if (bin_distance(i,j,k) < cutneighmaxsq)
            stencil[nstencil++] = k*mbiny*mbinx + j*mbinx + i;

  list->nstencil = nstencil;

  // Now include additional bins for AIR ghosts only
  for (k = -sz; k < 0; k++)
    for (j = -sy; j <= sy; j++)
      for (i = -sx; i <= sx; i++)
        if (bin_distance(i,j,k) < cutneighmaxsq)
          stencil[nstencil++] = k*mbiny*mbinx + j*mbinx + i;
  k = 0; // skip already included bins at k == 0
  for (j = -sy; j <= 0; j++)
    for (i = -sx; i <= sx; i++) {
      if (j == 0 && i > 0) continue;
      if (bin_distance(i,j,k) < cutneighmaxsq)
        stencil[nstencil++] = k*mbiny*mbinx + j*mbinx + i;
    }

  while (nstencil < list->maxstencil) {
    stencil[nstencil++] = INT_MAX;
  }
}

// space for static variable ssaAIRptr so it
// can be used in qsort's compair function "cmp_ssaAIR()"
static int *ssaAIRptr;
static int cmp_ssaAIR(const void *, const void *);

static int cmp_ssaAIR(const void *iptr, const void *jptr)
{
  int i = *((int *) iptr);
  int j = *((int *) jptr);
  if (ssaAIRptr[i] < ssaAIRptr[j]) return -1;
  if (ssaAIRptr[i] > ssaAIRptr[j]) return 1;
  return 0;
}


/* ----------------------------------------------------------------------
   build half list from full list for use by Shardlow Spliting Algorithm
   pair stored once if i,j are both owned and i < j
   if j is ghost, only store if j coords are "above and to the right" of i
   works if full list is a skip list
------------------------------------------------------------------------- */

void Neighbor::half_from_full_newton_ssa(NeighList *list)
{
  int i,j,ii,jj,n,jnum,joriginal;
  int *neighptr,*jlist;

  int nlocal = atom->nlocal;
  int *ssaAIR = atom->ssaAIR;

  int *ilist = list->ilist;
  int *numneigh = list->numneigh;
  int **firstneigh = list->firstneigh;
  MyPage<int> *ipage = list->ipage;

  int *ilist_full = list->listfull->ilist;
  int *numneigh_full = list->listfull->numneigh;
  int **firstneigh_full = list->listfull->firstneigh;
  int inum_full = list->listfull->inum;

  int inum = 0;
  ipage->reset();

  // loop over parent full list

  for (ii = 0; ii < inum_full; ii++) {
    int AIRct[8] = { 0 };
    n = 0;
    neighptr = ipage->vget();

    i = ilist_full[ii];

    // loop over full neighbor list

    jlist = firstneigh_full[i];
    jnum = numneigh_full[i];

    for (jj = 0; jj < jnum; jj++) {
      joriginal = jlist[jj];
      j = joriginal & NEIGHMASK;
      if (j < nlocal) {
        if (i > j) continue;
        ++(AIRct[0]);
      } else {
        if (ssaAIR[j] < 2) continue; // skip ghost atoms not in AIR
        ++(AIRct[ssaAIR[j] - 1]);
      }
      neighptr[n++] = joriginal;
    }

    ilist[inum++] = i;
    firstneigh[i] = neighptr;
    numneigh[i] = n;
    ipage->vgot(n);
    if (ipage->status())
      error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");

    // sort the locals+ghosts in the neighbor list by their ssaAIR number
    ssaAIRptr = atom->ssaAIR;
    qsort(&(neighptr[0]), n, sizeof(int), cmp_ssaAIR);

    // Do a prefix sum on the counts to turn them into indexes.
    list->ndxAIR_ssa[i][0] = AIRct[0];
    for (int ndx = 1; ndx < 8; ++ndx) {
      list->ndxAIR_ssa[i][ndx] = AIRct[ndx] + list->ndxAIR_ssa[i][ndx - 1];
    }
  }
/* ---------------------------------------------------------------------- */

  list->inum = inum;
}
NPairHalfBinNewtonSSA::NPairHalfBinNewtonSSA(LAMMPS *lmp) : NPair(lmp) {}

/* ----------------------------------------------------------------------
   for Shardlow Spliting Algorithm:
   binned neighbor list construction with full Newton's 3rd law
   for use by Shardlow Spliting Algorithm
   each owned atom i checks its own bin and other bins in Newton stencil
   every pair stored exactly once by some processor
------------------------------------------------------------------------- */

void Neighbor::half_bin_newton_ssa(NeighList *list)
void NPairHalfBinNewtonSSA::build(NeighList *list)
{
  int i,j,k,n,itype,jtype,ibin,which,imol,iatom,moltemplate;
  tagint tagprev;
@@ -220,6 +63,7 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
  int **nspecial = atom->nspecial;
  int nlocal = atom->nlocal;
  int nall = nlocal + atom->nghost;
  if (includegroup) nlocal = atom->nfirst;
  int *ssaAIR = atom->ssaAIR;

  int *molindex = atom->molindex;
@@ -232,18 +76,27 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
  int *ilist = list->ilist;
  int *numneigh = list->numneigh;
  int **firstneigh = list->firstneigh;
  int nstencil = list->nstencil;
  int maxstencil = list->maxstencil;
  int *stencil = list->stencil;
  MyPage<int> *ipage = list->ipage;

  int inum = 0;

  if (binatomflag) { /* only false in Neighbor::build_one */
/* ----------------------------------------------------------------------
   bin owned and ghost atoms for use by Shardlow Splitting Algorithm
    exclude ghost atoms that are not in the Active Interaction Regions (AIR)
------------------------------------------------------------------------- */
  // bin owned and ghost atoms for use by Shardlow Splitting Algorithm
  // exclude ghost atoms that are not in the Active Interaction Regions (AIR)

  // NOTE to Tim: this binatomflag no longer exists
  //   the logic up higher assures that binning has been done
  //     before this build() method is called
  //   maybe this code below needs to be in a new NBinShardlow class?
  // this class also inherits NPair::nb from its parent
  //   which points to the NBin class that did the binning
  //   there are last_step variables stored there which indicate
  //   the last time binning was done
  // the basic question is what data is created/stored by SSA binning
  //   and in what class should it live?
  //   if it is created by the binning operation, then I think
  //     it should be in a new NBinShardlow class

  if (true /* binatomflag */) { // only false in Neighbor::build_one

    if (mbins > list->maxhead_ssa) {
      list->maxhead_ssa = mbins;
@@ -257,8 +110,8 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
      list->binhead_ssa[i] = -1;
    }

    if (maxbin > list->maxbin_ssa) {
      list->maxbin_ssa = maxbin;
    if (nall > list->maxbin_ssa) {
      list->maxbin_ssa = nall;
      memory->destroy(list->bins_ssa);
      memory->create(list->bins_ssa,list->maxbin_ssa,"bins_ssa");
    }
@@ -267,7 +120,8 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)

    if (includegroup) {
      int bitmask = group->bitmask[includegroup];
      for (i = nall-1; i >= nlocal; i--) {
      int nowned = atom->nlocal; // NOTE: nlocal was set to atom->nfirst above
      for (i = nall-1; i >= nowned; i--) {
        if (ssaAIR[i] < 2) continue; // skip ghost atoms not in AIR
        if (mask[i] & bitmask) {
          ibin = coord2bin(x[i]);
@@ -275,7 +129,6 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
          list->gbinhead_ssa[ibin] = i;
        }
      }
      nlocal = atom->nfirst; // This is important for the code that follows!
    } else {
      for (i = nall-1; i >= nlocal; i--) {
        if (ssaAIR[i] < 2) continue; // skip ghost atoms not in AIR
@@ -289,7 +142,7 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
      list->bins_ssa[i] = list->binhead_ssa[ibin];
      list->binhead_ssa[ibin] = i;
    }
  } /* else reuse previous binning. See Neighbor::build_one comment. */
  }  // else reuse previous binning. See Neighbor::build_one comment

  ipage->reset();

@@ -343,8 +196,10 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
    ibin = coord2bin(x[i]);

    // loop over all local atoms in other bins in "half" stencil

    for (k = 0; k < nstencil; k++) {
      for (j = list->binhead_ssa[ibin+stencil[k]]; j >= 0; j = list->bins_ssa[j]) {
      for (j = list->binhead_ssa[ibin+stencil[k]]; j >= 0; 
           j = list->bins_ssa[j]) {

        jtype = type[j];
        if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
@@ -377,9 +232,10 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
    // Note: the non-AIR ghost atoms have already been filtered out
    // That is a significant time savings because of the "full" stencil
    // Note2: only non-pure locals can have ghosts as neighbors
    if (ssaAIR[i] == 1) for (k = 0; k < maxstencil; k++) {
      if (stencil[k] > mbins) break; /* Check if ghost stencil bins are exhausted */
      for (j = list->gbinhead_ssa[ibin+stencil[k]]; j >= 0; j = list->bins_ssa[j]) {

    if (ssaAIR[i] == 1) for (k = 0; k < nstencil_ssa; k++) {
      for (j = list->gbinhead_ssa[ibin+stencil[k]]; j >= 0; 
           j = list->bins_ssa[j]) {

        jtype = type[j];
        if (exclude && exclusion(i,j,itype,jtype,mask,molecule)) continue;
@@ -424,10 +280,12 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)
      error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");

    // sort the ghosts in the neighbor list by their ssaAIR number

    ssaAIRptr = atom->ssaAIR;
    qsort(&(neighptr[AIRct[0]]), n - AIRct[0], sizeof(int), cmp_ssaAIR);

    // Do a prefix sum on the counts to turn them into indexes.
    // do a prefix sum on the counts to turn them into indexes

    list->ndxAIR_ssa[i][0] = AIRct[0];
    for (int ndx = 1; ndx < 8; ++ndx) {
      list->ndxAIR_ssa[i][ndx] = AIRct[ndx] + list->ndxAIR_ssa[i][ndx - 1];
@@ -436,3 +294,18 @@ void Neighbor::half_bin_newton_ssa(NeighList *list)

  list->inum = inum;
}

/* ----------------------------------------------------------------------
   comparison function invoked by qsort()
   accesses static class member ssaAIRptr, set before call to qsort()
------------------------------------------------------------------------- */

static int cmp_ssaAIR(const void *iptr, const void *jptr)
{
  int i = *((int *) iptr);
  int j = *((int *) jptr);
  if (ssaAIRptr[i] < ssaAIRptr[j]) return -1;
  if (ssaAIRptr[i] > ssaAIRptr[j]) return 1;
  return 0;
}
+0 −1
Original line number Diff line number Diff line
@@ -226,7 +226,6 @@ void FixShardlow::ssa_update(
  int newton_pair = force->newton_pair;
  double randPair;

  int *ssaAIR = atom->ssaAIR;
  double *uCond = atom->uCond;
  double *uMech = atom->uMech;
  double *dpdTheta = atom->dpdTheta;
+311 −0

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading