From 74d89c4c9b417c7923af279e5bb09270ac993fbb Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Wed, 24 May 2023 11:07:03 -0600 Subject: [PATCH 01/17] init --- doc/src/compute_local_composition_atom.rst | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 doc/src/compute_local_composition_atom.rst diff --git a/doc/src/compute_local_composition_atom.rst b/doc/src/compute_local_composition_atom.rst new file mode 100644 index 0000000000..270783d749 --- /dev/null +++ b/doc/src/compute_local_composition_atom.rst @@ -0,0 +1,116 @@ +.. index:: compute ave/sphere/atom +.. index:: compute local_composition/atom/kk + +compute local_composition/atom command +================================ + +Accelerator Variants: *local_composition/atom/kk* + +Syntax +"""""" + +.. code-block:: LAMMPS + + compute ID group-ID local_composition/atom keyword values ... + +* ID, group-ID are documented in :doc:`compute ` command +* local_composition/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 local_composition/atom + + compute 1 all local_composition/atom cutoff 9.0 + comm_modify cutoff 9.0 + +.. + ****** UNDER CONSTRUCTION ****** + Description + """"""""""" + + .. versionadded:: 24May2023 + + Define a computation that calculates the local composition for each atom based on its neighbors inside a spherical + cutoff. If an atom has :math:`M` neighbors, then its local mass density is + calculated as the sum of its mass and its :math:`M` neighbor masses, divided + by the volume of the cutoff sphere (or circle in 2d). The local + temperature of the atom is calculated as the temperature of the + collection of :math:`M+1` atoms, after subtracting the center-of-mass velocity + of the :math:`M+1` atoms from each of the :math:`M+1` atom's velocities. This + is effectively the thermal velocity of the neighborhood of the central + atom, similar to :doc:`compute temp/com `. + + 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 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 + 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 compute 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: mass + density in density :doc:`units ` and temperature in temperature + :doc:`units `. + + 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 + """""""""""" + + 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 + """""""""""""""" + + :doc:`comm_modify ` + + Default + """"""" + + The option defaults are *cutoff* = pair style cutoff. + +.. \ No newline at end of file From d9937fc2c635f993acbb9c68cbd811c7fbab1577 Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Wed, 24 May 2023 13:16:08 -0600 Subject: [PATCH 02/17] add base tested code --- .../compute_local_composition_atom.cpp | 255 ++++++++++++++++++ .../compute_local_composition_atom.h | 48 ++++ 2 files changed, 303 insertions(+) create mode 100644 src/EXTRA-COMPUTE/compute_local_composition_atom.cpp create mode 100644 src/EXTRA-COMPUTE/compute_local_composition_atom.h diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp new file mode 100644 index 0000000000..157b31b33d --- /dev/null +++ b/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp @@ -0,0 +1,255 @@ +/* ---------------------------------------------------------------------- + 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 "compute_local_composition_atom.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "pair.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; +using namespace MathConst; + +/* ---------------------------------------------------------------------- */ + +ComputeLocalCompositionAtom::ComputeLocalCompositionAtom(LAMMPS *lmp, int narg, char **arg) : + Compute(lmp, narg, arg), result(nullptr) +{ + if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute local_composition/atom command"); + + // get nelements and ntypes + + int ntypes = atom->ntypes; + + // memory->create(map, ntypes + 1, "compute_sna_grid:map"); + // nelements = utils::inumeric(FLERR, 0, false, lmp); // !!!!!!!! what is 2nd arg in inumeric? + // for (int i = 0; i < ntypes; i++) { + // int jelem = utils::inumeric(FLERR, i, false, lmp); + // if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); + // map[i + 1] = jelem; + // printf("mapp[x] %d jelem %d \n", map[i + 1], jelem); + // } + + // printf("ntypes %d \n", ntypes); + // printf("elements %d \n", nelements); + + // 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 local_composition/atom command"); + cutoff = utils::numeric(FLERR, arg[iarg + 1], false, lmp); + if (cutoff <= 0.0) error->all(FLERR, "Illegal compute local_composition/atom command"); + iarg += 2; + } else + error->all(FLERR, "Illegal compute local_composition/atom command"); + } + + peratom_flag = 1; + + size_peratom_cols = 1 + ntypes; + + nmax = 0; +} + +/* ---------------------------------------------------------------------- */ + +ComputeLocalCompositionAtom::~ComputeLocalCompositionAtom() +{ + if (copymode) return; + + memory->destroy(result); + // memory->destroy(map); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeLocalCompositionAtom::init() +{ + if (!force->pair && cutoff == 0.0) + error->all(FLERR, + "Compute local_composition/atom requires a cutoff be specified " + "or a pair style be defined"); + + double skin = neighbor->skin; + if (cutoff != 0.0) { + double cutghost; // as computed by Neighbor and Comm + if (force->pair) + cutghost = MAX(force->pair->cutforce + skin, comm->cutghostuser); + else + cutghost = comm->cutghostuser; + + if (cutoff > cutghost) + error->all(FLERR, + "Compute local_composition/atom cutoff exceeds ghost atom range - " + "use comm_modify cutoff command"); + } + + int cutflag = 1; + if (force->pair) { + if (cutoff == 0.0) { cutoff = force->pair->cutforce; } + if (cutoff <= force->pair->cutforce + skin) cutflag = 0; + } + + cutsq = cutoff * cutoff; + if (domain->dimension == 3) + volume = 4.0 / 3.0 * MY_PI * cutsq * cutoff; + else + volume = MY_PI * cutsq; + + // need an occasional full neighbor list + + auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); + if (cutflag) req->set_cutoff(cutoff); +} + +/* ---------------------------------------------------------------------- */ + +void ComputeLocalCompositionAtom::init_list(int /*id*/, NeighList *ptr) +{ + list = ptr; +} + +/* ---------------------------------------------------------------------- */ + +void ComputeLocalCompositionAtom::compute_peratom() +{ + int i, j, ii, jj, inum, jnum; + double xtmp, ytmp, ztmp, delx, dely, delz, rsq; + int *ilist, *jlist, *numneigh, **firstneigh; + int count; + + invoked_peratom = update->ntimestep; + + // grow result array if necessary + + if (atom->nmax > nmax) { + memory->destroy(result); + nmax = atom->nmax; + + // TODO what is the LAMMPSIAN, idiomatic way to get correct num cols assigned here for memory? + // TODO is there any reason not to use size_peratom_cols? + + // orig from compute_ave_sphere_atom: + // memory->create(result, nmax, 2, "local_composition/atom:result"); + memory->create(result, nmax, size_peratom_cols, "local_composition/atom:result"); + array_atom = result; + } + + // 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 properties for each atom in group + // use full neighbor list to count atoms less than cutoff + + double **x = atom->x; + int *type = atom->type; + int *mask = atom->mask; + + int typeone_i, typeone_j; + + // TODO what is LAMMPSian way to get ntypes info here + // TODO continue to implement map (nelements instead of ntypes) + + int ntypes = atom->ntypes; + + // TODO what is LAMMPSian/c++ way to init and populate array + + double lcomp[ntypes]; + for (int i = 0; i < ntypes; i++) { + lcomp[i] = 0; + } + + // get per-atom local compositions + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + + if (mask[i] & groupbit) { + + typeone_i = type[i]; + + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + // i atom contribution + + count = 1; + + typeone_i = type[i]; + lcomp[typeone_i - 1]++; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + j &= NEIGHMASK; + + typeone_j = type[j]; + + 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++; + lcomp[typeone_j-1]++; + } + } + + // total count of atoms found in sampled radius range + + result[i][0] = count; + + // local composition fractions per element + for (int n = 0; n < ntypes; n++) { + result[i][n + 1] = lcomp[n] / count; + } + } + } +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based array +------------------------------------------------------------------------- */ + +double ComputeLocalCompositionAtom::memory_usage() +{ + double bytes = (double) 2 * nmax * sizeof(double); + return bytes; +} diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.h b/src/EXTRA-COMPUTE/compute_local_composition_atom.h new file mode 100644 index 0000000000..fb8c8b6c49 --- /dev/null +++ b/src/EXTRA-COMPUTE/compute_local_composition_atom.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- ---------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#ifdef COMPUTE_CLASS +// clang-format off +ComputeStyle(local_composition/atom,ComputeLocalCompositionAtom); +// clang-format on +#else + +#ifndef LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_H +#define LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_H + +#include "compute.h" + +namespace LAMMPS_NS { + +class ComputeLocalCompositionAtom : public Compute { + public: + ComputeLocalCompositionAtom(class LAMMPS *, int, char **); + ~ComputeLocalCompositionAtom() override; + void init() override; + void init_list(int, class NeighList *) override; + void compute_peratom() override; + double memory_usage() override; + + protected: + int nmax; + double cutoff, cutsq, volume, nelements; + int *map; // map types to [0,nelements), taken from example in compute_snap + class NeighList *list; + + double **result; +}; + +} // namespace LAMMPS_NS + +#endif +#endif From 40056e29a47a617a3da1a1b3b4627ef0f4f7ffd2 Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Thu, 25 May 2023 11:58:02 -0600 Subject: [PATCH 03/17] move reset of lcomp array to correct scope --- .../compute_local_composition_atom.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp index 157b31b33d..5aeb04c33e 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp @@ -154,12 +154,6 @@ void ComputeLocalCompositionAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(result); nmax = atom->nmax; - - // TODO what is the LAMMPSIAN, idiomatic way to get correct num cols assigned here for memory? - // TODO is there any reason not to use size_peratom_cols? - - // orig from compute_ave_sphere_atom: - // memory->create(result, nmax, 2, "local_composition/atom:result"); memory->create(result, nmax, size_peratom_cols, "local_composition/atom:result"); array_atom = result; } @@ -182,21 +176,20 @@ void ComputeLocalCompositionAtom::compute_peratom() int typeone_i, typeone_j; - // TODO what is LAMMPSian way to get ntypes info here // TODO continue to implement map (nelements instead of ntypes) int ntypes = atom->ntypes; - - // TODO what is LAMMPSian/c++ way to init and populate array double lcomp[ntypes]; - for (int i = 0; i < ntypes; i++) { - lcomp[i] = 0; - } // get per-atom local compositions for (ii = 0; ii < inum; ii++) { + + for (int i = 0; i < ntypes; i++) { + lcomp[i] = 0; + } + i = ilist[ii]; if (mask[i] & groupbit) { From 1124f7eb93ca7544aaaacb99cdb808e99956c5d7 Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Wed, 31 May 2023 13:32:37 -0600 Subject: [PATCH 04/17] adjust to one-liner --- src/EXTRA-COMPUTE/compute_local_composition_atom.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp index 5aeb04c33e..ba3e40d8c8 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp @@ -186,16 +186,12 @@ void ComputeLocalCompositionAtom::compute_peratom() for (ii = 0; ii < inum; ii++) { - for (int i = 0; i < ntypes; i++) { - lcomp[i] = 0; - } + for (int i = 0; i < ntypes; i++) lcomp[i] = 0; i = ilist[ii]; if (mask[i] & groupbit) { - typeone_i = type[i]; - xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; From 90e84a6ff8d5f0d3644a3b4d1c490f3cf043137b Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Wed, 31 May 2023 13:32:52 -0600 Subject: [PATCH 05/17] set up basic KOKKOS file (untested) --- src/KOKKOS/compute_local_composition_atom.cpp | 188 ++++++++++++++++++ src/KOKKOS/compute_local_composition_atom.h | 69 +++++++ 2 files changed, 257 insertions(+) create mode 100644 src/KOKKOS/compute_local_composition_atom.cpp create mode 100644 src/KOKKOS/compute_local_composition_atom.h diff --git a/src/KOKKOS/compute_local_composition_atom.cpp b/src/KOKKOS/compute_local_composition_atom.cpp new file mode 100644 index 0000000000..1c52d6c948 --- /dev/null +++ b/src/KOKKOS/compute_local_composition_atom.cpp @@ -0,0 +1,188 @@ +/* ---------------------------------------------------------------------- + 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 Gdirectoryeneral Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Stan Moore (SNL) +------------------------------------------------------------------------- */ + +#include "compute_local_composition_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "comm.h" +#include "domain.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 +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +template +ComputeLocalCompositionKokkos::ComputeLocalCompositionKokkos(LAMMPS *lmp, int narg, char **arg) : + ComputeLocalComposition(lmp, narg, arg) +{ + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = EMPTY_MASK; + datamask_modify = EMPTY_MASK; +} + +/* ---------------------------------------------------------------------- */ + +template +ComputeLocalCompositionKokkos::~ComputeLocalCompositionKokkos() +{ + if (copymode) return; + + memoryKK->destroy_kokkos(k_result,result); +} + +/* ---------------------------------------------------------------------- */ + +template +void ComputeLocalCompositionKokkos::init() +{ + ComputeLocalComposition::init(); + + // adjust neighbor list request for KOKKOS + + auto request = neighbor->find_request(this); + request->set_kokkos_host(std::is_same::value && + !std::is_same::value); + request->set_kokkos_device(std::is_same::value); +} + +/* ---------------------------------------------------------------------- */ + +template +void ComputeLocalCompositionKokkos::compute_peratom() +{ + invoked_peratom = update->ntimestep; + + // grow result array if necessary + + if (atom->nmax > nmax) { + memoryKK->destroy_kokkos(k_result,result); + nmax = atom->nmax; + memoryKK->create_kokkos(k_result,result,nmax,2,"local_composition/atom:result"); + d_result = k_result.view(); + array_atom = result; + } + + // // need velocities of ghost atoms + + // atomKK->sync(Host,V_MASK); + // comm->forward_comm(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 properties for each atom in group + // use full neighbor list to count atoms less than cutoff + + atomKK->sync(execution_space,X_MASK|V_MASK|RMASS_MASK|TYPE_MASK|MASK_MASK); + x = atomKK->k_x.view(); + type = atomKK->k_type.view(); + ntypes = atomKK->k_ntypes.view(); + mask = atomKK->k_mask.view(); + + Kokkos::deep_copy(d_result,0.0); + + copymode = 1; + typename Kokkos::RangePolicy policy(0,inum); + Kokkos::parallel_for("ComputeLocalComposition",policy,*this); + copymode = 0; + + k_result.modify(); + k_result.sync_host(); +} + +template +KOKKOS_INLINE_FUNCTION +void ComputeLocalCompositionKokkos::operator()(TagComputeLocalComposition, const int &ii) const +{ + double typeone_i, typeone_j; + + // TODO continue to implement map (nelements instead of ntypes) + + double lcomp[ntypes]; + + // get per-atom local compositions + + for (ii = 0; ii < inum; ii++) { + + for (int i = 0; i < ntypes; i++) lcomp[i] = 0; + + 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; + + typeone_i = type[i]; + + for (int jj = 0; jj < jnum; jj++) { + int j = d_neighbors(i,jj); + j &= NEIGHMASK; + + typeone_j = type[j]; + + 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++; + lcomp[typeone_j]++; + } + } + for (int n = 0 n < 4; n++) { + d_result(i,n+1) = lcomp[n] / density; + } + } + } +} + +namespace LAMMPS_NS { +template class ComputeLocalCompositionKokkos; +#ifdef LMP_KOKKOS_GPU +template class ComputeLocalCompositionKokkos; +#endif +} diff --git a/src/KOKKOS/compute_local_composition_atom.h b/src/KOKKOS/compute_local_composition_atom.h new file mode 100644 index 0000000000..fb0c914b36 --- /dev/null +++ b/src/KOKKOS/compute_local_composition_atom.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- ---------------------------------------------------------- + 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. +------------------------------------------------------------------------- */ + +#ifdef COMPUTE_CLASS +// clang-format off +ComputeStyle(local_composition/atom/kk,ComputeLocalCompositionAtomKokkos); +ComputeStyle(local_composition/atom/kk/device,ComputeLocalCompositionAtomKokkos); +ComputeStyle(local_composition/atom/kk/host,ComputeLocalCompositionAtomKokkos); +// clang-format on + +#else + +#ifndef LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_KOKKOS_H +#define LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_KOKKOS_H + +#include "compute_local_composition_atom.h" +#include "kokkos_type.h" + +namespace LAMMPS_NS { + +// clang-format off +struct TagComputeLocalCompositionAtom {}; +// clang-format on + +template class ComputeLocalCompositionAtomKokkos : public ComputeLocalCompositionAtom { + public: + typedef DeviceType device_type; + typedef ArrayTypes AT; + + ComputeLocalCompositionAtomKokkos(class LAMMPS *, int, char **); + ~ComputeLocalCompositionAtomKokkos() override; + void init() override; + void compute_peratom() override; + + KOKKOS_INLINE_FUNCTION + void operator()(TagComputeLocalCompositionAtom, const int &) const; + + private: + double adof, mvv2e, mv2d, boltz; + + typename AT::t_x_array x; + typename AT::t_v_array v; + typename ArrayTypes::t_float_1d rmass; + typename ArrayTypes::t_float_1d mass; + typename ArrayTypes::t_int_1d type; + typename ArrayTypes::t_int_1d mask; + + typename AT::t_neighbors_2d d_neighbors; + typename AT::t_int_1d d_ilist; + typename AT::t_int_1d d_numneigh; + + DAT::tdual_float_2d k_result; + typename AT::t_float_2d d_result; +}; + +} // namespace LAMMPS_NS + +#endif +#endif From 4ebc8afd1ea44386be4608bd3357d7f3d974a88d Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Thu, 1 Jun 2023 03:20:43 -0600 Subject: [PATCH 06/17] update documentation --- doc/src/compute_local_composition_atom.rst | 130 +++++++++++---------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/doc/src/compute_local_composition_atom.rst b/doc/src/compute_local_composition_atom.rst index 270783d749..2b8fb7f080 100644 --- a/doc/src/compute_local_composition_atom.rst +++ b/doc/src/compute_local_composition_atom.rst @@ -32,85 +32,91 @@ Examples compute 1 all local_composition/atom cutoff 9.0 comm_modify cutoff 9.0 -.. - ****** UNDER CONSTRUCTION ****** - Description - """"""""""" - .. versionadded:: 24May2023 +Description +""""""""""" - Define a computation that calculates the local composition for each atom based on its neighbors inside a spherical - cutoff. If an atom has :math:`M` neighbors, then its local mass density is - calculated as the sum of its mass and its :math:`M` neighbor masses, divided - by the volume of the cutoff sphere (or circle in 2d). The local - temperature of the atom is calculated as the temperature of the - collection of :math:`M+1` atoms, after subtracting the center-of-mass velocity - of the :math:`M+1` atoms from each of the :math:`M+1` atom's velocities. This - is effectively the thermal velocity of the neighborhood of the central - atom, similar to :doc:`compute temp/com `. +.. versionadded:: 24May2023 - 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 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. +Define a computation that calculates the local composition of atom types for a +central atom based on its neighbors inside a spherical cutoff. For a simulation with +:math:`N` atom types and an atom with :math:`M` neighbors within the cutoff, the +fraction of each atom type is counted and divided by the total number of atoms in the +sphere, including the central atom (:math:`M+1`). The sum of all fractions will +always add to one. - 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:: - .. note:: + This compute uses the number of atom types, not chemical species, assigned in + :doc:`pair_coeff ` command. If an interatomic potential has two + species (i.e., Cu and Ni) assigned to four different atom types in + :doc:`pair_coeff ` (i.e., 'Cu Cu Ni Ni'), the local composition will + output four fractional values. In those cases, the user may desire an extra + calculation step to consolidate per-type fractions into per-species fractions. + This calculation can be conducted within LAMMPS using another compute such as + :doc:`compute reduce `, an atom-style :doc:`variable`, or as a + post-processing step. - 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 compute 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. +---------- - ---------- +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 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 +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 compute 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 +.. include:: accel_styles.rst - ---------- +---------- - Output info - """"""""""" +Output info +""""""""""" - This compute calculates a per-atom array with two columns: mass - density in density :doc:`units ` and temperature in temperature - :doc:`units `. +This compute calculates a per-atom array with :math:`1 + N` columns, where :math:`N` is the number of atom types. The first column is a count of the number of atoms used to calcuate composition (including the central atom), and each subsequent column indicates the fraction of that atom type detected within the cutoff range. - 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. +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 - """""""""""" +Restrictions +"""""""""""" - 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. +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 - """""""""""""""" +Related commands +"""""""""""""""" - :doc:`comm_modify ` +:doc:`comm_modify ` - Default - """"""" +Default +""""""" - The option defaults are *cutoff* = pair style cutoff. - -.. \ No newline at end of file +The option defaults are *cutoff* = pair style cutoff. From 9a389fbac6d0e3b0e1d08297da0090bdcbf9c3df Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Thu, 1 Jun 2023 03:25:17 -0600 Subject: [PATCH 07/17] fix typo --- doc/src/compute_local_composition_atom.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/compute_local_composition_atom.rst b/doc/src/compute_local_composition_atom.rst index 2b8fb7f080..96e422122b 100644 --- a/doc/src/compute_local_composition_atom.rst +++ b/doc/src/compute_local_composition_atom.rst @@ -48,9 +48,9 @@ always add to one. .. note:: This compute uses the number of atom types, not chemical species, assigned in - :doc:`pair_coeff ` command. If an interatomic potential has two + :doc:`pair_coeff ` command. If an interatomic potential has two species (i.e., Cu and Ni) assigned to four different atom types in - :doc:`pair_coeff ` (i.e., 'Cu Cu Ni Ni'), the local composition will + :doc:`pair_coeff ` (i.e., 'Cu Cu Ni Ni'), the compute will output four fractional values. In those cases, the user may desire an extra calculation step to consolidate per-type fractions into per-species fractions. This calculation can be conducted within LAMMPS using another compute such as From 2c22bb49b4401dd38bbc13f6c8b9843520ef829b Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 1 Jun 2023 12:32:02 -0600 Subject: [PATCH 08/17] Added some comments to data members --- src/EXTRA-COMPUTE/compute_local_composition_atom.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.h b/src/EXTRA-COMPUTE/compute_local_composition_atom.h index fb8c8b6c49..64498b6640 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.h +++ b/src/EXTRA-COMPUTE/compute_local_composition_atom.h @@ -35,11 +35,14 @@ class ComputeLocalCompositionAtom : public Compute { protected: int nmax; - double cutoff, cutsq, volume, nelements; - int *map; // map types to [0,nelements), taken from example in compute_snap - class NeighList *list; + double cutoff; // global cutoff distance + double cutsq; // cutoff**2 + double volume; // local volume + double nelements; // number of elements + int *map; // map types to [0,nelements) + class NeighList *list; // neighbor list - double **result; + double **result; // peratom array of local compositions }; } // namespace LAMMPS_NS From 710597a353b906d4e460c3558ddb2bd9a9cbfc60 Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 1 Jun 2023 17:43:51 -0600 Subject: [PATCH 09/17] Made some coding style changes --- doc/src/Commands_compute.rst | 1 + doc/src/compute.rst | 1 + ...n_atom.rst => compute_local_comp_atom.rst} | 39 ++++------ doc/utils/sphinx-config/false_positives.txt | 2 + ...n_atom.cpp => compute_local_comp_atom.cpp} | 73 +++++++------------ ...ition_atom.h => compute_local_comp_atom.h} | 15 ++-- ...cpp => compute_local_comp_atom_kokkos.cpp} | 44 +++++------ ...tom.h => compute_local_comp_atom_kokkos.h} | 25 +++---- 8 files changed, 81 insertions(+), 119 deletions(-) rename doc/src/{compute_local_composition_atom.rst => compute_local_comp_atom.rst} (72%) rename src/EXTRA-COMPUTE/{compute_local_composition_atom.cpp => compute_local_comp_atom.cpp} (71%) rename src/EXTRA-COMPUTE/{compute_local_composition_atom.h => compute_local_comp_atom.h} (71%) rename src/KOKKOS/{compute_local_composition_atom.cpp => compute_local_comp_atom_kokkos.cpp} (77%) rename src/KOKKOS/{compute_local_composition_atom.h => compute_local_comp_atom_kokkos.h} (60%) diff --git a/doc/src/Commands_compute.rst b/doc/src/Commands_compute.rst index 755000c976..a2d0fd3823 100644 --- a/doc/src/Commands_compute.rst +++ b/doc/src/Commands_compute.rst @@ -91,6 +91,7 @@ KOKKOS, o = OPENMP, t = OPT. * :doc:`ke/atom/eff ` * :doc:`ke/eff ` * :doc:`ke/rigid ` + * :doc:`local/comp/atom ` * :doc:`mliap ` * :doc:`momentum ` * :doc:`msd ` diff --git a/doc/src/compute.rst b/doc/src/compute.rst index 950487cb72..2862e94b02 100644 --- a/doc/src/compute.rst +++ b/doc/src/compute.rst @@ -245,6 +245,7 @@ The individual style names on the :doc:`Commands compute ` pag * :doc:`ke/atom/eff ` - per-atom translational and radial kinetic energy in the electron force field model * :doc:`ke/eff ` - kinetic energy of a group of nuclei and electrons in the electron force field model * :doc:`ke/rigid ` - translational kinetic energy of rigid bodies +* :doc:`local/comp/atom ` - local composition for each atom * :doc:`mliap ` - gradients of energy and forces with respect to model parameters and related quantities for training machine learning interatomic potentials * :doc:`momentum ` - translational momentum * :doc:`msd ` - mean-squared displacement of group of atoms diff --git a/doc/src/compute_local_composition_atom.rst b/doc/src/compute_local_comp_atom.rst similarity index 72% rename from doc/src/compute_local_composition_atom.rst rename to doc/src/compute_local_comp_atom.rst index 96e422122b..ad9331895e 100644 --- a/doc/src/compute_local_composition_atom.rst +++ b/doc/src/compute_local_comp_atom.rst @@ -1,20 +1,17 @@ -.. index:: compute ave/sphere/atom -.. index:: compute local_composition/atom/kk +.. index:: compute local/comp/atom -compute local_composition/atom command -================================ - -Accelerator Variants: *local_composition/atom/kk* +compute local/comp/atom command +====================================== Syntax """""" .. code-block:: LAMMPS - compute ID group-ID local_composition/atom keyword values ... + compute ID group-ID local/comp/atom keyword values ... * ID, group-ID are documented in :doc:`compute ` command -* local_composition/atom = style name of this compute command +* local/comp/atom = style name of this compute command * one or more keyword/value pairs may be appended .. parsed-literal:: @@ -27,9 +24,9 @@ Examples .. code-block:: LAMMPS - compute 1 all local_composition/atom + compute 1 all local/comp/atom - compute 1 all local_composition/atom cutoff 9.0 + compute 1 all local/comp/atom cutoff 9.0 comm_modify cutoff 9.0 @@ -38,12 +35,11 @@ Description .. versionadded:: 24May2023 -Define a computation that calculates the local composition of atom types for a -central atom based on its neighbors inside a spherical cutoff. For a simulation with -:math:`N` atom types and an atom with :math:`M` neighbors within the cutoff, the -fraction of each atom type is counted and divided by the total number of atoms in the -sphere, including the central atom (:math:`M+1`). The sum of all fractions will -always add to one. +Define a computation that calculates a local composition vector for each +atom. For a central atom with :math:`M` neighbors within the neighbor cutoff sphere, +composition is defined as the number of atoms of a given type +(including the central atom) divided by (:math:`M+1`). For a given central atom, +the sum of all compositions equals one. .. note:: @@ -89,16 +85,13 @@ too frequently. ---------- - -.. include:: accel_styles.rst - - ----------- - Output info """"""""""" -This compute calculates a per-atom array with :math:`1 + N` columns, where :math:`N` is the number of atom types. The first column is a count of the number of atoms used to calcuate composition (including the central atom), and each subsequent column indicates the fraction of that atom type detected within the cutoff range. +This compute calculates a per-atom array with :math:`1 + N` columns, where :math:`N` +is the number of atom types. The first column is a count of the number of atoms +used to calculate composition (including the central atom), and each subsequent +column indicates the fraction of that atom type within the cutoff sphere. These values can be accessed by any command that uses per-atom values from a compute as input. See the :doc:`Howto output ` diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index d2d15633af..6c53226332 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3611,6 +3611,7 @@ Tk Tkin tloop tlsph +tm tmax Tmax tmd @@ -3736,6 +3737,7 @@ Umin un unary uncomment +uncommented uncompress uncompute underprediction diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp similarity index 71% rename from src/EXTRA-COMPUTE/compute_local_composition_atom.cpp rename to src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index ba3e40d8c8..50ad3ce72c 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -15,7 +15,7 @@ Contributing author: Stan Moore (SNL) ------------------------------------------------------------------------- */ -#include "compute_local_composition_atom.h" +#include "compute_local_comp_atom.h" #include "atom.h" #include "comm.h" @@ -37,40 +37,24 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -ComputeLocalCompositionAtom::ComputeLocalCompositionAtom(LAMMPS *lmp, int narg, char **arg) : +ComputeLocalCompAtom::ComputeLocalCompAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), result(nullptr) { - if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute local_composition/atom command"); - - // get nelements and ntypes + if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute local/comp/atom command"); int ntypes = atom->ntypes; - // memory->create(map, ntypes + 1, "compute_sna_grid:map"); - // nelements = utils::inumeric(FLERR, 0, false, lmp); // !!!!!!!! what is 2nd arg in inumeric? - // for (int i = 0; i < ntypes; i++) { - // int jelem = utils::inumeric(FLERR, i, false, lmp); - // if (jelem < 0 || jelem >= nelements) error->all(FLERR, "Illegal compute {} command", style); - // map[i + 1] = jelem; - // printf("mapp[x] %d jelem %d \n", map[i + 1], jelem); - // } - - // printf("ntypes %d \n", ntypes); - // printf("elements %d \n", nelements); - - // 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 local_composition/atom command"); + if (iarg + 2 > narg) error->all(FLERR, "Illegal compute local/comp/atom command"); cutoff = utils::numeric(FLERR, arg[iarg + 1], false, lmp); - if (cutoff <= 0.0) error->all(FLERR, "Illegal compute local_composition/atom command"); + if (cutoff <= 0.0) error->all(FLERR, "Illegal compute local/comp/atom command"); iarg += 2; } else - error->all(FLERR, "Illegal compute local_composition/atom command"); + error->all(FLERR, "Illegal compute local/comp/atom command"); } peratom_flag = 1; @@ -82,21 +66,20 @@ ComputeLocalCompositionAtom::ComputeLocalCompositionAtom(LAMMPS *lmp, int narg, /* ---------------------------------------------------------------------- */ -ComputeLocalCompositionAtom::~ComputeLocalCompositionAtom() +ComputeLocalCompAtom::~ComputeLocalCompAtom() { if (copymode) return; memory->destroy(result); - // memory->destroy(map); } /* ---------------------------------------------------------------------- */ -void ComputeLocalCompositionAtom::init() +void ComputeLocalCompAtom::init() { if (!force->pair && cutoff == 0.0) error->all(FLERR, - "Compute local_composition/atom requires a cutoff be specified " + "Compute local/comp/atom requires a cutoff be specified " "or a pair style be defined"); double skin = neighbor->skin; @@ -109,7 +92,7 @@ void ComputeLocalCompositionAtom::init() if (cutoff > cutghost) error->all(FLERR, - "Compute local_composition/atom cutoff exceeds ghost atom range - " + "Compute local/comp/atom cutoff exceeds ghost atom range - " "use comm_modify cutoff command"); } @@ -120,10 +103,6 @@ void ComputeLocalCompositionAtom::init() } cutsq = cutoff * cutoff; - if (domain->dimension == 3) - volume = 4.0 / 3.0 * MY_PI * cutsq * cutoff; - else - volume = MY_PI * cutsq; // need an occasional full neighbor list @@ -133,19 +112,19 @@ void ComputeLocalCompositionAtom::init() /* ---------------------------------------------------------------------- */ -void ComputeLocalCompositionAtom::init_list(int /*id*/, NeighList *ptr) +void ComputeLocalCompAtom::init_list(int /*id*/, NeighList *ptr) { list = ptr; } /* ---------------------------------------------------------------------- */ -void ComputeLocalCompositionAtom::compute_peratom() +void ComputeLocalCompAtom::compute_peratom() { int i, j, ii, jj, inum, jnum; double xtmp, ytmp, ztmp, delx, dely, delz, rsq; int *ilist, *jlist, *numneigh, **firstneigh; - int count; + int count, itype, jtype; invoked_peratom = update->ntimestep; @@ -154,7 +133,7 @@ void ComputeLocalCompositionAtom::compute_peratom() if (atom->nmax > nmax) { memory->destroy(result); nmax = atom->nmax; - memory->create(result, nmax, size_peratom_cols, "local_composition/atom:result"); + memory->create(result, nmax, size_peratom_cols, "local/comp/atom:result"); array_atom = result; } @@ -176,11 +155,9 @@ void ComputeLocalCompositionAtom::compute_peratom() int typeone_i, typeone_j; - // TODO continue to implement map (nelements instead of ntypes) - int ntypes = atom->ntypes; - double lcomp[ntypes]; + int lcomp[ntypes]; // get per-atom local compositions @@ -202,14 +179,14 @@ void ComputeLocalCompositionAtom::compute_peratom() count = 1; - typeone_i = type[i]; - lcomp[typeone_i - 1]++; + itype = type[i]; + lcomp[itype-1]++; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; j &= NEIGHMASK; - typeone_j = type[j]; + jtype = type[j]; delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; @@ -217,7 +194,7 @@ void ComputeLocalCompositionAtom::compute_peratom() rsq = delx * delx + dely * dely + delz * delz; if (rsq < cutsq) { count++; - lcomp[typeone_j-1]++; + lcomp[jtype-1]++; } } @@ -225,10 +202,12 @@ void ComputeLocalCompositionAtom::compute_peratom() result[i][0] = count; - // local composition fractions per element - for (int n = 0; n < ntypes; n++) { - result[i][n + 1] = lcomp[n] / count; - } + // local comp fractions per element + + double lfac = 1.0 / count; + for (int n = 0; n < ntypes; n++) + result[i][n+1] = lcomp[n] * lfac; + } } } @@ -237,7 +216,7 @@ void ComputeLocalCompositionAtom::compute_peratom() memory usage of local atom-based array ------------------------------------------------------------------------- */ -double ComputeLocalCompositionAtom::memory_usage() +double ComputeLocalCompAtom::memory_usage() { double bytes = (double) 2 * nmax * sizeof(double); return bytes; diff --git a/src/EXTRA-COMPUTE/compute_local_composition_atom.h b/src/EXTRA-COMPUTE/compute_local_comp_atom.h similarity index 71% rename from src/EXTRA-COMPUTE/compute_local_composition_atom.h rename to src/EXTRA-COMPUTE/compute_local_comp_atom.h index 64498b6640..22e40edab9 100644 --- a/src/EXTRA-COMPUTE/compute_local_composition_atom.h +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.h @@ -13,21 +13,21 @@ #ifdef COMPUTE_CLASS // clang-format off -ComputeStyle(local_composition/atom,ComputeLocalCompositionAtom); +ComputeStyle(local/comp/atom,ComputeLocalCompAtom); // clang-format on #else -#ifndef LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_H -#define LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_H +#ifndef LMP_COMPUTE_LOCAL_COMP_ATOM_H +#define LMP_COMPUTE_LOCAL_COMP_ATOM_H #include "compute.h" namespace LAMMPS_NS { -class ComputeLocalCompositionAtom : public Compute { +class ComputeLocalCompAtom : public Compute { public: - ComputeLocalCompositionAtom(class LAMMPS *, int, char **); - ~ComputeLocalCompositionAtom() override; + ComputeLocalCompAtom(class LAMMPS *, int, char **); + ~ComputeLocalCompAtom() override; void init() override; void init_list(int, class NeighList *) override; void compute_peratom() override; @@ -37,9 +37,6 @@ class ComputeLocalCompositionAtom : public Compute { int nmax; double cutoff; // global cutoff distance double cutsq; // cutoff**2 - double volume; // local volume - double nelements; // number of elements - int *map; // map types to [0,nelements) class NeighList *list; // neighbor list double **result; // peratom array of local compositions diff --git a/src/KOKKOS/compute_local_composition_atom.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp similarity index 77% rename from src/KOKKOS/compute_local_composition_atom.cpp rename to src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 1c52d6c948..7ee63eafea 100644 --- a/src/KOKKOS/compute_local_composition_atom.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -12,10 +12,10 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Stan Moore (SNL) + Contributing author: Stan Moore (SNL), Megan McCarthy (SNL) ------------------------------------------------------------------------- */ -#include "compute_local_composition_kokkos.h" +#include "compute_local_comp_atom_kokkos.h" #include "atom_kokkos.h" #include "atom_masks.h" @@ -39,8 +39,8 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ template -ComputeLocalCompositionKokkos::ComputeLocalCompositionKokkos(LAMMPS *lmp, int narg, char **arg) : - ComputeLocalComposition(lmp, narg, arg) +ComputeLocalCompAtomKokkos::ComputeLocalCompAtomKokkos(LAMMPS *lmp, int narg, char **arg) : + ComputeLocalCompAtom(lmp, narg, arg) { kokkosable = 1; atomKK = (AtomKokkos *) atom; @@ -52,7 +52,7 @@ ComputeLocalCompositionKokkos::ComputeLocalCompositionKokkos(LAMMPS /* ---------------------------------------------------------------------- */ template -ComputeLocalCompositionKokkos::~ComputeLocalCompositionKokkos() +ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() { if (copymode) return; @@ -62,9 +62,9 @@ ComputeLocalCompositionKokkos::~ComputeLocalCompositionKokkos() /* ---------------------------------------------------------------------- */ template -void ComputeLocalCompositionKokkos::init() +void ComputeLocalCompAtomKokkos::init() { - ComputeLocalComposition::init(); + ComputeLocalCompAtom::init(); // adjust neighbor list request for KOKKOS @@ -77,7 +77,7 @@ void ComputeLocalCompositionKokkos::init() /* ---------------------------------------------------------------------- */ template -void ComputeLocalCompositionKokkos::compute_peratom() +void ComputeLocalCompAtomKokkos::compute_peratom() { invoked_peratom = update->ntimestep; @@ -86,17 +86,11 @@ void ComputeLocalCompositionKokkos::compute_peratom() if (atom->nmax > nmax) { memoryKK->destroy_kokkos(k_result,result); nmax = atom->nmax; - memoryKK->create_kokkos(k_result,result,nmax,2,"local_composition/atom:result"); + memoryKK->create_kokkos(k_result,result,nmax,2,"local/comp/atom:result"); d_result = k_result.view(); array_atom = result; } - // // need velocities of ghost atoms - - // atomKK->sync(Host,V_MASK); - // comm->forward_comm(this); - // atomKK->modified(Host,V_MASK); - // invoke full neighbor list (will copy or build if necessary) neighbor->build_one(list); @@ -119,8 +113,8 @@ void ComputeLocalCompositionKokkos::compute_peratom() Kokkos::deep_copy(d_result,0.0); copymode = 1; - typename Kokkos::RangePolicy policy(0,inum); - Kokkos::parallel_for("ComputeLocalComposition",policy,*this); + typename Kokkos::RangePolicy policy(0,inum); + Kokkos::parallel_for("ComputeLocalComp",policy,*this); copymode = 0; k_result.modify(); @@ -129,13 +123,11 @@ void ComputeLocalCompositionKokkos::compute_peratom() template KOKKOS_INLINE_FUNCTION -void ComputeLocalCompositionKokkos::operator()(TagComputeLocalComposition, const int &ii) const +void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalComp, const int &ii) const { double typeone_i, typeone_j; - // TODO continue to implement map (nelements instead of ntypes) - - double lcomp[ntypes]; + int lcomp[ntypes]; // get per-atom local compositions @@ -156,13 +148,13 @@ void ComputeLocalCompositionKokkos::operator()(TagComputeLocalCompos int count = 1; - typeone_i = type[i]; + itype = type[i]; for (int jj = 0; jj < jnum; jj++) { int j = d_neighbors(i,jj); j &= NEIGHMASK; - typeone_j = type[j]; + jtype = type[j]; const F_FLOAT delx = x(j,0) - xtmp; const F_FLOAT dely = x(j,1) - ytmp; @@ -170,7 +162,7 @@ void ComputeLocalCompositionKokkos::operator()(TagComputeLocalCompos const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; if (rsq < cutsq) { count++; - lcomp[typeone_j]++; + lcomp[jtype]++; } } for (int n = 0 n < 4; n++) { @@ -181,8 +173,8 @@ void ComputeLocalCompositionKokkos::operator()(TagComputeLocalCompos } namespace LAMMPS_NS { -template class ComputeLocalCompositionKokkos; +template class ComputeLocalCompAtomKokkos; #ifdef LMP_KOKKOS_GPU -template class ComputeLocalCompositionKokkos; +template class ComputeLocalCompAtomKokkos; #endif } diff --git a/src/KOKKOS/compute_local_composition_atom.h b/src/KOKKOS/compute_local_comp_atom_kokkos.h similarity index 60% rename from src/KOKKOS/compute_local_composition_atom.h rename to src/KOKKOS/compute_local_comp_atom_kokkos.h index fb0c914b36..5f9baa2af0 100644 --- a/src/KOKKOS/compute_local_composition_atom.h +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.h @@ -13,45 +13,42 @@ #ifdef COMPUTE_CLASS // clang-format off -ComputeStyle(local_composition/atom/kk,ComputeLocalCompositionAtomKokkos); -ComputeStyle(local_composition/atom/kk/device,ComputeLocalCompositionAtomKokkos); -ComputeStyle(local_composition/atom/kk/host,ComputeLocalCompositionAtomKokkos); +ComputeStyle(local/comp/atom/kk,ComputeLocalCompAtomKokkos); +ComputeStyle(local/comp/atom/kk/device,ComputeLocalCompAtomKokkos); +ComputeStyle(local/comp/atom/kk/host,ComputeLocalCompAtomKokkos); // clang-format on #else -#ifndef LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_KOKKOS_H -#define LMP_COMPUTE_LOCAL_COMPOSITION_ATOM_KOKKOS_H +#ifndef LMP_COMPUTE_LOCAL_COMP_ATOM_KOKKOS_H +#define LMP_COMPUTE_LOCAL_COMP_ATOM_KOKKOS_H -#include "compute_local_composition_atom.h" +#include "compute_local_comp_atom.h" #include "kokkos_type.h" namespace LAMMPS_NS { // clang-format off -struct TagComputeLocalCompositionAtom {}; +struct TagComputeLocalCompAtom {}; // clang-format on -template class ComputeLocalCompositionAtomKokkos : public ComputeLocalCompositionAtom { +template class ComputeLocalCompAtomKokkos : public ComputeLocalCompAtom { public: typedef DeviceType device_type; typedef ArrayTypes AT; - ComputeLocalCompositionAtomKokkos(class LAMMPS *, int, char **); - ~ComputeLocalCompositionAtomKokkos() override; + ComputeLocalCompAtomKokkos(class LAMMPS *, int, char **); + ~ComputeLocalCompAtomKokkos() override; void init() override; void compute_peratom() override; KOKKOS_INLINE_FUNCTION - void operator()(TagComputeLocalCompositionAtom, const int &) const; + void operator()(TagComputeLocalCompAtom, const int &) const; private: - double adof, mvv2e, mv2d, boltz; typename AT::t_x_array x; typename AT::t_v_array v; - typename ArrayTypes::t_float_1d rmass; - typename ArrayTypes::t_float_1d mass; typename ArrayTypes::t_int_1d type; typename ArrayTypes::t_int_1d mask; From 0d875d4f8f60c4e33b132105e6b9e2acfe7d91ac Mon Sep 17 00:00:00 2001 From: Aidan Thompson Date: Thu, 1 Jun 2023 18:51:31 -0600 Subject: [PATCH 10/17] Fixed up kokkos version --- src/KOKKOS/compute_local_comp_atom_kokkos.cpp | 33 ++++++++++++------- src/KOKKOS/compute_local_comp_atom_kokkos.h | 1 - 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 7ee63eafea..5dbe436e29 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -83,10 +83,11 @@ void ComputeLocalCompAtomKokkos::compute_peratom() // grow result array if necessary + int size_peratom_cols = 1 + atom->ntypes; if (atom->nmax > nmax) { memoryKK->destroy_kokkos(k_result,result); nmax = atom->nmax; - memoryKK->create_kokkos(k_result,result,nmax,2,"local/comp/atom:result"); + memoryKK->create_kokkos(k_result,result,nmax,size_peratom_cols,"local/comp/atom:result"); d_result = k_result.view(); array_atom = result; } @@ -107,13 +108,12 @@ void ComputeLocalCompAtomKokkos::compute_peratom() atomKK->sync(execution_space,X_MASK|V_MASK|RMASS_MASK|TYPE_MASK|MASK_MASK); x = atomKK->k_x.view(); type = atomKK->k_type.view(); - ntypes = atomKK->k_ntypes.view(); mask = atomKK->k_mask.view(); Kokkos::deep_copy(d_result,0.0); copymode = 1; - typename Kokkos::RangePolicy policy(0,inum); + typename Kokkos::RangePolicy policy(0,inum); Kokkos::parallel_for("ComputeLocalComp",policy,*this); copymode = 0; @@ -123,15 +123,17 @@ void ComputeLocalCompAtomKokkos::compute_peratom() template KOKKOS_INLINE_FUNCTION -void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalComp, const int &ii) const +void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, const int &ii) const { double typeone_i, typeone_j; + int ntypes = atom->ntypes; int lcomp[ntypes]; // get per-atom local compositions - for (ii = 0; ii < inum; ii++) { + int inum = list->inum; + for (int ii = 0; ii < inum; ii++) { for (int i = 0; i < ntypes; i++) lcomp[i] = 0; @@ -148,13 +150,14 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalComp, con int count = 1; - itype = type[i]; + int itype = type[i]; + lcomp[itype-1]++; for (int jj = 0; jj < jnum; jj++) { int j = d_neighbors(i,jj); j &= NEIGHMASK; - jtype = type[j]; + int jtype = type[j]; const F_FLOAT delx = x(j,0) - xtmp; const F_FLOAT dely = x(j,1) - ytmp; @@ -162,12 +165,20 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalComp, con const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; if (rsq < cutsq) { count++; - lcomp[jtype]++; + lcomp[jtype-1]++; } } - for (int n = 0 n < 4; n++) { - d_result(i,n+1) = lcomp[n] / density; - } + + // total count of atoms found in sampled radius range + + d_result(i,0) = count; + + // local comp fractions per element + + double lfac = 1.0 / count; + for (int n = 0; n < ntypes; n++) + d_result(i,n+1) = lcomp[n] * lfac; + } } } diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.h b/src/KOKKOS/compute_local_comp_atom_kokkos.h index 5f9baa2af0..2f1c6ea3d4 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.h +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.h @@ -48,7 +48,6 @@ template class ComputeLocalCompAtomKokkos : public ComputeLoc private: typename AT::t_x_array x; - typename AT::t_v_array v; typename ArrayTypes::t_int_1d type; typename ArrayTypes::t_int_1d mask; From 9eb32fc6b09f6ab5ae0c53edc837dff8101fc5a2 Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Sat, 10 Jun 2023 07:54:40 -0600 Subject: [PATCH 11/17] fix memory allocation runtime error --- src/EXTRA-COMPUTE/compute_local_comp_atom.cpp | 18 ++-- src/EXTRA-COMPUTE/compute_local_comp_atom.h | 4 +- src/KOKKOS/compute_local_comp_atom_kokkos.cpp | 97 +++++++++++-------- src/KOKKOS/compute_local_comp_atom_kokkos.h | 2 + 4 files changed, 69 insertions(+), 52 deletions(-) diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index 50ad3ce72c..bb3f068bd7 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -42,8 +42,6 @@ ComputeLocalCompAtom::ComputeLocalCompAtom(LAMMPS *lmp, int narg, char **arg) : { if (narg < 3 || narg > 5) error->all(FLERR, "Illegal compute local/comp/atom command"); - int ntypes = atom->ntypes; - cutoff = 0.0; int iarg = 3; @@ -59,6 +57,7 @@ ComputeLocalCompAtom::ComputeLocalCompAtom(LAMMPS *lmp, int narg, char **arg) : peratom_flag = 1; + ntypes = atom->ntypes; size_peratom_cols = 1 + ntypes; nmax = 0; @@ -71,6 +70,7 @@ ComputeLocalCompAtom::~ComputeLocalCompAtom() if (copymode) return; memory->destroy(result); + memory->destroy(lcomp); } /* ---------------------------------------------------------------------- */ @@ -108,6 +108,7 @@ void ComputeLocalCompAtom::init() auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); if (cutflag) req->set_cutoff(cutoff); + } /* ---------------------------------------------------------------------- */ @@ -125,6 +126,9 @@ void ComputeLocalCompAtom::compute_peratom() double xtmp, ytmp, ztmp, delx, dely, delz, rsq; int *ilist, *jlist, *numneigh, **firstneigh; int count, itype, jtype; + // int lcomp[ntypes]; + + memory->create(lcomp, ntypes, "local/comp/atom:lcomp"); invoked_peratom = update->ntimestep; @@ -153,20 +157,14 @@ void ComputeLocalCompAtom::compute_peratom() int *type = atom->type; int *mask = atom->mask; - int typeone_i, typeone_j; - - int ntypes = atom->ntypes; - - int lcomp[ntypes]; - // get per-atom local compositions for (ii = 0; ii < inum; ii++) { - for (int i = 0; i < ntypes; i++) lcomp[i] = 0; - i = ilist[ii]; + for (int m = 0; m < ntypes; m++) lcomp[m] = 0.0; + if (mask[i] & groupbit) { xtmp = x[i][0]; diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.h b/src/EXTRA-COMPUTE/compute_local_comp_atom.h index 22e40edab9..8ec5cb685f 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.h +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.h @@ -34,11 +34,13 @@ class ComputeLocalCompAtom : public Compute { double memory_usage() override; protected: - int nmax; + int nmax, ntypes; double cutoff; // global cutoff distance double cutsq; // cutoff**2 class NeighList *list; // neighbor list + int *lcomp; // peratom array to track local compositions + double **result; // peratom array of local compositions }; diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 5dbe436e29..426ad28e0c 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Stan Moore (SNL), Megan McCarthy (SNL) + Contributing authors: Stan Moore (SNL), Megan McCarthy (SNL) ------------------------------------------------------------------------- */ #include "compute_local_comp_atom_kokkos.h" @@ -42,11 +42,13 @@ template ComputeLocalCompAtomKokkos::ComputeLocalCompAtomKokkos(LAMMPS *lmp, int narg, char **arg) : ComputeLocalCompAtom(lmp, narg, arg) { + kokkosable = 1; atomKK = (AtomKokkos *) atom; execution_space = ExecutionSpaceFromDevice::space; datamask_read = EMPTY_MASK; datamask_modify = EMPTY_MASK; + } /* ---------------------------------------------------------------------- */ @@ -57,6 +59,7 @@ ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() if (copymode) return; memoryKK->destroy_kokkos(k_result,result); + memoryKK->destroy_kokkos(k_lcomp,lcomp); } /* ---------------------------------------------------------------------- */ @@ -79,6 +82,7 @@ void ComputeLocalCompAtomKokkos::init() template void ComputeLocalCompAtomKokkos::compute_peratom() { + invoked_peratom = update->ntimestep; // grow result array if necessary @@ -90,8 +94,16 @@ void ComputeLocalCompAtomKokkos::compute_peratom() memoryKK->create_kokkos(k_result,result,nmax,size_peratom_cols,"local/comp/atom:result"); d_result = k_result.view(); array_atom = result; + + memoryKK->destroy_kokkos(k_lcomp,lcomp); + nmax = atom->nmax; + memoryKK->create_kokkos(k_lcomp,lcomp,nmax,"local/comp/atom:result"); + d_lcomp = k_lcomp.view(); } + memoryKK->create_kokkos(k_lcomp,lcomp,size_peratom_cols,"local/comp/atom:lcomp"); + d_lcomp = k_lcomp.view(); + // invoke full neighbor list (will copy or build if necessary) neighbor->build_one(list); @@ -105,12 +117,14 @@ void ComputeLocalCompAtomKokkos::compute_peratom() // 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|RMASS_MASK|TYPE_MASK|MASK_MASK); + atomKK->sync(execution_space,X_MASK|TYPE_MASK|MASK_MASK); x = atomKK->k_x.view(); type = atomKK->k_type.view(); mask = atomKK->k_mask.view(); - + ntypes = atom->ntypes; + Kokkos::deep_copy(d_result,0.0); + Kokkos::deep_copy(d_lcomp,0.0); copymode = 1; typename Kokkos::RangePolicy policy(0,inum); @@ -119,66 +133,67 @@ void ComputeLocalCompAtomKokkos::compute_peratom() k_result.modify(); k_result.sync_host(); + + k_lcomp.modify(); + k_lcomp.sync_host(); } template KOKKOS_INLINE_FUNCTION void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, const int &ii) const { - double typeone_i, typeone_j; - int ntypes = atom->ntypes; - int lcomp[ntypes]; + const int i = d_ilist[ii]; - // get per-atom local compositions + // initialize / reset lcomp - int inum = list->inum; - for (int ii = 0; ii < inum; ii++) { + for (int m = 0; m < ntypes; m++) d_lcomp(m) = 0; + // for (int m = 0; m < ntypes; m++) d_result(i,m) = 0; - for (int i = 0; i < ntypes; i++) lcomp[i] = 0; + if (mask[i] & groupbit) { - const int i = d_ilist[ii]; + 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]; - if (mask[i] & groupbit) { + // i atom contribution - 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]; + int count = 1; + int itype = type[i]; + d_lcomp(itype-1)++; + // d_result(i,itype-1)++; - // i atom contribution + for (int jj = 0; jj < jnum; jj++) { - int count = 1; + int j = d_neighbors(i,jj); + j &= NEIGHMASK; - int itype = type[i]; - lcomp[itype-1]++; + int jtype = type[j]; - for (int jj = 0; jj < jnum; jj++) { - int j = d_neighbors(i,jj); - j &= NEIGHMASK; - - int jtype = type[j]; - - 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++; - lcomp[jtype-1]++; - } + 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++; + d_lcomp(jtype-1)++; + // d_result(i,jtype-1)++; } - // total count of atoms found in sampled radius range + // total count of atoms found in sampled radius range - d_result(i,0) = count; + d_result(i,0) = count; - // local comp fractions per element + // local comp fractions per + + double lfac = 1.0 / count; + + for (int n = 0; n < ntypes; n++) { + d_result(i,n+1) = d_lcomp(n+1) * lfac; + // d_result(i,n+1) = d_result(i,n+1) * lfac; + } - double lfac = 1.0 / count; - for (int n = 0; n < ntypes; n++) - d_result(i,n+1) = lcomp[n] * lfac; - } } } diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.h b/src/KOKKOS/compute_local_comp_atom_kokkos.h index 2f1c6ea3d4..8b8a74b1af 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.h +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.h @@ -55,7 +55,9 @@ template class ComputeLocalCompAtomKokkos : public ComputeLoc typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; + DAT::tdual_int_1d k_lcomp; DAT::tdual_float_2d k_result; + typename AT::t_int_1d d_lcomp; typename AT::t_float_2d d_result; }; From 38fd78b867ecc683531e155c9d5d7e1fa006f1c4 Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Sat, 10 Jun 2023 09:11:09 -0600 Subject: [PATCH 12/17] factor out variable lcomp --- src/KOKKOS/compute_local_comp_atom_kokkos.cpp | 46 +++++++++---------- src/KOKKOS/compute_local_comp_atom_kokkos.h | 4 +- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 426ad28e0c..20caa00df0 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -59,7 +59,7 @@ ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() if (copymode) return; memoryKK->destroy_kokkos(k_result,result); - memoryKK->destroy_kokkos(k_lcomp,lcomp); + // memoryKK->destroy_kokkos(k_lcomp,lcomp); } /* ---------------------------------------------------------------------- */ @@ -94,15 +94,10 @@ void ComputeLocalCompAtomKokkos::compute_peratom() memoryKK->create_kokkos(k_result,result,nmax,size_peratom_cols,"local/comp/atom:result"); d_result = k_result.view(); array_atom = result; - - memoryKK->destroy_kokkos(k_lcomp,lcomp); - nmax = atom->nmax; - memoryKK->create_kokkos(k_lcomp,lcomp,nmax,"local/comp/atom:result"); - d_lcomp = k_lcomp.view(); } - memoryKK->create_kokkos(k_lcomp,lcomp,size_peratom_cols,"local/comp/atom:lcomp"); - d_lcomp = k_lcomp.view(); + // memoryKK->create_kokkos(k_lcomp,lcomp,size_peratom_cols,"local/comp/atom:lcomp"); + // d_lcomp = k_lcomp.view(); // invoke full neighbor list (will copy or build if necessary) @@ -122,9 +117,8 @@ void ComputeLocalCompAtomKokkos::compute_peratom() type = atomKK->k_type.view(); mask = atomKK->k_mask.view(); ntypes = atom->ntypes; - + Kokkos::deep_copy(d_result,0.0); - Kokkos::deep_copy(d_lcomp,0.0); copymode = 1; typename Kokkos::RangePolicy policy(0,inum); @@ -134,8 +128,6 @@ void ComputeLocalCompAtomKokkos::compute_peratom() k_result.modify(); k_result.sync_host(); - k_lcomp.modify(); - k_lcomp.sync_host(); } template @@ -145,13 +137,13 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, const int i = d_ilist[ii]; - // initialize / reset lcomp - - for (int m = 0; m < ntypes; m++) d_lcomp(m) = 0; - // for (int m = 0; m < ntypes; m++) d_result(i,m) = 0; - if (mask[i] & groupbit) { + // initialize / reset lcomp + + // for (int m = 0; m < ntypes; m++) d_lcomp(m) = 0; + // for (int m = 0; m < size_peratom_cols; m++) d_result(i,m) = 0.0; + const X_FLOAT xtmp = x(i,0); const X_FLOAT ytmp = x(i,1); const X_FLOAT ztmp = x(i,2); @@ -161,8 +153,10 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, int count = 1; int itype = type[i]; - d_lcomp(itype-1)++; - // d_result(i,itype-1)++; + + // d_lcomp(itype-1)++; + // d_result(i,itype-1) = d_result(i,itype-1) + 1; + d_result(i,itype)++; for (int jj = 0; jj < jnum; jj++) { @@ -177,8 +171,9 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; if (rsq < cutsq) { count++; - d_lcomp(jtype-1)++; - // d_result(i,jtype-1)++; + // d_lcomp(jtype-1)++; + // d_result(i,jtype) = d_result(i,jtype) + 1; + d_result(i,jtype)++; } // total count of atoms found in sampled radius range @@ -189,10 +184,11 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, double lfac = 1.0 / count; - for (int n = 0; n < ntypes; n++) { - d_result(i,n+1) = d_lcomp(n+1) * lfac; - // d_result(i,n+1) = d_result(i,n+1) * lfac; - } + // for (int n = 1; n < size_peratom_cols; n++) { + // // d_result(i,n+1) = d_lcomp(n+1) * lfac; + // d_result(i,n) = d_result(i,n) * lfac; + // // d_result(i,n+1) = 123.0; + // } } } diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.h b/src/KOKKOS/compute_local_comp_atom_kokkos.h index 8b8a74b1af..bf0f69de55 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.h +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.h @@ -55,9 +55,9 @@ template class ComputeLocalCompAtomKokkos : public ComputeLoc typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - DAT::tdual_int_1d k_lcomp; +// DAT::tdual_int_1d k_lcomp; DAT::tdual_float_2d k_result; - typename AT::t_int_1d d_lcomp; +// typename AT::t_int_1d d_lcomp; typename AT::t_float_2d d_result; }; From 2273c5c4754e22536e70f8216469582594e9f4cc Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Thu, 27 Jul 2023 03:28:46 -0600 Subject: [PATCH 13/17] fix memory and output bugs --- src/EXTRA-COMPUTE/compute_local_comp_atom.cpp | 14 +++---- src/EXTRA-COMPUTE/compute_local_comp_atom.h | 2 +- src/KOKKOS/compute_local_comp_atom_kokkos.cpp | 38 +++++++++---------- src/KOKKOS/compute_local_comp_atom_kokkos.h | 3 -- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index bb3f068bd7..dbd1d04cb2 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -70,7 +70,7 @@ ComputeLocalCompAtom::~ComputeLocalCompAtom() if (copymode) return; memory->destroy(result); - memory->destroy(lcomp); + } /* ---------------------------------------------------------------------- */ @@ -128,7 +128,7 @@ void ComputeLocalCompAtom::compute_peratom() int count, itype, jtype; // int lcomp[ntypes]; - memory->create(lcomp, ntypes, "local/comp/atom:lcomp"); + // memory->create(lcomp, ntypes, "local/comp/atom:lcomp"); invoked_peratom = update->ntimestep; @@ -163,7 +163,7 @@ void ComputeLocalCompAtom::compute_peratom() i = ilist[ii]; - for (int m = 0; m < ntypes; m++) lcomp[m] = 0.0; + // for (int m = 0; m < ntypes; m++) lcomp[m] = 0.0; if (mask[i] & groupbit) { @@ -178,7 +178,7 @@ void ComputeLocalCompAtom::compute_peratom() count = 1; itype = type[i]; - lcomp[itype-1]++; + result[i][itype]++; for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; @@ -192,7 +192,7 @@ void ComputeLocalCompAtom::compute_peratom() rsq = delx * delx + dely * dely + delz * delz; if (rsq < cutsq) { count++; - lcomp[jtype-1]++; + result[i][jtype]++; } } @@ -203,8 +203,8 @@ void ComputeLocalCompAtom::compute_peratom() // local comp fractions per element double lfac = 1.0 / count; - for (int n = 0; n < ntypes; n++) - result[i][n+1] = lcomp[n] * lfac; + for (int n = 1; n < size_peratom_cols; n++) + result[i][n+1] *= lfac; } } diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.h b/src/EXTRA-COMPUTE/compute_local_comp_atom.h index 8ec5cb685f..21362dc933 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.h +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.h @@ -39,7 +39,7 @@ class ComputeLocalCompAtom : public Compute { double cutsq; // cutoff**2 class NeighList *list; // neighbor list - int *lcomp; // peratom array to track local compositions +// int *lcomp; // peratom array to track local compositions double **result; // peratom array of local compositions }; diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 20caa00df0..59f3a50d3a 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -58,8 +58,9 @@ ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() { if (copymode) return; - memoryKK->destroy_kokkos(k_result,result); // memoryKK->destroy_kokkos(k_lcomp,lcomp); + memoryKK->destroy_kokkos(k_result,result); + } /* ---------------------------------------------------------------------- */ @@ -109,6 +110,7 @@ void ComputeLocalCompAtomKokkos::compute_peratom() d_neighbors = k_list->d_neighbors; d_ilist = k_list->d_ilist; + // compute properties for each atom in group // use full neighbor list to count atoms less than cutoff @@ -126,8 +128,15 @@ void ComputeLocalCompAtomKokkos::compute_peratom() copymode = 0; k_result.modify(); + + // printf("k_result pre-sync: %g ", k_result.view()(0,0)); + // printf("k_result pre-sync: %g \n\n", k_result.view()(0,1)); + k_result.sync_host(); + // printf("k_result post-sync: %g ", k_result.view()(0,0)); + // printf("k_result post-sync: %g \n\n", k_result.view()(0,1)); + } template @@ -139,11 +148,6 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, if (mask[i] & groupbit) { - // initialize / reset lcomp - - // for (int m = 0; m < ntypes; m++) d_lcomp(m) = 0; - // for (int m = 0; m < size_peratom_cols; m++) d_result(i,m) = 0.0; - const X_FLOAT xtmp = x(i,0); const X_FLOAT ytmp = x(i,1); const X_FLOAT ztmp = x(i,2); @@ -151,11 +155,8 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, // i atom contribution - int count = 1; + int count = 1.0; int itype = type[i]; - - // d_lcomp(itype-1)++; - // d_result(i,itype-1) = d_result(i,itype-1) + 1; d_result(i,itype)++; for (int jj = 0; jj < jnum; jj++) { @@ -171,25 +172,22 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; if (rsq < cutsq) { count++; - // d_lcomp(jtype-1)++; - // d_result(i,jtype) = d_result(i,jtype) + 1; - d_result(i,jtype)++; + d_result(i,jtype) += 1.0; } + } // total count of atoms found in sampled radius range d_result(i,0) = count; - // local comp fractions per + // local comp fractions per atom type double lfac = 1.0 / count; - // for (int n = 1; n < size_peratom_cols; n++) { - // // d_result(i,n+1) = d_lcomp(n+1) * lfac; - // d_result(i,n) = d_result(i,n) * lfac; - // // d_result(i,n+1) = 123.0; - // } - + for (int n = 1; n < size_peratom_cols; n++) { + // double item = d_result(i,n); + d_result(i,n) *= lfac; + // d_result(i,n) = 123.0; } } } diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.h b/src/KOKKOS/compute_local_comp_atom_kokkos.h index bf0f69de55..5fb52474b2 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.h +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.h @@ -54,10 +54,7 @@ template class ComputeLocalCompAtomKokkos : public ComputeLoc typename AT::t_neighbors_2d d_neighbors; typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - -// DAT::tdual_int_1d k_lcomp; DAT::tdual_float_2d k_result; -// typename AT::t_int_1d d_lcomp; typename AT::t_float_2d d_result; }; From 3657ed6beb12b1f060b1d5517a5a7dcf04ad64bd Mon Sep 17 00:00:00 2001 From: "Megan J. McCarthy" Date: Thu, 27 Jul 2023 03:35:46 -0600 Subject: [PATCH 14/17] clean up comments --- src/EXTRA-COMPUTE/compute_local_comp_atom.cpp | 7 +------ src/EXTRA-COMPUTE/compute_local_comp_atom.h | 3 --- src/KOKKOS/compute_local_comp_atom_kokkos.cpp | 16 +--------------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index dbd1d04cb2..02c1444fbf 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing author: Stan Moore (SNL) + Contributing authors: Megan McCarthy (SNL), Stan Moore (SNL) ------------------------------------------------------------------------- */ #include "compute_local_comp_atom.h" @@ -126,9 +126,6 @@ void ComputeLocalCompAtom::compute_peratom() double xtmp, ytmp, ztmp, delx, dely, delz, rsq; int *ilist, *jlist, *numneigh, **firstneigh; int count, itype, jtype; - // int lcomp[ntypes]; - - // memory->create(lcomp, ntypes, "local/comp/atom:lcomp"); invoked_peratom = update->ntimestep; @@ -163,8 +160,6 @@ void ComputeLocalCompAtom::compute_peratom() i = ilist[ii]; - // for (int m = 0; m < ntypes; m++) lcomp[m] = 0.0; - if (mask[i] & groupbit) { xtmp = x[i][0]; diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.h b/src/EXTRA-COMPUTE/compute_local_comp_atom.h index 21362dc933..76d92de08d 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.h +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.h @@ -38,9 +38,6 @@ class ComputeLocalCompAtom : public Compute { double cutoff; // global cutoff distance double cutsq; // cutoff**2 class NeighList *list; // neighbor list - -// int *lcomp; // peratom array to track local compositions - double **result; // peratom array of local compositions }; diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 59f3a50d3a..9360cbd82a 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing authors: Stan Moore (SNL), Megan McCarthy (SNL) + Contributing authors: Megan McCarthy (SNL), Stan Moore (SNL) ------------------------------------------------------------------------- */ #include "compute_local_comp_atom_kokkos.h" @@ -58,7 +58,6 @@ ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() { if (copymode) return; - // memoryKK->destroy_kokkos(k_lcomp,lcomp); memoryKK->destroy_kokkos(k_result,result); } @@ -97,9 +96,6 @@ void ComputeLocalCompAtomKokkos::compute_peratom() array_atom = result; } - // memoryKK->create_kokkos(k_lcomp,lcomp,size_peratom_cols,"local/comp/atom:lcomp"); - // d_lcomp = k_lcomp.view(); - // invoke full neighbor list (will copy or build if necessary) neighbor->build_one(list); @@ -110,7 +106,6 @@ void ComputeLocalCompAtomKokkos::compute_peratom() d_neighbors = k_list->d_neighbors; d_ilist = k_list->d_ilist; - // compute properties for each atom in group // use full neighbor list to count atoms less than cutoff @@ -128,15 +123,8 @@ void ComputeLocalCompAtomKokkos::compute_peratom() copymode = 0; k_result.modify(); - - // printf("k_result pre-sync: %g ", k_result.view()(0,0)); - // printf("k_result pre-sync: %g \n\n", k_result.view()(0,1)); - k_result.sync_host(); - // printf("k_result post-sync: %g ", k_result.view()(0,0)); - // printf("k_result post-sync: %g \n\n", k_result.view()(0,1)); - } template @@ -185,9 +173,7 @@ void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, double lfac = 1.0 / count; for (int n = 1; n < size_peratom_cols; n++) { - // double item = d_result(i,n); d_result(i,n) *= lfac; - // d_result(i,n) = 123.0; } } } From 4c68e3f5f379c5d93d67db6237477ab5162b6074 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Fri, 4 Aug 2023 13:29:22 -0600 Subject: [PATCH 15/17] Small tweaks --- src/.gitignore | 2 ++ src/EXTRA-COMPUTE/compute_local_comp_atom.cpp | 4 +--- src/KOKKOS/Install.sh | 2 ++ src/KOKKOS/compute_local_comp_atom_kokkos.cpp | 8 +------- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/.gitignore b/src/.gitignore index 6e2a8b92c9..115291c39a 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -580,6 +580,8 @@ /compute_ke_eff.h /compute_ke_rigid.cpp /compute_ke_rigid.h +/compute_local_comp_atom.cpp +/compute_local_comp_atom.h /compute_meso_e_atom.cpp /compute_meso_e_atom.h /compute_meso_rho_atom.cpp diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index 02c1444fbf..02ab91d969 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing authors: Megan McCarthy (SNL), Stan Moore (SNL) + Contributing author: Megan McCarthy (SNL) ------------------------------------------------------------------------- */ #include "compute_local_comp_atom.h" @@ -70,7 +70,6 @@ ComputeLocalCompAtom::~ComputeLocalCompAtom() if (copymode) return; memory->destroy(result); - } /* ---------------------------------------------------------------------- */ @@ -108,7 +107,6 @@ void ComputeLocalCompAtom::init() auto req = neighbor->add_request(this, NeighConst::REQ_FULL | NeighConst::REQ_OCCASIONAL); if (cutflag) req->set_cutoff(cutoff); - } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index ede766cbf8..a842a169c0 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -96,6 +96,8 @@ action compute_coord_atom_kokkos.cpp action compute_coord_atom_kokkos.h action compute_erotate_sphere_kokkos.cpp action compute_erotate_sphere_kokkos.h +action compute_local_comp_atom_kokkos.cpp compute_local_comp_atom.cpp +action compute_local_comp_atom_kokkos.h compute_local_comp_atom.h action compute_orientorder_atom_kokkos.cpp action compute_orientorder_atom_kokkos.h action compute_temp_deform_kokkos.cpp diff --git a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp index 9360cbd82a..356efea2f1 100644 --- a/src/KOKKOS/compute_local_comp_atom_kokkos.cpp +++ b/src/KOKKOS/compute_local_comp_atom_kokkos.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing authors: Megan McCarthy (SNL), Stan Moore (SNL) + Contributing author: Megan McCarthy (SNL) ------------------------------------------------------------------------- */ #include "compute_local_comp_atom_kokkos.h" @@ -42,13 +42,11 @@ template ComputeLocalCompAtomKokkos::ComputeLocalCompAtomKokkos(LAMMPS *lmp, int narg, char **arg) : ComputeLocalCompAtom(lmp, narg, arg) { - kokkosable = 1; atomKK = (AtomKokkos *) atom; execution_space = ExecutionSpaceFromDevice::space; datamask_read = EMPTY_MASK; datamask_modify = EMPTY_MASK; - } /* ---------------------------------------------------------------------- */ @@ -59,7 +57,6 @@ ComputeLocalCompAtomKokkos::~ComputeLocalCompAtomKokkos() if (copymode) return; memoryKK->destroy_kokkos(k_result,result); - } /* ---------------------------------------------------------------------- */ @@ -82,7 +79,6 @@ void ComputeLocalCompAtomKokkos::init() template void ComputeLocalCompAtomKokkos::compute_peratom() { - invoked_peratom = update->ntimestep; // grow result array if necessary @@ -124,14 +120,12 @@ void ComputeLocalCompAtomKokkos::compute_peratom() k_result.modify(); k_result.sync_host(); - } template KOKKOS_INLINE_FUNCTION void ComputeLocalCompAtomKokkos::operator()(TagComputeLocalCompAtom, const int &ii) const { - const int i = d_ilist[ii]; if (mask[i] & groupbit) { From 5e9658aff6ff76fe55886dac158cd0801dd6cdb0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Aug 2023 21:06:47 -0400 Subject: [PATCH 16/17] fix whitespace and minor documentation integration issues --- doc/src/Commands_compute.rst | 2 +- doc/src/compute_local_comp_atom.rst | 25 +++++++++++-------- src/EXTRA-COMPUTE/compute_local_comp_atom.cpp | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/doc/src/Commands_compute.rst b/doc/src/Commands_compute.rst index 73f7373f8c..19e56fcc83 100644 --- a/doc/src/Commands_compute.rst +++ b/doc/src/Commands_compute.rst @@ -91,7 +91,7 @@ KOKKOS, o = OPENMP, t = OPT. * :doc:`ke/atom/eff ` * :doc:`ke/eff ` * :doc:`ke/rigid ` - * :doc:`local/comp/atom ` + * :doc:`local/comp/atom (k) ` * :doc:`mliap ` * :doc:`momentum ` * :doc:`msd ` diff --git a/doc/src/compute_local_comp_atom.rst b/doc/src/compute_local_comp_atom.rst index ad9331895e..2d0dd8c6f2 100644 --- a/doc/src/compute_local_comp_atom.rst +++ b/doc/src/compute_local_comp_atom.rst @@ -1,7 +1,10 @@ .. index:: compute local/comp/atom +.. index:: compute local/comp/atom/kk compute local/comp/atom command -====================================== +=============================== + +Accelerator Variants: *local/comp/atom/kk* Syntax """""" @@ -33,7 +36,7 @@ Examples Description """"""""""" -.. versionadded:: 24May2023 +.. versionadded:: TBD Define a computation that calculates a local composition vector for each atom. For a central atom with :math:`M` neighbors within the neighbor cutoff sphere, @@ -43,14 +46,14 @@ the sum of all compositions equals one. .. note:: - This compute uses the number of atom types, not chemical species, assigned in - :doc:`pair_coeff ` command. If an interatomic potential has two - species (i.e., Cu and Ni) assigned to four different atom types in - :doc:`pair_coeff ` (i.e., 'Cu Cu Ni Ni'), the compute will - output four fractional values. In those cases, the user may desire an extra - calculation step to consolidate per-type fractions into per-species fractions. - This calculation can be conducted within LAMMPS using another compute such as - :doc:`compute reduce `, an atom-style :doc:`variable`, or as a + This compute uses the number of atom types, not chemical species, assigned in + :doc:`pair_coeff ` command. If an interatomic potential has two + species (i.e., Cu and Ni) assigned to four different atom types in + :doc:`pair_coeff ` (i.e., 'Cu Cu Ni Ni'), the compute will + output four fractional values. In those cases, the user may desire an extra + calculation step to consolidate per-type fractions into per-species fractions. + This calculation can be conducted within LAMMPS using another compute such as + :doc:`compute reduce `, an atom-style :doc:`variable`, or as a post-processing step. ---------- @@ -91,7 +94,7 @@ Output info This compute calculates a per-atom array with :math:`1 + N` columns, where :math:`N` is the number of atom types. The first column is a count of the number of atoms used to calculate composition (including the central atom), and each subsequent -column indicates the fraction of that atom type within the cutoff sphere. +column indicates the fraction of that atom type within the cutoff sphere. These values can be accessed by any command that uses per-atom values from a compute as input. See the :doc:`Howto output ` diff --git a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp index 02ab91d969..77c4993996 100644 --- a/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp +++ b/src/EXTRA-COMPUTE/compute_local_comp_atom.cpp @@ -198,7 +198,7 @@ void ComputeLocalCompAtom::compute_peratom() double lfac = 1.0 / count; for (int n = 1; n < size_peratom_cols; n++) result[i][n+1] *= lfac; - + } } } From 003a207038b419fa6fa1654be45010d6b8884298 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 Aug 2023 22:24:48 -0400 Subject: [PATCH 17/17] possible workaround for unit test failure taken from: https://github.com/open-mpi/ompi/issues/9656 --- unittest/formats/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 5b5dd056c9..9934c87ab1 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -40,6 +40,8 @@ set_tests_properties(TextFileReader PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${ add_executable(test_file_operations test_file_operations.cpp) target_link_libraries(test_file_operations PRIVATE lammps GTest::GMock) add_test(NAME FileOperations COMMAND test_file_operations) +# try to mitigate possible OpenMPI bug +set_tests_properties(TextFileReader PROPERTIES ENVIRONMENT "OMPI_MCA_sharedfp=\"^sm\"") add_executable(test_dump_atom test_dump_atom.cpp) target_link_libraries(test_dump_atom PRIVATE lammps GTest::GMock)