diff --git a/examples/reaxff/in.reaxff.tatb b/examples/reaxff/in.reaxff.tatb index 50f572a994..967ed0a1d6 100644 --- a/examples/reaxff/in.reaxff.tatb +++ b/examples/reaxff/in.reaxff.tatb @@ -31,7 +31,7 @@ neigh_modify delay 0 every 5 check no fix 1 all nve fix 2 all qeq/reaxff 1 0.0 10.0 1.0e-6 reaxff fix 4 all reaxff/bonds 5 bonds.reaxff -compute bonds all reaxff/bonds +compute bonds all reaxff/atom bonds yes variable nqeq equal f_2 # dumps out the local bond information diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 01db058d5b..28fe6d5cd6 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -165,8 +165,8 @@ action fix_qeq_reaxff_kokkos.cpp fix_qeq_reaxff.cpp action fix_qeq_reaxff_kokkos.h fix_qeq_reaxff.h action fix_reaxff_bonds_kokkos.cpp fix_reaxff_bonds.cpp action fix_reaxff_bonds_kokkos.h fix_reaxff_bonds.h -action compute_reaxff_bonds_kokkos.cpp compute_reaxff_bonds.cpp -action compute_reaxff_bonds_kokkos.h compute_reaxff_bonds.h +action compute_reaxff_atom_kokkos.cpp compute_reaxff_atom.cpp +action compute_reaxff_atom_kokkos.h compute_reaxff_atom.h action fix_reaxff_species_kokkos.cpp fix_reaxff_species.cpp action fix_reaxff_species_kokkos.h fix_reaxff_species.h action fix_rx_kokkos.cpp fix_rx.cpp diff --git a/src/KOKKOS/compute_reaxff_bonds_kokkos.cpp b/src/KOKKOS/compute_reaxff_atom_kokkos.cpp similarity index 76% rename from src/KOKKOS/compute_reaxff_bonds_kokkos.cpp rename to src/KOKKOS/compute_reaxff_atom_kokkos.cpp index f36832e6ac..2485d9ae72 100644 --- a/src/KOKKOS/compute_reaxff_bonds_kokkos.cpp +++ b/src/KOKKOS/compute_reaxff_atom_kokkos.cpp @@ -16,7 +16,7 @@ Contributing author: Richard Berger (LANL) ------------------------------------------------------------------------- */ -#include "compute_reaxff_bonds_kokkos.h" +#include "compute_reaxff_atom_kokkos.h" #include "atom.h" #include "molecule.h" #include "update.h" @@ -35,8 +35,8 @@ using namespace ReaxFF; /* ---------------------------------------------------------------------- */ template -ComputeReaxFFBondsKokkos::ComputeReaxFFBondsKokkos(LAMMPS *lmp, int narg, char **arg) : - ComputeReaxFFBonds(lmp, narg, arg), +ComputeReaxFFAtomKokkos::ComputeReaxFFAtomKokkos(LAMMPS *lmp, int narg, char **arg) : + ComputeReaxFFAtom(lmp, narg, arg), nbuf(-1), buf(nullptr) { kokkosable = 1; @@ -46,7 +46,7 @@ ComputeReaxFFBondsKokkos::ComputeReaxFFBondsKokkos(LAMMPS *lmp, int /* ---------------------------------------------------------------------- */ template -ComputeReaxFFBondsKokkos::~ComputeReaxFFBondsKokkos() +ComputeReaxFFAtomKokkos::~ComputeReaxFFAtomKokkos() { memoryKK->destroy_kokkos(k_buf, buf); } @@ -54,21 +54,21 @@ ComputeReaxFFBondsKokkos::~ComputeReaxFFBondsKokkos() /* ---------------------------------------------------------------------- */ template -void ComputeReaxFFBondsKokkos::init() +void ComputeReaxFFAtomKokkos::init() { reaxff = dynamic_cast(force->pair_match("^reax../kk",0)); - if (reaxff == nullptr) error->all(FLERR,"Cannot use compute reaxff/bonds without " + if (reaxff == nullptr) error->all(FLERR,"Cannot use compute reaxff/atom without " "pair_style reaxff/kk"); } /* ---------------------------------------------------------------------- */ template -void ComputeReaxFFBondsKokkos::compute_bonds() +void ComputeReaxFFAtomKokkos::compute_bonds() { if (atom->nlocal > nlocal) { memory->destroy(array_atom); nlocal = atom->nlocal; - memory->create(array_atom, nlocal, 3, "reaxff/bonds:array_atom"); + memory->create(array_atom, nlocal, 3, "reaxff/atom:array_atom"); } // retrieve bond information from kokkos pair style. the data potentially @@ -83,20 +83,20 @@ void ComputeReaxFFBondsKokkos::compute_bonds() else host_pair()->FindBond(maxnumbonds); - nbuf = (maxnumbonds*2 + 3)*nlocal; + nbuf = ((store_bonds ? maxnumbonds*2 : 0) + 3)*nlocal; if(!buf || k_buf.extent(0) < nbuf) { memoryKK->destroy_kokkos(k_buf, buf); - memoryKK->create_kokkos(k_buf, buf, nbuf, "reaxff/bonds:buf"); + memoryKK->create_kokkos(k_buf, buf, nbuf, "reaxff/atom:buf"); } // Pass information to buffer, will sync to host int nbuf_local; if (reaxff->execution_space == Device) - device_pair()->PackReducedBondBuffer(k_buf, nbuf_local); + device_pair()->PackReducedBondBuffer(k_buf, nbuf_local, store_bonds); else - host_pair()->PackReducedBondBuffer(k_buf, nbuf_local); + host_pair()->PackReducedBondBuffer(k_buf, nbuf_local, store_bonds); // Extract number of bonds from buffer @@ -105,14 +105,14 @@ void ComputeReaxFFBondsKokkos::compute_bonds() for (int i = 0; i < nlocal; i++) { int numbonds = static_cast(buf[j+2]); nbonds += numbonds; - j += 2*numbonds + 3; + j += (store_bonds ? 2*numbonds : 0) + 3; } } /* ---------------------------------------------------------------------- */ template -void ComputeReaxFFBondsKokkos::compute_local() +void ComputeReaxFFAtomKokkos::compute_local() { invoked_local = update->ntimestep; @@ -122,7 +122,7 @@ void ComputeReaxFFBondsKokkos::compute_local() if(nbonds > prev_nbonds) { // grow array_local memory->destroy(array_local); - memory->create(array_local, nbonds, 3, "reaxff/bonds:array_local"); + memory->create(array_local, nbonds, 3, "reaxff/atom:array_local"); prev_nbonds = nbonds; } @@ -150,7 +150,7 @@ void ComputeReaxFFBondsKokkos::compute_local() /* ---------------------------------------------------------------------- */ template -void ComputeReaxFFBondsKokkos::compute_peratom() +void ComputeReaxFFAtomKokkos::compute_peratom() { invoked_peratom = update->ntimestep; @@ -166,7 +166,7 @@ void ComputeReaxFFBondsKokkos::compute_peratom() ptr[0] = buf[j]; // sbo ptr[1] = buf[j+1]; // nlp ptr[2] = numbonds; - j += 2*numbonds + 3; + j += (store_bonds ? 2*numbonds : 0) + 3; } } @@ -175,16 +175,18 @@ void ComputeReaxFFBondsKokkos::compute_peratom() ------------------------------------------------------------------------- */ template -double ComputeReaxFFBondsKokkos::memory_usage() +double ComputeReaxFFAtomKokkos::memory_usage() { - double bytes = (double)(nbonds*3) * sizeof(double); - bytes += (double)(nlocal*3) * sizeof(double); + double bytes = (double)(nlocal*3) * sizeof(double); + if(store_bonds) + bytes += (double)(nbonds*3) * sizeof(double); + bytes += (double)(nbuf > 0 ? nbuf * sizeof(double) : 0); return bytes; } namespace LAMMPS_NS { -template class ComputeReaxFFBondsKokkos; +template class ComputeReaxFFAtomKokkos; #ifdef LMP_KOKKOS_GPU -template class ComputeReaxFFBondsKokkos; +template class ComputeReaxFFAtomKokkos; #endif } diff --git a/src/KOKKOS/compute_reaxff_bonds_kokkos.h b/src/KOKKOS/compute_reaxff_atom_kokkos.h similarity index 79% rename from src/KOKKOS/compute_reaxff_bonds_kokkos.h rename to src/KOKKOS/compute_reaxff_atom_kokkos.h index 48f3860283..7037c7e308 100644 --- a/src/KOKKOS/compute_reaxff_bonds_kokkos.h +++ b/src/KOKKOS/compute_reaxff_atom_kokkos.h @@ -17,29 +17,29 @@ #ifdef COMPUTE_CLASS // clang-format off -ComputeStyle(reaxff/bonds/kk,ComputeReaxFFBondsKokkos); -ComputeStyle(reaxff/bonds/kk/device,ComputeReaxFFBondsKokkos); -ComputeStyle(reaxff/bonds/kk/host,ComputeReaxFFBondsKokkos); +ComputeStyle(reaxff/atom/kk,ComputeReaxFFAtomKokkos); +ComputeStyle(reaxff/atom/kk/device,ComputeReaxFFAtomKokkos); +ComputeStyle(reaxff/atom/kk/host,ComputeReaxFFAtomKokkos); // clang-format on #else #ifndef LMP_COMPUTE_REAXFF_BONDS_KOKKOS_H #define LMP_COMPUTE_REAXFF_BONDS_KOKKOS_H -#include "compute_reaxff_bonds.h" +#include "compute_reaxff_atom.h" #include "pair_reaxff_kokkos.h" #include "kokkos_type.h" namespace LAMMPS_NS { template -class ComputeReaxFFBondsKokkos : public ComputeReaxFFBonds { +class ComputeReaxFFAtomKokkos : public ComputeReaxFFAtom { public: using device_type = DeviceType; using AT = ArrayTypes; - ComputeReaxFFBondsKokkos(class LAMMPS *, int, char **); - ~ComputeReaxFFBondsKokkos() override; + ComputeReaxFFAtomKokkos(class LAMMPS *, int, char **); + ~ComputeReaxFFAtomKokkos() override; void init() override; void compute_local() override; void compute_peratom() override; diff --git a/src/KOKKOS/pair_reaxff_kokkos.cpp b/src/KOKKOS/pair_reaxff_kokkos.cpp index e298eca2da..914962f0e6 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.cpp +++ b/src/KOKKOS/pair_reaxff_kokkos.cpp @@ -4250,15 +4250,21 @@ void PairReaxFFKokkos::PackBondBuffer(DAT::tdual_ffloat_1d k_buf, in /* ---------------------------------------------------------------------- */ template -void PairReaxFFKokkos::PackReducedBondBuffer(DAT::tdual_ffloat_1d k_buf, int &nbuf_local) +void PairReaxFFKokkos::PackReducedBondBuffer(DAT::tdual_ffloat_1d k_buf, int &nbuf_local, bool store_bonds) { d_buf = k_buf.view(); k_params_sing.template sync(); copymode = 1; nlocal = atomKK->nlocal; - PairReaxKokkosPackReducedBondBufferFunctor pack_bond_buffer_functor(this); - Kokkos::parallel_scan(nlocal,pack_bond_buffer_functor); + if(store_bonds) { + PairReaxKokkosPackReducedBondBufferFunctor pack_bond_buffer_functor(this); + Kokkos::parallel_scan(nlocal,pack_bond_buffer_functor); + } else { + PairReaxKokkosPackReducedBondBufferFunctor pack_bond_buffer_functor(this); + Kokkos::parallel_scan(nlocal,pack_bond_buffer_functor); + } + copymode = 0; k_buf.modify(); @@ -4313,6 +4319,7 @@ void PairReaxFFKokkos::pack_bond_buffer_item(int i, int &j, const bo } template +template KOKKOS_INLINE_FUNCTION void PairReaxFFKokkos::pack_reduced_bond_buffer_item(int i, int &j, const bool &final) const { @@ -4325,21 +4332,23 @@ void PairReaxFFKokkos::pack_reduced_bond_buffer_item(int i, int &j, j += 3; - if (final) { - for (int k = 0; k < numbonds; ++k) { - d_buf[j+k] = d_neighid(i,k); + if constexpr(STORE_BONDS) { + if (final) { + for (int k = 0; k < numbonds; ++k) { + d_buf[j+k] = d_neighid(i,k); + } } - } - j += numbonds; + j += numbonds; - if (final) { - for (int k = 0; k < numbonds; k++) { - d_buf[j+k] = d_abo(i,k); + if (final) { + for (int k = 0; k < numbonds; k++) { + d_buf[j+k] = d_abo(i,k); + } } - } - j += numbonds; + j += numbonds; + } if (final && i == nlocal-1) k_nbuf_local.view()() = j - 1; diff --git a/src/KOKKOS/pair_reaxff_kokkos.h b/src/KOKKOS/pair_reaxff_kokkos.h index 571dd63fd1..f246afcc86 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.h +++ b/src/KOKKOS/pair_reaxff_kokkos.h @@ -135,7 +135,7 @@ class PairReaxFFKokkos : public PairReaxFF { double memory_usage(); void FindBond(int &); void PackBondBuffer(DAT::tdual_ffloat_1d, int &); - void PackReducedBondBuffer(DAT::tdual_ffloat_1d, int &); + void PackReducedBondBuffer(DAT::tdual_ffloat_1d, int &, bool); void FindBondSpecies(); template @@ -293,6 +293,7 @@ class PairReaxFFKokkos : public PairReaxFF { KOKKOS_INLINE_FUNCTION void pack_bond_buffer_item(int, int&, const bool&) const; + template KOKKOS_INLINE_FUNCTION void pack_reduced_bond_buffer_item(int, int&, const bool&) const; @@ -553,7 +554,7 @@ struct PairReaxKokkosPackBondBufferFunctor { } }; -template +template struct PairReaxKokkosPackReducedBondBufferFunctor { typedef DeviceType device_type; typedef int value_type; @@ -562,7 +563,7 @@ struct PairReaxKokkosPackReducedBondBufferFunctor { KOKKOS_INLINE_FUNCTION void operator()(const int ii, int &j, const bool &final) const { - c.pack_reduced_bond_buffer_item(ii,j,final); + c.template pack_reduced_bond_buffer_item(ii,j,final); } }; diff --git a/src/REAXFF/compute_reaxff_bonds.cpp b/src/REAXFF/compute_reaxff_atom.cpp similarity index 74% rename from src/REAXFF/compute_reaxff_bonds.cpp rename to src/REAXFF/compute_reaxff_atom.cpp index 3b3520fda3..d975fe42f8 100644 --- a/src/REAXFF/compute_reaxff_bonds.cpp +++ b/src/REAXFF/compute_reaxff_atom.cpp @@ -16,7 +16,7 @@ Contributing author: Richard Berger (LANL) ------------------------------------------------------------------------- */ -#include "compute_reaxff_bonds.h" +#include "compute_reaxff_atom.h" #include "atom.h" #include "molecule.h" #include "update.h" @@ -33,14 +33,13 @@ using namespace ReaxFF; /* ---------------------------------------------------------------------- */ -ComputeReaxFFBonds::ComputeReaxFFBonds(LAMMPS *lmp, int narg, char **arg) : +ComputeReaxFFAtom::ComputeReaxFFAtom(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), abo(nullptr), neighid(nullptr), bondcount(nullptr), reaxff(nullptr) { if (atom->tag_consecutive() == 0) - error->all(FLERR,"Atom IDs must be consecutive for compute reaxff/bonds"); + error->all(FLERR,"Atom IDs must be consecutive for compute reaxff/atom"); - local_flag = 1; peratom_flag = 1; // initialize output @@ -54,12 +53,25 @@ ComputeReaxFFBonds::ComputeReaxFFBonds(LAMMPS *lmp, int narg, char **arg) : size_local_cols = 3; invoked_bonds = -1; + + store_bonds = false; + + int iarg = 3; + while (iarg narg) utils::missing_cmd_args(FLERR, "compute reaxff/atom bonds", error); + store_bonds = utils::logical(FLERR, arg[iarg+1], false, lmp); + iarg += 2; + } else error->all(FLERR,"Illegal compute reaxff/atom command"); + } + + local_flag = store_bonds; } /* ---------------------------------------------------------------------- */ -ComputeReaxFFBonds::~ComputeReaxFFBonds() +ComputeReaxFFAtom::~ComputeReaxFFAtom() { memory->destroy(array_local); memory->destroy(array_atom); @@ -70,16 +82,16 @@ ComputeReaxFFBonds::~ComputeReaxFFBonds() /* ---------------------------------------------------------------------- */ -void ComputeReaxFFBonds::init() +void ComputeReaxFFAtom::init() { reaxff = dynamic_cast(force->pair_match("^reax..",0)); - if (reaxff == nullptr) error->all(FLERR,"Cannot use compute reaxff/bonds without " + if (reaxff == nullptr) error->all(FLERR,"Cannot use compute reaxff/atom without " "pair_style reaxff, reaxff/kk, or reaxff/omp"); } /* ---------------------------------------------------------------------- */ -int ComputeReaxFFBonds::FindBond() +int ComputeReaxFFAtom::FindBond() { int *ilist, i, ii, inum; int j, pj, nj; @@ -105,8 +117,10 @@ int ComputeReaxFFBonds::FindBond() bo_tmp = bo_ij->bo_data.BO; if (bo_tmp > bo_cut) { - neighid[i][nj] = jtag; - abo[i][nj] = bo_tmp; + if(store_bonds) { + neighid[i][nj] = jtag; + abo[i][nj] = bo_tmp; + } nj++; } } @@ -119,7 +133,7 @@ int ComputeReaxFFBonds::FindBond() /* ---------------------------------------------------------------------- */ -void ComputeReaxFFBonds::compute_bonds() +void ComputeReaxFFAtom::compute_bonds() { invoked_bonds = update->ntimestep; @@ -129,15 +143,17 @@ void ComputeReaxFFBonds::compute_bonds() memory->destroy(bondcount); memory->destroy(array_atom); nlocal = atom->nlocal; - memory->create(abo, nlocal, MAXREAXBOND, "reaxff/bonds:abo"); - memory->create(neighid, nlocal, MAXREAXBOND, "reaxff/bonds:neighid"); - memory->create(bondcount, nlocal, "reaxff/bonds:bondcount"); - memory->create(array_atom, nlocal, 3, "reaxff/bonds:array_atom"); + if(store_bonds) { + memory->create(abo, nlocal, MAXREAXBOND, "reaxff/atom:abo"); + memory->create(neighid, nlocal, MAXREAXBOND, "reaxff/atom:neighid"); + } + memory->create(bondcount, nlocal, "reaxff/atom:bondcount"); + memory->create(array_atom, nlocal, 3, "reaxff/atom:array_atom"); } for (int i = 0; i < nlocal; i++) { bondcount[i] = 0; - for (int j = 0; j < MAXREAXBOND; j++) { + for (int j = 0; store_bonds && j < MAXREAXBOND; j++) { neighid[i][j] = 0; abo[i][j] = 0.0; } @@ -148,7 +164,7 @@ void ComputeReaxFFBonds::compute_bonds() /* ---------------------------------------------------------------------- */ -void ComputeReaxFFBonds::compute_local() +void ComputeReaxFFAtom::compute_local() { invoked_local = update->ntimestep; @@ -159,7 +175,7 @@ void ComputeReaxFFBonds::compute_local() if(nbonds > prev_nbonds) { // grow array_local memory->destroy(array_local); - memory->create(array_local, nbonds, 3, "reaxff/bonds:array_local"); + memory->create(array_local, nbonds, 3, "reaxff/atom:array_local"); prev_nbonds = nbonds; } @@ -181,7 +197,7 @@ void ComputeReaxFFBonds::compute_local() /* ---------------------------------------------------------------------- */ -void ComputeReaxFFBonds::compute_peratom() +void ComputeReaxFFAtom::compute_peratom() { invoked_peratom = update->ntimestep; @@ -201,11 +217,13 @@ void ComputeReaxFFBonds::compute_peratom() memory usage of local data ------------------------------------------------------------------------- */ -double ComputeReaxFFBonds::memory_usage() +double ComputeReaxFFAtom::memory_usage() { - double bytes = (double)(nbonds*3) * sizeof(double); - bytes += (double)(nlocal*3) * sizeof(double); - bytes += (double)(2*nlocal*MAXREAXBOND) * sizeof(double); + double bytes = (double)(nlocal*3) * sizeof(double); bytes += (double)(nlocal) * sizeof(int); + if(store_bonds) { + bytes += (double)(2*nlocal*MAXREAXBOND) * sizeof(double); + bytes += (double)(nbonds*3) * sizeof(double); + } return bytes; } diff --git a/src/REAXFF/compute_reaxff_bonds.h b/src/REAXFF/compute_reaxff_atom.h similarity index 84% rename from src/REAXFF/compute_reaxff_bonds.h rename to src/REAXFF/compute_reaxff_atom.h index b876c9e02d..31b18e7238 100644 --- a/src/REAXFF/compute_reaxff_bonds.h +++ b/src/REAXFF/compute_reaxff_atom.h @@ -17,21 +17,21 @@ #ifdef COMPUTE_CLASS // clang-format off -ComputeStyle(reaxff/bonds,ComputeReaxFFBonds); +ComputeStyle(reaxff/atom,ComputeReaxFFAtom); // clang-format on #else -#ifndef LMP_COMPUTE_REAXFF_BONDS_H -#define LMP_COMPUTE_REAXFF_BONDS_H +#ifndef LMP_COMPUTE_REAXFF_ATOM_H +#define LMP_COMPUTE_REAXFF_ATOM_H #include "compute.h" namespace LAMMPS_NS { -class ComputeReaxFFBonds : public Compute { +class ComputeReaxFFAtom : public Compute { public: - ComputeReaxFFBonds(class LAMMPS *, int, char **); - ~ComputeReaxFFBonds() override; + ComputeReaxFFAtom(class LAMMPS *, int, char **); + ~ComputeReaxFFAtom() override; void init() override; void compute_local() override; void compute_peratom() override; @@ -43,6 +43,7 @@ class ComputeReaxFFBonds : public Compute { int nlocal; int nbonds; int prev_nbonds; + bool store_bonds; tagint **neighid; double **abo;