Merge pull request #3659 from stanmoore1/kk_deform_rigid

Allow `fix deform/kk` to use rigid bodies, fix logic issues with Kokkos neigh list
This commit is contained in:
Axel Kohlmeyer
2023-03-02 19:04:13 -05:00
committed by GitHub
3 changed files with 92 additions and 97 deletions

View File

@ -315,14 +315,13 @@ void FixDeformKokkos::end_of_step()
int nlocal = atom->nlocal; int nlocal = atom->nlocal;
domainKK->x2lamda(nlocal); domainKK->x2lamda(nlocal);
//for (i = 0; i < nlocal; i++)
// if (mask[i] & groupbit)
// domain->x2lamda(x[i],x[i]);
if (rfix.size() > 0) if (rfix.size() > 0) {
error->all(FLERR,"Cannot (yet) use rigid bodies with fix deform and Kokkos"); atomKK->sync(Host,ALL_MASK);
//for (i = 0; i < nrigid; i++) for (auto &ifix : rfix)
// modify->fix[rfix[i]]->deform(0); ifix->deform(0);
atomKK->modified(Host,ALL_MASK);
}
} }
// reset global and local box to new size/shape // reset global and local box to new size/shape
@ -355,13 +354,13 @@ void FixDeformKokkos::end_of_step()
int nlocal = atom->nlocal; int nlocal = atom->nlocal;
domainKK->lamda2x(nlocal); domainKK->lamda2x(nlocal);
//for (i = 0; i < nlocal; i++)
// if (mask[i] & groupbit)
// domain->lamda2x(x[i],x[i]);
//if (nrigid) if (rfix.size() > 0) {
// for (i = 0; i < nrigid; i++) atomKK->sync(Host,ALL_MASK);
// modify->fix[rfix[i]]->deform(1); for (auto &ifix : rfix)
ifix->deform(1);
atomKK->modified(Host,ALL_MASK);
}
} }
// redo KSpace coeffs since box has changed // redo KSpace coeffs since box has changed

View File

@ -243,6 +243,8 @@ void NPairKokkos<DeviceType,HALF,NEWTON,GHOST,TRI,SIZE>::build(NeighList *list_)
#endif #endif
if (GHOST) { if (GHOST) {
// assumes newton off
NPairKokkosBuildFunctorGhost<DeviceType,HALF> f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); NPairKokkosBuildFunctorGhost<DeviceType,HALF> f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor);
#ifdef LMP_KOKKOS_GPU #ifdef LMP_KOKKOS_GPU
if (ExecutionSpaceFromDevice<DeviceType>::space == Device) { if (ExecutionSpaceFromDevice<DeviceType>::space == Device) {
@ -262,7 +264,7 @@ void NPairKokkos<DeviceType,HALF,NEWTON,GHOST,TRI,SIZE>::build(NeighList *list_)
#endif #endif
} else { } else {
if (SIZE) { if (SIZE) {
NPairKokkosBuildFunctorSize<DeviceType,TRI?0:HALF,NEWTON,TRI> f(data,atoms_per_bin * 6 * sizeof(X_FLOAT) * factor); NPairKokkosBuildFunctorSize<DeviceType,HALF,NEWTON,TRI> f(data,atoms_per_bin * 6 * sizeof(X_FLOAT) * factor);
#ifdef LMP_KOKKOS_GPU #ifdef LMP_KOKKOS_GPU
if (ExecutionSpaceFromDevice<DeviceType>::space == Device) { if (ExecutionSpaceFromDevice<DeviceType>::space == Device) {
int team_size = atoms_per_bin*factor; int team_size = atoms_per_bin*factor;
@ -280,7 +282,7 @@ void NPairKokkos<DeviceType,HALF,NEWTON,GHOST,TRI,SIZE>::build(NeighList *list_)
Kokkos::parallel_for(nall, f); Kokkos::parallel_for(nall, f);
#endif #endif
} else { } else {
NPairKokkosBuildFunctor<DeviceType,TRI?0:HALF,NEWTON,TRI> f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor); NPairKokkosBuildFunctor<DeviceType,HALF,NEWTON,TRI> f(data,atoms_per_bin * 5 * sizeof(X_FLOAT) * factor);
#ifdef LMP_KOKKOS_GPU #ifdef LMP_KOKKOS_GPU
if (ExecutionSpaceFromDevice<DeviceType>::space == Device) { if (ExecutionSpaceFromDevice<DeviceType>::space == Device) {
int team_size = atoms_per_bin*factor; int team_size = atoms_per_bin*factor;
@ -402,7 +404,6 @@ KOKKOS_FUNCTION
void NeighborKokkosExecute<DeviceType>:: void NeighborKokkosExecute<DeviceType>::
build_Item(const int &i) const build_Item(const int &i) const
{ {
/* if necessary, goto next page and add pages */
int n = 0; int n = 0;
int which = 0; int which = 0;
int moltemplate; int moltemplate;
@ -422,24 +423,31 @@ void NeighborKokkosExecute<DeviceType>::
const typename ArrayTypes<DeviceType>::t_int_1d_const_um stencil const typename ArrayTypes<DeviceType>::t_int_1d_const_um stencil
= d_stencil; = d_stencil;
// loop over all bins in neighborhood (includes ibin) // loop over rest of atoms in i's bin, ghosts are at end of linked list
if (HalfNeigh) // if j is owned atom, store it, since j is beyond i in linked list
// if j is ghost, only store if j coords are "above and to the right" of i
if (HalfNeigh && Newton && !Tri)
for (int m = 0; m < c_bincount(ibin); m++) { for (int m = 0; m < c_bincount(ibin); m++) {
const int j = c_bins(ibin,m); const int j = c_bins(ibin,m);
const int jtype = type(j);
//for same bin as atom i skip j if i==j and skip atoms "below and to the left" if using HalfNeighborlists if (j <= i) continue;
if ((j == i) || (HalfNeigh && !Newton && (j < i)) || if (j >= nlocal) {
(HalfNeigh && Newton && ((j < i) || ((j >= nlocal) && if (x(j,2) < ztmp) continue;
((x(j, 2) < ztmp) || (x(j, 2) == ztmp && x(j, 1) < ytmp) || if (x(j,2) == ztmp) {
(x(j, 2) == ztmp && x(j, 1) == ytmp && x(j, 0) < xtmp))))) if (x(j,1) < ytmp) continue;
) continue; if (x(j,1) == ytmp && x(j,0) < xtmp) continue;
}
}
const int jtype = type(j);
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - x(j, 0); const X_FLOAT delx = xtmp - x(j, 0);
const X_FLOAT dely = ytmp - x(j, 1); const X_FLOAT dely = ytmp - x(j, 1);
const X_FLOAT delz = ztmp - x(j, 2); const X_FLOAT delz = ztmp - x(j, 2);
const X_FLOAT rsq = delx*delx + dely*dely + delz*delz; const X_FLOAT rsq = delx*delx + dely*dely + delz*delz;
if (rsq <= cutneighsq(itype,jtype)) { if (rsq <= cutneighsq(itype,jtype)) {
if (molecular != Atom::ATOMIC) { if (molecular != Atom::ATOMIC) {
if (!moltemplate) if (!moltemplate)
@ -470,17 +478,16 @@ void NeighborKokkosExecute<DeviceType>::
for (int k = 0; k < nstencil; k++) { for (int k = 0; k < nstencil; k++) {
const int jbin = ibin + stencil[k]; const int jbin = ibin + stencil[k];
if (HalfNeigh && Newton && !Tri && (ibin == jbin)) continue;
// get subview of jbin // get subview of jbin
if (HalfNeigh && (ibin==jbin)) continue;
//const ArrayTypes<DeviceType>::t_int_1d_const_um =Kokkos::subview<t_int_1d_const_um>(bins,jbin,ALL); //const ArrayTypes<DeviceType>::t_int_1d_const_um =Kokkos::subview<t_int_1d_const_um>(bins,jbin,ALL);
for (int m = 0; m < c_bincount(jbin); m++) { for (int m = 0; m < c_bincount(jbin); m++) {
const int j = c_bins(jbin,m); const int j = c_bins(jbin,m);
const int jtype = type(j);
if (HalfNeigh && !Newton && (j < i)) continue; if (HalfNeigh && !Newton && j <= i) continue;
if (!HalfNeigh && j == i) continue; if (!HalfNeigh && j == i) continue;
if (Tri) { if (HalfNeigh && Newton && Tri) {
if (x(j,2) < ztmp) continue; if (x(j,2) < ztmp) continue;
if (x(j,2) == ztmp) { if (x(j,2) == ztmp) {
if (x(j,1) < ytmp) continue; if (x(j,1) < ytmp) continue;
@ -490,6 +497,8 @@ void NeighborKokkosExecute<DeviceType>::
} }
} }
} }
const int jtype = type(j);
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - x(j, 0); const X_FLOAT delx = xtmp - x(j, 0);
@ -522,7 +531,6 @@ void NeighborKokkosExecute<DeviceType>::
else n++; else n++;
} }
} }
} }
} }
@ -617,31 +625,28 @@ void NeighborKokkosExecute<DeviceType>::build_ItemGPU(typename Kokkos::TeamPolic
dev.team_barrier(); dev.team_barrier();
#endif #endif
// loop over rest of atoms in i's bin, ghosts are at end of linked list
// if j is owned atom, store it, since j is beyond i in linked list
// if j is ghost, only store if j coords are "above and to the right" of i
if (HalfNeigh && Newton && !Tri)
if (i >= 0 && i < nlocal) { if (i >= 0 && i < nlocal) {
#pragma unroll 4 #pragma unroll 4
for (int m = 0; m < bincount_current; m++) { for (int m = 0; m < bincount_current; m++) {
int j = other_id[m]; int j = other_id[m];
const int jtype = other_x[m + 3 * atoms_per_bin];
//for same bin as atom i skip j if i==j and skip atoms "below and to the left" if using halfneighborlists if (j <= i) continue;
if ((j == i) || if (j >= nlocal) {
(HalfNeigh && !Newton && (j < i)) ||
(HalfNeigh && Newton &&
((j < i) ||
((j >= nlocal) && ((x(j, 2) < ztmp) || (x(j, 2) == ztmp && x(j, 1) < ytmp) ||
(x(j, 2) == ztmp && x(j, 1) == ytmp && x(j, 0) < xtmp)))))
) continue;
if (Tri) {
if (x(j,2) < ztmp) continue; if (x(j,2) < ztmp) continue;
if (x(j,2) == ztmp) { if (x(j,2) == ztmp) {
if (x(j,1) < ytmp) continue; if (x(j,1) < ytmp) continue;
if (x(j,1) == ytmp) { if (x(j,1) == ytmp && x(j,0) < xtmp) continue;
if (x(j,0) < xtmp) continue;
if (x(j,0) == xtmp && j <= i) continue;
}
} }
} }
const int jtype = other_x[m + 3 * atoms_per_bin];
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - other_x[m]; const X_FLOAT delx = xtmp - other_x[m];
const X_FLOAT dely = ytmp - other_x[m + atoms_per_bin]; const X_FLOAT dely = ytmp - other_x[m + atoms_per_bin];
const X_FLOAT delz = ztmp - other_x[m + 2 * atoms_per_bin]; const X_FLOAT delz = ztmp - other_x[m + 2 * atoms_per_bin];
@ -683,7 +688,7 @@ void NeighborKokkosExecute<DeviceType>::build_ItemGPU(typename Kokkos::TeamPolic
for (int k = 0; k < nstencil; k++) { for (int k = 0; k < nstencil; k++) {
const int jbin = ibin + stencil[k]; const int jbin = ibin + stencil[k];
if (ibin == jbin) continue; if (HalfNeigh && Newton && !Tri && (ibin == jbin)) continue;
bincount_current = c_bincount[jbin]; bincount_current = c_bincount[jbin];
int j = MY_II < bincount_current ? c_bins(jbin, MY_II) : -1; int j = MY_II < bincount_current ? c_bins(jbin, MY_II) : -1;
@ -703,12 +708,10 @@ void NeighborKokkosExecute<DeviceType>::build_ItemGPU(typename Kokkos::TeamPolic
#pragma unroll 8 #pragma unroll 8
for (int m = 0; m < bincount_current; m++) { for (int m = 0; m < bincount_current; m++) {
const int j = other_id[m]; const int j = other_id[m];
const int jtype = other_x[m + 3 * atoms_per_bin];
//if(HalfNeigh && (j < i)) continue; if (HalfNeigh && !Newton && j <= i) continue;
if (HalfNeigh && !Newton && (j < i)) continue;
if (!HalfNeigh && j == i) continue; if (!HalfNeigh && j == i) continue;
if (Tri) { if (HalfNeigh && Newton && Tri) {
if (x(j,2) < ztmp) continue; if (x(j,2) < ztmp) continue;
if (x(j,2) == ztmp) { if (x(j,2) == ztmp) {
if (x(j,1) < ytmp) continue; if (x(j,1) < ytmp) continue;
@ -718,6 +721,8 @@ void NeighborKokkosExecute<DeviceType>::build_ItemGPU(typename Kokkos::TeamPolic
} }
} }
} }
const int jtype = other_x[m + 3 * atoms_per_bin];
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - other_x[m]; const X_FLOAT delx = xtmp - other_x[m];
@ -1091,17 +1096,24 @@ void NeighborKokkosExecute<DeviceType>::
const int mask_history = 3 << SBBITS; const int mask_history = 3 << SBBITS;
// loop over all bins in neighborhood (includes ibin) // loop over all bins in neighborhood (includes ibin)
if (HalfNeigh) // loop over rest of atoms in i's bin, ghosts are at end of linked list
// if j is owned atom, store it, since j is beyond i in linked list
// if j is ghost, only store if j coords are "above and to the right" of i
if (HalfNeigh && Newton && !Tri)
for (int m = 0; m < c_bincount(ibin); m++) { for (int m = 0; m < c_bincount(ibin); m++) {
const int j = c_bins(ibin,m); const int j = c_bins(ibin,m);
const int jtype = type(j);
//for same bin as atom i skip j if i==j and skip atoms "below and to the left" if using HalfNeighborlists if (j <= i) continue;
if ((j == i) || (HalfNeigh && !Newton && (j < i)) || if (j >= nlocal) {
(HalfNeigh && Newton && ((j < i) || ((j >= nlocal) && if (x(j,2) < ztmp) continue;
((x(j, 2) < ztmp) || (x(j, 2) == ztmp && x(j, 1) < ytmp) || if (x(j,2) == ztmp) {
(x(j, 2) == ztmp && x(j, 1) == ytmp && x(j, 0) < xtmp))))) if (x(j,1) < ytmp) continue;
) continue; if (x(j,1) == ytmp && x(j,0) < xtmp) continue;
}
}
const int jtype = type(j);
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - x(j, 0); const X_FLOAT delx = xtmp - x(j, 0);
@ -1123,17 +1135,16 @@ void NeighborKokkosExecute<DeviceType>::
for (int k = 0; k < nstencil; k++) { for (int k = 0; k < nstencil; k++) {
const int jbin = ibin + stencil[k]; const int jbin = ibin + stencil[k];
if (HalfNeigh && Newton && !Tri && (ibin == jbin)) continue;
// get subview of jbin // get subview of jbin
if (HalfNeigh && (ibin==jbin)) continue;
//const ArrayTypes<DeviceType>::t_int_1d_const_um =Kokkos::subview<t_int_1d_const_um>(bins,jbin,ALL); //const ArrayTypes<DeviceType>::t_int_1d_const_um =Kokkos::subview<t_int_1d_const_um>(bins,jbin,ALL);
for (int m = 0; m < c_bincount(jbin); m++) { for (int m = 0; m < c_bincount(jbin); m++) {
const int j = c_bins(jbin,m); const int j = c_bins(jbin,m);
const int jtype = type(j);
if (HalfNeigh && !Newton && (j < i)) continue; if (HalfNeigh && !Newton && j <= i) continue;
if (!HalfNeigh && j == i) continue; if (!HalfNeigh && j == i) continue;
if (Tri) { if (HalfNeigh && Newton && Tri) {
if (x(j,2) < ztmp) continue; if (x(j,2) < ztmp) continue;
if (x(j,2) == ztmp) { if (x(j,2) == ztmp) {
if (x(j,1) < ytmp) continue; if (x(j,1) < ytmp) continue;
@ -1143,6 +1154,8 @@ void NeighborKokkosExecute<DeviceType>::
} }
} }
} }
const int jtype = type(j);
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - x(j, 0); const X_FLOAT delx = xtmp - x(j, 0);
@ -1239,30 +1252,22 @@ void NeighborKokkosExecute<DeviceType>::build_ItemSizeGPU(typename Kokkos::TeamP
dev.team_barrier(); dev.team_barrier();
#endif #endif
if (HalfNeigh && Newton && !Tri)
if (i >= 0 && i < nlocal) { if (i >= 0 && i < nlocal) {
#pragma unroll 4 #pragma unroll 4
for (int m = 0; m < bincount_current; m++) { for (int m = 0; m < bincount_current; m++) {
int j = other_id[m]; int j = other_id[m];
const int jtype = other_x[m + 3 * atoms_per_bin];
//for same bin as atom i skip j if i==j and skip atoms "below and to the left" if using halfneighborlists if (j <= i) continue;
if ((j == i) || if (j >= nlocal) {
(HalfNeigh && !Newton && (j < i)) ||
(HalfNeigh && Newton &&
((j < i) ||
((j >= nlocal) && ((x(j, 2) < ztmp) || (x(j, 2) == ztmp && x(j, 1) < ytmp) ||
(x(j, 2) == ztmp && x(j, 1) == ytmp && x(j, 0) < xtmp)))))
) continue;
if (Tri) {
if (x(j,2) < ztmp) continue; if (x(j,2) < ztmp) continue;
if (x(j,2) == ztmp) { if (x(j,2) == ztmp) {
if (x(j,1) < ytmp) continue; if (x(j,1) < ytmp) continue;
if (x(j,1) == ytmp) { if (x(j,1) == ytmp && x(j,0) < xtmp) continue;
if (x(j,0) < xtmp) continue;
if (x(j,0) == xtmp && j <= i) continue;
}
} }
} }
const int jtype = other_x[m + 3 * atoms_per_bin];
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - other_x[m]; const X_FLOAT delx = xtmp - other_x[m];
const X_FLOAT dely = ytmp - other_x[m + atoms_per_bin]; const X_FLOAT dely = ytmp - other_x[m + atoms_per_bin];
@ -1288,6 +1293,7 @@ void NeighborKokkosExecute<DeviceType>::build_ItemSizeGPU(typename Kokkos::TeamP
const int jbin = ibin + stencil[k]; const int jbin = ibin + stencil[k];
if (ibin == jbin) continue; if (ibin == jbin) continue;
if (HalfNeigh && Newton && !Tri && (ibin == jbin)) continue;
bincount_current = c_bincount[jbin]; bincount_current = c_bincount[jbin];
int j = MY_II < bincount_current ? c_bins(jbin, MY_II) : -1; int j = MY_II < bincount_current ? c_bins(jbin, MY_II) : -1;
@ -1308,12 +1314,10 @@ void NeighborKokkosExecute<DeviceType>::build_ItemSizeGPU(typename Kokkos::TeamP
#pragma unroll 8 #pragma unroll 8
for (int m = 0; m < bincount_current; m++) { for (int m = 0; m < bincount_current; m++) {
const int j = other_id[m]; const int j = other_id[m];
const int jtype = other_x[m + 3 * atoms_per_bin];
if (HalfNeigh && (j < i)) continue; if (HalfNeigh && !Newton && j <= i) continue;
if (HalfNeigh && !Newton && (j < i)) continue;
if (!HalfNeigh && j == i) continue; if (!HalfNeigh && j == i) continue;
if (Tri) { if (HalfNeigh && Newton && Tri) {
if (x(j,2) < ztmp) continue; if (x(j,2) < ztmp) continue;
if (x(j,2) == ztmp) { if (x(j,2) == ztmp) {
if (x(j,1) < ytmp) continue; if (x(j,1) < ytmp) continue;
@ -1323,6 +1327,8 @@ void NeighborKokkosExecute<DeviceType>::build_ItemSizeGPU(typename Kokkos::TeamP
} }
} }
} }
const int jtype = other_x[m + 3 * atoms_per_bin];
if (exclude && exclusion(i,j,itype,jtype)) continue; if (exclude && exclusion(i,j,itype,jtype)) continue;
const X_FLOAT delx = xtmp - other_x[m]; const X_FLOAT delx = xtmp - other_x[m];

View File

@ -73,21 +73,11 @@ NPairStyle(half/bin/newtoff/kk/device,
NPairKokkosHalfBinNewtoffTriDevice, NPairKokkosHalfBinNewtoffTriDevice,
NP_KOKKOS_DEVICE | NP_HALF | NP_BIN | NP_NEWTOFF | NP_TRI); NP_KOKKOS_DEVICE | NP_HALF | NP_BIN | NP_NEWTOFF | NP_TRI);
typedef NPairKokkos<LMPHostType,1,1,1,0,0> NPairKokkosHalfBinNewtonGhostHost;
NPairStyle(half/bin/newton/ghost/kk/host,
NPairKokkosHalfBinNewtonGhostHost,
NP_BIN | NP_KOKKOS_HOST | NP_HALF | NP_NEWTON | NP_GHOST | NP_ORTHO | NP_TRI);
typedef NPairKokkos<LMPHostType,1,0,1,0,0> NPairKokkosHalfBinNewtoffGhostHost; typedef NPairKokkos<LMPHostType,1,0,1,0,0> NPairKokkosHalfBinNewtoffGhostHost;
NPairStyle(half/bin/newtoff/ghost/kk/host, NPairStyle(half/bin/newtoff/ghost/kk/host,
NPairKokkosHalfBinNewtoffGhostHost, NPairKokkosHalfBinNewtoffGhostHost,
NP_BIN | NP_KOKKOS_HOST | NP_HALF | NP_NEWTOFF | NP_GHOST | NP_ORTHO | NP_TRI); NP_BIN | NP_KOKKOS_HOST | NP_HALF | NP_NEWTOFF | NP_GHOST | NP_ORTHO | NP_TRI);
typedef NPairKokkos<LMPDeviceType,1,1,1,0,0> NPairKokkosHalfBinNewtonGhostDevice;
NPairStyle(half/bin/newton/ghost/kk/device,
NPairKokkosHalfBinNewtonGhostDevice,
NP_KOKKOS_DEVICE | NP_HALF | NP_BIN | NP_NEWTON | NP_GHOST | NP_ORTHO | NP_TRI);
typedef NPairKokkos<LMPDeviceType,1,0,1,0,0> NPairKokkosHalfBinNewtoffGhostDevice; typedef NPairKokkos<LMPDeviceType,1,0,1,0,0> NPairKokkosHalfBinNewtoffGhostDevice;
NPairStyle(half/bin/newtoff/ghost/kk/device, NPairStyle(half/bin/newtoff/ghost/kk/device,
NPairKokkosHalfBinNewtoffGhostDevice, NPairKokkosHalfBinNewtoffGhostDevice,