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; };