Rename compute to reaxff/atom

This commit is contained in:
Richard Berger 2023-11-20 15:36:46 -07:00
parent afd0107f01
commit 16f0806da0
8 changed files with 108 additions and 77 deletions

View File

@ -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

View File

@ -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

View File

@ -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<class DeviceType>
ComputeReaxFFBondsKokkos<DeviceType>::ComputeReaxFFBondsKokkos(LAMMPS *lmp, int narg, char **arg) :
ComputeReaxFFBonds(lmp, narg, arg),
ComputeReaxFFAtomKokkos<DeviceType>::ComputeReaxFFAtomKokkos(LAMMPS *lmp, int narg, char **arg) :
ComputeReaxFFAtom(lmp, narg, arg),
nbuf(-1), buf(nullptr)
{
kokkosable = 1;
@ -46,7 +46,7 @@ ComputeReaxFFBondsKokkos<DeviceType>::ComputeReaxFFBondsKokkos(LAMMPS *lmp, int
/* ---------------------------------------------------------------------- */
template<class DeviceType>
ComputeReaxFFBondsKokkos<DeviceType>::~ComputeReaxFFBondsKokkos()
ComputeReaxFFAtomKokkos<DeviceType>::~ComputeReaxFFAtomKokkos()
{
memoryKK->destroy_kokkos(k_buf, buf);
}
@ -54,21 +54,21 @@ ComputeReaxFFBondsKokkos<DeviceType>::~ComputeReaxFFBondsKokkos()
/* ---------------------------------------------------------------------- */
template<class DeviceType>
void ComputeReaxFFBondsKokkos<DeviceType>::init()
void ComputeReaxFFAtomKokkos<DeviceType>::init()
{
reaxff = dynamic_cast<PairReaxFF*>(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<class DeviceType>
void ComputeReaxFFBondsKokkos<DeviceType>::compute_bonds()
void ComputeReaxFFAtomKokkos<DeviceType>::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<DeviceType>::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<DeviceType>::compute_bonds()
for (int i = 0; i < nlocal; i++) {
int numbonds = static_cast<int>(buf[j+2]);
nbonds += numbonds;
j += 2*numbonds + 3;
j += (store_bonds ? 2*numbonds : 0) + 3;
}
}
/* ---------------------------------------------------------------------- */
template<class DeviceType>
void ComputeReaxFFBondsKokkos<DeviceType>::compute_local()
void ComputeReaxFFAtomKokkos<DeviceType>::compute_local()
{
invoked_local = update->ntimestep;
@ -122,7 +122,7 @@ void ComputeReaxFFBondsKokkos<DeviceType>::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<DeviceType>::compute_local()
/* ---------------------------------------------------------------------- */
template<class DeviceType>
void ComputeReaxFFBondsKokkos<DeviceType>::compute_peratom()
void ComputeReaxFFAtomKokkos<DeviceType>::compute_peratom()
{
invoked_peratom = update->ntimestep;
@ -166,7 +166,7 @@ void ComputeReaxFFBondsKokkos<DeviceType>::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<DeviceType>::compute_peratom()
------------------------------------------------------------------------- */
template<class DeviceType>
double ComputeReaxFFBondsKokkos<DeviceType>::memory_usage()
double ComputeReaxFFAtomKokkos<DeviceType>::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<LMPDeviceType>;
template class ComputeReaxFFAtomKokkos<LMPDeviceType>;
#ifdef LMP_KOKKOS_GPU
template class ComputeReaxFFBondsKokkos<LMPHostType>;
template class ComputeReaxFFAtomKokkos<LMPHostType>;
#endif
}

View File

@ -17,29 +17,29 @@
#ifdef COMPUTE_CLASS
// clang-format off
ComputeStyle(reaxff/bonds/kk,ComputeReaxFFBondsKokkos<LMPDeviceType>);
ComputeStyle(reaxff/bonds/kk/device,ComputeReaxFFBondsKokkos<LMPDeviceType>);
ComputeStyle(reaxff/bonds/kk/host,ComputeReaxFFBondsKokkos<LMPHostType>);
ComputeStyle(reaxff/atom/kk,ComputeReaxFFAtomKokkos<LMPDeviceType>);
ComputeStyle(reaxff/atom/kk/device,ComputeReaxFFAtomKokkos<LMPDeviceType>);
ComputeStyle(reaxff/atom/kk/host,ComputeReaxFFAtomKokkos<LMPHostType>);
// 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 DeviceType>
class ComputeReaxFFBondsKokkos : public ComputeReaxFFBonds {
class ComputeReaxFFAtomKokkos : public ComputeReaxFFAtom {
public:
using device_type = DeviceType;
using AT = ArrayTypes<DeviceType>;
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;

View File

@ -4250,15 +4250,21 @@ void PairReaxFFKokkos<DeviceType>::PackBondBuffer(DAT::tdual_ffloat_1d k_buf, in
/* ---------------------------------------------------------------------- */
template<class DeviceType>
void PairReaxFFKokkos<DeviceType>::PackReducedBondBuffer(DAT::tdual_ffloat_1d k_buf, int &nbuf_local)
void PairReaxFFKokkos<DeviceType>::PackReducedBondBuffer(DAT::tdual_ffloat_1d k_buf, int &nbuf_local, bool store_bonds)
{
d_buf = k_buf.view<DeviceType>();
k_params_sing.template sync<DeviceType>();
copymode = 1;
nlocal = atomKK->nlocal;
PairReaxKokkosPackReducedBondBufferFunctor<DeviceType> pack_bond_buffer_functor(this);
Kokkos::parallel_scan(nlocal,pack_bond_buffer_functor);
if(store_bonds) {
PairReaxKokkosPackReducedBondBufferFunctor<DeviceType, true> pack_bond_buffer_functor(this);
Kokkos::parallel_scan(nlocal,pack_bond_buffer_functor);
} else {
PairReaxKokkosPackReducedBondBufferFunctor<DeviceType, false> pack_bond_buffer_functor(this);
Kokkos::parallel_scan(nlocal,pack_bond_buffer_functor);
}
copymode = 0;
k_buf.modify<DeviceType>();
@ -4313,6 +4319,7 @@ void PairReaxFFKokkos<DeviceType>::pack_bond_buffer_item(int i, int &j, const bo
}
template<class DeviceType>
template<bool STORE_BONDS>
KOKKOS_INLINE_FUNCTION
void PairReaxFFKokkos<DeviceType>::pack_reduced_bond_buffer_item(int i, int &j, const bool &final) const
{
@ -4325,21 +4332,23 @@ void PairReaxFFKokkos<DeviceType>::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<DeviceType>()() = j - 1;

View File

@ -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<int NEIGHFLAG>
@ -293,6 +293,7 @@ class PairReaxFFKokkos : public PairReaxFF {
KOKKOS_INLINE_FUNCTION
void pack_bond_buffer_item(int, int&, const bool&) const;
template<bool STORE_BONDS>
KOKKOS_INLINE_FUNCTION
void pack_reduced_bond_buffer_item(int, int&, const bool&) const;
@ -553,7 +554,7 @@ struct PairReaxKokkosPackBondBufferFunctor {
}
};
template <class DeviceType>
template <class DeviceType, bool STORE_BONDS>
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<STORE_BONDS>(ii,j,final);
}
};

View File

@ -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) {
if (strcmp(arg[iarg], "bonds") == 0) {
if (iarg+2 > 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<PairReaxFF *>(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;
}

View File

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