From fa412c13aa3de31b8af8e6e2ac473f90dd515e21 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Fri, 15 Oct 2021 15:43:26 -0600 Subject: [PATCH 01/20] Add compute phase/atom --- src/KOKKOS/Install.sh | 2 + src/KOKKOS/compute_phase_atom_kokkos.cpp | 210 +++++++++++++++++++ src/KOKKOS/compute_phase_atom_kokkos.h | 73 +++++++ src/compute_phase_atom.cpp | 246 +++++++++++++++++++++++ src/compute_phase_atom.h | 88 ++++++++ 5 files changed, 619 insertions(+) create mode 100644 src/KOKKOS/compute_phase_atom_kokkos.cpp create mode 100644 src/KOKKOS/compute_phase_atom_kokkos.h create mode 100644 src/compute_phase_atom.cpp create mode 100644 src/compute_phase_atom.h diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 04bf84ed31..ac5efec076 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -92,6 +92,8 @@ action compute_coord_atom_kokkos.cpp action compute_coord_atom_kokkos.h action compute_orientorder_atom_kokkos.cpp action compute_orientorder_atom_kokkos.h +action compute_phase_atom_kokkos.cpp +action compute_phase_atom_kokkos.h action compute_temp_kokkos.cpp action compute_temp_kokkos.h action compute_temp_deform_kokkos.cpp diff --git a/src/KOKKOS/compute_phase_atom_kokkos.cpp b/src/KOKKOS/compute_phase_atom_kokkos.cpp new file mode 100644 index 0000000000..0b30c5d6fd --- /dev/null +++ b/src/KOKKOS/compute_phase_atom_kokkos.cpp @@ -0,0 +1,210 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "compute_phase_atom_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory_kokkos.h" +#include "modify.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor_kokkos.h" +#include "pair.h" +#include "update.h" +#include "math_const.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; + + +/* ---------------------------------------------------------------------- */ + +template +ComputePhaseAtomKokkos::ComputePhaseAtomKokkos(LAMMPS *lmp, int narg, char **arg) : + ComputePhaseAtom(lmp, narg, arg) +{ + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = EMPTY_MASK; + datamask_modify = EMPTY_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +ComputePhaseAtomKokkos::~ComputePhaseAtomKokkos() +{ + if (copymode) return; + + memoryKK->destroy_kokkos(k_phase,phase); +} + +/* ---------------------------------------------------------------------- */ + +template +void ComputePhaseAtomKokkos::init() +{ + ComputePhaseAtom::init(); + + // need an occasional full neighbor list + + // irequest = neigh request made by parent class + + int irequest = neighbor->nrequest - 1; + + neighbor->requests[irequest]-> + kokkos_host = std::is_same::value && + !std::is_same::value; + neighbor->requests[irequest]-> + kokkos_device = std::is_same::value; +} + +/* ---------------------------------------------------------------------- */ + +template +void ComputePhaseAtomKokkos::compute_peratom() +{ + invoked_peratom = update->ntimestep; + + // grow phase array if necessary + + if (atom->nmax > nmax) { + memoryKK->destroy_kokkos(k_phase,phase); + nmax = atom->nmax; + memoryKK->create_kokkos(k_phase,phase,nmax,2,"phase/atom:phase"); + d_phase = k_phase.view(); + array_atom = phase; + } + + // need velocities of ghost atoms + + atomKK->sync(Host,V_MASK); + comm->forward_comm_compute(this); + atomKK->modified(Host,V_MASK); + + // invoke full neighbor list (will copy or build if necessary) + + neighbor->build_one(list); + int inum = list->inum; + + NeighListKokkos* k_list = static_cast*>(list); + d_numneigh = k_list->d_numneigh; + d_neighbors = k_list->d_neighbors; + d_ilist = k_list->d_ilist; + + // compute phase for each atom in group + // use full neighbor list to count atoms less than cutoff + + atomKK->sync(execution_space,X_MASK|V_MASK|TYPE_MASK|MASK_MASK); + x = atomKK->k_x.view(); + v = atomKK->k_v.view(); + type = atomKK->k_type.view(); + mask = atomKK->k_mask.view(); + + Kokkos::deep_copy(d_phase,0.0); + + copymode = 1; + typename Kokkos::RangePolicy policy(0,inum); + Kokkos::parallel_for("ComputePhaseAtom",policy,*this); + copymode = 0; + + k_phase.modify(); + k_phase.sync_host(); +} + +template +KOKKOS_INLINE_FUNCTION +void ComputePhaseAtomKokkos::operator()(TagComputePhaseAtom, const int &ii) const +{ + const int i = d_ilist[ii]; + if (mask[i] & groupbit) { + const X_FLOAT xtmp = x(i,0); + const X_FLOAT ytmp = x(i,1); + const X_FLOAT ztmp = x(i,2); + const int jnum = d_numneigh[i]; + + // i atom contribution + + int count = 1; + double vsum[3]; + vsum[0] = v(i,0); + vsum[1] = v(i,1); + vsum[2] = v(i,2); + + for (int jj = 0; jj < jnum; jj++) { + int j = d_neighbors(i,jj); + j &= NEIGHMASK; + + const F_FLOAT delx = x(j,0) - xtmp; + const F_FLOAT dely = x(j,1) - ytmp; + const F_FLOAT delz = x(j,2) - ztmp; + const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; + if (rsq < cutsq) { + count++; + vsum[0] += v(j,0); + vsum[1] += v(j,1); + vsum[2] += v(j,2); + } + } + + double vavg[3]; + vavg[0] = vsum[0]/count; + vavg[1] = vsum[1]/count; + vavg[2] = vsum[2]/count; + + // i atom contribution + + count = 1; + double vnet[3]; + vnet[0] = v(i,0) - vavg[0]; + vnet[1] = v(i,1) - vavg[1]; + vnet[2] = v(i,2) - vavg[2]; + double ke_sum = vnet[0]*vnet[0] + vnet[1]*vnet[1] + vnet[2]*vnet[2]; + + for (int jj = 0; jj < jnum; jj++) { + int j = d_neighbors(i,jj); + j &= NEIGHMASK; + + const F_FLOAT delx = x(j,0) - xtmp; + const F_FLOAT dely = x(j,1) - ytmp; + const F_FLOAT delz = x(j,2) - ztmp; + const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; + if (rsq < cutsq) { + count++; + vnet[0] = v(j,0) - vavg[0]; + vnet[1] = v(j,1) - vavg[1]; + vnet[2] = v(j,2) - vavg[2]; + ke_sum += vnet[0]*vnet[0] + vnet[1]*vnet[1] + vnet[2]*vnet[2]; + } + } + double density = count/sphere_vol; + double temp = ke_sum/3.0/count; + d_phase(i,0) = density; + d_phase(i,1) = temp; + } +} + +namespace LAMMPS_NS { +template class ComputePhaseAtomKokkos; +#ifdef LMP_KOKKOS_GPU +template class ComputePhaseAtomKokkos; +#endif +} diff --git a/src/KOKKOS/compute_phase_atom_kokkos.h b/src/KOKKOS/compute_phase_atom_kokkos.h new file mode 100644 index 0000000000..8cfa35d2c8 --- /dev/null +++ b/src/KOKKOS/compute_phase_atom_kokkos.h @@ -0,0 +1,73 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#ifdef COMPUTE_CLASS + +ComputeStyle(phase/atom/kk,ComputePhaseAtomKokkos) +ComputeStyle(phase/atom/kk/device,ComputePhaseAtomKokkos) +ComputeStyle(phase/atom/kk/host,ComputePhaseAtomKokkos) + +#else + +#ifndef LMP_COMPUTE_PHASE_KOKKOS_ATOM_H +#define LMP_COMPUTE_PHASE_KOKKOS_ATOM_H + +#include "compute_phase_atom.h" +#include "kokkos_type.h" + +namespace LAMMPS_NS { + +struct TagComputePhaseAtom{}; + +template +class ComputePhaseAtomKokkos : public ComputePhaseAtom { + public: + typedef DeviceType device_type; + typedef ArrayTypes AT; + + ComputePhaseAtomKokkos(class LAMMPS *, int, char **); + virtual ~ComputePhaseAtomKokkos(); + void init(); + void compute_peratom(); + + KOKKOS_INLINE_FUNCTION + void operator()(TagComputePhaseAtom, const int&) const; + + private: + typename AT::t_x_array_randomread x; + typename AT::t_v_array_randomread v; + typename ArrayTypes::t_int_1d_randomread type; + typename ArrayTypes::t_int_1d mask; + + typename AT::t_neighbors_2d d_neighbors; + typename AT::t_int_1d_randomread d_ilist; + typename AT::t_int_1d_randomread d_numneigh; + + DAT::tdual_float_2d k_phase; + typename AT::t_float_2d d_phase; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +*/ diff --git a/src/compute_phase_atom.cpp b/src/compute_phase_atom.cpp new file mode 100644 index 0000000000..0f166b2be2 --- /dev/null +++ b/src/compute_phase_atom.cpp @@ -0,0 +1,246 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#include "compute_phase_atom.h" + +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "pair.h" +#include "update.h" +#include "math_const.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace MathConst; + + +/* ---------------------------------------------------------------------- */ + +ComputePhaseAtom::ComputePhaseAtom(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg), + phase(nullptr) +{ + if (narg != 4) error->all(FLERR,"Illegal compute phase/atom command"); + + cutoff = utils::numeric(FLERR,arg[3],false,lmp); + cutsq = cutoff*cutoff; + sphere_vol = 4.0/3.0*MY_PI*cutsq*cutoff; + + peratom_flag = 1; + size_peratom_cols = 2; + + comm_forward = 3; + + nmax = 0; +} + +/* ---------------------------------------------------------------------- */ + +ComputePhaseAtom::~ComputePhaseAtom() +{ + if (copymode) return; + + memory->destroy(phase); +} + +/* ---------------------------------------------------------------------- */ + +void ComputePhaseAtom::init() +{ + int cutflag = 1; + if (force->pair && sqrt(cutsq) <= force->pair->cutforce) + cutflag = 0; + + // need an occasional full neighbor list + + int irequest = neighbor->request(this,instance_me); + neighbor->requests[irequest]->pair = 0; + neighbor->requests[irequest]->compute = 1; + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full = 1; + neighbor->requests[irequest]->occasional = 1; + if (cutflag) { + neighbor->requests[irequest]->cut = 1; + neighbor->requests[irequest]->cutoff = cutoff; + } +} + +/* ---------------------------------------------------------------------- */ + +void ComputePhaseAtom::init_list(int /*id*/, NeighList *ptr) +{ + list = ptr; +} + +/* ---------------------------------------------------------------------- */ + +void ComputePhaseAtom::compute_peratom() +{ + int i,j,ii,jj,inum,jnum; + double xtmp,ytmp,ztmp,delx,dely,delz,rsq; + int *ilist,*jlist,*numneigh,**firstneigh; + int count; + double vsum[3],vavg[3],vnet[3]; + + invoked_peratom = update->ntimestep; + + // grow phase array if necessary + + if (atom->nmax > nmax) { + memory->destroy(phase); + nmax = atom->nmax; + memory->create(phase,nmax,2,"phase/atom:phase"); + array_atom = phase; + } + + // need velocities of ghost atoms + + comm->forward_comm_compute(this); + + // invoke full neighbor list (will copy or build if necessary) + + neighbor->build_one(list); + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // compute phase for each atom in group + // use full neighbor list to count atoms less than cutoff + + double **x = atom->x; + double **v = atom->v; + int *type = atom->type; + int *mask = atom->mask; + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + + if (mask[i] & groupbit) { + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + // i atom contribution + + count = 1; + vsum[0] = v[i][0]; + vsum[1] = v[i][1]; + vsum[2] = v[i][2]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + if (rsq < cutsq) { + count++; + vsum[0] += v[j][0]; + vsum[1] += v[j][1]; + vsum[2] += v[j][2]; + } + } + + vavg[0] = vsum[0]/count; + vavg[1] = vsum[1]/count; + vavg[2] = vsum[2]/count; + + // i atom contribution + + count = 1; + vnet[0] = v[i][0] - vavg[0]; + vnet[1] = v[i][1] - vavg[1]; + vnet[2] = v[i][2] - vavg[2]; + double ke_sum = vnet[0]*vnet[0] + vnet[1]*vnet[1] + vnet[2]*vnet[2]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + if (rsq < cutsq) { + count++; + vnet[0] = v[j][0] - vavg[0]; + vnet[1] = v[j][1] - vavg[1]; + vnet[2] = v[j][2] - vavg[2]; + ke_sum += vnet[0]*vnet[0] + vnet[1]*vnet[1] + vnet[2]*vnet[2]; + } + } + double density = count/sphere_vol; + double temp = ke_sum/3.0/count; + phase[i][0] = density; + phase[i][1] = temp; + } + } +} + +/* ---------------------------------------------------------------------- */ + +int ComputePhaseAtom::pack_forward_comm(int n, int *list, double *buf, + int /*pbc_flag*/, int * /*pbc*/) +{ + double **v = atom->v; + + int i,m=0; + for (i = 0; i < n; ++i) { + buf[m++] = v[list[i]][0]; + buf[m++] = v[list[i]][1]; + buf[m++] = v[list[i]][2]; + } + + return m; +} + +/* ---------------------------------------------------------------------- */ + +void ComputePhaseAtom::unpack_forward_comm(int n, int first, double *buf) +{ + double **v = atom->v; + + int i,last,m=0; + last = first + n; + for (i = first; i < last; ++i) { + v[i][0] = buf[m++]; + v[i][1] = buf[m++]; + v[i][2] = buf[m++]; + } +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based array +------------------------------------------------------------------------- */ + +double ComputePhaseAtom::memory_usage() +{ + double bytes = (double)2*nmax * sizeof(double); + return bytes; +} diff --git a/src/compute_phase_atom.h b/src/compute_phase_atom.h new file mode 100644 index 0000000000..26d9636cc8 --- /dev/null +++ b/src/compute_phase_atom.h @@ -0,0 +1,88 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + 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. +------------------------------------------------------------------------- */ + +#ifdef COMPUTE_CLASS + +ComputeStyle(phase/atom,ComputePhaseAtom) + +#else + +#ifndef LMP_COMPUTE_PHASE_ATOM_H +#define LMP_COMPUTE_PHASE_ATOM_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputePhaseAtom : public Compute { + public: + ComputePhaseAtom(class LAMMPS *, int, char **); + virtual ~ComputePhaseAtom(); + virtual void init(); + void init_list(int, class NeighList *); + virtual void compute_peratom(); + int pack_forward_comm(int, int *, double *, int, int *); + void unpack_forward_comm(int, int, double *); + double memory_usage(); + + protected: + int nmax; + double cutoff,cutsq,sphere_vol; + class NeighList *list; + + double **phase; +}; + +} + +#endif +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +Self-explanatory. Check the input script syntax and compare to the +documentation for the command. You can use -echo screen as a +command-line option when running LAMMPS to see the offending line. + +E: Could not find compute phase/atom compute ID + +UNDOCUMENTED + +E: Compute phase/atom compute ID is not orientorder/atom + +UNDOCUMENTED + +E: Compute phase/atom threshold not between -1 and 1 + +UNDOCUMENTED + +E: Invalid cstyle in compute phase/atom + +UNDOCUMENTED + +E: Compute phase/atom requires components option in compute orientorder/atom + +UNDOCUMENTED + +E: Compute phase/atom requires a pair style be defined + +Self-explanatory. + +E: Compute phase/atom cutoff is longer than pairwise cutoff + +Cannot compute phase at distances longer than the pair cutoff, +since those atoms are not in the neighbor list. + +*/ From 20cd742b4ab6ec6645ba1fd7ed9209f90af2d199 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Fri, 15 Oct 2021 15:59:15 -0600 Subject: [PATCH 02/20] whitespace & urls --- src/KOKKOS/compute_phase_atom_kokkos.cpp | 4 ++-- src/KOKKOS/compute_phase_atom_kokkos.h | 2 +- src/compute_phase_atom.cpp | 20 ++++++++++---------- src/compute_phase_atom.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/KOKKOS/compute_phase_atom_kokkos.cpp b/src/KOKKOS/compute_phase_atom_kokkos.cpp index 0b30c5d6fd..b0637526de 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.cpp +++ b/src/KOKKOS/compute_phase_atom_kokkos.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -182,7 +182,7 @@ void ComputePhaseAtomKokkos::operator()(TagComputePhaseAtom, const i for (int jj = 0; jj < jnum; jj++) { int j = d_neighbors(i,jj); j &= NEIGHMASK; - + const F_FLOAT delx = x(j,0) - xtmp; const F_FLOAT dely = x(j,1) - ytmp; const F_FLOAT delz = x(j,2) - ztmp; diff --git a/src/KOKKOS/compute_phase_atom_kokkos.h b/src/KOKKOS/compute_phase_atom_kokkos.h index 8cfa35d2c8..247acd3f03 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.h +++ b/src/KOKKOS/compute_phase_atom_kokkos.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract diff --git a/src/compute_phase_atom.cpp b/src/compute_phase_atom.cpp index 0f166b2be2..c1382392d7 100644 --- a/src/compute_phase_atom.cpp +++ b/src/compute_phase_atom.cpp @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract @@ -152,19 +152,19 @@ void ComputePhaseAtom::compute_peratom() vsum[2] = v[i][2]; for (jj = 0; jj < jnum; jj++) { - j = jlist[jj]; - j &= NEIGHMASK; + j = jlist[jj]; + j &= NEIGHMASK; - delx = xtmp - x[j][0]; - dely = ytmp - x[j][1]; - delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; - if (rsq < cutsq) { - count++; + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + if (rsq < cutsq) { + count++; vsum[0] += v[j][0]; vsum[1] += v[j][1]; vsum[2] += v[j][2]; - } + } } vavg[0] = vsum[0]/count; diff --git a/src/compute_phase_atom.h b/src/compute_phase_atom.h index 26d9636cc8..ab0dc3081e 100644 --- a/src/compute_phase_atom.h +++ b/src/compute_phase_atom.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract From 136c15a8bafc43c7245d6f02e6f22eae0cfd40f1 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 4 Nov 2021 19:59:48 -0600 Subject: [PATCH 03/20] Allow dump sort to work with more than 2 billion atoms --- src/dump.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dump.cpp b/src/dump.cpp index 4c02aa3070..282ea0c696 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -237,7 +237,8 @@ void Dump::init() irregular = new Irregular(lmp); bigint size = group->count(igroup); - if (size > MAXSMALLINT) error->all(FLERR,"Too many atoms to dump sort"); + int bigintflag = 0; + if (size > MAXSMALLINT) bigintflag = 1; int isize = static_cast (size); // set reorderflag = 1 if can simply reorder local atoms rather than sort @@ -252,7 +253,7 @@ void Dump::init() if (utils::strmatch(fix->style,"^gcmc")) gcmcflag = 1; - if (sortcol == 0 && atom->tag_consecutive() && !gcmcflag) { + if (sortcol == 0 && atom->tag_consecutive() && !gcmcflag && !bigintflag) { tagint *tag = atom->tag; int *mask = atom->mask; int nlocal = atom->nlocal; From 07a25144ee23560d7d612df96d73b7eaa9d9bbb0 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 4 Nov 2021 20:06:30 -0600 Subject: [PATCH 04/20] Remove error from dump.h --- src/dump.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/dump.h b/src/dump.h index 730d4c9ca9..4237faf8b4 100644 --- a/src/dump.h +++ b/src/dump.h @@ -186,10 +186,6 @@ E: Dump sort column is invalid Self-explanatory. -E: Too many atoms to dump sort - -Cannot sort when running with more than 2^31 atoms. - E: Dump could not find refresh compute ID UNDOCUMENTED From ebb3dcd9ff2317665dcb11476aacc0c2e651b0e8 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 4 Nov 2021 20:20:07 -0600 Subject: [PATCH 05/20] Remove error message --- doc/src/Errors_messages.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/src/Errors_messages.rst b/doc/src/Errors_messages.rst index 3a593b5a3f..c06f4c86e3 100644 --- a/doc/src/Errors_messages.rst +++ b/doc/src/Errors_messages.rst @@ -7772,9 +7772,6 @@ keyword to allow for additional bonds to be formed The system size must fit in a 32-bit integer to use this dump style. -*Too many atoms to dump sort* - Cannot sort when running with more than 2\^31 atoms. - *Too many elements extracted from MEAM library.* Increase 'maxelt' in meam.h and recompile. From 5616336d5e711630857301f9c618d8755b4e5de4 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 18 Nov 2021 07:59:45 -0700 Subject: [PATCH 06/20] Allow sorting with reorderflag for more than 2 billion atoms --- src/dump.cpp | 9 +++------ src/dump.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/dump.cpp b/src/dump.cpp index 282ea0c696..587bd6c9d3 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -237,9 +237,6 @@ void Dump::init() irregular = new Irregular(lmp); bigint size = group->count(igroup); - int bigintflag = 0; - if (size > MAXSMALLINT) bigintflag = 1; - int isize = static_cast (size); // set reorderflag = 1 if can simply reorder local atoms rather than sort // criteria: sorting by ID, atom IDs are consecutive from 1 to Natoms @@ -253,7 +250,7 @@ void Dump::init() if (utils::strmatch(fix->style,"^gcmc")) gcmcflag = 1; - if (sortcol == 0 && atom->tag_consecutive() && !gcmcflag && !bigintflag) { + if (sortcol == 0 && atom->tag_consecutive() && !gcmcflag) { tagint *tag = atom->tag; int *mask = atom->mask; int nlocal = atom->nlocal; @@ -269,7 +266,7 @@ void Dump::init() MPI_Allreduce(&min,&minall,1,MPI_LMP_TAGINT,MPI_MIN,world); MPI_Allreduce(&max,&maxall,1,MPI_LMP_TAGINT,MPI_MAX,world); - if (maxall-minall+1 == isize) { + if (maxall-minall+1 == size) { reorderflag = 1; double range = maxall-minall + EPSILON; idlo = static_cast (range*me/nprocs + minall); @@ -285,7 +282,7 @@ void Dump::init() else if (me+1 != hi) idhi++; nme_reorder = idhi-idlo; - ntotal_reorder = isize; + ntotal_reorder = size; } } } diff --git a/src/dump.h b/src/dump.h index 4237faf8b4..681ce88c96 100644 --- a/src/dump.h +++ b/src/dump.h @@ -116,7 +116,7 @@ class Dump : protected Pointers { bigint ntotal; // total # of per-atom lines in snapshot int reorderflag; // 1 if OK to reorder instead of sort - int ntotal_reorder; // # of atoms that must be in snapshot + bigint ntotal_reorder; // # of atoms that must be in snapshot int nme_reorder; // # of atoms I must own in snapshot tagint idlo; // lowest ID I own when reordering From 94b11964f80c4b4243267c04c6d58244b0226ba6 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 18 Nov 2021 08:32:41 -0700 Subject: [PATCH 07/20] Write dump header after sort to fix incorrect atom count for multiproc --- src/dump.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/dump.cpp b/src/dump.cpp index 587bd6c9d3..9ca7e61e76 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -367,16 +367,6 @@ void Dump::write() if (multiproc != nprocs) MPI_Allreduce(&nme,&nmax,1,MPI_INT,MPI_MAX,world); else nmax = nme; - // write timestep header - // for multiproc, - // nheader = # of lines in this file via Allreduce on clustercomm - - bigint nheader = ntotal; - if (multiproc) - MPI_Allreduce(&bnme,&nheader,1,MPI_LMP_BIGINT,MPI_SUM,clustercomm); - - if (filewriter && write_header_flag) write_header(nheader); - // insure buf is sized for packing and communicating // use nmax to insure filewriter proc can receive info from others // limit nmax*size_one to int since used as arg in MPI calls @@ -429,6 +419,19 @@ void Dump::write() else pack(nullptr); if (sort_flag) sort(); + // write timestep header + // for multiproc, + // nheader = # of lines in this file via Allreduce on clustercomm + // must come after sort, which can change nme + + bigint nheader = ntotal; + if (multiproc) { + bnme = nme; + MPI_Allreduce(&bnme,&nheader,1,MPI_LMP_BIGINT,MPI_SUM,clustercomm); + } + + if (filewriter && write_header_flag) write_header(nheader); + // if buffering, convert doubles into strings // insure sbuf is sized for communicating // cannot buffer if output is to binary file From 15f1c2d9600562624fb9a9a82f61d4a5b080fceb Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 18 Nov 2021 08:50:09 -0700 Subject: [PATCH 08/20] Fix inaccurate error message --- doc/src/dump_modify.rst | 4 +++- src/dump.cpp | 2 +- src/dump.h | 5 ++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/src/dump_modify.rst b/doc/src/dump_modify.rst index da7ccffeb2..88b375ecb6 100644 --- a/doc/src/dump_modify.rst +++ b/doc/src/dump_modify.rst @@ -561,7 +561,9 @@ The dump *local* style cannot be sorted by atom ID, since there are typically multiple lines of output per atom. Some dump styles, such as *dcd* and *xtc*, require sorting by atom ID to format the output file correctly. If multiple processors are writing the dump file, via -the "%" wildcard in the dump filename, then sorting cannot be +the "%" wildcard in the dump filename and the *nfile* or *fileper* +keywords are set to non-default values (i.e. the number of dump file +pieces is not equal to the number of procs), then sorting cannot be performed. .. note:: diff --git a/src/dump.cpp b/src/dump.cpp index 9ca7e61e76..2917099ff9 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -228,7 +228,7 @@ void Dump::init() if (sort_flag) { if (multiproc > 1) error->all(FLERR, - "Cannot dump sort when multiple dump files are written"); + "Cannot dump sort when 'nfile' or 'fileper' keywords are set to non-default values"); if (sortcol == 0 && atom->tag_enable == 0) error->all(FLERR,"Cannot dump sort on atom IDs with no atom IDs defined"); if (sortcol && sortcol > size_one) diff --git a/src/dump.h b/src/dump.h index 681ce88c96..468b007096 100644 --- a/src/dump.h +++ b/src/dump.h @@ -173,10 +173,9 @@ E: Dump file MPI-IO output not allowed with % in filename This is because a % signifies one file per processor and MPI-IO creates one large file for all processors. -E: Cannot dump sort when multiple dump files are written +E: Cannot dump sort when 'nfile' or 'fileper' keywords are set to non-default values -In this mode, each processor dumps its atoms to a file, so -no sorting is allowed. +Can only dump sort when the number of dump file pieces using % in filename equals the number of processors E: Cannot dump sort on atom IDs with no atom IDs defined From f271d2180ffe87396d3ac6af4801347d9428250e Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Mon, 20 Dec 2021 16:05:44 -0700 Subject: [PATCH 09/20] Remove unused variable --- src/KOKKOS/compute_phase_atom_kokkos.cpp | 1 - src/KOKKOS/compute_phase_atom_kokkos.h | 1 - src/compute_phase_atom.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/src/KOKKOS/compute_phase_atom_kokkos.cpp b/src/KOKKOS/compute_phase_atom_kokkos.cpp index b0637526de..5a21393252 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.cpp +++ b/src/KOKKOS/compute_phase_atom_kokkos.cpp @@ -116,7 +116,6 @@ void ComputePhaseAtomKokkos::compute_peratom() atomKK->sync(execution_space,X_MASK|V_MASK|TYPE_MASK|MASK_MASK); x = atomKK->k_x.view(); v = atomKK->k_v.view(); - type = atomKK->k_type.view(); mask = atomKK->k_mask.view(); Kokkos::deep_copy(d_phase,0.0); diff --git a/src/KOKKOS/compute_phase_atom_kokkos.h b/src/KOKKOS/compute_phase_atom_kokkos.h index 247acd3f03..7bcc418d85 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.h +++ b/src/KOKKOS/compute_phase_atom_kokkos.h @@ -46,7 +46,6 @@ class ComputePhaseAtomKokkos : public ComputePhaseAtom { private: typename AT::t_x_array_randomread x; typename AT::t_v_array_randomread v; - typename ArrayTypes::t_int_1d_randomread type; typename ArrayTypes::t_int_1d mask; typename AT::t_neighbors_2d d_neighbors; diff --git a/src/compute_phase_atom.cpp b/src/compute_phase_atom.cpp index c1382392d7..ed6bbb844f 100644 --- a/src/compute_phase_atom.cpp +++ b/src/compute_phase_atom.cpp @@ -131,7 +131,6 @@ void ComputePhaseAtom::compute_peratom() double **x = atom->x; double **v = atom->v; - int *type = atom->type; int *mask = atom->mask; for (ii = 0; ii < inum; ii++) { From 65204e5df06b4be860d250b1f8e5011511a06ed9 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 10:46:00 -0700 Subject: [PATCH 10/20] Add error checks, tweak input --- src/compute_phase_atom.cpp | 49 ++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/compute_phase_atom.cpp b/src/compute_phase_atom.cpp index ed6bbb844f..b8c6b374bf 100644 --- a/src/compute_phase_atom.cpp +++ b/src/compute_phase_atom.cpp @@ -40,15 +40,24 @@ ComputePhaseAtom::ComputePhaseAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), phase(nullptr) { - if (narg != 4) error->all(FLERR,"Illegal compute phase/atom command"); + if (narg < 3 || narg > 5) error->all(FLERR,"Illegal compute phase/atom command"); - cutoff = utils::numeric(FLERR,arg[3],false,lmp); - cutsq = cutoff*cutoff; - sphere_vol = 4.0/3.0*MY_PI*cutsq*cutoff; + // process optional args + + cutoff = 0.0; + + int iarg = 3; + while (iarg < narg) { + if (strcmp(arg[iarg],"cutoff") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal compute phase/atom command"); + cutoff = utils::numeric(FLERR,arg[iarg+1],false,lmp); + if (cutoff <= 0.0) error->all(FLERR,"Illegal compute phase/atom command"); + iarg += 2; + } else error->all(FLERR,"Illegal compute phase/atom command"); + } peratom_flag = 1; size_peratom_cols = 2; - comm_forward = 3; nmax = 0; @@ -67,9 +76,35 @@ ComputePhaseAtom::~ComputePhaseAtom() void ComputePhaseAtom::init() { + if (!force->pair && cutoff == 0.0) + error->all(FLERR,"Compute phase/atom requires a cutoff be specified " + "or a pair style be defined"); + + double skin = neighbor->skin; + if (cutoff != 0.0) { + double mycutneigh = cutoff + skin; + + double cutghost; // as computed by Neighbor and Comm + if (force->pair) + cutghost = MAX(force->pair->cutforce+skin,comm->cutghostuser); + else + cutghost = comm->cutghostuser; + + if (mycutneigh > cutghost) + error->all(FLERR,"Compute phase/atom cutoff exceeds ghost atom range - " + "use comm_modify cutoff command"); + } + int cutflag = 1; - if (force->pair && sqrt(cutsq) <= force->pair->cutforce) - cutflag = 0; + if (force->pair) { + if (cutoff == 0.0) { + cutoff = force->pair->cutforce; + } + if (cutoff <= force->pair->cutforce+skin) cutflag = 0; + } + + cutsq = cutoff*cutoff; + sphere_vol = 4.0/3.0*MY_PI*cutsq*cutoff; // need an occasional full neighbor list From 2533abb2668266a8e070f875737735c1bfb559a0 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 10:46:23 -0700 Subject: [PATCH 11/20] Add doc page --- doc/src/compute_phase_atom.rst | 98 ++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 doc/src/compute_phase_atom.rst diff --git a/doc/src/compute_phase_atom.rst b/doc/src/compute_phase_atom.rst new file mode 100644 index 0000000000..db1e1725f6 --- /dev/null +++ b/doc/src/compute_phase_atom.rst @@ -0,0 +1,98 @@ +.. index:: compute phase/atom +.. index:: compute phase/atom/kk + +compute phase/atom command +================================ + +Accelerator Variants: *phase/atom/kk* + +Syntax +"""""" + +.. parsed-literal:: + + compute ID group-ID phase/atom keyword values ... + +* ID, group-ID are documented in :doc:`compute ` command +* phase/atom = style name of this compute command +* one or more keyword/value pairs may be appended + + .. parsed-literal:: + + keyword = *cutoff* + *cutoff* value = distance cutoff + +Examples +"""""""" + +.. code-block:: LAMMPS + + compute 1 all phase/atom + + compute 1 all phase/atom cutoff 5.0 + comm_modify cutoff 5.0 + +Description +""""""""""" + +Define a computation that calculates the local density and temperature +for each atom and neighbors inside a spherical cutoff. + +The optional keyword *cutoff* defines the distance cutoff +used when searching for neighbors. The default value is the cutoff +specified by the pair style. If the specified cutoff is larger than +that of the pair_style plus neighbor skin, the *comm_modify cutoff* +option must also be set to match the specified cutoff. + +The neighbor list needed to compute this quantity is constructed each +time the calculation is performed (i.e. each time a snapshot of atoms +is dumped). Thus it can be inefficient to compute/dump this quantity +too frequently. + +.. note:: + + If you have a bonded system, then the settings of + :doc:`special_bonds ` command can remove pairwise + interactions between atoms in the same bond, angle, or dihedral. This + is the default setting for the :doc:`special_bonds ` + command, and means those pairwise interactions do not appear in the + neighbor list. Because this fix uses the neighbor list, it also means + those pairs will not be included in the order parameter. This + difficulty can be circumvented by writing a dump file, and using the + :doc:`rerun ` command to compute the order parameter for + snapshots in the dump file. The rerun script can use a + :doc:`special_bonds ` command that includes all pairs in + the neighbor list. + +---------- + + +.. include:: accel_styles.rst + + +---------- + +Output info +""""""""""" + +This compute calculates a per-atom array with two columns: density and temperature. + +These values can be accessed by any command that uses per-atom values +from a compute as input. See the :doc:`Howto output ` doc +page for an overview of LAMMPS output options. + +Restrictions +"""""""""""" + +none + +Related commands +"""""""""""""""" + +:doc:`comm_modify ` + +Default +""""""" + +The option defaults are *cutoff* = pair style cutoff + From a2ab59b162f94f665a7db43f756b5a23eb5f43bd Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 11:07:03 -0700 Subject: [PATCH 12/20] Fix cutoff logic --- src/compute_phase_atom.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compute_phase_atom.cpp b/src/compute_phase_atom.cpp index b8c6b374bf..f8f5e35abf 100644 --- a/src/compute_phase_atom.cpp +++ b/src/compute_phase_atom.cpp @@ -82,15 +82,13 @@ void ComputePhaseAtom::init() double skin = neighbor->skin; if (cutoff != 0.0) { - double mycutneigh = cutoff + skin; - double cutghost; // as computed by Neighbor and Comm if (force->pair) cutghost = MAX(force->pair->cutforce+skin,comm->cutghostuser); else cutghost = comm->cutghostuser; - if (mycutneigh > cutghost) + if (cutoff > cutghost) error->all(FLERR,"Compute phase/atom cutoff exceeds ghost atom range - " "use comm_modify cutoff command"); } From c98f7b3e50bdde536d9b3333950675ab4ce35d15 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 11:40:04 -0700 Subject: [PATCH 13/20] Clean up error message text --- src/KOKKOS/compute_phase_atom_kokkos.h | 6 ------ src/compute_phase_atom.h | 27 +++----------------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/src/KOKKOS/compute_phase_atom_kokkos.h b/src/KOKKOS/compute_phase_atom_kokkos.h index 7bcc418d85..d65f3d571e 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.h +++ b/src/KOKKOS/compute_phase_atom_kokkos.h @@ -63,10 +63,4 @@ class ComputePhaseAtomKokkos : public ComputePhaseAtom { /* ERROR/WARNING messages: -E: Illegal ... command - -Self-explanatory. Check the input script syntax and compare to the -documentation for the command. You can use -echo screen as a -command-line option when running LAMMPS to see the offending line. - */ diff --git a/src/compute_phase_atom.h b/src/compute_phase_atom.h index ab0dc3081e..b39026b3b5 100644 --- a/src/compute_phase_atom.h +++ b/src/compute_phase_atom.h @@ -56,33 +56,12 @@ Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. -E: Could not find compute phase/atom compute ID - -UNDOCUMENTED - -E: Compute phase/atom compute ID is not orientorder/atom - -UNDOCUMENTED - -E: Compute phase/atom threshold not between -1 and 1 - -UNDOCUMENTED - -E: Invalid cstyle in compute phase/atom - -UNDOCUMENTED - -E: Compute phase/atom requires components option in compute orientorder/atom - -UNDOCUMENTED - -E: Compute phase/atom requires a pair style be defined +E: Compute phase/atom requires a cutoff be specified or a pair style be defined Self-explanatory. -E: Compute phase/atom cutoff is longer than pairwise cutoff +E: Compute phase/atom cutoff exceeds ghost atom range - use comm_modify cutoff command -Cannot compute phase at distances longer than the pair cutoff, -since those atoms are not in the neighbor list. +Self-explanatory. */ From e06222099a45884040503823995c451b7fdf63da Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 11:51:30 -0700 Subject: [PATCH 14/20] Small tweak to docs --- doc/src/compute_phase_atom.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/compute_phase_atom.rst b/doc/src/compute_phase_atom.rst index db1e1725f6..6540e52041 100644 --- a/doc/src/compute_phase_atom.rst +++ b/doc/src/compute_phase_atom.rst @@ -40,9 +40,11 @@ for each atom and neighbors inside a spherical cutoff. The optional keyword *cutoff* defines the distance cutoff used when searching for neighbors. The default value is the cutoff -specified by the pair style. If the specified cutoff is larger than -that of the pair_style plus neighbor skin, the *comm_modify cutoff* -option must also be set to match the specified cutoff. +specified by the pair style. If no pair style is defined, then a cutoff +must be defined using this keyword. If the specified cutoff is larger than +that of the pair_style plus neighbor skin (or no pair style is defined), +the *comm_modify cutoff* option must also be set to match that of the +*cutoff* keyword. The neighbor list needed to compute this quantity is constructed each time the calculation is performed (i.e. each time a snapshot of atoms From 2fec3eee6b18f5fc2f21ed392bc5ef6ffc16bd53 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 13:28:36 -0700 Subject: [PATCH 15/20] Add overflow check to dump_h5md --- src/H5MD/dump_h5md.cpp | 1 + src/H5MD/dump_h5md.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/H5MD/dump_h5md.cpp b/src/H5MD/dump_h5md.cpp index bc9c98caa0..a59de9773c 100644 --- a/src/H5MD/dump_h5md.cpp +++ b/src/H5MD/dump_h5md.cpp @@ -181,6 +181,7 @@ DumpH5MD::DumpH5MD(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg) // allocate global array for atom coords bigint n = group->count(igroup); + if ((bigint) domain->dimension*n > MAXSMALLINT) error->all(FLERR,"Too many atoms for dump h5md"); natoms = static_cast (n); if (every_position>=0) diff --git a/src/H5MD/dump_h5md.h b/src/H5MD/dump_h5md.h index 28b74649c6..5e3f3f8279 100644 --- a/src/H5MD/dump_h5md.h +++ b/src/H5MD/dump_h5md.h @@ -90,6 +90,11 @@ E: Dump h5md requires sorting by atom ID Use the dump_modify sort command to enable this. +E: Too many atoms for dump h5md + +The system size must fit in a 32-bit integer to use this dump +style. + E: Cannot use variable every setting for dump xtc The format of this file requires snapshots at regular intervals. From 1bbf45784bd7c7b6be26351907921547b0743ec6 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 16:29:11 -0700 Subject: [PATCH 16/20] Rename and relocate --- ...e_atom.rst => compute_ave_sphere_atom.rst} | 19 ++++---- src/Depend.sh | 4 ++ .../compute_ave_sphere_atom.cpp} | 48 +++++++++---------- .../compute_ave_sphere_atom.h} | 18 +++---- src/KOKKOS/Install.sh | 4 +- ...cpp => compute_ave_sphere_atom_kokkos.cpp} | 48 +++++++++---------- ...kos.h => compute_ave_sphere_atom_kokkos.h} | 26 +++++----- 7 files changed, 86 insertions(+), 81 deletions(-) rename doc/src/{compute_phase_atom.rst => compute_ave_sphere_atom.rst} (82%) rename src/{compute_phase_atom.cpp => EXTRA-COMPUTE/compute_ave_sphere_atom.cpp} (82%) rename src/{compute_phase_atom.h => EXTRA-COMPUTE/compute_ave_sphere_atom.h} (74%) rename src/KOKKOS/{compute_phase_atom_kokkos.cpp => compute_ave_sphere_atom_kokkos.cpp} (79%) rename src/KOKKOS/{compute_phase_atom_kokkos.h => compute_ave_sphere_atom_kokkos.h} (63%) diff --git a/doc/src/compute_phase_atom.rst b/doc/src/compute_ave_sphere_atom.rst similarity index 82% rename from doc/src/compute_phase_atom.rst rename to doc/src/compute_ave_sphere_atom.rst index 6540e52041..db04682865 100644 --- a/doc/src/compute_phase_atom.rst +++ b/doc/src/compute_ave_sphere_atom.rst @@ -1,20 +1,20 @@ -.. index:: compute phase/atom -.. index:: compute phase/atom/kk +.. index:: compute ave/sphere/atom +.. index:: compute ave/sphere/atom/kk -compute phase/atom command +compute ave/sphere/atom command ================================ -Accelerator Variants: *phase/atom/kk* +Accelerator Variants: *ave/sphere/atom/kk* Syntax """""" .. parsed-literal:: - compute ID group-ID phase/atom keyword values ... + compute ID group-ID ave/sphere/atom keyword values ... * ID, group-ID are documented in :doc:`compute ` command -* phase/atom = style name of this compute command +* ave/sphere/atom = style name of this compute command * one or more keyword/value pairs may be appended .. parsed-literal:: @@ -27,9 +27,9 @@ Examples .. code-block:: LAMMPS - compute 1 all phase/atom + compute 1 all ave/sphere/atom - compute 1 all phase/atom cutoff 5.0 + compute 1 all ave/sphere/atom cutoff 5.0 comm_modify cutoff 5.0 Description @@ -86,7 +86,8 @@ page for an overview of LAMMPS output options. Restrictions """""""""""" -none +This compute is part of the EXTRA-COMPUTE package. It is only enabled if +LAMMPS was built with that package. See the :doc:`Build package ` page for more info. Related commands """""""""""""""" diff --git a/src/Depend.sh b/src/Depend.sh index af88f24bb4..a8e17e0546 100755 --- a/src/Depend.sh +++ b/src/Depend.sh @@ -77,6 +77,10 @@ if (test $1 = "DPD-BASIC") then depend INTEL fi +if (test $1 = "EXTRA-COMPUTE") then + depend KOKKOS +fi + if (test $1 = "EXTRA-MOLECULE") then depend GPU depend OPENMP diff --git a/src/compute_phase_atom.cpp b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp similarity index 82% rename from src/compute_phase_atom.cpp rename to src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp index f8f5e35abf..14a4c364a1 100644 --- a/src/compute_phase_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.cpp @@ -11,7 +11,7 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "compute_phase_atom.h" +#include "compute_ave_sphere_atom.h" #include "atom.h" #include "comm.h" @@ -36,11 +36,11 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -ComputePhaseAtom::ComputePhaseAtom(LAMMPS *lmp, int narg, char **arg) : +ComputeAveSphereAtom::ComputeAveSphereAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), - phase(nullptr) + result(nullptr) { - if (narg < 3 || narg > 5) error->all(FLERR,"Illegal compute phase/atom command"); + if (narg < 3 || narg > 5) error->all(FLERR,"Illegal compute ave/sphere/atom command"); // process optional args @@ -49,11 +49,11 @@ ComputePhaseAtom::ComputePhaseAtom(LAMMPS *lmp, int narg, char **arg) : int iarg = 3; while (iarg < narg) { if (strcmp(arg[iarg],"cutoff") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal compute phase/atom command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal compute ave/sphere/atom command"); cutoff = utils::numeric(FLERR,arg[iarg+1],false,lmp); - if (cutoff <= 0.0) error->all(FLERR,"Illegal compute phase/atom command"); + if (cutoff <= 0.0) error->all(FLERR,"Illegal compute ave/sphere/atom command"); iarg += 2; - } else error->all(FLERR,"Illegal compute phase/atom command"); + } else error->all(FLERR,"Illegal compute ave/sphere/atom command"); } peratom_flag = 1; @@ -65,19 +65,19 @@ ComputePhaseAtom::ComputePhaseAtom(LAMMPS *lmp, int narg, char **arg) : /* ---------------------------------------------------------------------- */ -ComputePhaseAtom::~ComputePhaseAtom() +ComputeAveSphereAtom::~ComputeAveSphereAtom() { if (copymode) return; - memory->destroy(phase); + memory->destroy(result); } /* ---------------------------------------------------------------------- */ -void ComputePhaseAtom::init() +void ComputeAveSphereAtom::init() { if (!force->pair && cutoff == 0.0) - error->all(FLERR,"Compute phase/atom requires a cutoff be specified " + error->all(FLERR,"Compute ave/sphere/atom requires a cutoff be specified " "or a pair style be defined"); double skin = neighbor->skin; @@ -89,7 +89,7 @@ void ComputePhaseAtom::init() cutghost = comm->cutghostuser; if (cutoff > cutghost) - error->all(FLERR,"Compute phase/atom cutoff exceeds ghost atom range - " + error->all(FLERR,"Compute ave/sphere/atom cutoff exceeds ghost atom range - " "use comm_modify cutoff command"); } @@ -120,14 +120,14 @@ void ComputePhaseAtom::init() /* ---------------------------------------------------------------------- */ -void ComputePhaseAtom::init_list(int /*id*/, NeighList *ptr) +void ComputeAveSphereAtom::init_list(int /*id*/, NeighList *ptr) { list = ptr; } /* ---------------------------------------------------------------------- */ -void ComputePhaseAtom::compute_peratom() +void ComputeAveSphereAtom::compute_peratom() { int i,j,ii,jj,inum,jnum; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; @@ -137,13 +137,13 @@ void ComputePhaseAtom::compute_peratom() invoked_peratom = update->ntimestep; - // grow phase array if necessary + // grow result array if necessary if (atom->nmax > nmax) { - memory->destroy(phase); + memory->destroy(result); nmax = atom->nmax; - memory->create(phase,nmax,2,"phase/atom:phase"); - array_atom = phase; + memory->create(result,nmax,2,"ave/sphere/atom:result"); + array_atom = result; } // need velocities of ghost atoms @@ -159,7 +159,7 @@ void ComputePhaseAtom::compute_peratom() numneigh = list->numneigh; firstneigh = list->firstneigh; - // compute phase for each atom in group + // compute properties for each atom in group // use full neighbor list to count atoms less than cutoff double **x = atom->x; @@ -229,15 +229,15 @@ void ComputePhaseAtom::compute_peratom() } double density = count/sphere_vol; double temp = ke_sum/3.0/count; - phase[i][0] = density; - phase[i][1] = temp; + result[i][0] = density; + result[i][1] = temp; } } } /* ---------------------------------------------------------------------- */ -int ComputePhaseAtom::pack_forward_comm(int n, int *list, double *buf, +int ComputeAveSphereAtom::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/, int * /*pbc*/) { double **v = atom->v; @@ -254,7 +254,7 @@ int ComputePhaseAtom::pack_forward_comm(int n, int *list, double *buf, /* ---------------------------------------------------------------------- */ -void ComputePhaseAtom::unpack_forward_comm(int n, int first, double *buf) +void ComputeAveSphereAtom::unpack_forward_comm(int n, int first, double *buf) { double **v = atom->v; @@ -271,7 +271,7 @@ void ComputePhaseAtom::unpack_forward_comm(int n, int first, double *buf) memory usage of local atom-based array ------------------------------------------------------------------------- */ -double ComputePhaseAtom::memory_usage() +double ComputeAveSphereAtom::memory_usage() { double bytes = (double)2*nmax * sizeof(double); return bytes; diff --git a/src/compute_phase_atom.h b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.h similarity index 74% rename from src/compute_phase_atom.h rename to src/EXTRA-COMPUTE/compute_ave_sphere_atom.h index b39026b3b5..9b5e38750b 100644 --- a/src/compute_phase_atom.h +++ b/src/EXTRA-COMPUTE/compute_ave_sphere_atom.h @@ -13,21 +13,21 @@ #ifdef COMPUTE_CLASS -ComputeStyle(phase/atom,ComputePhaseAtom) +ComputeStyle(ave/sphere/atom,ComputeAveSphereAtom) #else -#ifndef LMP_COMPUTE_PHASE_ATOM_H -#define LMP_COMPUTE_PHASE_ATOM_H +#ifndef LMP_COMPUTE_AVE_SPHERE_ATOM_H +#define LMP_COMPUTE_AVE_SPHERE_ATOM_H #include "compute.h" namespace LAMMPS_NS { -class ComputePhaseAtom : public Compute { +class ComputeAveSphereAtom : public Compute { public: - ComputePhaseAtom(class LAMMPS *, int, char **); - virtual ~ComputePhaseAtom(); + ComputeAveSphereAtom(class LAMMPS *, int, char **); + virtual ~ComputeAveSphereAtom(); virtual void init(); void init_list(int, class NeighList *); virtual void compute_peratom(); @@ -40,7 +40,7 @@ class ComputePhaseAtom : public Compute { double cutoff,cutsq,sphere_vol; class NeighList *list; - double **phase; + double **result; }; } @@ -56,11 +56,11 @@ Self-explanatory. Check the input script syntax and compare to the documentation for the command. You can use -echo screen as a command-line option when running LAMMPS to see the offending line. -E: Compute phase/atom requires a cutoff be specified or a pair style be defined +E: Compute ave/sphere/atom requires a cutoff be specified or a pair style be defined Self-explanatory. -E: Compute phase/atom cutoff exceeds ghost atom range - use comm_modify cutoff command +E: Compute ave/sphere/atom cutoff exceeds ghost atom range - use comm_modify cutoff command Self-explanatory. diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index ac5efec076..261a4d807a 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -88,12 +88,12 @@ action comm_kokkos.cpp action comm_kokkos.h action comm_tiled_kokkos.cpp action comm_tiled_kokkos.h +action compute_ave_sphere_atom_kokkos.cpp +action compute_ave_sphere_atom_kokkos.h action compute_coord_atom_kokkos.cpp action compute_coord_atom_kokkos.h action compute_orientorder_atom_kokkos.cpp action compute_orientorder_atom_kokkos.h -action compute_phase_atom_kokkos.cpp -action compute_phase_atom_kokkos.h action compute_temp_kokkos.cpp action compute_temp_kokkos.h action compute_temp_deform_kokkos.cpp diff --git a/src/KOKKOS/compute_phase_atom_kokkos.cpp b/src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp similarity index 79% rename from src/KOKKOS/compute_phase_atom_kokkos.cpp rename to src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp index 5a21393252..3f83c24fb6 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.cpp +++ b/src/KOKKOS/compute_ave_sphere_atom_kokkos.cpp @@ -11,7 +11,7 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "compute_phase_atom_kokkos.h" +#include "compute_ave_sphere_atom_kokkos.h" #include "atom_kokkos.h" #include "atom_masks.h" @@ -37,8 +37,8 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ template -ComputePhaseAtomKokkos::ComputePhaseAtomKokkos(LAMMPS *lmp, int narg, char **arg) : - ComputePhaseAtom(lmp, narg, arg) +ComputeAveSphereAtomKokkos::ComputeAveSphereAtomKokkos(LAMMPS *lmp, int narg, char **arg) : + ComputeAveSphereAtom(lmp, narg, arg) { kokkosable = 1; atomKK = (AtomKokkos *) atom; @@ -50,19 +50,19 @@ ComputePhaseAtomKokkos::ComputePhaseAtomKokkos(LAMMPS *lmp, int narg /* ---------------------------------------------------------------------- */ template -ComputePhaseAtomKokkos::~ComputePhaseAtomKokkos() +ComputeAveSphereAtomKokkos::~ComputeAveSphereAtomKokkos() { if (copymode) return; - memoryKK->destroy_kokkos(k_phase,phase); + memoryKK->destroy_kokkos(k_result,result); } /* ---------------------------------------------------------------------- */ template -void ComputePhaseAtomKokkos::init() +void ComputeAveSphereAtomKokkos::init() { - ComputePhaseAtom::init(); + ComputeAveSphereAtom::init(); // need an occasional full neighbor list @@ -80,18 +80,18 @@ void ComputePhaseAtomKokkos::init() /* ---------------------------------------------------------------------- */ template -void ComputePhaseAtomKokkos::compute_peratom() +void ComputeAveSphereAtomKokkos::compute_peratom() { invoked_peratom = update->ntimestep; - // grow phase array if necessary + // grow result array if necessary if (atom->nmax > nmax) { - memoryKK->destroy_kokkos(k_phase,phase); + memoryKK->destroy_kokkos(k_result,result); nmax = atom->nmax; - memoryKK->create_kokkos(k_phase,phase,nmax,2,"phase/atom:phase"); - d_phase = k_phase.view(); - array_atom = phase; + memoryKK->create_kokkos(k_result,result,nmax,2,"ave/sphere/atom:result"); + d_result = k_result.view(); + array_atom = result; } // need velocities of ghost atoms @@ -110,7 +110,7 @@ void ComputePhaseAtomKokkos::compute_peratom() d_neighbors = k_list->d_neighbors; d_ilist = k_list->d_ilist; - // compute phase for each atom in group + // compute properties for each atom in group // use full neighbor list to count atoms less than cutoff atomKK->sync(execution_space,X_MASK|V_MASK|TYPE_MASK|MASK_MASK); @@ -118,20 +118,20 @@ void ComputePhaseAtomKokkos::compute_peratom() v = atomKK->k_v.view(); mask = atomKK->k_mask.view(); - Kokkos::deep_copy(d_phase,0.0); + Kokkos::deep_copy(d_result,0.0); copymode = 1; - typename Kokkos::RangePolicy policy(0,inum); - Kokkos::parallel_for("ComputePhaseAtom",policy,*this); + typename Kokkos::RangePolicy policy(0,inum); + Kokkos::parallel_for("ComputeAveSphereAtom",policy,*this); copymode = 0; - k_phase.modify(); - k_phase.sync_host(); + k_result.modify(); + k_result.sync_host(); } template KOKKOS_INLINE_FUNCTION -void ComputePhaseAtomKokkos::operator()(TagComputePhaseAtom, const int &ii) const +void ComputeAveSphereAtomKokkos::operator()(TagComputeAveSphereAtom, const int &ii) const { const int i = d_ilist[ii]; if (mask[i] & groupbit) { @@ -196,14 +196,14 @@ void ComputePhaseAtomKokkos::operator()(TagComputePhaseAtom, const i } double density = count/sphere_vol; double temp = ke_sum/3.0/count; - d_phase(i,0) = density; - d_phase(i,1) = temp; + d_result(i,0) = density; + d_result(i,1) = temp; } } namespace LAMMPS_NS { -template class ComputePhaseAtomKokkos; +template class ComputeAveSphereAtomKokkos; #ifdef LMP_KOKKOS_GPU -template class ComputePhaseAtomKokkos; +template class ComputeAveSphereAtomKokkos; #endif } diff --git a/src/KOKKOS/compute_phase_atom_kokkos.h b/src/KOKKOS/compute_ave_sphere_atom_kokkos.h similarity index 63% rename from src/KOKKOS/compute_phase_atom_kokkos.h rename to src/KOKKOS/compute_ave_sphere_atom_kokkos.h index d65f3d571e..42607e5239 100644 --- a/src/KOKKOS/compute_phase_atom_kokkos.h +++ b/src/KOKKOS/compute_ave_sphere_atom_kokkos.h @@ -13,35 +13,35 @@ #ifdef COMPUTE_CLASS -ComputeStyle(phase/atom/kk,ComputePhaseAtomKokkos) -ComputeStyle(phase/atom/kk/device,ComputePhaseAtomKokkos) -ComputeStyle(phase/atom/kk/host,ComputePhaseAtomKokkos) +ComputeStyle(ave/sphere/atom/kk,ComputeAveSphereAtomKokkos) +ComputeStyle(ave/sphere/atom/kk/device,ComputeAveSphereAtomKokkos) +ComputeStyle(ave/sphere/atom/kk/host,ComputeAveSphereAtomKokkos) #else -#ifndef LMP_COMPUTE_PHASE_KOKKOS_ATOM_H -#define LMP_COMPUTE_PHASE_KOKKOS_ATOM_H +#ifndef LMP_COMPUTE_AVE_SPHERE_ATOM_KOKKOS_H +#define LMP_COMPUTE_AVE_SPHERE_ATOM_KOKKOS_H -#include "compute_phase_atom.h" +#include "compute_ave_sphere_atom.h" #include "kokkos_type.h" namespace LAMMPS_NS { -struct TagComputePhaseAtom{}; +struct TagComputeAveSphereAtom{}; template -class ComputePhaseAtomKokkos : public ComputePhaseAtom { +class ComputeAveSphereAtomKokkos : public ComputeAveSphereAtom { public: typedef DeviceType device_type; typedef ArrayTypes AT; - ComputePhaseAtomKokkos(class LAMMPS *, int, char **); - virtual ~ComputePhaseAtomKokkos(); + ComputeAveSphereAtomKokkos(class LAMMPS *, int, char **); + virtual ~ComputeAveSphereAtomKokkos(); void init(); void compute_peratom(); KOKKOS_INLINE_FUNCTION - void operator()(TagComputePhaseAtom, const int&) const; + void operator()(TagComputeAveSphereAtom, const int&) const; private: typename AT::t_x_array_randomread x; @@ -52,8 +52,8 @@ class ComputePhaseAtomKokkos : public ComputePhaseAtom { typename AT::t_int_1d_randomread d_ilist; typename AT::t_int_1d_randomread d_numneigh; - DAT::tdual_float_2d k_phase; - typename AT::t_float_2d d_phase; + DAT::tdual_float_2d k_result; + typename AT::t_float_2d d_result; }; } From 9271323cc0ccef50818b8044dcb8814aa1d205b9 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 16:33:14 -0700 Subject: [PATCH 17/20] Add dependency --- src/KOKKOS/Install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 261a4d807a..45fa0654a9 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -88,8 +88,8 @@ action comm_kokkos.cpp action comm_kokkos.h action comm_tiled_kokkos.cpp action comm_tiled_kokkos.h -action compute_ave_sphere_atom_kokkos.cpp -action compute_ave_sphere_atom_kokkos.h +action compute_ave_sphere_atom_kokkos.cpp compute_ave_sphere_atom.cpp +action compute_ave_sphere_atom_kokkos.h compute_ave_sphere_atom.h action compute_coord_atom_kokkos.cpp action compute_coord_atom_kokkos.h action compute_orientorder_atom_kokkos.cpp From 2788bc666a3ce67d0c364fc66ed6b829557ac0ce Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 16:44:14 -0700 Subject: [PATCH 18/20] Update .gitignore --- src/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/.gitignore b/src/.gitignore index 19bafa4b52..695c9a19af 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -429,6 +429,8 @@ /commgrid.h /compute_ackland_atom.cpp /compute_ackland_atom.h +/compute_ave_sphere_atom.cpp +/compute_ave_sphere_atom.h /compute_basal_atom.cpp /compute_basal_atom.h /compute_body_local.cpp From cde7dd34fdc02215a89c9c13e56e1cdc9454fbe5 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 21 Dec 2021 16:46:53 -0700 Subject: [PATCH 19/20] Doc update --- doc/src/Commands_compute.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/src/Commands_compute.rst b/doc/src/Commands_compute.rst index 2c67d44f24..91910ccdaa 100644 --- a/doc/src/Commands_compute.rst +++ b/doc/src/Commands_compute.rst @@ -28,6 +28,7 @@ KOKKOS, o = OPENMP, t = OPT. * :doc:`angle ` * :doc:`angle/local ` * :doc:`angmom/chunk ` + * :doc:`ave/sphere/atom (k) ` * :doc:`basal/atom ` * :doc:`body/local ` * :doc:`bond ` From 8f62cd79f4be90edf24a9ccae41bac786ee620fe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 22 Dec 2021 19:55:06 -0500 Subject: [PATCH 20/20] add missing list entry --- doc/src/compute.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/src/compute.rst b/doc/src/compute.rst index 71d3bada76..9edd7e8474 100644 --- a/doc/src/compute.rst +++ b/doc/src/compute.rst @@ -174,6 +174,7 @@ The individual style names on the :doc:`Commands compute ` pag * :doc:`angle ` - energy of each angle sub-style * :doc:`angle/local ` - theta and energy of each angle * :doc:`angmom/chunk ` - angular momentum for each chunk +* :doc:`ave/sphere/atom ` - compute local density and temperature around each atom * :doc:`basal/atom ` - calculates the hexagonal close-packed "c" lattice vector of each atom * :doc:`body/local ` - attributes of body sub-particles * :doc:`bond ` - energy of each bond sub-style