Skip to content

Commit

Permalink
Merge pull request lammps#3974 from stanmoore1/skip_trim
Browse files Browse the repository at this point in the history
Add trim option to skip neighbor list build styles
  • Loading branch information
akohlmey authored Nov 19, 2023
2 parents 6ae0715 + d1f3411 commit de7f876
Show file tree
Hide file tree
Showing 30 changed files with 1,511 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@

#ifdef NPAIR_CLASS
// clang-format off
NPairStyle(halffull/newtoff/trim/intel,
NPairHalffullNewtoffTrim,
NPairStyle(halffull/trim/newtoff/intel,
NPairHalffullTrimNewtoff,
NP_HALF_FULL | NP_NEWTOFF | NP_NSQ | NP_BIN | NP_MULTI | NP_HALF |
NP_ORTHO | NP_TRI | NP_TRIM | NP_INTEL);

NPairStyle(halffull/newtoff/skip/trim/intel,
NPairHalffullNewtoffTrim,
NPairStyle(halffull/trim/newtoff/skip/intel,
NPairHalffullTrimNewtoff,
NP_HALF_FULL | NP_NEWTOFF | NP_NSQ | NP_BIN | NP_MULTI | NP_HALF |
NP_ORTHO | NP_TRI | NP_SKIP | NP_TRIM | NP_INTEL);
NP_ORTHO | NP_TRI | NP_TRIM | NP_SKIP | NP_INTEL);

NPairStyle(halffull/newtoff/ghost/trim/intel,
NPairHalffullNewtoffTrim,
NPairStyle(halffull/trim/newtoff/ghost/intel,
NPairHalffullTrimNewtoff,
NP_HALF_FULL | NP_NEWTOFF | NP_NSQ | NP_BIN | NP_MULTI | NP_HALF |
NP_ORTHO | NP_TRI | NP_GHOST | NP_TRIM | NP_INTEL);
NP_ORTHO | NP_TRI | NP_TRIM | NP_GHOST | NP_INTEL);

NPairStyle(halffull/newtoff/skip/ghost/trim/intel,
NPairHalffullNewtoffTrim,
NPairStyle(halffull/trim/newtoff/skip/ghost/intel,
NPairHalffullTrimNewtoff,
NP_HALF_FULL | NP_NEWTOFF | NP_NSQ | NP_BIN | NP_MULTI | NP_HALF |
NP_ORTHO | NP_TRI | NP_SKIP | NP_GHOST | NP_TRIM | NP_INTEL);
NP_ORTHO | NP_TRI | NP_TRIM | NP_SKIP | NP_GHOST | NP_INTEL);
// clang-format on
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Contributing author: Stan Moore (SNL)
------------------------------------------------------------------------- */

#include "npair_halffull_newton_trim_intel.h"
#include "npair_halffull_trim_newton_intel.h"

#include "atom.h"
#include "comm.h"
Expand All @@ -31,7 +31,7 @@ using namespace LAMMPS_NS;

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

NPairHalffullNewtonTrimIntel::NPairHalffullNewtonTrimIntel(LAMMPS *lmp) : NPair(lmp) {
NPairHalffullTrimNewtonIntel::NPairHalffullTrimNewtonIntel(LAMMPS *lmp) : NPair(lmp) {
_fix = static_cast<FixIntel *>(modify->get_fix_by_id("package_intel"));
if (!_fix) error->all(FLERR, "The 'package intel' command is required for /intel styles");
}
Expand All @@ -44,7 +44,7 @@ NPairHalffullNewtonTrimIntel::NPairHalffullNewtonTrimIntel(LAMMPS *lmp) : NPair(
------------------------------------------------------------------------- */

template <class flt_t, class acc_t>
void NPairHalffullNewtonTrimIntel::build_t(NeighList *list,
void NPairHalffullTrimNewtonIntel::build_t(NeighList *list,
IntelBuffers<flt_t,acc_t> *buffers)
{
const int inum_full = list->listfull->inum;
Expand Down Expand Up @@ -182,7 +182,7 @@ void NPairHalffullNewtonTrimIntel::build_t(NeighList *list,
------------------------------------------------------------------------- */

template <class flt_t, class acc_t>
void NPairHalffullNewtonTrimIntel::build_t3(NeighList *list, int *numhalf,
void NPairHalffullTrimNewtonIntel::build_t3(NeighList *list, int *numhalf,
IntelBuffers<flt_t,acc_t> *buffers)
{
const int inum_full = list->listfull->inum;
Expand Down Expand Up @@ -272,7 +272,7 @@ void NPairHalffullNewtonTrimIntel::build_t3(NeighList *list, int *numhalf,

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

void NPairHalffullNewtonTrimIntel::build(NeighList *list)
void NPairHalffullTrimNewtonIntel::build(NeighList *list)
{
if (_fix->three_body_neighbor() == 0 || domain->triclinic) {
if (_fix->precision() == FixIntel::PREC_MODE_MIXED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

#ifdef NPAIR_CLASS
// clang-format off
NPairStyle(halffull/newton/trim/intel,
NPairHalffullNewtonTrimIntel,
NPairStyle(halffull/trim/newton/intel,
NPairHalffullTrimNewtonIntel,
NP_HALF_FULL | NP_NEWTON | NP_HALF | NP_NSQ | NP_BIN | NP_MULTI |
NP_ORTHO | NP_TRI| NP_TRIM | NP_INTEL);

NPairStyle(halffull/newton/skip/trim/intel,
NPairHalffullNewtonTrimIntel,
NPairStyle(halffull/trim/newton/skip/intel,
NPairHalffullTrimNewtonIntel,
NP_HALF_FULL | NP_NEWTON | NP_HALF | NP_NSQ | NP_BIN | NP_MULTI |
NP_ORTHO | NP_TRI | NP_SKIP | NP_TRIM | NP_INTEL);
// clang-format on
#else

#ifndef LMP_NPAIR_HALFFULL_NEWTON_TRIM_INTEL_H
#define LMP_NPAIR_HALFFULL_NEWTON_TRIM_INTEL_H
#ifndef LMP_NPAIR_HALFFULL_TRIM_NEWTON_INTEL_H
#define LMP_NPAIR_HALFFULL_TRIM_NEWTON_INTEL_H

#include "fix_intel.h"
#include "npair.h"
Expand All @@ -42,9 +42,9 @@ NPairStyle(halffull/newton/skip/trim/intel,

namespace LAMMPS_NS {

class NPairHalffullNewtonTrimIntel : public NPair {
class NPairHalffullTrimNewtonIntel : public NPair {
public:
NPairHalffullNewtonTrimIntel(class LAMMPS *);
NPairHalffullTrimNewtonIntel(class LAMMPS *);
void build(class NeighList *) override;

protected:
Expand Down
271 changes: 271 additions & 0 deletions src/INTEL/npair_skip_trim_intel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

/* ----------------------------------------------------------------------
Contributing author: Stan Moore (SNL)
------------------------------------------------------------------------- */

#include "npair_skip_trim_intel.h"

#include "atom.h"
#include "comm.h"
#include "error.h"
#include "modify.h"
#include "my_page.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "neighbor.h"

using namespace LAMMPS_NS;

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

NPairSkipTrimIntel::NPairSkipTrimIntel(LAMMPS *lmp) : NPair(lmp) {
_fix = static_cast<FixIntel *>(modify->get_fix_by_id("package_intel"));
if (!_fix) error->all(FLERR, "The 'package intel' command is required for /intel styles");
_inum_starts = new int[comm->nthreads];
_inum_counts = new int[comm->nthreads];
_full_props = nullptr;
}

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

NPairSkipTrimIntel::~NPairSkipTrimIntel() {
delete []_inum_starts;
delete []_inum_counts;
delete[] _full_props;
}

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

void NPairSkipTrimIntel::copy_neighbor_info()
{
NPair::copy_neighbor_info();
// Only need to set _full_props once; npair object deleted for changes
if (_full_props) return;
_full_props = new int[neighbor->nrequest];
for (int i = 0; i < neighbor->nrequest; i++)
_full_props[i] = neighbor->requests[i]->full;
}

/* ----------------------------------------------------------------------
build skip list for subset of types from parent list
works for half and full lists
works for owned (non-ghost) list, also for ghost list
iskip and ijskip flag which atom types and type pairs to skip
if ghost, also store neighbors of ghost atoms & set inum,gnum correctly
------------------------------------------------------------------------- */

template<class flt_t, class acc_t, int THREE>
void NPairSkipTrimIntel::build_t(NeighList *list, int *numhalf, int *cnumneigh,
int *numhalf_skip, IntelBuffers<flt_t,acc_t> *buffers)
{
const int nlocal = atom->nlocal;
const int e_nall = nlocal + atom->nghost;
const ATOM_T * _noalias const x = buffers->get_x();
const int * _noalias const type = atom->type;
int * _noalias const ilist = list->ilist;
int * _noalias const numneigh = list->numneigh;
int ** _noalias const firstneigh = (int ** const)list->firstneigh; // NOLINT
const int * _noalias const ilist_skip = list->listskip->ilist;
const int * _noalias const numneigh_skip = list->listskip->numneigh;
const int ** _noalias const firstneigh_skip = (const int ** const)list->listskip->firstneigh; // NOLINT
const int * _noalias const iskip = list->iskip;
const int ** _noalias const ijskip = (const int ** const)list->ijskip; // NOLINT

const flt_t cutsq_custom = cutoff_custom * cutoff_custom;
int num_skip = list->listskip->inum;
if (list->ghost) num_skip += list->listskip->gnum;

int packthreads;
if (comm->nthreads > INTEL_HTHREADS && THREE==0)
packthreads = comm->nthreads;
else
packthreads = 1;

#if defined(_OPENMP)
#pragma omp parallel if (packthreads > 1)
#endif
{
int tid, ifrom, ito;
IP_PRE_omp_range_id(ifrom, ito, tid, num_skip, packthreads);

// each thread has its own page allocator
MyPage<int> &ipage = list->ipage[tid];
ipage.reset();

int my_inum = ifrom;
_inum_starts[tid] = ifrom;

// loop over parent full list
for (int ii = ifrom; ii < ito; ii++) {
const int i = ilist_skip[ii];
const int itype = type[i];
if (iskip[itype]) continue;

const flt_t xtmp = x[i].x;
const flt_t ytmp = x[i].y;
const flt_t ztmp = x[i].z;

int n = 0;
int *neighptr = ipage.vget();

// loop over parent non-skip list

const int * _noalias const jlist = firstneigh_skip[i];
const int jnum = numneigh_skip[i];

if (THREE) {
const int jnumhalf = numhalf_skip[ii];
for (int jj = 0; jj < jnumhalf; jj++) {
const int joriginal = jlist[jj];
const int j = joriginal & NEIGHMASK;

int addme = 1;
if (ijskip[itype][type[j]]) addme = 0;

// trim to shorter cutoff

const flt_t delx = xtmp - x[j].x;
const flt_t dely = ytmp - x[j].y;
const flt_t delz = ztmp - x[j].z;
const flt_t rsq = delx * delx + dely * dely + delz * delz;
if (rsq > cutsq_custom) addme = 0;

if (addme)
neighptr[n++] = joriginal;
}
numhalf[my_inum] = n;

for (int jj = jnumhalf; jj < jnum; jj++) {
const int joriginal = jlist[jj];
const int j = joriginal & NEIGHMASK;

int addme = 1;
if (ijskip[itype][type[j]]) addme = 0;

// trim to shorter cutoff

const flt_t delx = xtmp - x[j].x;
const flt_t dely = ytmp - x[j].y;
const flt_t delz = ztmp - x[j].z;
const flt_t rsq = delx * delx + dely * dely + delz * delz;
if (rsq > cutsq_custom) addme = 0;

if (addme)
neighptr[n++] = joriginal;
}
} else {
#if defined(LMP_SIMD_COMPILER)
#pragma vector aligned
#pragma ivdep
#endif
for (int jj = 0; jj < jnum; jj++) {
const int joriginal = jlist[jj];
const int j = joriginal & NEIGHMASK;

int addme = 1;
if (ijskip[itype][type[j]]) addme = 0;

// trim to shorter cutoff

const flt_t delx = xtmp - x[j].x;
const flt_t dely = ytmp - x[j].y;
const flt_t delz = ztmp - x[j].z;
const flt_t rsq = delx * delx + dely * dely + delz * delz;
if (rsq > cutsq_custom) addme = 0;

if (addme)
neighptr[n++] = joriginal;
}
}

ilist[my_inum++] = i;
firstneigh[i] = neighptr;
numneigh[i] = n;

int pad_end = n;
IP_PRE_neighbor_pad(pad_end, 0);
#if defined(LMP_SIMD_COMPILER)
#pragma vector aligned
#pragma loop_count min=1, max=INTEL_COMPILE_WIDTH-1, \
avg=INTEL_COMPILE_WIDTH/2
#endif
for ( ; n < pad_end; n++)
neighptr[n] = e_nall;

ipage.vgot(n);
if (ipage.status())
error->one(FLERR,"Neighbor list overflow, boost neigh_modify one");
}

int last_inum = 0, loop_end;
_inum_counts[tid] = my_inum;
}
int inum = _inum_counts[0];
for (int tid = 1; tid < packthreads; tid++) {
for (int i = _inum_starts[tid]; i < _inum_counts[tid]; i++) {
if (THREE) numhalf[inum] = numhalf[i];
ilist[inum++] = ilist[i];
}
}
list->inum = inum;

if (THREE && num_skip > 0) {
int * const list_start = firstneigh[ilist[0]];
for (int ii = 0; ii < inum; ii++) {
int i = ilist[ii];
cnumneigh[ii] = static_cast<int>(firstneigh[i] - list_start);
}
}
if (list->ghost) {
int num = 0;
int my_inum = list->inum;
for (int i = 0; i < my_inum; i++)
if (ilist[i] < nlocal) num++;
else break;
list->inum = num;
list->gnum = my_inum - num;
}
}

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

void NPairSkipTrimIntel::build(NeighList *list)
{
if (_fix->three_body_neighbor()==0 ||
_full_props[list->listskip->index] == 0) {
if (_fix->precision() == FixIntel::PREC_MODE_MIXED)
build_t<float,double,0>(list, nullptr, nullptr, nullptr, _fix->get_mixed_buffers());
else if (_fix->precision() == FixIntel::PREC_MODE_DOUBLE)
build_t<double,double,0>(list, nullptr, nullptr, nullptr, _fix->get_double_buffers());
else
build_t<float,float,0>(list, nullptr, nullptr, nullptr, _fix->get_single_buffers());
} else {
int *nhalf, *cnumneigh, *nhalf_skip, *u;
if (_fix->precision() == FixIntel::PREC_MODE_MIXED) {
_fix->get_mixed_buffers()->get_list_data3(list->listskip,nhalf_skip,u);
_fix->get_mixed_buffers()->grow_data3(list, nhalf, cnumneigh);
build_t<float,double,1>(list, nhalf, cnumneigh, nhalf_skip, _fix->get_mixed_buffers());
} else if (_fix->precision() == FixIntel::PREC_MODE_DOUBLE) {
_fix->get_double_buffers()->get_list_data3(list->listskip,nhalf_skip,u);
_fix->get_double_buffers()->grow_data3(list, nhalf, cnumneigh);
build_t<double,double,1>(list, nhalf, cnumneigh, nhalf_skip, _fix->get_double_buffers());
} else {
_fix->get_single_buffers()->get_list_data3(list->listskip,nhalf_skip,u);
_fix->get_single_buffers()->grow_data3(list,nhalf,cnumneigh);
build_t<float,float,1>(list, nhalf, cnumneigh, nhalf_skip, _fix->get_single_buffers());
}
}
}
Loading

0 comments on commit de7f876

Please sign in to comment.