diff --git a/src/DPD-REACT/atom_vec_dpd.h b/src/DPD-REACT/atom_vec_dpd.h index 32bf9a25a8..2a45ad6997 100644 --- a/src/DPD-REACT/atom_vec_dpd.h +++ b/src/DPD-REACT/atom_vec_dpd.h @@ -24,7 +24,7 @@ AtomStyle(dpd,AtomVecDPD); namespace LAMMPS_NS { -class AtomVecDPD : public AtomVec { +class AtomVecDPD : virtual public AtomVec { public: AtomVecDPD(class LAMMPS *); diff --git a/src/KOKKOS/Install.sh b/src/KOKKOS/Install.sh index 5c46a89e26..b30461d5c6 100755 --- a/src/KOKKOS/Install.sh +++ b/src/KOKKOS/Install.sh @@ -64,8 +64,8 @@ action atom_vec_bond_kokkos.cpp atom_vec_bond.cpp action atom_vec_bond_kokkos.h atom_vec_bond.h action atom_vec_charge_kokkos.cpp action atom_vec_charge_kokkos.h -action atom_vec_spin_kokkos.cpp -action atom_vec_spin_kokkos.h +action atom_vec_spin_kokkos.cpp atom_vec_spin.cpp +action atom_vec_spin_kokkos.h atom_vec_spin.h action atom_vec_dpd_kokkos.cpp atom_vec_dpd.cpp action atom_vec_dpd_kokkos.h atom_vec_dpd.h action atom_vec_full_kokkos.cpp atom_vec_full.cpp diff --git a/src/KOKKOS/atom_kokkos.cpp b/src/KOKKOS/atom_kokkos.cpp index 1984d631c3..2de65e24fb 100644 --- a/src/KOKKOS/atom_kokkos.cpp +++ b/src/KOKKOS/atom_kokkos.cpp @@ -104,23 +104,23 @@ AtomKokkos::~AtomKokkos() void AtomKokkos::sync(const ExecutionSpace space, unsigned int mask) { - if (space == Device && lmp->kokkos->auto_sync) ((AtomVecKokkos *) avec)->modified(Host, mask); + if (space == Device && lmp->kokkos->auto_sync) avecKK->modified(Host, mask); - ((AtomVecKokkos *) avec)->sync(space, mask); + avecKK->sync(space, mask); } /* ---------------------------------------------------------------------- */ void AtomKokkos::modified(const ExecutionSpace space, unsigned int mask) { - ((AtomVecKokkos *) avec)->modified(space, mask); + avecKK->modified(space, mask); - if (space == Device && lmp->kokkos->auto_sync) ((AtomVecKokkos *) avec)->sync(Host, mask); + if (space == Device && lmp->kokkos->auto_sync) avecKK->sync(Host, mask); } void AtomKokkos::sync_overlapping_device(const ExecutionSpace space, unsigned int mask) { - ((AtomVecKokkos *) avec)->sync_overlapping_device(space, mask); + avecKK->sync_overlapping_device(space, mask); } /* ---------------------------------------------------------------------- */ @@ -380,5 +380,8 @@ AtomVec *AtomKokkos::new_avec(const std::string &style, int trysuffix, int &sfla { AtomVec *avec = Atom::new_avec(style, trysuffix, sflag); if (!avec->kokkosable) error->all(FLERR, "KOKKOS package requires a kokkos enabled atom_style"); + + avecKK = dynamic_cast(avec); + return avec; } diff --git a/src/KOKKOS/atom_kokkos.h b/src/KOKKOS/atom_kokkos.h index 8754c9bb51..08bfaf20cd 100644 --- a/src/KOKKOS/atom_kokkos.h +++ b/src/KOKKOS/atom_kokkos.h @@ -78,6 +78,8 @@ class AtomKokkos : public Atom { DAT::tdual_int_scalar k_error_flag; dual_hash_type k_map_hash; + class AtomVecKokkos* avecKK; + // map lookup function inlined for efficiency // return -1 if no map defined diff --git a/src/KOKKOS/atom_vec_angle_kokkos.cpp b/src/KOKKOS/atom_vec_angle_kokkos.cpp index ef020f8f75..23406415d0 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.cpp +++ b/src/KOKKOS/atom_vec_angle_kokkos.cpp @@ -27,27 +27,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecAngleKokkos::AtomVecAngleKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecAngleKokkos::AtomVecAngleKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecAngle(lmp) { - molecular = Atom::MOLECULAR; - bonds_allow = angles_allow = 1; - mass_type = PER_TYPE; - comm_x_only = comm_f_only = 1; - size_forward = 3; - size_reverse = 3; - size_border = 7; - size_velocity = 3; - size_data_atom = 6; - size_data_vel = 4; - xcol_data = 4; - - atom->molecule_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; - buffer = nullptr; } /* ---------------------------------------------------------------------- @@ -172,52 +155,6 @@ void AtomVecAngleKokkos::grow_pointers() h_angle_atom3 = atomKK->k_angle_atom3.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::copy(int i, int j, int delflag) -{ - int k; - - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_molecule(j) = h_molecule(i); - - h_num_bond(j) = h_num_bond(i); - for (k = 0; k < h_num_bond(j); k++) { - h_bond_type(j,k) = h_bond_type(i,k); - h_bond_atom(j,k) = h_bond_atom(i,k); - } - - h_nspecial(j,0) = h_nspecial(i,0); - h_nspecial(j,1) = h_nspecial(i,1); - h_nspecial(j,2) = h_nspecial(i,2); - for (k = 0; k < h_nspecial(j,2); k++) - h_special(j,k) = h_special(i,k); - - h_num_angle(j) = h_num_angle(i); - for (k = 0; k < h_num_angle(j); k++) { - h_angle_type(j,k) = h_angle_type(i,k); - h_angle_atom1(j,k) = h_angle_atom1(i,k); - h_angle_atom2(j,k) = h_angle_atom2(i,k); - h_angle_atom3(j,k) = h_angle_atom3(i,k); - } - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -508,171 +445,6 @@ void AtomVecAngleKokkos::unpack_comm_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -int AtomVecAngleKokkos::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::unpack_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::unpack_comm_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_reverse(int n, int first, double *buf) -{ - if (n > 0) - atomKK->sync(Host,F_MASK); - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - buf[m++] = h_f(i,0); - buf[m++] = h_f(i,1); - buf[m++] = h_f(i,2); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::unpack_reverse(int n, int *list, double *buf) -{ - if (n > 0) - atomKK->modified(Host,F_MASK); - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - h_f(j,0) += buf[m++]; - h_f(j,1) += buf[m++]; - h_f(j,2) += buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAngleKokkos_PackBorder { typedef DeviceType device_type; @@ -774,149 +546,6 @@ int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, /* ---------------------------------------------------------------------- */ -int AtomVecAngleKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_molecule(j); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAngleKokkos_UnpackBorder { typedef DeviceType device_type; @@ -977,78 +606,6 @@ void AtomVecAngleKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecAngleKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK|V_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAngleKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -1245,50 +802,6 @@ int AtomVecAngleKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_ /* ---------------------------------------------------------------------- */ -int AtomVecAngleKokkos::pack_exchange(int i, double *buf) -{ - int k; - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(h_bond_type(i,k)).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - buf[m++] = ubuf(h_num_angle(i)).d; - for (k = 0; k < h_num_angle(i); k++) { - buf[m++] = ubuf(h_angle_type(i,k)).d; - buf[m++] = ubuf(h_angle_atom1(i,k)).d; - buf[m++] = ubuf(h_angle_atom2(i,k)).d; - buf[m++] = ubuf(h_angle_atom3(i,k)).d; - } - buf[m++] = ubuf(h_nspecial(i,0)).d; - buf[m++] = ubuf(h_nspecial(i,1)).d; - buf[m++] = ubuf(h_nspecial(i,2)).d; - for (k = 0; k < h_nspecial(i,2); k++) - buf[m++] = ubuf(h_special(i,k)).d; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAngleKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -1416,361 +929,6 @@ int AtomVecAngleKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int n /* ---------------------------------------------------------------------- */ -int AtomVecAngleKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | SPECIAL_MASK); - - int k; - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_angle(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_angle(nlocal); k++) { - h_angle_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_angle_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_nspecial(nlocal,0) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,1) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,2) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_nspecial(nlocal,2); k++) - h_special(nlocal,k) = (tagint) ubuf(buf[m++]).i; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 0; - for (i = 0; i < nlocal; i++) - n += 14 + 2*h_num_bond(i) + 4*h_num_angle(i); - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | SPECIAL_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (int k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(MAX(h_bond_type(i,k),-h_bond_type(i,k))).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - - buf[m++] = ubuf(h_num_angle(i)).d; - for (int k = 0; k < h_num_angle(i); k++) { - buf[m++] = ubuf(MAX(h_angle_type(i,k),-h_angle_type(i,k))).d; - buf[m++] = ubuf(h_angle_atom1(i,k)).d; - buf[m++] = ubuf(h_angle_atom2(i,k)).d; - buf[m++] = ubuf(h_angle_atom3(i,k)).d; - } - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::unpack_restart(double *buf) -{ - int k; - - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | SPECIAL_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_angle(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_angle(nlocal); k++) { - h_angle_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_angle_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - atomKK->modified(Host,ALL_MASK); - grow(0); - } - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask(nlocal) = 1; - h_image(nlocal) = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_molecule(nlocal) = 0; - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,ALL_MASK); - - h_tag(nlocal) = utils::inumeric(FLERR,values[0],true,lmp); - h_molecule(nlocal) = utils::inumeric(FLERR,values[1],true,lmp); - h_type(nlocal) = utils::inumeric(FLERR,values[2],true,lmp); - extract = values[2]; - if (h_type(nlocal) <= 0 || h_type(nlocal) > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image(nlocal) = imagetmp; - - h_mask(nlocal) = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_molecule(nlocal) = utils::inumeric(FLERR,values[offset],true,lmp); - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - return 1; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag(i); - buf[i][1] = h_molecule(i); - buf[i][2] = h_type(i); - buf[i][3] = h_x(i,0); - buf[i][4] = h_x(i,1); - buf[i][5] = h_x(i,2); - buf[i][6] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_data_hybrid(int i, double *buf) -{ - buf[0] = h_molecule(i); - return 1; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %d %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1], (int) buf[i][2], - buf[i][3],buf[i][4],buf[i][5], - (int) buf[i][6],(int) buf[i][7],(int) buf[i][8]); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," " TAGINT_FORMAT, (tagint) (buf[0])); - return 1; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecAngleKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax); - if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3); - if (atom->memcheck("special")) - bytes += memory->usage(special,nmax,atom->maxspecial); - - if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax); - if (atom->memcheck("bond_type")) - bytes += memory->usage(bond_type,nmax,atom->bond_per_atom); - if (atom->memcheck("bond_atom")) - bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom); - - if (atom->memcheck("num_angle")) bytes += memory->usage(num_angle,nmax); - if (atom->memcheck("angle_type")) - bytes += memory->usage(angle_type,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom1")) - bytes += memory->usage(angle_atom1,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom2")) - bytes += memory->usage(angle_atom2,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom3")) - bytes += memory->usage(angle_atom3,nmax,atom->angle_per_atom); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecAngleKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1826,6 +984,8 @@ void AtomVecAngleKokkos::sync(ExecutionSpace space, unsigned int mask) } } +/* ---------------------------------------------------------------------- */ + void AtomVecAngleKokkos::sync_overlapping_device(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1973,4 +1133,3 @@ void AtomVecAngleKokkos::modified(ExecutionSpace space, unsigned int mask) } } } - diff --git a/src/KOKKOS/atom_vec_angle_kokkos.h b/src/KOKKOS/atom_vec_angle_kokkos.h index 82b2c3f967..eba1d7ead2 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.h +++ b/src/KOKKOS/atom_vec_angle_kokkos.h @@ -24,41 +24,15 @@ AtomStyle(angle/kk/host,AtomVecAngleKokkos); #define LMP_ATOM_VEC_ANGLE_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_angle.h" namespace LAMMPS_NS { -class AtomVecAngleKokkos : public AtomVecKokkos { +class AtomVecAngleKokkos : public AtomVecKokkos, public AtomVecAngle { public: AtomVecAngleKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_comm(int, int *, double *, int, int *) override; - int pack_comm_vel(int, int *, double *, int, int *) override; - void unpack_comm(int, int, double *) override; - void unpack_comm_vel(int, int, double *) override; - int pack_reverse(int, int, double *) override; - void unpack_reverse(int, int *, double *) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - void grow_pointers() override; int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, const int & iswap, @@ -142,9 +116,6 @@ class AtomVecAngleKokkos : public AtomVecKokkos { HAT::t_int_1d h_num_angle; HAT::t_int_2d h_angle_type; HAT::t_tagint_2d h_angle_atom1,h_angle_atom2,h_angle_atom3; - - DAT::tdual_int_1d k_count; - }; } diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.cpp b/src/KOKKOS/atom_vec_atomic_kokkos.cpp index ace5878eb6..632383154a 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.cpp +++ b/src/KOKKOS/atom_vec_atomic_kokkos.cpp @@ -27,23 +27,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecAtomicKokkos::AtomVecAtomicKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecAtomicKokkos::AtomVecAtomicKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecAtomic(lmp) { - molecular = Atom::ATOMIC; - mass_type = PER_TYPE; - comm_x_only = comm_f_only = 1; - size_forward = 3; - size_reverse = 3; - size_border = 6; - size_velocity = 3; - size_data_atom = 5; - size_data_vel = 4; - xcol_data = 3; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- @@ -113,28 +100,6 @@ void AtomVecAtomicKokkos::grow_pointers() h_f = atomKK->k_f.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecAtomicKokkos::copy(int i, int j, int delflag) -{ - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -232,130 +197,6 @@ int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, /* ---------------------------------------------------------------------- */ -int AtomVecAtomicKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecAtomicKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAtomicKokkos_UnpackBorder { typedef DeviceType device_type; @@ -408,63 +249,6 @@ void AtomVecAtomicKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecAtomicKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecAtomicKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|V_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAtomicKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -568,30 +352,6 @@ int AtomVecAtomicKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat /* ---------------------------------------------------------------------- */ -int AtomVecAtomicKokkos::pack_exchange(int i, double *buf) -{ - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAtomicKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -671,238 +431,6 @@ int AtomVecAtomicKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int /* ---------------------------------------------------------------------- */ -int AtomVecAtomicKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecAtomicKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 11 * nlocal; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecAtomicKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK ); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecAtomicKokkos::unpack_restart(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK ); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecAtomicKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - //if(nlocal>2) printf("typeA: %i %i\n",type[0],type[1]); - atomKK->modified(Host,ALL_MASK); - grow(0); - //if(nlocal>2) printf("typeB: %i %i\n",type[0],type[1]); - } - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask[nlocal] = 1; - h_image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | - ((tagint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecAtomicKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - h_tag[nlocal] = utils::inumeric(FLERR,values[0],true,lmp); - h_type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp); - extract = values[1]; - if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image[nlocal] = imagetmp; - - h_mask[nlocal] = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - atomKK->modified(Host,ALL_MASK); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecAtomicKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag[i]; - buf[i][1] = h_type[i]; - buf[i][2] = h_x(i,0); - buf[i][3] = h_x(i,1); - buf[i][4] = h_x(i,2); - buf[i][5] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][6] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecAtomicKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1],buf[i][2],buf[i][3],buf[i][4], - (int) buf[i][5],(int) buf[i][6],(int) buf[i][7]); -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecAtomicKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecAtomicKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -983,4 +511,3 @@ void AtomVecAtomicKokkos::modified(ExecutionSpace space, unsigned int mask) if (mask & IMAGE_MASK) atomKK->k_image.modify(); } } - diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.h b/src/KOKKOS/atom_vec_atomic_kokkos.h index e152e68248..83c311483e 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.h +++ b/src/KOKKOS/atom_vec_atomic_kokkos.h @@ -24,31 +24,16 @@ AtomStyle(atomic/kk/host,AtomVecAtomicKokkos); #define LMP_ATOM_VEC_ATOMIC_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_atomic.h" #include "kokkos_type.h" namespace LAMMPS_NS { -class AtomVecAtomicKokkos : public AtomVecKokkos { +class AtomVecAtomicKokkos : public AtomVecKokkos, public AtomVecAtomic { public: AtomVecAtomicKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - void pack_data(double **) override; - void write_data(FILE *, int, double **) override; - double memory_usage() override; - void grow_pointers() override; int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, @@ -70,11 +55,6 @@ class AtomVecAtomicKokkos : public AtomVecKokkos { void sync_overlapping_device(ExecutionSpace space, unsigned int mask) override; protected: - tagint *tag; - imageint *image; - int *type,*mask; - double **x,**v,**f; - DAT::t_tagint_1d d_tag; HAT::t_tagint_1d h_tag; DAT::t_imageint_1d d_image; @@ -85,8 +65,6 @@ class AtomVecAtomicKokkos : public AtomVecKokkos { DAT::t_x_array d_x; DAT::t_v_array d_v; DAT::t_f_array d_f; - - DAT::tdual_int_1d k_count; }; } diff --git a/src/KOKKOS/atom_vec_bond_kokkos.cpp b/src/KOKKOS/atom_vec_bond_kokkos.cpp index 104800231e..17419c7338 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.cpp +++ b/src/KOKKOS/atom_vec_bond_kokkos.cpp @@ -27,26 +27,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecBondKokkos::AtomVecBondKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecBondKokkos::AtomVecBondKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecBond(lmp) { - molecular = Atom::MOLECULAR; - bonds_allow = 1; - mass_type = PER_TYPE; - comm_x_only = comm_f_only = 1; - size_forward = 3; - size_reverse = 3; - size_border = 7; - size_velocity = 3; - size_data_atom = 6; - size_data_vel = 4; - xcol_data = 4; - - atom->molecule_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- @@ -142,43 +126,6 @@ void AtomVecBondKokkos::grow_pointers() h_bond_atom = atomKK->k_bond_atom.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecBondKokkos::copy(int i, int j, int delflag) -{ - int k; - - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_molecule(j) = h_molecule(i); - - h_num_bond(j) = h_num_bond(i); - for (k = 0; k < h_num_bond(j); k++) { - h_bond_type(j,k) = h_bond_type(i,k); - h_bond_atom(j,k) = h_bond_atom(i,k); - } - - h_nspecial(j,0) = h_nspecial(i,0); - h_nspecial(j,1) = h_nspecial(i,1); - h_nspecial(j,2) = h_nspecial(i,2); - for (k = 0; k < h_nspecial(j,2); k++) h_special(j,k) = h_special(i,k); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -282,149 +229,6 @@ int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, /* ---------------------------------------------------------------------- */ -int AtomVecBondKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecBondKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecBondKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_molecule(j); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecBondKokkos_UnpackBorder { typedef DeviceType device_type; @@ -485,78 +289,6 @@ void AtomVecBondKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecBondKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecBondKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK|V_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecBondKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecBondKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -721,43 +453,6 @@ int AtomVecBondKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2 /* ---------------------------------------------------------------------- */ -int AtomVecBondKokkos::pack_exchange(int i, double *buf) -{ - int k; - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(h_bond_type(i,k)).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - buf[m++] = ubuf(h_nspecial(i,0)).d; - buf[m++] = ubuf(h_nspecial(i,1)).d; - buf[m++] = ubuf(h_nspecial(i,2)).d; - for (k = 0; k < h_nspecial(i,2); k++) - buf[m++] = ubuf(h_special(i,k)).d; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecBondKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -870,321 +565,6 @@ int AtomVecBondKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int nr /* ---------------------------------------------------------------------- */ -int AtomVecBondKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | SPECIAL_MASK); - - int k; - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_nspecial(nlocal,0) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,1) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,2) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_nspecial(nlocal,2); k++) - h_special(nlocal,k) = (tagint) ubuf(buf[m++]).i; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecBondKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 0; - for (i = 0; i < nlocal; i++) - n += 13 + 2*h_num_bond[i]; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecBondKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | SPECIAL_MASK); - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (int k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(MAX(h_bond_type(i,k),-h_bond_type(i,k))).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecBondKokkos::unpack_restart(double *buf) -{ - int k; - - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | SPECIAL_MASK); - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecBondKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - atomKK->modified(Host,ALL_MASK); - grow(0); - } - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask(nlocal) = 1; - h_image(nlocal) = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_molecule(nlocal) = 0; - h_num_bond(nlocal) = 0; - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecBondKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atomKK->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,ALL_MASK); - - h_tag(nlocal) = utils::inumeric(FLERR,values[0],true,lmp); - h_molecule(nlocal) = utils::inumeric(FLERR,values[1],true,lmp); - h_type(nlocal) = utils::inumeric(FLERR,values[2],true,lmp); - extract = values[2]; - if (h_type(nlocal) <= 0 || h_type(nlocal) > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image(nlocal) = imagetmp; - - h_mask(nlocal) = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - h_num_bond(nlocal) = 0; - - atomKK->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecBondKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_molecule(nlocal) = utils::inumeric(FLERR,values[offset],true,lmp); - h_num_bond(nlocal) = 0; - return 1; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecBondKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag(i); - buf[i][1] = h_molecule(i); - buf[i][2] = h_type(i); - buf[i][3] = h_x(i,0); - buf[i][4] = h_x(i,1); - buf[i][5] = h_x(i,2); - buf[i][6] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecBondKokkos::pack_data_hybrid(int i, double *buf) -{ - buf[0] = h_molecule(i); - return 1; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecBondKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %d %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1], (int) buf[i][2], - buf[i][3],buf[i][4],buf[i][5], - (int) buf[i][6],(int) buf[i][7],(int) buf[i][8]); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecBondKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," " TAGINT_FORMAT, (tagint) (buf[0])); - return 1; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecBondKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax); - if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3); - if (atom->memcheck("special")) - bytes += memory->usage(special,nmax,atom->maxspecial); - - if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax); - if (atom->memcheck("bond_type")) - bytes += memory->usage(bond_type,nmax,atom->bond_per_atom); - if (atom->memcheck("bond_atom")) - bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecBondKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1337,4 +717,3 @@ void AtomVecBondKokkos::modified(ExecutionSpace space, unsigned int mask) } } } - diff --git a/src/KOKKOS/atom_vec_bond_kokkos.h b/src/KOKKOS/atom_vec_bond_kokkos.h index 7826148d88..a8befcf521 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.h +++ b/src/KOKKOS/atom_vec_bond_kokkos.h @@ -24,35 +24,15 @@ AtomStyle(bond/kk/host,AtomVecBondKokkos); #define LMP_ATOM_VEC_BOND_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_bond.h" namespace LAMMPS_NS { -class AtomVecBondKokkos : public AtomVecKokkos { +class AtomVecBondKokkos : public AtomVecKokkos, public AtomVecBond { public: AtomVecBondKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - void grow_pointers() override; int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, @@ -112,9 +92,6 @@ class AtomVecBondKokkos : public AtomVecKokkos { HAT::t_int_1d h_num_bond; HAT::t_int_2d h_bond_type; HAT::t_tagint_2d h_bond_atom; - - DAT::tdual_int_1d k_count; - }; } diff --git a/src/KOKKOS/atom_vec_charge_kokkos.cpp b/src/KOKKOS/atom_vec_charge_kokkos.cpp index e7087b0219..66520652be 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.cpp +++ b/src/KOKKOS/atom_vec_charge_kokkos.cpp @@ -27,25 +27,9 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecChargeKokkos::AtomVecChargeKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecChargeKokkos::AtomVecChargeKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecCharge(lmp) { - molecular = Atom::ATOMIC; - mass_type = PER_TYPE; - - comm_x_only = comm_f_only = 1; - size_forward = 3; - size_reverse = 3; - size_border = 7; - size_velocity = 3; - size_data_atom = 6; - size_data_vel = 4; - xcol_data = 4; - - atom->q_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } @@ -123,30 +107,6 @@ void AtomVecChargeKokkos::grow_pointers() } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecChargeKokkos::copy(int i, int j, int delflag) -{ - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_q[j] = h_q[i]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -297,150 +257,6 @@ int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, return n*size_border; } -/* ---------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q[j]; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q[j]; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q[j]; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_q[j]; - } - return m; -} - - /* ---------------------------------------------------------------------- */ template @@ -500,78 +316,6 @@ void AtomVecChargeKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecChargeKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_q[i] = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|Q_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecChargeKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_q[i] = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|Q_MASK|V_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) - h_q[i] = buf[m++]; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecChargeKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -688,31 +432,6 @@ int AtomVecChargeKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat /* ---------------------------------------------------------------------- */ -int AtomVecChargeKokkos::pack_exchange(int i, double *buf) -{ - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_q[i]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecChargeKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -797,281 +516,6 @@ int AtomVecChargeKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int /* ---------------------------------------------------------------------- */ -int AtomVecChargeKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_q[nlocal] = buf[m++]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 12 * nlocal; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = h_q[i]; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::unpack_restart(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_q[nlocal] = buf[m++]; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecChargeKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - atomKK->modified(Host,ALL_MASK); - grow(0); - } - atomKK->sync(Host,ALL_MASK); - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask[nlocal] = 1; - h_image[nlocal] = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_q[nlocal] = 0.0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecChargeKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - h_tag[nlocal] = utils::inumeric(FLERR,values[0],true,lmp); - h_type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp); - extract = values[1]; - if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_q[nlocal] = utils::numeric(FLERR,values[2],true,lmp); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image[nlocal] = imagetmp; - - h_mask[nlocal] = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - atomKK->modified(Host,ALL_MASK); - - atom->nlocal++; -} -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_q[nlocal] = utils::numeric(FLERR,values[offset],true,lmp); - - return 1; -} -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecChargeKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag[i]; - buf[i][1] = h_type[i]; - buf[i][2] = h_q[i]; - buf[i][3] = h_x(i,0); - buf[i][4] = h_x(i,1); - buf[i][5] = h_x(i,2); - buf[i][6] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::pack_data_hybrid(int i, double *buf) -{ - buf[0] = h_q[i]; - return 1; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecChargeKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1],buf[i][2],buf[i][3],buf[i][4],buf[i][5], - (int) buf[i][6],(int) buf[i][7],(int) buf[i][8]); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecChargeKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," %-1.16e",buf[0]); - return 1; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecChargeKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - if (atom->memcheck("q")) bytes += memory->usage(q,nmax); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecChargeKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1120,6 +564,8 @@ void AtomVecChargeKokkos::modified(ExecutionSpace space, unsigned int mask) } } +/* ---------------------------------------------------------------------- */ + void AtomVecChargeKokkos::sync_overlapping_device(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1158,4 +604,3 @@ void AtomVecChargeKokkos::sync_overlapping_device(ExecutionSpace space, unsigned perform_async_copy(atomKK->k_q,space); } } - diff --git a/src/KOKKOS/atom_vec_charge_kokkos.h b/src/KOKKOS/atom_vec_charge_kokkos.h index 91e2be522c..a09d1d3cf0 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.h +++ b/src/KOKKOS/atom_vec_charge_kokkos.h @@ -24,36 +24,16 @@ AtomStyle(charge/kk/host,AtomVecChargeKokkos); #define LMP_ATOM_VEC_CHARGE_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_charge.h" #include "kokkos_type.h" namespace LAMMPS_NS { -class AtomVecChargeKokkos : public AtomVecKokkos { +class AtomVecChargeKokkos : public AtomVecKokkos, public AtomVecCharge { public: AtomVecChargeKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int , const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - void grow_pointers() override; int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, @@ -98,8 +78,6 @@ class AtomVecChargeKokkos : public AtomVecKokkos { DAT::t_float_1d d_q; HAT::t_float_1d h_q; - - DAT::tdual_int_1d k_count; }; } diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.cpp b/src/KOKKOS/atom_vec_dpd_kokkos.cpp index defa7410f4..7bf54445e0 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dpd_kokkos.cpp @@ -27,27 +27,9 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecDPDKokkos::AtomVecDPDKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecDPDKokkos::AtomVecDPDKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecDPD(lmp) { - molecular = Atom::ATOMIC; - mass_type = PER_TYPE; - - comm_x_only = comm_f_only = 0; - size_forward = 7; - size_reverse = 3; - size_border = 12; - size_velocity = 3; - size_data_atom = 6; - size_data_vel = 4; - xcol_data = 4; - - atom->rho_flag = 1; - atom->dpd_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; - no_comm_vel_flag = 1; } @@ -153,44 +135,6 @@ void AtomVecDPDKokkos::grow_pointers() h_duChem = atomKK->k_duChem.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::copy(int i, int j, int delflag) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | DPDTHETA_MASK | - UCG_MASK | UCGNEW_MASK | - UCOND_MASK | UMECH_MASK | UCHEM_MASK | DVECTOR_MASK); - - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - h_dpdTheta[j] = h_dpdTheta[i]; - h_uCond[j] = h_uCond[i]; - h_uMech[j] = h_uMech[i]; - h_uChem[j] = h_uChem[i]; - h_uCG[j] = h_uCG[i]; - h_uCGnew[j] = h_uCGnew[i]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | DPDTHETA_MASK | - UCG_MASK | UCGNEW_MASK | - UCOND_MASK | UMECH_MASK | UCHEM_MASK | DVECTOR_MASK); -} - /* ---------------------------------------------------------------------- */ template @@ -547,209 +491,6 @@ void AtomVecDPDKokkos::unpack_comm_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_dpdTheta[j]; - buf[m++] = h_uCond[j]; - buf[m++] = h_uMech[j]; - buf[m++] = h_uChem[j]; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_dpdTheta[j]; - buf[m++] = h_uCond[j]; - buf[m++] = h_uMech[j]; - buf[m++] = h_uChem[j]; - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - atomKK->sync(Host,X_MASK|V_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_dpdTheta[j]; - buf[m++] = h_uCond[j]; - buf[m++] = h_uMech[j]; - buf[m++] = h_uChem[j]; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_dpdTheta[j]; - buf[m++] = h_uCond[j]; - buf[m++] = h_uMech[j]; - buf[m++] = h_uChem[j]; - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - buf[m++] = h_dpdTheta(j); - buf[m++] = h_uCond(j); - buf[m++] = h_uMech(j); - buf[m++] = h_uChem(j); - } - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::unpack_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_dpdTheta[i] = buf[m++]; - h_uCond[i] = buf[m++]; - h_uMech[i] = buf[m++]; - h_uChem[i] = buf[m++]; - } - - atomKK->modified(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::unpack_comm_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - h_dpdTheta[i] = buf[m++]; - h_uCond[i] = buf[m++]; - h_uMech[i] = buf[m++]; - h_uChem[i] = buf[m++]; - } - - atomKK->modified(Host,X_MASK|V_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_reverse(int n, int first, double *buf) -{ - if (n > 0) - atomKK->sync(Host,F_MASK); - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - buf[m++] = h_f(i,0); - buf[m++] = h_f(i,1); - buf[m++] = h_f(i,2); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::unpack_reverse(int n, int *list, double *buf) -{ - if (n > 0) { - atomKK->sync(Host,F_MASK); - atomKK->modified(Host,F_MASK); - } - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - h_f(j,0) += buf[m++]; - h_f(j,1) += buf[m++]; - h_f(j,2) += buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecDPDKokkos_PackBorder { typedef DeviceType device_type; @@ -871,206 +612,6 @@ int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DA /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - atomKK->sync(Host,ALL_MASK); - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_dpdTheta(j); - buf[m++] = h_uCond(j); - buf[m++] = h_uMech(j); - buf[m++] = h_uChem(j); - buf[m++] = h_uCG(j); - buf[m++] = h_uCGnew(j); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_dpdTheta(j); - buf[m++] = h_uCond(j); - buf[m++] = h_uMech(j); - buf[m++] = h_uChem(j); - buf[m++] = h_uCG(j); - buf[m++] = h_uCGnew(j); - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - atomKK->sync(Host,ALL_MASK); - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_dpdTheta(j); - buf[m++] = h_uCond(j); - buf[m++] = h_uMech(j); - buf[m++] = h_uChem(j); - buf[m++] = h_uCG(j); - buf[m++] = h_uCGnew(j); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_dpdTheta(j); - buf[m++] = h_uCond(j); - buf[m++] = h_uMech(j); - buf[m++] = h_uChem(j); - buf[m++] = h_uCG(j); - buf[m++] = h_uCGnew(j); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - buf[m++] = h_dpdTheta(j); - buf[m++] = h_uCond(j); - buf[m++] = h_uMech(j); - buf[m++] = h_uChem(j); - buf[m++] = h_uCG(j); - buf[m++] = h_uCGnew(j); - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_comm_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - atomKK->sync(Host,DPDTHETA_MASK | UCOND_MASK | - UMECH_MASK | UCHEM_MASK); - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_dpdTheta[j]; - buf[m++] = h_uCond[j]; - buf[m++] = h_uMech[j]; - buf[m++] = h_uChem[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - atomKK->sync(Host,DPDTHETA_MASK | UCOND_MASK | - UMECH_MASK | UCHEM_MASK | UCG_MASK | UCGNEW_MASK); - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_dpdTheta[j]; - buf[m++] = h_uCond[j]; - buf[m++] = h_uMech[j]; - buf[m++] = h_uChem[j]; - buf[m++] = h_uCG[j]; - buf[m++] = h_uCGnew[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecDPDKokkos_UnpackBorder { typedef DeviceType device_type; @@ -1152,123 +693,6 @@ void AtomVecDPDKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecDPDKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_dpdTheta(i) = buf[m++]; - h_uCond(i) = buf[m++]; - h_uMech(i) = buf[m++]; - h_uChem(i) = buf[m++]; - h_uCG(i) = buf[m++]; - h_uCGnew(i) = buf[m++]; - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK| - DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK| - UCG_MASK|UCGNEW_MASK|DVECTOR_MASK); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - h_dpdTheta(i) = buf[m++]; - h_uCond(i) = buf[m++]; - h_uMech(i) = buf[m++]; - h_uChem(i) = buf[m++]; - h_uCG(i) = buf[m++]; - h_uCGnew(i) = buf[m++]; - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); - - atomKK->modified(Host,X_MASK|V_MASK|TAG_MASK|TYPE_MASK|MASK_MASK| - DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK| - UCG_MASK|UCGNEW_MASK|DVECTOR_MASK); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::unpack_comm_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_dpdTheta(i) = buf[m++]; - h_uCond(i) = buf[m++]; - h_uMech(i) = buf[m++]; - h_uChem(i) = buf[m++]; - } - - atomKK->modified(Host,DPDTHETA_MASK | UCOND_MASK | - UMECH_MASK | UCHEM_MASK ); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_dpdTheta(i) = buf[m++]; - h_uCond(i) = buf[m++]; - h_uMech(i) = buf[m++]; - h_uChem(i) = buf[m++]; - h_uCG(i) = buf[m++]; - h_uCGnew(i) = buf[m++]; - } - - atomKK->modified(Host,DPDTHETA_MASK | UCOND_MASK | - UMECH_MASK | UCHEM_MASK | UCG_MASK | UCGNEW_MASK); - - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecDPDKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -1401,41 +825,6 @@ int AtomVecDPDKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2d /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_exchange(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK| DPDTHETA_MASK | UCOND_MASK | - UMECH_MASK | UCHEM_MASK | UCG_MASK | UCGNEW_MASK | - DVECTOR_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_dpdTheta[i]; - buf[m++] = h_uCond[i]; - buf[m++] = h_uMech[i]; - buf[m++] = h_uChem[i]; - buf[m++] = h_uCG[i]; - buf[m++] = h_uCGnew[i]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecDPDKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -1531,334 +920,6 @@ int AtomVecDPDKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int nre /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_dpdTheta[nlocal] = buf[m++]; - h_uCond[nlocal] = buf[m++]; - h_uMech[nlocal] = buf[m++]; - h_uChem[nlocal] = buf[m++]; - h_uCG[nlocal] = buf[m++]; - h_uCGnew[nlocal] = buf[m++]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK| DPDTHETA_MASK | UCOND_MASK | - UMECH_MASK | UCHEM_MASK | UCG_MASK | UCGNEW_MASK | - DVECTOR_MASK); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 15 * nlocal; // 11 + dpdTheta + uCond + uMech + uChem - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | DPDTHETA_MASK | - UCOND_MASK | UMECH_MASK | UCHEM_MASK | DVECTOR_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = h_dpdTheta[i]; - buf[m++] = h_uCond[i]; - buf[m++] = h_uMech[i]; - buf[m++] = h_uChem[i]; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::unpack_restart(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_dpdTheta[nlocal] = buf[m++]; - h_uCond[nlocal] = buf[m++]; - h_uMech[nlocal] = buf[m++]; - h_uChem[nlocal] = buf[m++]; - h_uCG[nlocal] = 0.0; - h_uCGnew[nlocal] = 0.0; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | DPDTHETA_MASK | - UCG_MASK | UCGNEW_MASK | - UCOND_MASK | UMECH_MASK | UCHEM_MASK | DVECTOR_MASK); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - //if(nlocal>2) printf("typeA: %i %i\n",type[0],type[1]); - atomKK->modified(Host,ALL_MASK); - grow(0); - //if(nlocal>2) printf("typeB: %i %i\n",type[0],type[1]); - } - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask[nlocal] = 1; - h_image[nlocal] = ((tagint) IMGMAX << IMG2BITS) | - ((tagint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - h_rho[nlocal] = 0.0; - h_dpdTheta[nlocal] = 0.0; - h_uCond[nlocal] = 0.0; - h_uMech[nlocal] = 0.0; - h_uChem[nlocal] = 0.0; - h_uCG[nlocal] = 0.0; - h_uCGnew[nlocal] = 0.0; - h_duChem[nlocal] = 0.0; - - //atomKK->modified(Host,TAG_MASK|TYPE_MASK|DPDTHETA_MASK|X_MASK|IMAGE_MASK| - // MASK_MASK|V_MASK|DPDRHO_MASK|UCOND_MASK|UMECH_MASK| - // UCHEM_MASK|UCG_MASK|UCGNEW_MASK); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - h_tag[nlocal] = utils::tnumeric(FLERR,values[0],true,lmp); - h_type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp); - extract = values[1]; - if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_dpdTheta[nlocal] = utils::numeric(FLERR,values[2],true,lmp); - if (h_dpdTheta[nlocal] <= 0) - error->one(FLERR,"Internal temperature in Atoms section of date file must be > zero"); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image[nlocal] = imagetmp; - - h_mask[nlocal] = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_rho[nlocal] = 0.0; - h_uCond[nlocal] = 0.0; - h_uMech[nlocal] = 0.0; - h_uChem[nlocal] = 0.0; - h_uCG[nlocal] = 0.0; - h_uCGnew[nlocal] = 0.0; - - atomKK->modified(Host,ALL_MASK); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_dpdTheta(nlocal) = utils::numeric(FLERR,values[offset],true,lmp); - - atomKK->modified(Host,DPDTHETA_MASK); - - return 1; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::pack_data(double **buf) -{ - atomKK->sync(Host,TAG_MASK|TYPE_MASK|DPDTHETA_MASK|X_MASK|IMAGE_MASK); - - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = ubuf(h_tag(i)).d; - buf[i][1] = ubuf(h_type(i)).d; - buf[i][2] = h_dpdTheta(i); - buf[i][3] = h_x(i,0); - buf[i][4] = h_x(i,1); - buf[i][5] = h_x(i,2); - buf[i][6] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::pack_data_hybrid(int i, double *buf) -{ - atomKK->sync(Host,DPDTHETA_MASK); - - buf[0] = h_dpdTheta(i); - return 1; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecDPDKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,TAGINT_FORMAT " %d %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d\n", - (tagint) ubuf(buf[i][0]).i,(int) ubuf(buf[i][1]).i, - buf[i][2],buf[i][3],buf[i][4],buf[i][5], - (int) ubuf(buf[i][6]).i,(int) ubuf(buf[i][7]).i, - (int) ubuf(buf[i][8]).i); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecDPDKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," %-1.16e",buf[0]); - return 1; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecDPDKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - if (atom->memcheck("rho")) bytes += memory->usage(rho,nmax); - if (atom->memcheck("dpdTheta")) bytes += memory->usage(dpdTheta,nmax); - if (atom->memcheck("uCond")) bytes += memory->usage(uCond,nmax); - if (atom->memcheck("uMech")) bytes += memory->usage(uMech,nmax); - if (atom->memcheck("uChem")) bytes += memory->usage(uChem,nmax); - if (atom->memcheck("uCG")) bytes += memory->usage(uCG,nmax); - if (atom->memcheck("uCGnew")) bytes += memory->usage(uCGnew,nmax); - if (atom->memcheck("duChem")) bytes += memory->usage(duChem,nmax); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecDPDKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -2011,4 +1072,3 @@ void AtomVecDPDKokkos::modified(ExecutionSpace space, unsigned int mask) if (mask & DVECTOR_MASK) atomKK->k_dvector.modify(); } } - diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.h b/src/KOKKOS/atom_vec_dpd_kokkos.h index d0f0087a08..ddc590b2c7 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.h +++ b/src/KOKKOS/atom_vec_dpd_kokkos.h @@ -24,44 +24,16 @@ AtomStyle(dpd/kk/host,AtomVecDPDKokkos); #define LMP_ATOM_VEC_DPD_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_dpd.h" #include "kokkos_type.h" namespace LAMMPS_NS { -class AtomVecDPDKokkos : public AtomVecKokkos { +class AtomVecDPDKokkos : public AtomVecKokkos, public AtomVecDPD { public: AtomVecDPDKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_comm(int, int *, double *, int, int *) override; - int pack_comm_vel(int, int *, double *, int, int *) override; - int pack_comm_hybrid(int, int *, double *) override; - void unpack_comm(int, int, double *) override; - void unpack_comm_vel(int, int, double *) override; - int unpack_comm_hybrid(int, int, double *) override; - int pack_reverse(int, int, double *) override; - void unpack_reverse(int, int *, double *) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - void grow_pointers() override; int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, const int & iswap, @@ -112,8 +84,6 @@ class AtomVecDPDKokkos : public AtomVecKokkos { DAT::t_x_array d_x; DAT::t_v_array d_v; DAT::t_f_array d_f; - - DAT::tdual_int_1d k_count; }; } diff --git a/src/KOKKOS/atom_vec_full_kokkos.cpp b/src/KOKKOS/atom_vec_full_kokkos.cpp index 96c7e5312a..bce165240b 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.cpp +++ b/src/KOKKOS/atom_vec_full_kokkos.cpp @@ -27,26 +27,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecFullKokkos::AtomVecFullKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecFullKokkos::AtomVecFullKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecFull(lmp) { - molecular = Atom::MOLECULAR; - bonds_allow = angles_allow = dihedrals_allow = impropers_allow = 1; - mass_type = PER_TYPE; - comm_x_only = comm_f_only = 1; - size_forward = 3; - size_reverse = 3; - size_border = 8; - size_velocity = 3; - size_data_atom = 7; - size_data_vel = 4; - xcol_data = 5; - - atom->molecule_flag = atom->q_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- @@ -241,71 +225,6 @@ void AtomVecFullKokkos::grow_pointers() h_improper_atom4 = atomKK->k_improper_atom4.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecFullKokkos::copy(int i, int j, int delflag) -{ - int k; - - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_q[j] = h_q[i]; - h_molecule(j) = h_molecule(i); - - h_num_bond(j) = h_num_bond(i); - for (k = 0; k < h_num_bond(j); k++) { - h_bond_type(j,k) = h_bond_type(i,k); - h_bond_atom(j,k) = h_bond_atom(i,k); - } - - h_nspecial(j,0) = h_nspecial(i,0); - h_nspecial(j,1) = h_nspecial(i,1); - h_nspecial(j,2) = h_nspecial(i,2); - for (k = 0; k < h_nspecial(j,2); k++) - h_special(j,k) = h_special(i,k); - - h_num_angle(j) = h_num_angle(i); - for (k = 0; k < h_num_angle(j); k++) { - h_angle_type(j,k) = h_angle_type(i,k); - h_angle_atom1(j,k) = h_angle_atom1(i,k); - h_angle_atom2(j,k) = h_angle_atom2(i,k); - h_angle_atom3(j,k) = h_angle_atom3(i,k); - } - - h_num_dihedral(j) = h_num_dihedral(i); - for (k = 0; k < h_num_dihedral(j); k++) { - h_dihedral_type(j,k) = h_dihedral_type(i,k); - h_dihedral_atom1(j,k) = h_dihedral_atom1(i,k); - h_dihedral_atom2(j,k) = h_dihedral_atom2(i,k); - h_dihedral_atom3(j,k) = h_dihedral_atom3(i,k); - h_dihedral_atom4(j,k) = h_dihedral_atom4(i,k); - } - - h_num_improper(j) = h_num_improper(i); - for (k = 0; k < h_num_improper(j); k++) { - h_improper_type(j,k) = h_improper_type(i,k); - h_improper_atom1(j,k) = h_improper_atom1(i,k); - h_improper_atom2(j,k) = h_improper_atom2(i,k); - h_improper_atom3(j,k) = h_improper_atom3(i,k); - h_improper_atom4(j,k) = h_improper_atom4(i,k); - } - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -413,155 +332,6 @@ int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, /* ---------------------------------------------------------------------- */ -int AtomVecFullKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - buf[m++] = ubuf(h_molecule(j)).d; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - buf[m++] = ubuf(h_molecule(j)).d; - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecFullKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_q(j); - buf[m++] = ubuf(h_molecule(j)).d; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecFullKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_q(j); - buf[m++] = ubuf(h_molecule(j)).d; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecFullKokkos_UnpackBorder { typedef DeviceType device_type; @@ -628,82 +398,6 @@ void AtomVecFullKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecFullKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_q(i) = buf[m++]; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|Q_MASK|MOLECULE_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecFullKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_q(i) = buf[m++]; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|Q_MASK|MOLECULE_MASK|V_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecFullKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_q(i) = buf[m++]; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecFullKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -983,66 +677,6 @@ int AtomVecFullKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2 /* ---------------------------------------------------------------------- */ -int AtomVecFullKokkos::pack_exchange(int i, double *buf) -{ - int k; - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_q(i); - buf[m++] = ubuf(h_molecule(i)).d; - buf[m++] = ubuf(h_num_bond(i)).d; - for (k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(h_bond_type(i,k)).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - buf[m++] = ubuf(h_num_angle(i)).d; - for (k = 0; k < h_num_angle(i); k++) { - buf[m++] = ubuf(h_angle_type(i,k)).d; - buf[m++] = ubuf(h_angle_atom1(i,k)).d; - buf[m++] = ubuf(h_angle_atom2(i,k)).d; - buf[m++] = ubuf(h_angle_atom3(i,k)).d; - } - buf[m++] = ubuf(h_num_dihedral(i)).d; - for (k = 0; k < h_num_dihedral(i); k++) { - buf[m++] = ubuf(h_dihedral_type(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom1(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom2(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom3(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom4(i,k)).d; - } - buf[m++] = ubuf(h_num_improper(i)).d; - for (k = 0; k < h_num_improper(i); k++) { - buf[m++] = ubuf(h_improper_type(i,k)).d; - buf[m++] = ubuf(h_improper_atom1(i,k)).d; - buf[m++] = ubuf(h_improper_atom2(i,k)).d; - buf[m++] = ubuf(h_improper_atom3(i,k)).d; - buf[m++] = ubuf(h_improper_atom4(i,k)).d; - } - buf[m++] = ubuf(h_nspecial(i,0)).d; - buf[m++] = ubuf(h_nspecial(i,1)).d; - buf[m++] = ubuf(h_nspecial(i,2)).d; - for (k = 0; k < h_nspecial(i,2); k++) - buf[m++] = ubuf(h_special(i,k)).d; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecFullKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -1211,457 +845,6 @@ int AtomVecFullKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int nr /* ---------------------------------------------------------------------- */ -int AtomVecFullKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - - int k; - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_q(nlocal) = buf[m++]; - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_angle(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_angle(nlocal); k++) { - h_angle_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_angle_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_dihedral(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_dihedral(nlocal); k++) { - h_dihedral_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_dihedral_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_improper(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_improper(nlocal); k++) { - h_improper_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_improper_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_nspecial(nlocal,0) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,1) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,2) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_nspecial(nlocal,2); k++) - h_special(nlocal,k) = (tagint) ubuf(buf[m++]).i; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecFullKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 0; - for (i = 0; i < nlocal; i++) - n += 17 + 2*num_bond[i] + 4*num_angle[i] + - 5*num_dihedral[i] + 5*num_improper[i]; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecFullKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = h_q(i); - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (int k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(MAX(h_bond_type(i,k),-h_bond_type(i,k))).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - - buf[m++] = ubuf(h_num_angle(i)).d; - for (int k = 0; k < h_num_angle(i); k++) { - buf[m++] = ubuf(MAX(h_angle_type(i,k),-h_angle_type(i,k))).d; - buf[m++] = ubuf(h_angle_atom1(i,k)).d; - buf[m++] = ubuf(h_angle_atom2(i,k)).d; - buf[m++] = ubuf(h_angle_atom3(i,k)).d; - } - - buf[m++] = ubuf(h_num_dihedral(i)).d; - for (int k = 0; k < h_num_dihedral(i); k++) { - buf[m++] = ubuf(MAX(h_dihedral_type(i,k),-h_dihedral_type(i,k))).d; - buf[m++] = ubuf(h_dihedral_atom1(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom2(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom3(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom4(i,k)).d; - } - - buf[m++] = ubuf(h_num_improper(i)).d; - for (int k = 0; k < h_num_improper(i); k++) { - buf[m++] = ubuf(MAX(h_improper_type(i,k),-h_improper_type(i,k))).d; - buf[m++] = ubuf(h_improper_atom1(i,k)).d; - buf[m++] = ubuf(h_improper_atom2(i,k)).d; - buf[m++] = ubuf(h_improper_atom3(i,k)).d; - buf[m++] = ubuf(h_improper_atom4(i,k)).d; - } - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecFullKokkos::unpack_restart(double *buf) -{ - int k; - - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | Q_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_q(nlocal) = buf[m++]; - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_angle(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_angle(nlocal); k++) { - h_angle_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_angle_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_dihedral(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_dihedral(nlocal); k++) { - h_dihedral_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_dihedral_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_improper(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_improper(nlocal); k++) { - h_improper_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_improper_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecFullKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - atomKK->modified(Host,ALL_MASK); - grow(0); - } - atomKK->sync(Host,ALL_MASK); - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask(nlocal) = 1; - h_image(nlocal) = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_q(nlocal) = 0.0; - h_molecule(nlocal) = 0; - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_num_dihedral(nlocal) = 0; - h_num_improper(nlocal) = 0; - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecFullKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,ALL_MASK); - - h_tag(nlocal) = utils::inumeric(FLERR,values[0],true,lmp); - h_molecule(nlocal) = utils::inumeric(FLERR,values[1],true,lmp); - h_type(nlocal) = utils::inumeric(FLERR,values[2],true,lmp); - extract = values[2]; - if (h_type(nlocal) <= 0 || h_type(nlocal) > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_q(nlocal) = utils::numeric(FLERR,values[3],true,lmp); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image(nlocal) = imagetmp; - - h_mask(nlocal) = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_num_dihedral(nlocal) = 0; - h_num_improper(nlocal) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecFullKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_molecule(nlocal) = utils::inumeric(FLERR,values[offset],true,lmp); - h_q(nlocal) = utils::numeric(FLERR,values[offset+1],true,lmp); - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_num_dihedral(nlocal) = 0; - h_num_improper(nlocal) = 0; - return 2; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecFullKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag(i); - buf[i][1] = h_molecule(i); - buf[i][2] = h_type(i); - buf[i][3] = h_q(i); - buf[i][4] = h_x(i,0); - buf[i][5] = h_x(i,1); - buf[i][6] = h_x(i,2); - buf[i][7] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][9] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecFullKokkos::pack_data_hybrid(int i, double *buf) -{ - buf[0] = h_molecule(i); - buf[1] = h_q(i); - return 2; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecFullKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %d %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1], (int) buf[i][2], buf[i][3], - buf[i][4],buf[i][5],buf[i][6], - (int) buf[i][7],(int) buf[i][8],(int) buf[i][9]); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecFullKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," " TAGINT_FORMAT " %-1.16e",(tagint) ubuf(buf[0]).i,buf[1]); - return 2; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecFullKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - if (atom->memcheck("q")) bytes += memory->usage(q,nmax); - if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax); - if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3); - if (atom->memcheck("special")) - bytes += memory->usage(special,nmax,atom->maxspecial); - - if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax); - if (atom->memcheck("bond_type")) - bytes += memory->usage(bond_type,nmax,atom->bond_per_atom); - if (atom->memcheck("bond_atom")) - bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom); - - if (atom->memcheck("num_angle")) bytes += memory->usage(num_angle,nmax); - if (atom->memcheck("angle_type")) - bytes += memory->usage(angle_type,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom1")) - bytes += memory->usage(angle_atom1,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom2")) - bytes += memory->usage(angle_atom2,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom3")) - bytes += memory->usage(angle_atom3,nmax,atom->angle_per_atom); - - if (atom->memcheck("num_dihedral")) bytes += memory->usage(num_dihedral,nmax); - if (atom->memcheck("dihedral_type")) - bytes += memory->usage(dihedral_type,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom1")) - bytes += memory->usage(dihedral_atom1,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom2")) - bytes += memory->usage(dihedral_atom2,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom3")) - bytes += memory->usage(dihedral_atom3,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom4")) - bytes += memory->usage(dihedral_atom4,nmax,atom->dihedral_per_atom); - if (atom->memcheck("num_improper")) bytes += memory->usage(num_improper,nmax); - if (atom->memcheck("improper_type")) - bytes += memory->usage(improper_type,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom1")) - bytes += memory->usage(improper_atom1,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom2")) - bytes += memory->usage(improper_atom2,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom3")) - bytes += memory->usage(improper_atom3,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom4")) - bytes += memory->usage(improper_atom4,nmax,atom->improper_per_atom); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecFullKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1992,4 +1175,3 @@ void AtomVecFullKokkos::modified(ExecutionSpace space, unsigned int mask) } } } - diff --git a/src/KOKKOS/atom_vec_full_kokkos.h b/src/KOKKOS/atom_vec_full_kokkos.h index 72e48ed513..5de3246f4e 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.h +++ b/src/KOKKOS/atom_vec_full_kokkos.h @@ -24,35 +24,15 @@ AtomStyle(full/kk/host,AtomVecFullKokkos); #define LMP_ATOM_VEC_FULL_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_full.h" namespace LAMMPS_NS { -class AtomVecFullKokkos : public AtomVecKokkos { +class AtomVecFullKokkos : public AtomVecKokkos, public AtomVecFull { public: AtomVecFullKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - void grow_pointers() override; int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, @@ -154,9 +134,6 @@ class AtomVecFullKokkos : public AtomVecKokkos { HAT::t_int_2d h_improper_type; HAT::t_tagint_2d h_improper_atom1,h_improper_atom2, h_improper_atom3,h_improper_atom4; - - HAT::tdual_int_1d k_count; - }; } diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 9a7709a699..c8bccc00c8 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -28,7 +28,9 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecHybridKokkos::AtomVecHybridKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) { +AtomVecHybridKokkos::AtomVecHybridKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecHybrid(lmp) +{ no_comm_vel_flag = 1; no_border_vel_flag = 1; } @@ -37,218 +39,7 @@ AtomVecHybridKokkos::AtomVecHybridKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) { AtomVecHybridKokkos::~AtomVecHybridKokkos() { - for (int k = 0; k < nstyles; k++) delete styles[k]; - delete [] styles; - for (int k = 0; k < nstyles; k++) delete [] keywords[k]; - delete [] keywords; -} -/* ---------------------------------------------------------------------- - process sub-style args -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::process_args(int narg, char **arg) -{ - // build list of all known atom styles - - build_styles(); - - // allocate list of sub-styles as big as possibly needed if no extra args - - styles = new AtomVec*[narg]; - keywords = new char*[narg]; - - // allocate each sub-style - // call process_args() with set of args that are not atom style names - // use known_style() to determine which args these are - - int i,jarg,dummy; - - int iarg = 0; - nstyles = 0; - while (iarg < narg) { - if (strcmp(arg[iarg],"hybrid") == 0) - error->all(FLERR,"Atom style hybrid cannot have hybrid as an argument"); - for (i = 0; i < nstyles; i++) - if (strcmp(arg[iarg],keywords[i]) == 0) - error->all(FLERR,"Atom style hybrid cannot use same atom style twice"); - styles[nstyles] = atom->new_avec(arg[iarg],1,dummy); - keywords[nstyles] = utils::strdup(arg[iarg]); - jarg = iarg + 1; - while (jarg < narg && !known_style(arg[jarg])) jarg++; - styles[nstyles]->process_args(jarg-iarg-1,&arg[iarg+1]); - iarg = jarg; - nstyles++; - } - - // free allstyles created by build_styles() - - for (int i = 0; i < nallstyles; i++) delete [] allstyles[i]; - delete [] allstyles; - - // hybrid settings are MAX or MIN of sub-style settings - // hybrid sizes are minimal values plus extra values for each sub-style - - molecular = Atom::ATOMIC; - comm_x_only = comm_f_only = 1; - - size_forward = 3; - size_reverse = 3; - size_border = 6; - size_data_atom = 5; - size_data_vel = 4; - xcol_data = 3; - - for (int k = 0; k < nstyles; k++) { - if ((styles[k]->molecular == Atom::MOLECULAR && molecular == Atom::TEMPLATE) || - (styles[k]->molecular == Atom::TEMPLATE && molecular == Atom::MOLECULAR)) - error->all(FLERR,"Cannot mix molecular and molecule template " - "atom styles"); - molecular = MAX(molecular,styles[k]->molecular); - - bonds_allow = MAX(bonds_allow,styles[k]->bonds_allow); - angles_allow = MAX(angles_allow,styles[k]->angles_allow); - dihedrals_allow = MAX(dihedrals_allow,styles[k]->dihedrals_allow); - impropers_allow = MAX(impropers_allow,styles[k]->impropers_allow); - mass_type = MAX(mass_type,styles[k]->mass_type); - dipole_type = MAX(dipole_type,styles[k]->dipole_type); - forceclearflag = MAX(forceclearflag,styles[k]->forceclearflag); - - if (styles[k]->molecular == Atom::TEMPLATE) onemols = styles[k]->onemols; - - comm_x_only = MIN(comm_x_only,styles[k]->comm_x_only); - comm_f_only = MIN(comm_f_only,styles[k]->comm_f_only); - size_forward += styles[k]->size_forward - 3; - size_reverse += styles[k]->size_reverse - 3; - size_border += styles[k]->size_border - 6; - size_data_atom += styles[k]->size_data_atom - 5; - size_data_vel += styles[k]->size_data_vel - 4; - } - - size_velocity = 3; - if (atom->omega_flag) size_velocity += 3; - if (atom->angmom_flag) size_velocity += 3; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::init() -{ - AtomVec::init(); - for (int k = 0; k < nstyles; k++) styles[k]->init(); -} - -/* ---------------------------------------------------------------------- - grow atom arrays - n = 0 grows arrays by a chunk - n > 0 allocates arrays to size n -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::grow(int n) -{ - if (n == 0) grow_nmax(); - else nmax = n; - atom->nmax = nmax; - if (nmax < 0 || nmax > MAXSMALLINT) - error->one(FLERR,"Per-processor system is too big"); - - // sub-styles perform all reallocation - // turn off nextra_grow so hybrid can do that once below - - int tmp = atom->nextra_grow; - atom->nextra_grow = 0; - for (int k = 0; k < nstyles; k++) styles[k]->grow(nmax); - atom->nextra_grow = tmp; - - // insure hybrid local ptrs and sub-style ptrs are up to date - // for sub-styles, do this in case - // multiple sub-style reallocs of same array occurred - - grow_pointers(); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax); -} - -/* ---------------------------------------------------------------------- - reset local array ptrs -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::grow_pointers() -{ - tag = atomKK->tag; - d_tag = atomKK->k_tag.d_view; - h_tag = atomKK->k_tag.h_view; - - type = atomKK->type; - d_type = atomKK->k_type.d_view; - h_type = atomKK->k_type.h_view; - - mask = atomKK->mask; - d_mask = atomKK->k_mask.d_view; - h_mask = atomKK->k_mask.h_view; - - image = atomKK->image; - d_image = atomKK->k_image.d_view; - h_image = atomKK->k_image.h_view; - - x = atomKK->x; - d_x = atomKK->k_x.d_view; - h_x = atomKK->k_x.h_view; - - v = atomKK->v; - d_v = atomKK->k_v.d_view; - h_v = atomKK->k_v.h_view; - - f = atomKK->f; - d_f = atomKK->k_f.d_view; - h_f = atomKK->k_f.h_view; - - v = atomKK->v; - d_v = atomKK->k_v.d_view; - h_v = atomKK->k_v.h_view; - - omega = atomKK->omega; - d_omega = atomKK->k_omega.d_view; - h_omega = atomKK->k_omega.h_view; - - angmom = atomKK->angmom; - d_angmom = atomKK->k_angmom.d_view; - h_angmom = atomKK->k_angmom.h_view; - - for (int k = 0; k < nstyles; k++) styles[k]->grow_pointers(); -} - -/* ---------------------------------------------------------------------- - copy atom I info to atom J for all sub-styles -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::copy(int i, int j, int delflag) -{ - int tmp = atom->nextra_grow; - atom->nextra_grow = 0; - for (int k = 0; k < nstyles; k++) styles[k]->copy(i,j,delflag); - atom->nextra_grow = tmp; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::clear_bonus() -{ - for (int k = 0; k < nstyles; k++) styles[k]->clear_bonus(); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::force_clear(int n, size_t nbytes) -{ - for (int k = 0; k < nstyles; k++) - if (styles[k]->forceclearflag) styles[k]->force_clear(n,nbytes); } /* ---------------------------------------------------------------------- */ @@ -261,11 +52,13 @@ int AtomVecHybridKokkos::pack_comm_kokkos(const int &/*n*/, const DAT::tdual_int error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); return 0; } + void AtomVecHybridKokkos::unpack_comm_kokkos(const int &/*n*/, const int &/*nfirst*/, const DAT::tdual_xfloat_2d &/*buf*/) { error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); } + int AtomVecHybridKokkos::pack_comm_self(const int &/*n*/, const DAT::tdual_int_2d &/*list*/, const int & /*iswap*/, const int /*nfirst*/, const int &/*pbc_flag*/, const int pbc[]) @@ -273,6 +66,7 @@ int AtomVecHybridKokkos::pack_comm_self(const int &/*n*/, const DAT::tdual_int_2 error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); return 0; } + int AtomVecHybridKokkos::pack_border_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sendlist*/, DAT::tdual_xfloat_2d /*buf*/,int /*iswap*/, int /*pbc_flag*/, int * /*pbc*/, ExecutionSpace /*space*/) @@ -280,12 +74,14 @@ int AtomVecHybridKokkos::pack_border_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sen error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); return 0; } + void AtomVecHybridKokkos::unpack_border_kokkos(const int &/*n*/, const int &/*nfirst*/, const DAT::tdual_xfloat_2d &/*buf*/, ExecutionSpace /*space*/) { error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); } + int AtomVecHybridKokkos::pack_exchange_kokkos(const int &/*nsend*/,DAT::tdual_xfloat_2d &/*buf*/, DAT::tdual_int_1d /*k_sendlist*/, DAT::tdual_int_1d /*k_copylist*/, @@ -295,6 +91,7 @@ int AtomVecHybridKokkos::pack_exchange_kokkos(const int &/*nsend*/,DAT::tdual_xf error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); return 0; } + int AtomVecHybridKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d & /*k_buf*/, int /*nrecv*/, int /*nlocal*/, int /*dim*/, X_FLOAT /*lo*/, X_FLOAT /*hi*/, ExecutionSpace /*space*/) @@ -303,921 +100,25 @@ int AtomVecHybridKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d & /*k_buf*/ return 0; } -/* ---------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - atomKK->sync(Host,X_MASK); - - int i,j,k,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - } - } - - // pack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_comm_hybrid(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - atomKK->sync(Host,X_MASK|V_MASK|OMEGA_MASK/*|ANGMOM_MASK*/); - - int i,j,k,m; - double dx,dy,dz,dvx,dvy,dvz; - int omega_flag = atom->omega_flag; - int angmom_flag = atom->angmom_flag; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - if (omega_flag) { - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - if (angmom_flag) { - buf[m++] = h_angmom(j,0); - buf[m++] = h_angmom(j,1); - buf[m++] = h_angmom(j,2); - } - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - if (omega_flag) { - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - if (angmom_flag) { - buf[m++] = h_angmom(j,0); - buf[m++] = h_angmom(j,1); - buf[m++] = h_angmom(j,2); - } - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - if (h_mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - if (omega_flag) { - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - if (angmom_flag) { - buf[m++] = h_angmom(j,0); - buf[m++] = h_angmom(j,1); - buf[m++] = h_angmom(j,2); - } - } - } - } - - // pack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_comm_hybrid(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::unpack_comm(int n, int first, double *buf) -{ - int i,k,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK); - - // unpack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->unpack_comm_hybrid(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::unpack_comm_vel(int n, int first, double *buf) -{ - int i,k,m,last; - int omega_flag = atom->omega_flag; - int angmom_flag = atom->angmom_flag; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - if (omega_flag) { - h_omega(i,0) = buf[m++]; - h_omega(i,1) = buf[m++]; - h_omega(i,2) = buf[m++]; - } - if (angmom_flag) { - h_angmom(i,0) = buf[m++]; - h_angmom(i,1) = buf[m++]; - h_angmom(i,2) = buf[m++]; - } - } - - atomKK->modified(Host,X_MASK|V_MASK|OMEGA_MASK/*|ANGMOM_MASK*/); - - // unpack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->unpack_comm_hybrid(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_reverse(int n, int first, double *buf) -{ - atomKK->sync(Host,F_MASK); - - int i,k,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - buf[m++] = h_f(i,0); - buf[m++] = h_f(i,1); - buf[m++] = h_f(i,2); - } - - // pack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_reverse_hybrid(n,first,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::unpack_reverse(int n, int *list, double *buf) -{ - int i,j,k,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - h_f(j,0) += buf[m++]; - h_f(j,1) += buf[m++]; - h_f(j,2) += buf[m++]; - } - - atomKK->modified(Host,F_MASK); - - // unpack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->unpack_reverse_hybrid(n,list,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - atomKK->sync(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK); - - int i,j,k,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - } - } - - // pack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_border_hybrid(n,list,&buf[m]); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - atomKK->sync(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|V_MASK|OMEGA_MASK/*|ANGMOM_MASK*/); - int i,j,k,m; - double dx,dy,dz,dvx,dvy,dvz; - int omega_flag = atom->omega_flag; - int angmom_flag = atom->angmom_flag; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - if (omega_flag) { - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - if (angmom_flag) { - buf[m++] = h_angmom(j,0); - buf[m++] = h_angmom(j,1); - buf[m++] = h_angmom(j,2); - } - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - if (omega_flag) { - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - if (angmom_flag) { - buf[m++] = h_angmom(j,0); - buf[m++] = h_angmom(j,1); - buf[m++] = h_angmom(j,2); - } - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - if (h_mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - if (omega_flag) { - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - if (angmom_flag) { - buf[m++] = h_angmom(j,0); - buf[m++] = h_angmom(j,1); - buf[m++] = h_angmom(j,2); - } - } - } - } - - // pack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_border_hybrid(n,list,&buf[m]); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::unpack_border(int n, int first, double *buf) -{ - int i,k,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag[i] = (tagint) ubuf(buf[m++]).i; - h_type[i] = (int) ubuf(buf[m++]).i; - h_mask[i] = (int) ubuf(buf[m++]).i; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK); - - // unpack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->unpack_border_hybrid(n,first,&buf[m]); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,k,m,last; - int omega_flag = atom->omega_flag; - int angmom_flag = atom->angmom_flag; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag[i] = (tagint) ubuf(buf[m++]).i; - h_type[i] = (int) ubuf(buf[m++]).i; - h_mask[i] = (int) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - if (omega_flag) { - h_omega(i,0) = buf[m++]; - h_omega(i,1) = buf[m++]; - h_omega(i,2) = buf[m++]; - } - if (angmom_flag) { - h_angmom(i,0) = buf[m++]; - h_angmom(i,1) = buf[m++]; - h_angmom(i,2) = buf[m++]; - } - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|V_MASK|OMEGA_MASK/*|ANGMOM_MASK*/); - - // unpack sub-style contributions as contiguous chunks - - for (k = 0; k < nstyles; k++) - m += styles[k]->unpack_border_hybrid(n,first,&buf[m]); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- - pack data for atom I for sending to another proc - pack each sub-style one after the other -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_exchange(int i, double *buf) -{ - int k,m; - - int tmp = atom->nextra_grow; - atom->nextra_grow = 0; - - m = 0; - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_exchange(i,&buf[m]); - - atom->nextra_grow = tmp; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for single atom received from another proc - unpack each sub-style one after the other - grow() occurs here so arrays for all sub-styles are grown -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::unpack_exchange(double *buf) -{ - int k,m; - - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - int tmp = atom->nextra_grow; - atom->nextra_grow = 0; - - m = 0; - for (k = 0; k < nstyles; k++) { - m += styles[k]->unpack_exchange(&buf[m]); - atom->nlocal--; - } - - atom->nextra_grow = tmp; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::size_restart() -{ - int tmp = atom->nextra_restart; - atom->nextra_restart = 0; - - int n = 0; - for (int k = 0; k < nstyles; k++) - n += styles[k]->size_restart(); - - atom->nextra_restart = tmp; - - int nlocal = atom->nlocal; - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (int i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - pack each sub-style one after the other -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::pack_restart(int i, double *buf) -{ - int tmp = atom->nextra_restart; - atom->nextra_restart = 0; - - int m = 0; - for (int k = 0; k < nstyles; k++) - m += styles[k]->pack_restart(i,&buf[m]); - - atom->nextra_restart = tmp; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities - unpack each sub-style one after the other - grow() occurs here so arrays for all sub-styles are grown -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::unpack_restart(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - - int tmp = atom->nextra_store; - atom->nextra_store = 0; - - int m = 0; - for (int k = 0; k < nstyles; k++) { - m += styles[k]->unpack_restart(&buf[m]); - atom->nlocal--; - } - atom->nextra_store = tmp; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - create each sub-style one after the other - grow() occurs here so arrays for all sub-styles are grown -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - for (int k = 0; k < nstyles; k++) { - styles[k]->create_atom(itype,coord); - atom->nlocal--; - } - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - grow() occurs here so arrays for all sub-styles are grown -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - atomKK->sync(Host,X_MASK|TAG_MASK|TYPE_MASK|IMAGE_MASK|MASK_MASK|V_MASK|OMEGA_MASK/*|ANGMOM_MASK*/); - - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - h_tag[nlocal] = utils::tnumeric(FLERR,values[0],true,lmp); - h_type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp); - extract = values[1]; - if (h_type[nlocal] <= 0 || h_type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom h_type in Atoms section of data file"); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image[nlocal] = imagetmp; - h_mask[nlocal] = 1; - - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - if (atom->omega_flag) { - h_omega(nlocal,0) = 0.0; - h_omega(nlocal,1) = 0.0; - h_omega(nlocal,2) = 0.0; - } - if (atom->angmom_flag) { - h_angmom(nlocal,0) = 0.0; - h_angmom(nlocal,1) = 0.0; - h_angmom(nlocal,2) = 0.0; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|IMAGE_MASK|MASK_MASK|V_MASK|OMEGA_MASK/*|ANGMOM_MASK*/); - - // each sub-style parses sub-style specific values - - int m = 5; - for (int k = 0; k < nstyles; k++) - m += styles[k]->data_atom_hybrid(nlocal,values,m); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Velocities section of data file -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::data_vel(int m, const std::vector &values) -{ - atomKK->sync(Host,V_MASK); - - int ivalue = 1; - h_v(m,0) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_v(m,1) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_v(m,2) = utils::numeric(FLERR,values[ivalue++],true,lmp); - - atomKK->modified(Host,V_MASK); - - // each sub-style parses sub-style specific values - - for (int k = 0; k < nstyles; k++) - ivalue += styles[k]->data_vel_hybrid(m,values,ivalue); -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::pack_data(double **buf) -{ - atomKK->sync(Host,TAG_MASK|TYPE_MASK|X_MASK); - - int k,m; - - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = ubuf(h_tag[i]).d; - buf[i][1] = ubuf(h_type[i]).d; - buf[i][2] = h_x(i,0); - buf[i][3] = h_x(i,1); - buf[i][4] = h_x(i,2); - - m = 5; - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_data_hybrid(i,&buf[i][m]); - - buf[i][m] = ubuf((h_image[i] & IMGMASK) - IMGMAX).d; - buf[i][m+1] = ubuf((h_image[i] >> IMGBITS & IMGMASK) - IMGMAX).d; - buf[i][m+2] = ubuf((h_image[i] >> IMG2BITS) - IMGMAX).d; - } -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 h_image flags -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::write_data(FILE *fp, int n, double **buf) -{ - int k,m; - - for (int i = 0; i < n; i++) { - fmt::print(fp,"{} {} {:.16e} {:.16e} {:.16e}", ubuf(buf[i][0]).i, ubuf(buf[i][1]).i, - buf[i][2], buf[i][3], buf[i][4]); - - m = 5; - for (k = 0; k < nstyles; k++) - m += styles[k]->write_data_hybrid(fp,&buf[i][m]); - - fmt::print(fp," {} {} {}\n", ubuf(buf[i][m]).i, ubuf(buf[i][m+1]).i, ubuf(buf[i][m+2]).i); - } -} - -/* ---------------------------------------------------------------------- - pack velocity info for data file -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::pack_vel(double **buf) -{ - atomKK->sync(Host,V_MASK); - - int k,m; - - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = ubuf(h_tag[i]).d; - buf[i][1] = h_v(i,0); - buf[i][2] = h_v(i,1); - buf[i][3] = h_v(i,2); - - m = 4; - for (k = 0; k < nstyles; k++) - m += styles[k]->pack_vel_hybrid(i,&buf[i][m]); - } -} - -/* ---------------------------------------------------------------------- - write velocity info to data file -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::write_vel(FILE *fp, int n, double **buf) -{ - int k,m; - - for (int i = 0; i < n; i++) { - fmt::print(fp,"{} {} {} {}", (tagint) ubuf(buf[i][0]).i,buf[i][1],buf[i][2],buf[i][3]); - - m = 4; - for (k = 0; k < nstyles; k++) - m += styles[k]->write_vel_hybrid(fp,&buf[i][m]); - - fprintf(fp,"\n"); - } -} - -/* ---------------------------------------------------------------------- - assign an index to named atom property and return index - returned value encodes which sub-style and index returned by sub-style - return -1 if name is unknown to any sub-styles -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::property_atom(const std::string &name) -{ - for (int k = 0; k < nstyles; k++) { - int index = styles[k]->property_atom(name); - if (index >= 0) return index*nstyles + k; - } - return -1; -} - -/* ---------------------------------------------------------------------- - pack per-atom data into buf for ComputePropertyAtom - index maps to data specific to this atom style -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::pack_property_atom(int multiindex, double *buf, int nvalues, int groupbit) -{ - int k = multiindex % nstyles; - int index = multiindex/nstyles; - styles[k]->pack_property_atom(index,buf,nvalues,groupbit); -} - -/* ---------------------------------------------------------------------- - allstyles = list of all atom styles in this LAMMPS executable -------------------------------------------------------------------------- */ - -void AtomVecHybridKokkos::build_styles() -{ - nallstyles = 0; -#define ATOM_CLASS -#define AtomStyle(key,Class) nallstyles++; -#include "style_atom.h" -#undef AtomStyle -#undef ATOM_CLASS - - allstyles = new char*[nallstyles]; - - nallstyles = 0; -#define ATOM_CLASS -#define AtomStyle(key,Class) \ - allstyles[nallstyles] = utils::strdup(#key); \ - nallstyles++; -#include "style_atom.h" // IWYU pragma: keep -#undef AtomStyle -#undef ATOM_CLASS -} - -/* ---------------------------------------------------------------------- - allstyles = list of all known atom styles -------------------------------------------------------------------------- */ - -int AtomVecHybridKokkos::known_style(char *str) -{ - for (int i = 0; i < nallstyles; i++) - if (strcmp(str,allstyles[i]) == 0) return 1; - return 0; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecHybridKokkos::memory_usage() -{ - double bytes = 0; - for (int k = 0; k < nstyles; k++) bytes += styles[k]->memory_usage(); - return bytes; -} +// TODO: move dynamic_cast into init /* ---------------------------------------------------------------------- */ void AtomVecHybridKokkos::sync(ExecutionSpace space, unsigned int h_mask) { - for (int k = 0; k < nstyles; k++) ((AtomVecKokkos*) styles[k])->sync(space,h_mask); + for (int k = 0; k < nstyles; k++) (dynamic_cast(styles[k]))->sync(space,h_mask); } /* ---------------------------------------------------------------------- */ void AtomVecHybridKokkos::sync_overlapping_device(ExecutionSpace space, unsigned int h_mask) { - for (int k = 0; k < nstyles; k++) ((AtomVecKokkos*) styles[k])->sync_overlapping_device(space,h_mask); + for (int k = 0; k < nstyles; k++) (dynamic_cast(styles[k]))->sync_overlapping_device(space,h_mask); } /* ---------------------------------------------------------------------- */ void AtomVecHybridKokkos::modified(ExecutionSpace space, unsigned int h_mask) { - for (int k = 0; k < nstyles; k++) ((AtomVecKokkos*) styles[k])->modified(space,h_mask); + for (int k = 0; k < nstyles; k++) (dynamic_cast(styles[k]))->modified(space,h_mask); } diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.h b/src/KOKKOS/atom_vec_hybrid_kokkos.h index a815779336..5249f3ef93 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.h +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.h @@ -22,11 +22,12 @@ AtomStyle(hybrid/kk,AtomVecHybridKokkos); #define LMP_ATOM_VEC_HYBRID_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_hybrid.h" #include "kokkos_type.h" namespace LAMMPS_NS { -class AtomVecHybridKokkos : public AtomVecKokkos { +class AtomVecHybridKokkos : public AtomVecKokkos, public AtomVecHybrid { public: int nstyles; class AtomVec **styles; @@ -34,39 +35,6 @@ class AtomVecHybridKokkos : public AtomVecKokkos { AtomVecHybridKokkos(class LAMMPS *); ~AtomVecHybridKokkos() override; - void process_args(int, char **) override; - void init() override; - void grow(int) override; - void grow_pointers() override; - void copy(int, int, int) override; - void clear_bonus() override; - void force_clear(int, size_t) override; - int pack_comm(int, int *, double *, int, int *) override; - int pack_comm_vel(int, int *, double *, int, int *) override; - void unpack_comm(int, int, double *) override; - void unpack_comm_vel(int, int, double *) override; - int pack_reverse(int, int, double *) override; - void unpack_reverse(int, int *, double *) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override {return 0;} - void data_vel(int, const std::vector &) override; - void pack_data(double **) override; - void write_data(FILE *, int, double **) override; - void pack_vel(double **) override; - void write_vel(FILE *, int, double **) override; - int property_atom(const std::string &) override; - void pack_property_atom(int, double *, int, int) override; - double memory_usage() override; int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, const int & iswap, diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index 12b6a5e1af..6286dae0f9 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -32,22 +32,10 @@ AtomVecKokkos::AtomVecKokkos(LAMMPS *lmp) : AtomVec(lmp) no_comm_vel_flag = 0; no_border_vel_flag = 1; -} -/* ---------------------------------------------------------------------- - roundup N so it is a multiple of DELTA - error if N exceeds 32-bit int, since will be used as arg to grow() - overload needed because Kokkos uses a smaller DELTA than in atom_vec.cpp - and an exponential instead of a linear growth -------------------------------------------------------------------------- */ - -bigint AtomVecKokkos::roundup(bigint n) -{ - auto DELTA = LMP_KOKKOS_AV_DELTA; - if (n % DELTA) n = n/DELTA * DELTA + DELTA; - if (n > MAXSMALLINT) - error->one(FLERR,"Too many atoms created on one or more procs"); - return n; + k_count = DAT::tdual_int_1d("atom::k_count",1); + atomKK = (AtomKokkos *) atom; + commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- */ @@ -708,138 +696,6 @@ void AtomVecKokkos::unpack_comm_vel_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -int AtomVecKokkos::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecKokkos::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - if (atom->mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecKokkos::unpack_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecKokkos::unpack_comm_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecKokkos_PackReverse { typedef DeviceType device_type; @@ -977,84 +833,3 @@ void AtomVecKokkos::unpack_reverse_kokkos(const int &n, atomKK->modified(Device,F_MASK); } } - -/* ---------------------------------------------------------------------- */ - -int AtomVecKokkos::pack_reverse(int n, int first, double *buf) -{ - if (n > 0) - atomKK->sync(Host,F_MASK); - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - buf[m++] = h_f(i,0); - buf[m++] = h_f(i,1); - buf[m++] = h_f(i,2); - } - - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecKokkos::unpack_reverse(int n, int *list, double *buf) -{ - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - h_f(j,0) += buf[m++]; - h_f(j,1) += buf[m++]; - h_f(j,2) += buf[m++]; - } - - if (n > 0) - atomKK->modified(Host,F_MASK); -} - -/* ---------------------------------------------------------------------- - * unpack one line from Velocities section of data file - * ------------------------------------------------------------------------- */ - -void AtomVecKokkos::data_vel(int m, const std::vector &values) -{ - double **v = atom->v; - int ivalue = 1; - v[m][0] = utils::numeric(FLERR,values[ivalue++],true,lmp); - v[m][1] = utils::numeric(FLERR,values[ivalue++],true,lmp); - v[m][2] = utils::numeric(FLERR,values[ivalue++],true,lmp); - - atomKK->modified(Host,V_MASK); -} - -/* ---------------------------------------------------------------------- - * pack velocity info for data file - * ------------------------------------------------------------------------- */ - -void AtomVecKokkos::pack_vel(double **buf) -{ - double **v = atom->v; - tagint *tag = atom->tag; - int nlocal = atom->nlocal; - - atomKK->sync(Host,V_MASK|TAG_MASK); - - for (int i = 0; i < nlocal; i++) { - buf[i][0] = ubuf(tag[i]).d; - buf[i][1] = v[i][0]; - buf[i][2] = v[i][1]; - buf[i][3] = v[i][2]; - } -} - -/* ---------------------------------------------------------------------- - * write velocity info to data file - * ------------------------------------------------------------------------- */ - -void AtomVecKokkos::write_vel(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,TAGINT_FORMAT " %-1.16e %-1.16e %-1.16e\n", - (tagint) ubuf(buf[i][0]).i,buf[i][1],buf[i][2],buf[i][3]); -} - diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index 0c8174ed9c..a332024a7d 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -33,21 +33,10 @@ union d_ubuf { d_ubuf(int arg) : i(arg) {} }; -class AtomVecKokkos : public AtomVec { +class AtomVecKokkos : virtual public AtomVec { public: AtomVecKokkos(class LAMMPS *); - bigint roundup(bigint) override; - int pack_comm(int, int *, double *, int, int *) override; - int pack_comm_vel(int, int *, double *, int, int *) override; - void unpack_comm(int, int, double *) override; - void unpack_comm_vel(int, int, double *) override; - int pack_reverse(int, int, double *) override; - void unpack_reverse(int, int *, double *) override; - void data_vel(int, const std::vector &) override; - void pack_vel(double **) override; - void write_vel(FILE *, int, double **) override; - virtual void sync(ExecutionSpace space, unsigned int mask) = 0; virtual void modified(ExecutionSpace space, unsigned int mask) = 0; virtual void sync_overlapping_device(ExecutionSpace space, unsigned int mask) = 0; @@ -130,7 +119,6 @@ class AtomVecKokkos : public AtomVec { int no_comm_vel_flag,no_border_vel_flag; protected: - HAT::t_x_array h_x; HAT::t_v_array h_v; HAT::t_f_array h_f; @@ -139,6 +127,8 @@ class AtomVecKokkos : public AtomVec { size_t buffer_size; void* buffer; + DAT::tdual_int_1d k_count; + #ifdef LMP_KOKKOS_GPU template Kokkos::Viewmolecule_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- @@ -233,70 +217,6 @@ void AtomVecMolecularKokkos::grow_pointers() h_improper_atom4 = atomKK->k_improper_atom4.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::copy(int i, int j, int delflag) -{ - int k; - - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_molecule(j) = h_molecule(i); - - h_num_bond(j) = h_num_bond(i); - for (k = 0; k < h_num_bond(j); k++) { - h_bond_type(j,k) = h_bond_type(i,k); - h_bond_atom(j,k) = h_bond_atom(i,k); - } - - h_nspecial(j,0) = h_nspecial(i,0); - h_nspecial(j,1) = h_nspecial(i,1); - h_nspecial(j,2) = h_nspecial(i,2); - for (k = 0; k < h_nspecial(j,2); k++) - h_special(j,k) = h_special(i,k); - - h_num_angle(j) = h_num_angle(i); - for (k = 0; k < h_num_angle(j); k++) { - h_angle_type(j,k) = h_angle_type(i,k); - h_angle_atom1(j,k) = h_angle_atom1(i,k); - h_angle_atom2(j,k) = h_angle_atom2(i,k); - h_angle_atom3(j,k) = h_angle_atom3(i,k); - } - - h_num_dihedral(j) = h_num_dihedral(i); - for (k = 0; k < h_num_dihedral(j); k++) { - h_dihedral_type(j,k) = h_dihedral_type(i,k); - h_dihedral_atom1(j,k) = h_dihedral_atom1(i,k); - h_dihedral_atom2(j,k) = h_dihedral_atom2(i,k); - h_dihedral_atom3(j,k) = h_dihedral_atom3(i,k); - h_dihedral_atom4(j,k) = h_dihedral_atom4(i,k); - } - - h_num_improper(j) = h_num_improper(i); - for (k = 0; k < h_num_improper(j); k++) { - h_improper_type(j,k) = h_improper_type(i,k); - h_improper_atom1(j,k) = h_improper_atom1(i,k); - h_improper_atom2(j,k) = h_improper_atom2(i,k); - h_improper_atom3(j,k) = h_improper_atom3(i,k); - h_improper_atom4(j,k) = h_improper_atom4(i,k); - } - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -580,171 +500,6 @@ void AtomVecMolecularKokkos::unpack_comm_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -int AtomVecMolecularKokkos::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::unpack_comm(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::unpack_comm_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_reverse(int n, int first, double *buf) -{ - if (n > 0) - atomKK->sync(Host,F_MASK); - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - buf[m++] = h_f(i,0); - buf[m++] = h_f(i,1); - buf[m++] = h_f(i,2); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::unpack_reverse(int n, int *list, double *buf) -{ - if (n > 0) - atomKK->modified(Host,F_MASK); - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - h_f(j,0) += buf[m++]; - h_f(j,1) += buf[m++]; - h_f(j,2) += buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecMolecularKokkos_PackBorder { typedef DeviceType device_type; @@ -846,149 +601,6 @@ int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendli /* ---------------------------------------------------------------------- */ -int AtomVecMolecularKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = ubuf(h_molecule(j)).d; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_molecule(j); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecMolecularKokkos_UnpackBorder { typedef DeviceType device_type; @@ -1049,78 +661,6 @@ void AtomVecMolecularKokkos::unpack_border_kokkos(const int &n, const int &first /* ---------------------------------------------------------------------- */ -void AtomVecMolecularKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - while (last > nmax) grow(0); - - for (i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|MOLECULE_MASK|V_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) - h_molecule(i) = (tagint) ubuf(buf[m++]).i; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecMolecularKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -1393,66 +933,6 @@ int AtomVecMolecularKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfl /* ---------------------------------------------------------------------- */ -int AtomVecMolecularKokkos::pack_exchange(int i, double *buf) -{ - int k; - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(h_bond_type(i,k)).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - buf[m++] = ubuf(h_num_angle(i)).d; - for (k = 0; k < h_num_angle(i); k++) { - buf[m++] = ubuf(h_angle_type(i,k)).d; - buf[m++] = ubuf(h_angle_atom1(i,k)).d; - buf[m++] = ubuf(h_angle_atom2(i,k)).d; - buf[m++] = ubuf(h_angle_atom3(i,k)).d; - } - buf[m++] = ubuf(h_num_dihedral(i)).d; - for (k = 0; k < h_num_dihedral(i); k++) { - buf[m++] = ubuf(h_dihedral_type(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom1(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom2(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom3(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom4(i,k)).d; - } - buf[m++] = ubuf(h_num_improper(i)).d; - for (k = 0; k < h_num_improper(i); k++) { - buf[m++] = ubuf(h_improper_type(i,k)).d; - buf[m++] = ubuf(h_improper_atom1(i,k)).d; - buf[m++] = ubuf(h_improper_atom2(i,k)).d; - buf[m++] = ubuf(h_improper_atom3(i,k)).d; - buf[m++] = ubuf(h_improper_atom4(i,k)).d; - } - buf[m++] = ubuf(h_nspecial(i,0)).d; - buf[m++] = ubuf(h_nspecial(i,1)).d; - buf[m++] = ubuf(h_nspecial(i,2)).d; - for (k = 0; k < h_nspecial(i,2); k++) - buf[m++] = ubuf(h_special(i,k)).d; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecMolecularKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -1619,444 +1099,6 @@ int AtomVecMolecularKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,i /* ---------------------------------------------------------------------- */ -int AtomVecMolecularKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - - int k; - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_angle(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_angle(nlocal); k++) { - h_angle_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_angle_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_dihedral(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_dihedral(nlocal); k++) { - h_dihedral_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_dihedral_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_num_improper(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_improper(nlocal); k++) { - h_improper_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_improper_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - h_nspecial(nlocal,0) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,1) = (int) ubuf(buf[m++]).i; - h_nspecial(nlocal,2) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_nspecial(nlocal,2); k++) - h_special(nlocal,k) = (tagint) ubuf(buf[m++]).i; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 0; - for (i = 0; i < nlocal; i++) - n += 16 + 2*num_bond[i] + 4*num_angle[i] + - 5*num_dihedral[i] + 5*num_improper[i]; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = ubuf(h_molecule(i)).d; - - buf[m++] = ubuf(h_num_bond(i)).d; - for (int k = 0; k < h_num_bond(i); k++) { - buf[m++] = ubuf(MAX(h_bond_type(i,k),-h_bond_type(i,k))).d; - buf[m++] = ubuf(h_bond_atom(i,k)).d; - } - - buf[m++] = ubuf(h_num_angle(i)).d; - for (int k = 0; k < h_num_angle(i); k++) { - buf[m++] = ubuf(MAX(h_angle_type(i,k),-h_angle_type(i,k))).d; - buf[m++] = ubuf(h_angle_atom1(i,k)).d; - buf[m++] = ubuf(h_angle_atom2(i,k)).d; - buf[m++] = ubuf(h_angle_atom3(i,k)).d; - } - - buf[m++] = ubuf(h_num_dihedral(i)).d; - for (int k = 0; k < h_num_dihedral(i); k++) { - buf[m++] = ubuf(MAX(h_dihedral_type(i,k),-h_dihedral_type(i,k))).d; - buf[m++] = ubuf(h_dihedral_atom1(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom2(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom3(i,k)).d; - buf[m++] = ubuf(h_dihedral_atom4(i,k)).d; - } - - buf[m++] = ubuf(h_num_improper(i)).d; - for (int k = 0; k < h_num_improper(i); k++) { - buf[m++] = ubuf(MAX(h_improper_type(i,k),-h_improper_type(i,k))).d; - buf[m++] = ubuf(h_improper_atom1(i,k)).d; - buf[m++] = ubuf(h_improper_atom2(i,k)).d; - buf[m++] = ubuf(h_improper_atom3(i,k)).d; - buf[m++] = ubuf(h_improper_atom4(i,k)).d; - } - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::unpack_restart(double *buf) -{ - int k; - - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | MOLECULE_MASK | BOND_MASK | - ANGLE_MASK | DIHEDRAL_MASK | IMPROPER_MASK | SPECIAL_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_molecule(nlocal) = (tagint) ubuf(buf[m++]).i; - - h_num_bond(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_bond(nlocal); k++) { - h_bond_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_bond_atom(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_angle(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_angle(nlocal); k++) { - h_angle_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_angle_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_angle_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_dihedral(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_dihedral(nlocal); k++) { - h_dihedral_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_dihedral_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_dihedral_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_num_improper(nlocal) = (int) ubuf(buf[m++]).i; - for (k = 0; k < h_num_improper(nlocal); k++) { - h_improper_type(nlocal,k) = (int) ubuf(buf[m++]).i; - h_improper_atom1(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom2(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom3(nlocal,k) = (tagint) ubuf(buf[m++]).i; - h_improper_atom4(nlocal,k) = (tagint) ubuf(buf[m++]).i; - } - - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - atomKK->modified(Host,ALL_MASK); - grow(0); - } - atomKK->modified(Host,ALL_MASK); - - tag[nlocal] = 0; - type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask(nlocal) = 1; - h_image(nlocal) = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_molecule(nlocal) = 0; - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_num_dihedral(nlocal) = 0; - h_num_improper(nlocal) = 0; - h_nspecial(nlocal,0) = h_nspecial(nlocal,1) = h_nspecial(nlocal,2) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,ALL_MASK); - - h_tag(nlocal) = utils::inumeric(FLERR,values[0],true,lmp); - h_molecule(nlocal) = utils::inumeric(FLERR,values[1],true,lmp); - h_type(nlocal) = utils::inumeric(FLERR,values[2],true,lmp); - extract = values[2]; - if (h_type(nlocal) <= 0 || h_type(nlocal) > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image(nlocal) = imagetmp; - - h_mask(nlocal) = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_num_dihedral(nlocal) = 0; - h_num_improper(nlocal) = 0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_molecule(nlocal) = utils::inumeric(FLERR,values[offset],true,lmp); - h_num_bond(nlocal) = 0; - h_num_angle(nlocal) = 0; - h_num_dihedral(nlocal) = 0; - h_num_improper(nlocal) = 0; - return 1; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag(i); - buf[i][1] = h_molecule(i); - buf[i][2] = h_type(i); - buf[i][3] = h_x(i,0); - buf[i][4] = h_x(i,1); - buf[i][5] = h_x(i,2); - buf[i][6] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_data_hybrid(int i, double *buf) -{ - buf[0] = h_molecule(i); - return 1; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %d %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1], (int) buf[i][2], - buf[i][3],buf[i][4],buf[i][5], - (int) buf[i][6],(int) buf[i][7],(int) buf[i][8]); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," " TAGINT_FORMAT, (tagint) (buf[0])); - return 1; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecMolecularKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - if (atom->memcheck("molecule")) bytes += memory->usage(molecule,nmax); - if (atom->memcheck("nspecial")) bytes += memory->usage(nspecial,nmax,3); - if (atom->memcheck("special")) - bytes += memory->usage(special,nmax,atom->maxspecial); - - if (atom->memcheck("num_bond")) bytes += memory->usage(num_bond,nmax); - if (atom->memcheck("bond_type")) - bytes += memory->usage(bond_type,nmax,atom->bond_per_atom); - if (atom->memcheck("bond_atom")) - bytes += memory->usage(bond_atom,nmax,atom->bond_per_atom); - - if (atom->memcheck("num_angle")) bytes += memory->usage(num_angle,nmax); - if (atom->memcheck("angle_type")) - bytes += memory->usage(angle_type,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom1")) - bytes += memory->usage(angle_atom1,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom2")) - bytes += memory->usage(angle_atom2,nmax,atom->angle_per_atom); - if (atom->memcheck("angle_atom3")) - bytes += memory->usage(angle_atom3,nmax,atom->angle_per_atom); - - if (atom->memcheck("num_dihedral")) bytes += memory->usage(num_dihedral,nmax); - if (atom->memcheck("dihedral_type")) - bytes += memory->usage(dihedral_type,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom1")) - bytes += memory->usage(dihedral_atom1,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom2")) - bytes += memory->usage(dihedral_atom2,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom3")) - bytes += memory->usage(dihedral_atom3,nmax,atom->dihedral_per_atom); - if (atom->memcheck("dihedral_atom4")) - bytes += memory->usage(dihedral_atom4,nmax,atom->dihedral_per_atom); - if (atom->memcheck("num_improper")) bytes += memory->usage(num_improper,nmax); - if (atom->memcheck("improper_type")) - bytes += memory->usage(improper_type,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom1")) - bytes += memory->usage(improper_atom1,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom2")) - bytes += memory->usage(improper_atom2,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom3")) - bytes += memory->usage(improper_atom3,nmax,atom->improper_per_atom); - if (atom->memcheck("improper_atom4")) - bytes += memory->usage(improper_atom4,nmax,atom->improper_per_atom); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecMolecularKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -2377,4 +1419,3 @@ void AtomVecMolecularKokkos::modified(ExecutionSpace space, unsigned int mask) } } } - diff --git a/src/KOKKOS/atom_vec_molecular_kokkos.h b/src/KOKKOS/atom_vec_molecular_kokkos.h index 7f7cb82028..0e0eb3af95 100644 --- a/src/KOKKOS/atom_vec_molecular_kokkos.h +++ b/src/KOKKOS/atom_vec_molecular_kokkos.h @@ -24,41 +24,15 @@ AtomStyle(molecular/kk/host,AtomVecMolecularKokkos); #define LMP_ATOM_VEC_MOLECULAR_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_molecular.h" namespace LAMMPS_NS { -class AtomVecMolecularKokkos : public AtomVecKokkos { +class AtomVecMolecularKokkos : public AtomVecKokkos, public AtomVecMolecular { public: AtomVecMolecularKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_comm(int, int *, double *, int, int *) override; - int pack_comm_vel(int, int *, double *, int, int *) override; - void unpack_comm(int, int, double *) override; - void unpack_comm_vel(int, int, double *) override; - int pack_reverse(int, int, double *) override; - void unpack_reverse(int, int *, double *) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - void grow_pointers() override; int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, const int & iswap, @@ -167,9 +141,6 @@ class AtomVecMolecularKokkos : public AtomVecKokkos { HAT::t_int_2d h_improper_type; HAT::t_tagint_2d h_improper_atom1,h_improper_atom2, h_improper_atom3,h_improper_atom4; - - HAT::tdual_int_1d k_count; - }; } diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index 023b4ab6a7..b197e7c831 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -33,55 +33,12 @@ using namespace MathConst; /* ---------------------------------------------------------------------- */ -AtomVecSphereKokkos::AtomVecSphereKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecSphereKokkos::AtomVecSphereKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecSphere(lmp) { - molecular = Atom::ATOMIC; - - comm_x_only = 1; - comm_f_only = 0; - size_forward = 3; - size_reverse = 6; - size_border = 8; - size_velocity = 6; - size_data_atom = 7; - size_data_vel = 7; - xcol_data = 5; - - atom->sphere_flag = 1; - atom->radius_flag = atom->rmass_flag = atom->omega_flag = - atom->torque_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; - no_border_vel_flag = 0; } -/* ---------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::init() -{ - AtomVec::init(); - - // set radvary if particle diameters are time-varying due to fix adapt - - radvary = 0; - comm_x_only = 1; - size_forward = 3; - - for (int i = 0; i < modify->nfix; i++) { - if (strcmp(modify->fix[i]->style,"adapt") == 0) { - FixAdapt *fix = (FixAdapt *) modify->fix[i]; - if (fix->diamflag) { - radvary = 1; - comm_x_only = 0; - size_forward = 5; - } - } - } -} - /* ---------------------------------------------------------------------- grow atom arrays n = 0 grows arrays by a chunk @@ -165,42 +122,6 @@ void AtomVecSphereKokkos::grow_pointers() h_torque = atomKK->k_torque.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::copy(int i, int j, int delflag) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | RADIUS_MASK | - RMASS_MASK | OMEGA_MASK); - - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - h_mask[j] = h_mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_radius[j] = h_radius[i]; - h_rmass[j] = h_rmass[i]; - h_omega(j,0) = h_omega(i,0); - h_omega(j,1) = h_omega(i,1); - h_omega(j,2) = h_omega(i,2); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | RADIUS_MASK | - RMASS_MASK | OMEGA_MASK); -} - /* ---------------------------------------------------------------------- */ template @@ -1035,397 +956,6 @@ void AtomVecSphereKokkos::unpack_comm_vel_kokkos( /* ---------------------------------------------------------------------- */ -int AtomVecSphereKokkos::pack_comm(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - if (radvary == 0) { - // Not sure if we need to call sync for X here - atomKK->sync(Host,X_MASK); - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - } - } - } else { - atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK); - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - } - } - } - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_comm_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - if (radvary == 0) { - atomKK->sync(Host,X_MASK|V_MASK|OMEGA_MASK); - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } - } - } else { - atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]*domain->xprd + pbc[5]*domain->xy + pbc[4]*domain->xz; - dy = pbc[1]*domain->yprd + pbc[3]*domain->yz; - dz = pbc[2]*domain->zprd; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } - } - } - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_comm_hybrid(int n, int *list, double *buf) -{ - if (radvary == 0) return 0; - - atomKK->sync(Host,RADIUS_MASK|RMASS_MASK); - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::unpack_comm(int n, int first, double *buf) -{ - if (radvary == 0) { - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - } - atomKK->modified(Host,X_MASK); - } else { - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_radius[i] = buf[m++]; - h_rmass[i] = buf[m++]; - } - atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK); - } -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::unpack_comm_vel(int n, int first, double *buf) -{ - if (radvary == 0) { - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - h_omega(i,0) = buf[m++]; - h_omega(i,1) = buf[m++]; - h_omega(i,2) = buf[m++]; - } - atomKK->modified(Host,X_MASK|V_MASK|OMEGA_MASK); - } else { - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_radius[i] = buf[m++]; - h_rmass[i] = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - h_omega(i,0) = buf[m++]; - h_omega(i,1) = buf[m++]; - h_omega(i,2) = buf[m++]; - } - atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); - } -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::unpack_comm_hybrid(int n, int first, double *buf) -{ - if (radvary == 0) return 0; - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - h_radius[i] = buf[m++]; - h_rmass[i] = buf[m++]; - } - atomKK->modified(Host,RADIUS_MASK|RMASS_MASK); - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_reverse(int n, int first, double *buf) -{ - if (n > 0) - atomKK->sync(Host,F_MASK|TORQUE_MASK); - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - buf[m++] = h_f(i,0); - buf[m++] = h_f(i,1); - buf[m++] = h_f(i,2); - buf[m++] = h_torque(i,0); - buf[m++] = h_torque(i,1); - buf[m++] = h_torque(i,2); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_reverse_hybrid(int n, int first, double *buf) -{ - if (n > 0) - atomKK->sync(Host,TORQUE_MASK); - - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - buf[m++] = h_torque(i,0); - buf[m++] = h_torque(i,1); - buf[m++] = h_torque(i,2); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::unpack_reverse(int n, int *list, double *buf) -{ - if (n > 0) { - atomKK->modified(Host,F_MASK|TORQUE_MASK); - } - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - h_f(j,0) += buf[m++]; - h_f(j,1) += buf[m++]; - h_f(j,2) += buf[m++]; - h_torque(j,0) += buf[m++]; - h_torque(j,1) += buf[m++]; - h_torque(j,2) += buf[m++]; - } -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::unpack_reverse_hybrid(int n, int *list, double *buf) -{ - if (n > 0) { - atomKK->modified(Host,TORQUE_MASK); - } - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - h_torque(j,0) += buf[m++]; - h_torque(j,1) += buf[m++]; - h_torque(j,2) += buf[m++]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSphereKokkos_PackBorder { typedef DeviceType device_type; @@ -1541,60 +1071,6 @@ int AtomVecSphereKokkos::pack_border_kokkos( /* ---------------------------------------------------------------------- */ -int AtomVecSphereKokkos::pack_border( - int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - atomKK->sync(Host,ALL_MASK); - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSphereKokkos_PackBorderVel { typedef DeviceType device_type; @@ -1769,115 +1245,6 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( /* ---------------------------------------------------------------------- */ -int AtomVecSphereKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - atomKK->sync(Host,ALL_MASK); - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag[j]).d; - buf[m++] = ubuf(h_type[j]).d; - buf[m++] = ubuf(h_mask[j]).d; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - buf[m++] = h_omega(j,0); - buf[m++] = h_omega(j,1); - buf[m++] = h_omega(j,2); - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - atomKK->sync(Host,RADIUS_MASK|RMASS_MASK); - - int m = 0; - for (int i = 0; i < n; i++) { - const int j = list[i]; - buf[m++] = h_radius[j]; - buf[m++] = h_rmass[j]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSphereKokkos_UnpackBorder { typedef DeviceType device_type; @@ -1945,34 +1312,6 @@ void AtomVecSphereKokkos::unpack_border_kokkos(const int &n, const int &first, RADIUS_MASK|RMASS_MASK); } -/* ---------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::unpack_border(int n, int first, double *buf) -{ - int m = 0; - const int last = first + n; - while (last > nmax) grow(0); - - for (int i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag[i] = (tagint) ubuf(buf[m++]).i; - h_type[i] = (int) ubuf(buf[m++]).i; - h_mask[i] = (int) ubuf(buf[m++]).i; - h_radius[i] = buf[m++]; - h_rmass[i] = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|RADIUS_MASK|RMASS_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - - /* ---------------------------------------------------------------------- */ template @@ -2058,53 +1397,6 @@ void AtomVecSphereKokkos::unpack_border_vel_kokkos( /* ---------------------------------------------------------------------- */ -void AtomVecSphereKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int m = 0; - const int last = first + n; - while (last > nmax) grow(0); - - for (int i = first; i < last; i++) { - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag[i] = (tagint) ubuf(buf[m++]).i; - h_type[i] = (int) ubuf(buf[m++]).i; - h_mask[i] = (int) ubuf(buf[m++]).i; - h_radius[i] = buf[m++]; - h_rmass[i] = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - h_omega(i,0) = buf[m++]; - h_omega(i,1) = buf[m++]; - h_omega(i,2) = buf[m++]; - } - - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int m = 0; - const int last = first + n; - for (int i = first; i < last; i++) { - h_radius[i] = buf[m++]; - h_rmass[i] = buf[m++]; - } - atomKK->modified(Host,RADIUS_MASK|RMASS_MASK); - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSphereKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -2233,44 +1525,6 @@ int AtomVecSphereKokkos::pack_exchange_kokkos( return nsend*16; } -/* ---------------------------------------------------------------------- - pack data for atom I for sending to another proc - xyz must be 1st 3 values, so comm::exchange() can test on them -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_exchange(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK| RADIUS_MASK | RMASS_MASK | - OMEGA_MASK); - - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag[i]).d; - buf[m++] = ubuf(h_type[i]).d; - buf[m++] = ubuf(h_mask[i]).d; - buf[m++] = ubuf(h_image[i]).d; - - buf[m++] = h_radius[i]; - buf[m++] = h_rmass[i]; - buf[m++] = h_omega(i,0); - buf[m++] = h_omega(i,1); - buf[m++] = h_omega(i,2); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - /* ---------------------------------------------------------------------- */ template @@ -2366,437 +1620,6 @@ int AtomVecSphereKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int /* ---------------------------------------------------------------------- */ -int AtomVecSphereKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag[nlocal] = (tagint) ubuf(buf[m++]).i; - h_type[nlocal] = (int) ubuf(buf[m++]).i; - h_mask[nlocal] = (int) ubuf(buf[m++]).i; - h_image[nlocal] = (imageint) ubuf(buf[m++]).i; - - h_radius[nlocal] = buf[m++]; - h_rmass[nlocal] = buf[m++]; - h_omega(nlocal,0) = buf[m++]; - h_omega(nlocal,1) = buf[m++]; - h_omega(nlocal,2) = buf[m++]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | RADIUS_MASK | RMASS_MASK | - OMEGA_MASK); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 16 * nlocal; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | V_MASK | - RADIUS_MASK | RMASS_MASK | OMEGA_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag[i]).d; - buf[m++] = ubuf(h_type[i]).d; - buf[m++] = ubuf(h_mask[i]).d; - buf[m++] = ubuf(h_image[i]).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = h_radius[i]; - buf[m++] = h_rmass[i]; - buf[m++] = h_omega(i,0); - buf[m++] = h_omega(i,1); - buf[m++] = h_omega(i,2); - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::unpack_restart(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag[nlocal] = (tagint) ubuf(buf[m++]).i; - h_type[nlocal] = (int) ubuf(buf[m++]).i; - h_mask[nlocal] = (int) ubuf(buf[m++]).i; - h_image[nlocal] = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_radius[nlocal] = buf[m++]; - h_rmass[nlocal] = buf[m++]; - h_omega(nlocal,0) = buf[m++]; - h_omega(nlocal,1) = buf[m++]; - h_omega(nlocal,2) = buf[m++]; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atomKK->modified(Host,X_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | V_MASK | - RADIUS_MASK | RMASS_MASK | OMEGA_MASK); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - } - - h_tag[nlocal] = 0; - h_type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask[nlocal] = 1; - h_image[nlocal] = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_radius[nlocal] = 0.5; - h_rmass[nlocal] = 4.0*MY_PI/3.0 * h_radius[nlocal]*h_radius[nlocal]*h_radius[nlocal]; - h_omega(nlocal,0) = 0.0; - h_omega(nlocal,1) = 0.0; - h_omega(nlocal,2) = 0.0; - - atomKK->modified(Host,ALL_MASK); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - tag[nlocal] = utils::tnumeric(FLERR,values[0],true,lmp); - type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp); - extract = values[1]; - if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - radius[nlocal] = 0.5 * utils::numeric(FLERR,values[2],true,lmp); - if (radius[nlocal] < 0.0) - error->one(FLERR,"Invalid radius in Atoms section of data file"); - - double density = utils::numeric(FLERR,values[3],true,lmp); - if (density <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); - - if (radius[nlocal] == 0.0) rmass[nlocal] = density; - else - rmass[nlocal] = 4.0*MY_PI/3.0 * - radius[nlocal]*radius[nlocal]*radius[nlocal] * density; - - x[nlocal][0] = coord[0]; - x[nlocal][1] = coord[1]; - x[nlocal][2] = coord[2]; - - image[nlocal] = imagetmp; - - mask[nlocal] = 1; - v[nlocal][0] = 0.0; - v[nlocal][1] = 0.0; - v[nlocal][2] = 0.0; - omega[nlocal][0] = 0.0; - omega[nlocal][1] = 0.0; - omega[nlocal][2] = 0.0; - - atomKK->modified(Host,ALL_MASK); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - radius[nlocal] = 0.5 * utils::numeric(FLERR,values[offset],true,lmp); - if (radius[nlocal] < 0.0) - error->one(FLERR,"Invalid radius in Atoms section of data file"); - - double density = utils::numeric(FLERR,values[offset+1],true,lmp); - if (density <= 0.0) - error->one(FLERR,"Invalid density in Atoms section of data file"); - - if (radius[nlocal] == 0.0) rmass[nlocal] = density; - else - rmass[nlocal] = 4.0*MY_PI/3.0 * - radius[nlocal]*radius[nlocal]*radius[nlocal] * density; - - - atomKK->modified(Host,RADIUS_MASK|RMASS_MASK); - - return 2; -} - -/* ---------------------------------------------------------------------- - unpack one line from Velocities section of data file -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::data_vel(int m, const std::vector &values) -{ - int ivalue = 1; - atomKK->sync(Host,V_MASK|OMEGA_MASK); - h_v(m,0) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_v(m,1) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_v(m,2) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_omega(m,0) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_omega(m,1) = utils::numeric(FLERR,values[ivalue++],true,lmp); - h_omega(m,2) = utils::numeric(FLERR,values[ivalue++],true,lmp); - atomKK->modified(Host,V_MASK|OMEGA_MASK); -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Velocities section of data file -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::data_vel_hybrid(int m, const std::vector &values, - int offset) -{ - atomKK->sync(Host,OMEGA_MASK); - omega[m][0] = utils::numeric(FLERR,values[offset],true,lmp); - omega[m][1] = utils::numeric(FLERR,values[offset+1],true,lmp); - omega[m][2] = utils::numeric(FLERR,values[offset+2],true,lmp); - atomKK->modified(Host,OMEGA_MASK); - return 3; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::pack_data(double **buf) -{ - atomKK->sync(Host,TAG_MASK|TYPE_MASK|RADIUS_MASK|RMASS_MASK|X_MASK|IMAGE_MASK); - - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = ubuf(h_tag[i]).d; - buf[i][1] = ubuf(h_type[i]).d; - buf[i][2] = 2.0*h_radius[i]; - if (h_radius[i] == 0.0) buf[i][3] = h_rmass[i]; - else - buf[i][3] = h_rmass[i] / (4.0*MY_PI/3.0 * h_radius[i]*h_radius[i]*h_radius[i]); - buf[i][4] = h_x(i,0); - buf[i][5] = h_x(i,1); - buf[i][6] = h_x(i,2); - buf[i][7] = ubuf((h_image[i] & IMGMASK) - IMGMAX).d; - buf[i][8] = ubuf((h_image[i] >> IMGBITS & IMGMASK) - IMGMAX).d; - buf[i][9] = ubuf((h_image[i] >> IMG2BITS) - IMGMAX).d; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_data_hybrid(int i, double *buf) -{ - atomKK->sync(Host,RADIUS_MASK|RMASS_MASK); - - buf[0] = 2.0*h_radius[i]; - if (h_radius[i] == 0.0) buf[1] = h_rmass[i]; - else buf[1] = h_rmass[i] / (4.0*MY_PI/3.0 * h_radius[i]*h_radius[i]*h_radius[i]); - return 2; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,TAGINT_FORMAT - " %d %-1.16e %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d\n", - (tagint) ubuf(buf[i][0]).i,(int) ubuf(buf[i][1]).i, - buf[i][2],buf[i][3], - buf[i][4],buf[i][5],buf[i][6], - (int) ubuf(buf[i][7]).i,(int) ubuf(buf[i][8]).i, - (int) ubuf(buf[i][9]).i); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," %-1.16e %-1.16e",buf[0],buf[1]); - return 2; -} - -/* ---------------------------------------------------------------------- - pack velocity info for data file -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::pack_vel(double **buf) -{ - atomKK->sync(Host,TAG_MASK|V_MASK|OMEGA_MASK); - - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = ubuf(h_tag[i]).d; - buf[i][1] = h_v(i,0); - buf[i][2] = h_v(i,1); - buf[i][3] = h_v(i,2); - buf[i][4] = h_omega(i,0); - buf[i][5] = h_omega(i,1); - buf[i][6] = h_omega(i,2); - } -} - -/* ---------------------------------------------------------------------- - pack hybrid velocity info for data file -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::pack_vel_hybrid(int i, double *buf) -{ - atomKK->sync(Host,OMEGA_MASK); - - buf[0] = h_omega(i,0); - buf[1] = h_omega(i,1); - buf[2] = h_omega(i,2); - return 3; -} - -/* ---------------------------------------------------------------------- - write velocity info to data file -------------------------------------------------------------------------- */ - -void AtomVecSphereKokkos::write_vel(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,TAGINT_FORMAT - " %-1.16e %-1.16e %-1.16e %-1.16e %-1.16e %-1.16e\n", - (tagint) ubuf(buf[i][0]).i,buf[i][1],buf[i][2],buf[i][3], - buf[i][4],buf[i][5],buf[i][6]); -} - -/* ---------------------------------------------------------------------- - write hybrid velocity info to data file -------------------------------------------------------------------------- */ - -int AtomVecSphereKokkos::write_vel_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," %-1.16e %-1.16e %-1.16e",buf[0],buf[1],buf[2]); - return 3; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecSphereKokkos::memory_usage() -{ - double bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*comm->nthreads,3); - - if (atom->memcheck("radius")) bytes += memory->usage(radius,nmax); - if (atom->memcheck("rmass")) bytes += memory->usage(rmass,nmax); - if (atom->memcheck("omega")) bytes += memory->usage(omega,nmax,3); - if (atom->memcheck("torque")) - bytes += memory->usage(torque,nmax*comm->nthreads,3); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecSphereKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.h b/src/KOKKOS/atom_vec_sphere_kokkos.h index de3cd17065..c566f9ee50 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.h +++ b/src/KOKKOS/atom_vec_sphere_kokkos.h @@ -24,53 +24,17 @@ AtomStyle(sphere/kk/host,AtomVecSphereKokkos); #define LMP_ATOM_VEC_SPHERE_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_sphere.h" #include "kokkos_type.h" namespace LAMMPS_NS { -class AtomVecSphereKokkos : public AtomVecKokkos { +class AtomVecSphereKokkos : public AtomVecKokkos, public AtomVecSphere { public: AtomVecSphereKokkos(class LAMMPS *); - void init() override; void grow(int) override; void grow_pointers() override; - void copy(int, int, int) override; - int pack_comm(int, int *, double *, int, int *) override; - int pack_comm_vel(int, int *, double *, int, int *) override; - int pack_comm_hybrid(int, int *, double *) override; - void unpack_comm(int, int, double *) override; - void unpack_comm_vel(int, int, double *) override; - int unpack_comm_hybrid(int, int, double *) override; - int pack_reverse(int, int, double *) override; - int pack_reverse_hybrid(int, int, double *) override; - void unpack_reverse(int, int *, double *) override; - int unpack_reverse_hybrid(int, int *, double *) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void data_vel(int, const std::vector &) override; - int data_vel_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - void pack_vel(double **) override; - int pack_vel_hybrid(int, double *) override; - void write_vel(FILE *, int, double **) override; - int write_vel_hybrid(FILE *, double *) override; - double memory_usage() override; int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, const int & iswap, @@ -139,8 +103,6 @@ class AtomVecSphereKokkos : public AtomVecKokkos { HAT::t_v_array h_omega; DAT::t_f_array d_torque; HAT::t_f_array h_torque; - - DAT::tdual_int_1d k_count; }; } diff --git a/src/KOKKOS/atom_vec_spin_kokkos.cpp b/src/KOKKOS/atom_vec_spin_kokkos.cpp index cc54fefa80..655f2ec8c1 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.cpp +++ b/src/KOKKOS/atom_vec_spin_kokkos.cpp @@ -41,26 +41,10 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -AtomVecSpinKokkos::AtomVecSpinKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) +AtomVecSpinKokkos::AtomVecSpinKokkos(LAMMPS *lmp) : AtomVec(lmp), +AtomVecKokkos(lmp), AtomVecSpin(lmp) { - molecular = 0; - mass_type = 1; - forceclearflag = 1; - comm_x_only = comm_f_only = 0; - size_forward = 7; - size_reverse = 9; - size_border = 10; - size_velocity = 3; - size_data_atom = 9; - size_data_vel = 4; - xcol_data = 4; - - atom->sp_flag = 1; - - k_count = DAT::tdual_int_1d("atom::k_count",1); - atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- @@ -147,33 +131,6 @@ void AtomVecSpinKokkos::grow_pointers() h_fm_long = atomKK->k_fm_long.h_view; } -/* ---------------------------------------------------------------------- - copy atom I info to atom J -------------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::copy(int i, int j, int delflag) -{ - h_tag[j] = h_tag[i]; - h_type[j] = h_type[i]; - mask[j] = mask[i]; - h_image[j] = h_image[i]; - h_x(j,0) = h_x(i,0); - h_x(j,1) = h_x(i,1); - h_x(j,2) = h_x(i,2); - h_v(j,0) = h_v(i,0); - h_v(j,1) = h_v(i,1); - h_v(j,2) = h_v(i,2); - - h_sp(j,0) = h_sp(i,0); - h_sp(j,1) = h_sp(i,1); - h_sp(j,2) = h_sp(i,2); - h_sp(j,3) = h_sp(i,3); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - modify->fix[atom->extra_grow[iextra]]->copy_arrays(i,j,delflag); -} - /* ---------------------------------------------------------------------- */ template @@ -347,167 +304,6 @@ int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, D /* ---------------------------------------------------------------------- */ -int AtomVecSpinKokkos::pack_border(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_sp(j,0); - buf[m++] = h_sp(j,1); - buf[m++] = h_sp(j,2); - buf[m++] = h_sp(j,3); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_sp(j,0); - buf[m++] = h_sp(j,1); - buf[m++] = h_sp(j,2); - buf[m++] = h_sp(j,3); - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::pack_border_vel(int n, int *list, double *buf, - int pbc_flag, int *pbc) -{ - int i,j,m; - double dx,dy,dz,dvx,dvy,dvz; - - m = 0; - if (pbc_flag == 0) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0); - buf[m++] = h_x(j,1); - buf[m++] = h_x(j,2); - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_sp(j,0); - buf[m++] = h_sp(j,1); - buf[m++] = h_sp(j,2); - buf[m++] = h_sp(j,3); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - if (domain->triclinic == 0) { - dx = pbc[0]*domain->xprd; - dy = pbc[1]*domain->yprd; - dz = pbc[2]*domain->zprd; - } else { - dx = pbc[0]; - dy = pbc[1]; - dz = pbc[2]; - } - if (!deform_vremap) { - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_sp(j,0); - buf[m++] = h_sp(j,1); - buf[m++] = h_sp(j,2); - buf[m++] = h_sp(j,3); - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } else { - dvx = pbc[0]*h_rate[0] + pbc[5]*h_rate[5] + pbc[4]*h_rate[4]; - dvy = pbc[1]*h_rate[1] + pbc[3]*h_rate[3]; - dvz = pbc[2]*h_rate[2]; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_x(j,0) + dx; - buf[m++] = h_x(j,1) + dy; - buf[m++] = h_x(j,2) + dz; - buf[m++] = ubuf(h_tag(j)).d; - buf[m++] = ubuf(h_type(j)).d; - buf[m++] = ubuf(h_mask(j)).d; - buf[m++] = h_sp(j,0); - buf[m++] = h_sp(j,1); - buf[m++] = h_sp(j,2); - buf[m++] = h_sp(j,3); - if (mask[i] & deform_groupbit) { - buf[m++] = h_v(j,0) + dvx; - buf[m++] = h_v(j,1) + dvy; - buf[m++] = h_v(j,2) + dvz; - } else { - buf[m++] = h_v(j,0); - buf[m++] = h_v(j,1); - buf[m++] = h_v(j,2); - } - } - } - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]->pack_border(n,list,&buf[m]); - - return m; -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::pack_border_hybrid(int n, int *list, double *buf) -{ - int i,j,m; - - m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = h_sp(j,0); - buf[m++] = h_sp(j,1); - buf[m++] = h_sp(j,2); - buf[m++] = h_sp(j,3); - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSpinKokkos_UnpackBorder { typedef DeviceType device_type; @@ -568,87 +364,6 @@ void AtomVecSpinKokkos::unpack_border_kokkos(const int &n, const int &first, /* ---------------------------------------------------------------------- */ -void AtomVecSpinKokkos::unpack_border(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - - for (i = first; i < last; i++) { - if (i == nmax) { - grow(0); - } - atomKK->modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|SP_MASK); - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_sp(i,0) = buf[m++]; - h_sp(i,1) = buf[m++]; - h_sp(i,2) = buf[m++]; - h_sp(i,3) = buf[m++]; - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::unpack_border_vel(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - if (i == nmax) grow(0); - atomKK->modified(Host,X_MASK|V_MASK|TAG_MASK|TYPE_MASK|MASK_MASK|SP_MASK); - h_x(i,0) = buf[m++]; - h_x(i,1) = buf[m++]; - h_x(i,2) = buf[m++]; - h_tag(i) = (tagint) ubuf(buf[m++]).i; - h_type(i) = (int) ubuf(buf[m++]).i; - h_mask(i) = (int) ubuf(buf[m++]).i; - h_sp(i,0) = buf[m++]; - h_sp(i,1) = buf[m++]; - h_sp(i,2) = buf[m++]; - h_sp(i,3) = buf[m++]; - h_v(i,0) = buf[m++]; - h_v(i,1) = buf[m++]; - h_v(i,2) = buf[m++]; - } - - if (atom->nextra_border) - for (int iextra = 0; iextra < atom->nextra_border; iextra++) - m += modify->fix[atom->extra_border[iextra]]-> - unpack_border(n,first,&buf[m]); -} - -/* ---------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::unpack_border_hybrid(int n, int first, double *buf) -{ - int i,m,last; - - m = 0; - last = first + n; - for (i = first; i < last; i++) { - h_sp(i,0) = buf[m++]; - h_sp(i,1) = buf[m++]; - h_sp(i,2) = buf[m++]; - h_sp(i,3) = buf[m++]; - } - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSpinKokkos_PackExchangeFunctor { typedef DeviceType device_type; @@ -771,34 +486,6 @@ int AtomVecSpinKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2 /* ---------------------------------------------------------------------- */ -int AtomVecSpinKokkos::pack_exchange(int i, double *buf) -{ - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_sp(i,0); - buf[m++] = h_sp(i,1); - buf[m++] = h_sp(i,2); - buf[m++] = h_sp(i,3); - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]->pack_exchange(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecSpinKokkos_UnpackExchangeFunctor { typedef DeviceType device_type; @@ -886,321 +573,6 @@ int AtomVecSpinKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int nr /* ---------------------------------------------------------------------- */ -int AtomVecSpinKokkos::unpack_exchange(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | SP_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_sp(nlocal,0) = buf[m++]; - h_sp(nlocal,1) = buf[m++]; - h_sp(nlocal,2) = buf[m++]; - h_sp(nlocal,3) = buf[m++]; - - if (atom->nextra_grow) - for (int iextra = 0; iextra < atom->nextra_grow; iextra++) - m += modify->fix[atom->extra_grow[iextra]]-> - unpack_exchange(nlocal,&buf[m]); - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - size of restart data for all atoms owned by this proc - include extra data stored by fixes -------------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::size_restart() -{ - int i; - - int nlocal = atom->nlocal; - int n = 15 * nlocal; - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - for (i = 0; i < nlocal; i++) - n += modify->fix[atom->extra_restart[iextra]]->size_restart(i); - - return n; -} - -/* ---------------------------------------------------------------------- - pack atom I's data for restart file including extra quantities - xyz must be 1st 3 values, so that read_restart can test on them - molecular types may be negative, but write as positive -------------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::pack_restart(int i, double *buf) -{ - atomKK->sync(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | SP_MASK); - - int m = 1; - buf[m++] = h_x(i,0); - buf[m++] = h_x(i,1); - buf[m++] = h_x(i,2); - buf[m++] = ubuf(h_tag(i)).d; - buf[m++] = ubuf(h_type(i)).d; - buf[m++] = ubuf(h_mask(i)).d; - buf[m++] = ubuf(h_image(i)).d; - buf[m++] = h_v(i,0); - buf[m++] = h_v(i,1); - buf[m++] = h_v(i,2); - - buf[m++] = h_sp(i,0); - buf[m++] = h_sp(i,1); - buf[m++] = h_sp(i,2); - buf[m++] = h_sp(i,3); - - if (atom->nextra_restart) - for (int iextra = 0; iextra < atom->nextra_restart; iextra++) - m += modify->fix[atom->extra_restart[iextra]]->pack_restart(i,&buf[m]); - - buf[0] = m; - return m; -} - -/* ---------------------------------------------------------------------- - unpack data for one atom from restart file including extra quantities -------------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::unpack_restart(double *buf) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - grow(0); - if (atom->nextra_store) - memory->grow(atom->extra,nmax,atom->nextra_store,"atom:extra"); - } - - atomKK->modified(Host,X_MASK | V_MASK | TAG_MASK | TYPE_MASK | - MASK_MASK | IMAGE_MASK | SP_MASK); - - int m = 1; - h_x(nlocal,0) = buf[m++]; - h_x(nlocal,1) = buf[m++]; - h_x(nlocal,2) = buf[m++]; - h_tag(nlocal) = (tagint) ubuf(buf[m++]).i; - h_type(nlocal) = (int) ubuf(buf[m++]).i; - h_mask(nlocal) = (int) ubuf(buf[m++]).i; - h_image(nlocal) = (imageint) ubuf(buf[m++]).i; - h_v(nlocal,0) = buf[m++]; - h_v(nlocal,1) = buf[m++]; - h_v(nlocal,2) = buf[m++]; - - h_sp(nlocal,0) = buf[m++]; - h_sp(nlocal,1) = buf[m++]; - h_sp(nlocal,2) = buf[m++]; - h_sp(nlocal,3) = buf[m++]; - - double **extra = atom->extra; - if (atom->nextra_store) { - int size = static_cast (buf[0]) - m; - for (int i = 0; i < size; i++) extra[nlocal][i] = buf[m++]; - } - - atom->nlocal++; - return m; -} - -/* ---------------------------------------------------------------------- - create one atom of itype at coord - set other values to defaults -------------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::create_atom(int itype, double *coord) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) { - atomKK->modified(Host,ALL_MASK); - grow(0); - } - atomKK->sync(Host,ALL_MASK); - atomKK->modified(Host,ALL_MASK); - - h_tag[nlocal] = 0; - h_type[nlocal] = itype; - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - h_mask[nlocal] = 1; - h_image[nlocal] = ((imageint) IMGMAX << IMG2BITS) | - ((imageint) IMGMAX << IMGBITS) | IMGMAX; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - h_sp(nlocal,0) = 0.0; - h_sp(nlocal,1) = 0.0; - h_sp(nlocal,2) = 0.0; - h_sp(nlocal,3) = 0.0; - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack one line from Atoms section of data file - initialize other atom quantities -------------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::data_atom(double *coord, imageint imagetmp, - const std::vector &values, std::string &extract) -{ - int nlocal = atom->nlocal; - if (nlocal == nmax) grow(0); - - h_tag[nlocal] = utils::inumeric(FLERR,values[0],true,lmp); - h_type[nlocal] = utils::inumeric(FLERR,values[1],true,lmp); - extract = values[1]; - if (type[nlocal] <= 0 || type[nlocal] > atom->ntypes) - error->one(FLERR,"Invalid atom type in Atoms section of data file"); - - h_sp(nlocal,3) = utils::numeric(FLERR,values[2],true,lmp); - h_sp(nlocal,0) = utils::numeric(FLERR,values[6],true,lmp); - h_sp(nlocal,1) = utils::numeric(FLERR,values[7],true,lmp); - h_sp(nlocal,2) = utils::numeric(FLERR,values[8],true,lmp); - double inorm = 1.0/sqrt(sp[nlocal][0]*sp[nlocal][0] + - sp[nlocal][1]*sp[nlocal][1] + - sp[nlocal][2]*sp[nlocal][2]); - h_sp(nlocal,0) *= inorm; - h_sp(nlocal,1) *= inorm; - h_sp(nlocal,2) *= inorm; - - h_x(nlocal,0) = coord[0]; - h_x(nlocal,1) = coord[1]; - h_x(nlocal,2) = coord[2]; - - h_image[nlocal] = imagetmp; - - h_mask[nlocal] = 1; - h_v(nlocal,0) = 0.0; - h_v(nlocal,1) = 0.0; - h_v(nlocal,2) = 0.0; - - atomKK->modified(Host,ALL_MASK); - - atom->nlocal++; -} - -/* ---------------------------------------------------------------------- - unpack hybrid quantities from one line in Atoms section of data file - initialize other atom quantities for this sub-style -------------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::data_atom_hybrid(int nlocal, const std::vector &values, - int offset) -{ - h_sp(nlocal,3) = utils::numeric(FLERR,values[offset],true,lmp); - h_sp(nlocal,0) = utils::numeric(FLERR,values[offset+1],true,lmp); - h_sp(nlocal,1) = utils::numeric(FLERR,values[offset+2],true,lmp); - h_sp(nlocal,2) = utils::numeric(FLERR,values[offset+3],true,lmp); - double inorm = 1.0/sqrt(sp[nlocal][0]*sp[nlocal][0] + - sp[nlocal][1]*sp[nlocal][1] + - sp[nlocal][2]*sp[nlocal][2]); - sp[nlocal][0] *= inorm; - sp[nlocal][1] *= inorm; - sp[nlocal][2] *= inorm; - - return 4; -} - -/* ---------------------------------------------------------------------- - pack atom info for data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::pack_data(double **buf) -{ - int nlocal = atom->nlocal; - for (int i = 0; i < nlocal; i++) { - buf[i][0] = h_tag[i]; - buf[i][1] = h_type[i]; - buf[i][2] = h_sp(i,0); - buf[i][3] = h_x(i,0); - buf[i][4] = h_x(i,1); - buf[i][5] = h_x(i,2); - buf[i][2] = h_sp(i,1); - buf[i][2] = h_sp(i,2); - buf[i][2] = h_sp(i,3); - buf[i][6] = (h_image[i] & IMGMASK) - IMGMAX; - buf[i][7] = (h_image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][8] = (h_image[i] >> IMG2BITS) - IMGMAX; - } -} - -/* ---------------------------------------------------------------------- - pack hybrid atom info for data file -------------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::pack_data_hybrid(int i, double *buf) -{ - buf[0] = h_sp(i,3); - buf[1] = h_sp(i,0); - buf[2] = h_sp(i,1); - buf[3] = h_sp(i,2); - return 4; -} - -/* ---------------------------------------------------------------------- - write atom info to data file including 3 image flags -------------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::write_data(FILE *fp, int n, double **buf) -{ - for (int i = 0; i < n; i++) - fprintf(fp,"%d %d %-1.16e %-1.16e %-1.16e %-1.16e %d %d %d\n", - (int) buf[i][0],(int) buf[i][1],buf[i][2],buf[i][3],buf[i][4], - buf[i][5],(int) buf[i][6],(int) buf[i][7],(int) buf[i][8]); -} - -/* ---------------------------------------------------------------------- - write hybrid atom info to data file -------------------------------------------------------------------------- */ - -int AtomVecSpinKokkos::write_data_hybrid(FILE *fp, double *buf) -{ - fprintf(fp," %-1.16e %-1.16e %-1.16e %-1.16e",buf[0],buf[1],buf[2],buf[3]); - return 4; -} - -/* ---------------------------------------------------------------------- - return # of bytes of allocated memory -------------------------------------------------------------------------- */ - -double AtomVecSpinKokkos::memory_usage() -{ - bigint bytes = 0; - - if (atom->memcheck("tag")) bytes += memory->usage(tag,nmax); - if (atom->memcheck("type")) bytes += memory->usage(type,nmax); - if (atom->memcheck("mask")) bytes += memory->usage(mask,nmax); - if (atom->memcheck("image")) bytes += memory->usage(image,nmax); - if (atom->memcheck("x")) bytes += memory->usage(x,nmax,3); - if (atom->memcheck("v")) bytes += memory->usage(v,nmax,3); - if (atom->memcheck("f")) bytes += memory->usage(f,nmax*commKK->nthreads,3); - - if (atom->memcheck("sp")) bytes += memory->usage(sp,nmax,4); - if (atom->memcheck("fm")) bytes += memory->usage(fm,nmax*comm->nthreads,3); - if (atom->memcheck("fm_long")) bytes += memory->usage(fm_long,nmax*comm->nthreads,3); - - return bytes; -} - -/* ---------------------------------------------------------------------- */ - void AtomVecSpinKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { @@ -1303,14 +675,3 @@ void AtomVecSpinKokkos::sync_overlapping_device(ExecutionSpace space, unsigned i perform_async_copy(atomKK->k_fm_long,space); } } - -/* ---------------------------------------------------------------------- - clear all forces (mech and mag) -------------------------------------------------------------------------- */ - -void AtomVecSpinKokkos::force_clear(int n, size_t nbytes) -{ - memset(&f[n][0],0,3*nbytes); - memset(&fm[n][0],0,3*nbytes); - memset(&fm_long[n][0],0,3*nbytes); -} diff --git a/src/KOKKOS/atom_vec_spin_kokkos.h b/src/KOKKOS/atom_vec_spin_kokkos.h index 36895ef632..1d969fc510 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.h +++ b/src/KOKKOS/atom_vec_spin_kokkos.h @@ -24,39 +24,15 @@ AtomStyle(spin/kk/host,AtomVecSpinKokkos); #define LMP_ATOM_VEC_SPIN_KOKKOS_H #include "atom_vec_kokkos.h" +#include "atom_vec_spin.h" #include "kokkos_type.h" namespace LAMMPS_NS { -class AtomVecSpinKokkos : public AtomVecKokkos { +class AtomVecSpinKokkos : public AtomVecKokkos, public AtomVecSpin { public: AtomVecSpinKokkos(class LAMMPS *); void grow(int) override; - void copy(int, int, int) override; - int pack_border(int, int *, double *, int, int *) override; - int pack_border_vel(int, int *, double *, int, int *) override; - int pack_border_hybrid(int, int *, double *) override; - void unpack_border(int, int, double *) override; - void unpack_border_vel(int, int, double *) override; - int unpack_border_hybrid(int, int, double *) override; - int pack_exchange(int, double *) override; - int unpack_exchange(double *) override; - int size_restart() override; - int pack_restart(int, double *) override; - int unpack_restart(double *) override; - void create_atom(int, double *) override; - void data_atom(double *, imageint, const std::vector &, std::string &) override; - int data_atom_hybrid(int, const std::vector &, int) override; - void pack_data(double **) override; - int pack_data_hybrid(int, double *) override; - void write_data(FILE *, int, double **) override; - int write_data_hybrid(FILE *, double *) override; - double memory_usage() override; - - // clear magnetic and mechanic forces - - void force_clear(int, size_t) override; - void grow_pointers() override; // input lists to be checked int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, @@ -110,8 +86,6 @@ class AtomVecSpinKokkos : public AtomVecKokkos { HAT::t_sp_array h_sp; HAT::t_fm_array h_fm; HAT::t_fm_long_array h_fm_long; - - DAT::tdual_int_1d k_count; }; } diff --git a/src/KOKKOS/comm_kokkos.cpp b/src/KOKKOS/comm_kokkos.cpp index 2b603da635..a21d5482e7 100644 --- a/src/KOKKOS/comm_kokkos.cpp +++ b/src/KOKKOS/comm_kokkos.cpp @@ -146,8 +146,12 @@ void CommKokkos::init() if (!comm_f_only) // not all Kokkos atom_vec styles have reverse pack/unpack routines yet reverse_comm_classic = true; - if (ghost_velocity && ((AtomVecKokkos*)atom->avec)->no_comm_vel_flag) // not all Kokkos atom_vec styles have comm vel pack/unpack routines yet + atomKK->avecKK = dynamic_cast(atom->avec); + + if (ghost_velocity && atomKK->avecKK->no_comm_vel_flag) // not all Kokkos atom_vec styles have comm vel pack/unpack routines yet forward_comm_classic = true; + + } /* ---------------------------------------------------------------------- @@ -186,7 +190,6 @@ void CommKokkos::forward_comm_device(int) { int n; MPI_Request request; - AtomVecKokkos *avec = (AtomVecKokkos *) atom->avec; double *buf; // exchange data with another proc @@ -200,7 +203,7 @@ void CommKokkos::forward_comm_device(int) k_swap.sync(); k_swap2.sync(); k_pbc.sync(); - n = avec->pack_comm_self_fused(totalsend,k_sendlist,k_sendnum_scan, + n = atomKK->avecKK->pack_comm_self_fused(totalsend,k_sendlist,k_sendnum_scan, k_firstrecv,k_pbc_flag,k_pbc,k_g2l); } else { @@ -213,7 +216,7 @@ void CommKokkos::forward_comm_device(int) MPI_Irecv(buf,size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); } - n = avec->pack_comm_kokkos(sendnum[iswap],k_sendlist, + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist, iswap,k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) { @@ -232,7 +235,7 @@ void CommKokkos::forward_comm_device(int) size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); } - n = avec->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) { @@ -240,34 +243,34 @@ void CommKokkos::forward_comm_device(int) MPI_DOUBLE,sendproc[iswap],0,world); } if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); - avec->unpack_comm_vel_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv); + atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv); DeviceType().fence(); } else { if (size_forward_recv[iswap]) MPI_Irecv(k_buf_recv.view().data(), size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); - n = avec->pack_comm_kokkos(sendnum[iswap],k_sendlist,iswap, + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist,iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) MPI_Send(k_buf_send.view().data(),n, MPI_DOUBLE,sendproc[iswap],0,world); if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); - avec->unpack_comm_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv); + atomKK->avecKK->unpack_comm_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_recv); DeviceType().fence(); } } else { if (!ghost_velocity) { if (sendnum[iswap]) - n = avec->pack_comm_self(sendnum[iswap],k_sendlist,iswap, + n = atomKK->avecKK->pack_comm_self(sendnum[iswap],k_sendlist,iswap, firstrecv[iswap],pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); } else { - n = avec->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); - avec->unpack_comm_vel_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_send); + atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_send); DeviceType().fence(); } } @@ -310,7 +313,6 @@ void CommKokkos::reverse_comm_device() { int n; MPI_Request request; - AtomVecKokkos *avec = (AtomVecKokkos *) atom->avec; double *buf; // exchange data with another proc @@ -343,19 +345,19 @@ void CommKokkos::reverse_comm_device() MPI_Irecv(k_buf_recv.view().data(), size_reverse_recv[iswap],MPI_DOUBLE, sendproc[iswap],0,world,&request); - n = avec->pack_reverse_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_send); + n = atomKK->avecKK->pack_reverse_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_send); DeviceType().fence(); if (n) MPI_Send(k_buf_send.view().data(),n, MPI_DOUBLE,recvproc[iswap],0,world); if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); } - avec->unpack_reverse_kokkos(sendnum[iswap],k_sendlist,iswap, + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap],k_sendlist,iswap, k_buf_recv); DeviceType().fence(); } else { if (sendnum[iswap]) - n = avec->unpack_reverse_self(sendnum[iswap],k_sendlist,iswap, + n = atomKK->avecKK->unpack_reverse_self(sendnum[iswap],k_sendlist,iswap, firstrecv[iswap]); } } @@ -717,7 +719,6 @@ void CommKokkos::exchange_device() double **x; double *sublo,*subhi; MPI_Request request; - AtomVecKokkos *avec = (AtomVecKokkos *) atom->avec; // clear global->local map for owned and ghost atoms // b/c atoms migrate to new procs in exchange() and @@ -800,7 +801,7 @@ void CommKokkos::exchange_device() nsend = k_count.h_view(); if (nsend > maxsend) grow_send_kokkos(nsend,1); nsend = - avec->pack_exchange_kokkos(k_count.h_view(),k_buf_send, + atomKK->avecKK->pack_exchange_kokkos(k_count.h_view(),k_buf_send, k_exchange_sendlist,k_exchange_copylist, ExecutionSpaceFromDevice::space, dim,lo,hi); @@ -809,8 +810,8 @@ void CommKokkos::exchange_device() while (i < nlocal) { if (x[i][dim] < lo || x[i][dim] >= hi) { if (nsend > maxsend) grow_send_kokkos(nsend,1); - nsend += avec->pack_exchange(i,&buf_send[nsend]); - avec->copy(nlocal-1,i,1); + nsend += atomKK->avecKK->pack_exchange(i,&buf_send[nsend]); + atomKK->avecKK->copy(nlocal-1,i,1); nlocal--; } else i++; } @@ -825,7 +826,7 @@ void CommKokkos::exchange_device() if (procgrid[dim] == 1) { nrecv = nsend; if (nrecv) { - atom->nlocal=avec-> + atom->nlocal=atomKK->avecKK-> unpack_exchange_kokkos(k_buf_send,nrecv,atom->nlocal,dim,lo,hi, ExecutionSpaceFromDevice::space); DeviceType().fence(); @@ -858,7 +859,7 @@ void CommKokkos::exchange_device() } if (nrecv) { - atom->nlocal = avec-> + atom->nlocal = atomKK->avecKK-> unpack_exchange_kokkos(k_buf_recv,nrecv,atom->nlocal,dim,lo,hi, ExecutionSpaceFromDevice::space); DeviceType().fence(); @@ -896,7 +897,7 @@ void CommKokkos::borders() static int print = 1; if (mode != Comm::SINGLE || bordergroup || - (ghost_velocity && ((AtomVecKokkos*)atom->avec)->no_border_vel_flag)) { + (ghost_velocity && atomKK->avecKK->no_border_vel_flag)) { if (print && comm->me==0) { error->warning(FLERR,"Required border comm not yet implemented in Kokkos communication, " "switching to classic exchange/border communication"); @@ -982,7 +983,6 @@ void CommKokkos::borders_device() { double **x; double *mlo,*mhi; MPI_Request request; - AtomVecKokkos *avec = (AtomVecKokkos *) atom->avec; ExecutionSpace exec_space = ExecutionSpaceFromDevice::space; atomKK->sync(exec_space,ALL_MASK); @@ -1122,13 +1122,13 @@ void CommKokkos::borders_device() { if (nsend*size_border > maxsend) grow_send_kokkos(nsend*size_border,0); if (ghost_velocity) { - n = avec-> + n = atomKK->avecKK-> pack_border_vel_kokkos(nsend,k_sendlist,k_buf_send,iswap, pbc_flag[iswap],pbc[iswap],exec_space); DeviceType().fence(); } else { - n = avec-> + n = atomKK->avecKK-> pack_border_kokkos(nsend,k_sendlist,k_buf_send,iswap, pbc_flag[iswap],pbc[iswap],exec_space); DeviceType().fence(); @@ -1157,21 +1157,21 @@ void CommKokkos::borders_device() { if (ghost_velocity) { if (sendproc[iswap] != me) { - avec->unpack_border_vel_kokkos(nrecv,atom->nlocal+atom->nghost, + atomKK->avecKK->unpack_border_vel_kokkos(nrecv,atom->nlocal+atom->nghost, k_buf_recv,exec_space); DeviceType().fence(); } else { - avec->unpack_border_vel_kokkos(nrecv,atom->nlocal+atom->nghost, + atomKK->avecKK->unpack_border_vel_kokkos(nrecv,atom->nlocal+atom->nghost, k_buf_send,exec_space); DeviceType().fence(); } } else { if (sendproc[iswap] != me) { - avec->unpack_border_kokkos(nrecv,atom->nlocal+atom->nghost, + atomKK->avecKK->unpack_border_kokkos(nrecv,atom->nlocal+atom->nghost, k_buf_recv,exec_space); DeviceType().fence(); } else { - avec->unpack_border_kokkos(nrecv,atom->nlocal+atom->nghost, + atomKK->avecKK->unpack_border_kokkos(nrecv,atom->nlocal+atom->nghost, k_buf_send,exec_space); DeviceType().fence(); } @@ -1299,7 +1299,7 @@ void CommKokkos::grow_recv(int n) void CommKokkos::grow_send_kokkos(int n, int flag, ExecutionSpace space) { maxsend = static_cast (BUFFACTOR * n); - int maxsend_border = (maxsend+BUFEXTRA+5)/atom->avec->size_border + 2; + int maxsend_border = (maxsend+BUFEXTRA+5)/atomKK->avecKK->size_border + 2; if (flag) { if (space == Device) k_buf_send.modify(); @@ -1308,9 +1308,9 @@ void CommKokkos::grow_send_kokkos(int n, int flag, ExecutionSpace space) if (ghost_velocity) k_buf_send.resize(maxsend_border, - atom->avec->size_border + atom->avec->size_velocity); + atomKK->avecKK->size_border + atomKK->avecKK->size_velocity); else - k_buf_send.resize(maxsend_border,atom->avec->size_border); + k_buf_send.resize(maxsend_border,atomKK->avecKK->size_border); buf_send = k_buf_send.view().data(); } else { @@ -1318,10 +1318,10 @@ void CommKokkos::grow_send_kokkos(int n, int flag, ExecutionSpace space) k_buf_send = DAT:: tdual_xfloat_2d("comm:k_buf_send", maxsend_border, - atom->avec->size_border + atom->avec->size_velocity); + atomKK->avecKK->size_border + atomKK->avecKK->size_velocity); else k_buf_send = DAT:: - tdual_xfloat_2d("comm:k_buf_send",maxsend_border,atom->avec->size_border); + tdual_xfloat_2d("comm:k_buf_send",maxsend_border,atomKK->avecKK->size_border); buf_send = k_buf_send.view().data(); } } @@ -1333,9 +1333,9 @@ void CommKokkos::grow_send_kokkos(int n, int flag, ExecutionSpace space) void CommKokkos::grow_recv_kokkos(int n, ExecutionSpace /*space*/) { maxrecv = static_cast (BUFFACTOR * n); - int maxrecv_border = (maxrecv+BUFEXTRA+5)/atom->avec->size_border + 2; + int maxrecv_border = (maxrecv+BUFEXTRA+5)/atomKK->avecKK->size_border + 2; k_buf_recv = DAT:: - tdual_xfloat_2d("comm:k_buf_recv",maxrecv_border,atom->avec->size_border); + tdual_xfloat_2d("comm:k_buf_recv",maxrecv_border,atomKK->avecKK->size_border); buf_recv = k_buf_recv.view().data(); } diff --git a/src/KOKKOS/comm_kokkos.h b/src/KOKKOS/comm_kokkos.h index f7cf06d191..178c104b28 100644 --- a/src/KOKKOS/comm_kokkos.h +++ b/src/KOKKOS/comm_kokkos.h @@ -96,6 +96,8 @@ class CommKokkos : public CommBrick { void grow_list(int, int) override; void grow_swap(int) override; void copy_swap_info(); + + class AtomVecKokkos* avec_kk; }; } diff --git a/src/MOLECULE/atom_vec_angle.h b/src/MOLECULE/atom_vec_angle.h index 59bca56d82..f3fead3c02 100644 --- a/src/MOLECULE/atom_vec_angle.h +++ b/src/MOLECULE/atom_vec_angle.h @@ -24,7 +24,7 @@ AtomStyle(angle,AtomVecAngle); namespace LAMMPS_NS { -class AtomVecAngle : public AtomVec { +class AtomVecAngle : virtual public AtomVec { public: AtomVecAngle(class LAMMPS *); ~AtomVecAngle() override; diff --git a/src/MOLECULE/atom_vec_bond.h b/src/MOLECULE/atom_vec_bond.h index ab61089227..0b018e5ac1 100644 --- a/src/MOLECULE/atom_vec_bond.h +++ b/src/MOLECULE/atom_vec_bond.h @@ -24,7 +24,7 @@ AtomStyle(bond,AtomVecBond); namespace LAMMPS_NS { -class AtomVecBond : public AtomVec { +class AtomVecBond : virtual public AtomVec { public: AtomVecBond(class LAMMPS *); ~AtomVecBond() override; diff --git a/src/MOLECULE/atom_vec_full.h b/src/MOLECULE/atom_vec_full.h index 91e8085f0d..0f55131d5d 100644 --- a/src/MOLECULE/atom_vec_full.h +++ b/src/MOLECULE/atom_vec_full.h @@ -24,7 +24,7 @@ AtomStyle(full,AtomVecFull); namespace LAMMPS_NS { -class AtomVecFull : public AtomVec { +class AtomVecFull : virtual public AtomVec { public: AtomVecFull(class LAMMPS *); ~AtomVecFull() override; diff --git a/src/MOLECULE/atom_vec_molecular.h b/src/MOLECULE/atom_vec_molecular.h index 8f2bb1dfba..6e33a6c1c6 100644 --- a/src/MOLECULE/atom_vec_molecular.h +++ b/src/MOLECULE/atom_vec_molecular.h @@ -24,7 +24,7 @@ AtomStyle(molecular,AtomVecMolecular); namespace LAMMPS_NS { -class AtomVecMolecular : public AtomVec { +class AtomVecMolecular : virtual public AtomVec { public: AtomVecMolecular(class LAMMPS *); ~AtomVecMolecular() override; diff --git a/src/SPIN/atom_vec_spin.h b/src/SPIN/atom_vec_spin.h index f2eb24afc9..9ee6329acd 100644 --- a/src/SPIN/atom_vec_spin.h +++ b/src/SPIN/atom_vec_spin.h @@ -24,7 +24,7 @@ AtomStyle(spin,AtomVecSpin); namespace LAMMPS_NS { -class AtomVecSpin : public AtomVec { +class AtomVecSpin : virtual public AtomVec { public: AtomVecSpin(class LAMMPS *); diff --git a/src/atom_vec.h b/src/atom_vec.h index d5294d2f86..a4db054752 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -157,21 +157,6 @@ class AtomVec : protected Pointers { virtual double memory_usage(); virtual double memory_usage_bonus() { return 0; } - // old hybrid functions, needed by Kokkos package - - virtual int pack_comm_hybrid(int, int *, double *) { return 0; } - virtual int unpack_comm_hybrid(int, int, double *) { return 0; } - virtual int pack_reverse_hybrid(int, int, double *) { return 0; } - virtual int unpack_reverse_hybrid(int, int *, double *) { return 0; } - virtual int pack_border_hybrid(int, int *, double *) { return 0; } - virtual int unpack_border_hybrid(int, int, double *) { return 0; } - virtual int data_atom_hybrid(int, const std::vector &, int) { return 0; } - virtual int data_vel_hybrid(int, const std::vector &, int) { return 0; } - virtual int pack_data_hybrid(int, double *) { return 0; } - virtual int write_data_hybrid(FILE *, double *) { return 0; } - virtual int pack_vel_hybrid(int, double *) { return 0; } - virtual int write_vel_hybrid(FILE *, double *) { return 0; } - protected: int nmax; // local copy of atom->nmax int deform_vremap; // local copy of domain properties diff --git a/src/atom_vec_atomic.h b/src/atom_vec_atomic.h index 5afd63bd7c..6fdd570c2e 100644 --- a/src/atom_vec_atomic.h +++ b/src/atom_vec_atomic.h @@ -24,7 +24,7 @@ AtomStyle(atomic,AtomVecAtomic); namespace LAMMPS_NS { -class AtomVecAtomic : public AtomVec { +class AtomVecAtomic : virtual public AtomVec { public: AtomVecAtomic(class LAMMPS *); }; diff --git a/src/atom_vec_charge.h b/src/atom_vec_charge.h index 5f3bc333e7..2953b7cfcb 100644 --- a/src/atom_vec_charge.h +++ b/src/atom_vec_charge.h @@ -24,7 +24,7 @@ AtomStyle(charge,AtomVecCharge); namespace LAMMPS_NS { -class AtomVecCharge : public AtomVec { +class AtomVecCharge : virtual public AtomVec { public: AtomVecCharge(class LAMMPS *); }; diff --git a/src/atom_vec_hybrid.h b/src/atom_vec_hybrid.h index 8a81282f5b..afe44bae6e 100644 --- a/src/atom_vec_hybrid.h +++ b/src/atom_vec_hybrid.h @@ -24,7 +24,7 @@ AtomStyle(hybrid,AtomVecHybrid); namespace LAMMPS_NS { -class AtomVecHybrid : public AtomVec { +class AtomVecHybrid : virtual public AtomVec { public: int nstyles; class AtomVec **styles; diff --git a/src/atom_vec_sphere.h b/src/atom_vec_sphere.h index 2e42e95fc1..e6c903da4b 100644 --- a/src/atom_vec_sphere.h +++ b/src/atom_vec_sphere.h @@ -24,7 +24,7 @@ AtomStyle(sphere,AtomVecSphere); namespace LAMMPS_NS { -class AtomVecSphere : public AtomVec { +class AtomVecSphere : virtual public AtomVec { public: AtomVecSphere(class LAMMPS *); void process_args(int, char **) override;