diff --git a/examples/reaxff/in.reaxff.tatb b/examples/reaxff/in.reaxff.tatb index f422943a13..50f572a994 100644 --- a/examples/reaxff/in.reaxff.tatb +++ b/examples/reaxff/in.reaxff.tatb @@ -38,7 +38,7 @@ variable nqeq equal f_2 dump 1 all local 5 bonds_local.reaxff c_bonds[1] c_bonds[2] c_bonds[3] # dumps out the peratom bond information -dump 2 all custom 5 bonds_atom.reaxff c_bonds[*] +dump 2 all custom 5 bonds_atom.reaxff id type q c_bonds[*] thermo 5 thermo_style custom step temp epair etotal press & diff --git a/src/KOKKOS/compute_reaxff_bonds_kokkos.cpp b/src/KOKKOS/compute_reaxff_bonds_kokkos.cpp index 5c8885ce7a..f36832e6ac 100644 --- a/src/KOKKOS/compute_reaxff_bonds_kokkos.cpp +++ b/src/KOKKOS/compute_reaxff_bonds_kokkos.cpp @@ -68,7 +68,7 @@ void ComputeReaxFFBondsKokkos::compute_bonds() if (atom->nlocal > nlocal) { memory->destroy(array_atom); nlocal = atom->nlocal; - memory->create(array_atom, nlocal, 7, "reaxff/bonds:array_atom"); + memory->create(array_atom, nlocal, 3, "reaxff/bonds:array_atom"); } // retrieve bond information from kokkos pair style. the data potentially @@ -76,13 +76,14 @@ void ComputeReaxFFBondsKokkos::compute_bonds() // compute_local and compute_atom then expand the data from this buffer into // appropiate arrays for consumption by others (e.g. dump local, dump custom // or library interface) + int maxnumbonds = 0; if (reaxff->execution_space == Device) device_pair()->FindBond(maxnumbonds); else host_pair()->FindBond(maxnumbonds); - nbuf = 1+(maxnumbonds*2 + 7)*nlocal; + nbuf = (maxnumbonds*2 + 3)*nlocal; if(!buf || k_buf.extent(0) < nbuf) { memoryKK->destroy_kokkos(k_buf, buf); @@ -90,20 +91,21 @@ void ComputeReaxFFBondsKokkos::compute_bonds() } // Pass information to buffer, will sync to host + int nbuf_local; if (reaxff->execution_space == Device) - device_pair()->PackBondBuffer(k_buf, nbuf_local); + device_pair()->PackReducedBondBuffer(k_buf, nbuf_local); else - host_pair()->PackBondBuffer(k_buf, nbuf_local); - buf[0] = nlocal; + host_pair()->PackReducedBondBuffer(k_buf, nbuf_local); // Extract number of bonds from buffer + nbonds = 0; - int j = 1; + int j = 0; for (int i = 0; i < nlocal; i++) { - int numbonds = static_cast(buf[j+5]); + int numbonds = static_cast(buf[j+2]); nbonds += numbonds; - j += 2*numbonds + 7; + j += 2*numbonds + 3; } } @@ -127,20 +129,21 @@ void ComputeReaxFFBondsKokkos::compute_local() size_local_rows = nbonds; // extract local bond information from buffer + int b = 0; - int j = 1; + int j = 0; for (int i = 0; i < nlocal; ++i) { - const int numbonds = static_cast(buf[j+5]); - const int neigh_offset = j + 6; - const int bo_offset = neigh_offset + numbonds + 1; + const int numbonds = static_cast(buf[j+2]); + const int neigh_offset = j + 3; + const int bo_offset = neigh_offset + numbonds; for (int k = 0; k < numbonds; k++) { auto bond = array_local[b++]; bond[0] = i; bond[1] = static_cast (buf[neigh_offset+k]); bond[2] = buf[bo_offset+k]; } - j += 2*numbonds + 7; + j += 2*numbonds + 3; } } @@ -155,19 +158,15 @@ void ComputeReaxFFBondsKokkos::compute_peratom() compute_bonds(); // extract peratom bond information from buffer - int j = 1; + + int j = 0; for (int i = 0; i < nlocal; ++i) { auto ptr = array_atom[i]; - int numbonds = static_cast(buf[j+5]); - const int mol_offset = j + 6 + numbonds; - ptr[0] = buf[j]; // jtag - ptr[1] = buf[j+1]; // itype + int numbonds = static_cast(buf[j+2]); + ptr[0] = buf[j]; // sbo + ptr[1] = buf[j+1]; // nlp ptr[2] = numbonds; - ptr[3] = buf[mol_offset]; // mol - ptr[4] = buf[j+2]; // sbo - ptr[5] = buf[j+3]; // nlp - ptr[6] = buf[j+4]; // q - j += 2*numbonds + 7; + j += 2*numbonds + 3; } } @@ -179,7 +178,7 @@ template double ComputeReaxFFBondsKokkos::memory_usage() { double bytes = (double)(nbonds*3) * sizeof(double); - bytes += (double)(nlocal*7) * sizeof(double); + bytes += (double)(nlocal*3) * sizeof(double); return bytes; } diff --git a/src/KOKKOS/compute_reaxff_bonds_kokkos.h b/src/KOKKOS/compute_reaxff_bonds_kokkos.h index 45020ffa81..48f3860283 100644 --- a/src/KOKKOS/compute_reaxff_bonds_kokkos.h +++ b/src/KOKKOS/compute_reaxff_bonds_kokkos.h @@ -52,11 +52,11 @@ class ComputeReaxFFBondsKokkos : public ComputeReaxFFBonds { typename AT::tdual_float_1d k_buf; auto device_pair() { - return dynamic_cast*>(reaxff); + return static_cast*>(reaxff); } auto host_pair() { - return dynamic_cast*>(reaxff); + return static_cast*>(reaxff); } }; diff --git a/src/KOKKOS/pair_reaxff_kokkos.cpp b/src/KOKKOS/pair_reaxff_kokkos.cpp index c7d54b80cd..e298eca2da 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.cpp +++ b/src/KOKKOS/pair_reaxff_kokkos.cpp @@ -4247,6 +4247,30 @@ void PairReaxFFKokkos::PackBondBuffer(DAT::tdual_ffloat_1d k_buf, in nbuf_local = k_nbuf_local.h_view(); } +/* ---------------------------------------------------------------------- */ + +template +void PairReaxFFKokkos::PackReducedBondBuffer(DAT::tdual_ffloat_1d k_buf, int &nbuf_local) +{ + 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); + copymode = 0; + + k_buf.modify(); + k_nbuf_local.modify(); + + k_buf.sync(); + k_nbuf_local.sync(); + nbuf_local = k_nbuf_local.h_view(); +} + +/* ---------------------------------------------------------------------- */ + template KOKKOS_INLINE_FUNCTION void PairReaxFFKokkos::pack_bond_buffer_item(int i, int &j, const bool &final) const @@ -4288,6 +4312,39 @@ void PairReaxFFKokkos::pack_bond_buffer_item(int i, int &j, const bo k_nbuf_local.view()() = j - 1; } +template +KOKKOS_INLINE_FUNCTION +void PairReaxFFKokkos::pack_reduced_bond_buffer_item(int i, int &j, const bool &final) const +{ + const int numbonds = d_numneigh_bonds[i]; + if (final) { + d_buf[j] = d_total_bo[i]; + d_buf[j+1] = paramssing(type[i]).nlp_opt - d_Delta_lp[i]; + d_buf[j+2] = numbonds; + } + + j += 3; + + if (final) { + for (int k = 0; k < numbonds; ++k) { + d_buf[j+k] = d_neighid(i,k); + } + } + + j += numbonds; + + if (final) { + for (int k = 0; k < numbonds; k++) { + d_buf[j+k] = d_abo(i,k); + } + } + + j += numbonds; + + if (final && i == nlocal-1) + k_nbuf_local.view()() = j - 1; +} + /* ---------------------------------------------------------------------- */ template diff --git a/src/KOKKOS/pair_reaxff_kokkos.h b/src/KOKKOS/pair_reaxff_kokkos.h index 1ad0955a1e..571dd63fd1 100644 --- a/src/KOKKOS/pair_reaxff_kokkos.h +++ b/src/KOKKOS/pair_reaxff_kokkos.h @@ -135,6 +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 FindBondSpecies(); template @@ -292,6 +293,9 @@ class PairReaxFFKokkos : public PairReaxFF { KOKKOS_INLINE_FUNCTION void pack_bond_buffer_item(int, int&, const bool&) const; + KOKKOS_INLINE_FUNCTION + void pack_reduced_bond_buffer_item(int, int&, const bool&) const; + KOKKOS_INLINE_FUNCTION void operator()(TagPairReaxFindBondSpeciesZero, const int&) const; @@ -549,6 +553,19 @@ struct PairReaxKokkosPackBondBufferFunctor { } }; +template +struct PairReaxKokkosPackReducedBondBufferFunctor { + typedef DeviceType device_type; + typedef int value_type; + PairReaxFFKokkos c; + PairReaxKokkosPackReducedBondBufferFunctor(PairReaxFFKokkos* c_ptr):c(*c_ptr) {}; + + KOKKOS_INLINE_FUNCTION + void operator()(const int ii, int &j, const bool &final) const { + c.pack_reduced_bond_buffer_item(ii,j,final); + } +}; + } #endif diff --git a/src/REAXFF/compute_reaxff_bonds.cpp b/src/REAXFF/compute_reaxff_bonds.cpp index 7f1605263c..3b3520fda3 100644 --- a/src/REAXFF/compute_reaxff_bonds.cpp +++ b/src/REAXFF/compute_reaxff_bonds.cpp @@ -35,7 +35,7 @@ using namespace ReaxFF; ComputeReaxFFBonds::ComputeReaxFFBonds(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), - abo(nullptr), neighid(nullptr), numneigh(nullptr), reaxff(nullptr) + 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"); @@ -48,7 +48,7 @@ ComputeReaxFFBonds::ComputeReaxFFBonds(LAMMPS *lmp, int narg, char **arg) : nlocal = -1; prev_nbonds = -1; - size_peratom_cols = 7; + size_peratom_cols = 3; size_local_rows = 0; size_local_cols = 3; @@ -65,7 +65,7 @@ ComputeReaxFFBonds::~ComputeReaxFFBonds() memory->destroy(array_atom); memory->destroy(abo); memory->destroy(neighid); - memory->destroy(numneigh); + memory->destroy(bondcount); } /* ---------------------------------------------------------------------- */ @@ -110,7 +110,7 @@ int ComputeReaxFFBonds::FindBond() nj++; } } - numneigh[i] = nj; + bondcount[i] = nj; numbonds += nj; } return numbonds; @@ -126,17 +126,17 @@ void ComputeReaxFFBonds::compute_bonds() if (atom->nlocal > nlocal) { memory->destroy(abo); memory->destroy(neighid); - memory->destroy(numneigh); + 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(numneigh, nlocal, "reaxff/bonds:numneigh"); - memory->create(array_atom, nlocal, 7, "reaxff/bonds:array_atom"); + memory->create(bondcount, nlocal, "reaxff/bonds:bondcount"); + memory->create(array_atom, nlocal, 3, "reaxff/bonds:array_atom"); } for (int i = 0; i < nlocal; i++) { - numneigh[i] = 0; + bondcount[i] = 0; for (int j = 0; j < MAXREAXBOND; j++) { neighid[i][j] = 0; abo[i][j] = 0.0; @@ -168,7 +168,7 @@ void ComputeReaxFFBonds::compute_local() int b = 0; for (int i = 0; i < nlocal; ++i) { - const int numbonds = numneigh[i]; + const int numbonds = bondcount[i]; for (int k = 0; k < numbonds; k++) { auto bond = array_local[b++]; @@ -191,13 +191,9 @@ void ComputeReaxFFBonds::compute_peratom() for (int i = 0; i < nlocal; ++i) { auto ptr = array_atom[i]; - ptr[0] = atom->tag[i]; - ptr[1] = atom->type[i]; - ptr[2] = numneigh[i]; - ptr[3] = (atom->molecule == nullptr) ? 0.0 : atom->molecule[i]; - ptr[4] = reaxff->api->workspace->total_bond_order[i]; - ptr[5] = reaxff->api->workspace->nlp[i]; - ptr[6] = atom->q[i]; + ptr[0] = reaxff->api->workspace->total_bond_order[i]; + ptr[1] = reaxff->api->workspace->nlp[i]; + ptr[2] = bondcount[i]; } } @@ -208,7 +204,7 @@ void ComputeReaxFFBonds::compute_peratom() double ComputeReaxFFBonds::memory_usage() { double bytes = (double)(nbonds*3) * sizeof(double); - bytes += (double)(nlocal*7) * sizeof(double); + bytes += (double)(nlocal*3) * sizeof(double); bytes += (double)(2*nlocal*MAXREAXBOND) * sizeof(double); bytes += (double)(nlocal) * sizeof(int); return bytes; diff --git a/src/REAXFF/compute_reaxff_bonds.h b/src/REAXFF/compute_reaxff_bonds.h index 6b00cef7ed..b876c9e02d 100644 --- a/src/REAXFF/compute_reaxff_bonds.h +++ b/src/REAXFF/compute_reaxff_bonds.h @@ -46,7 +46,7 @@ class ComputeReaxFFBonds : public Compute { tagint **neighid; double **abo; - int *numneigh; + int *bondcount; class PairReaxFF *reaxff; private: