/* ---------------------------------------------------------------------- LAMMPS - Large-scale AtomicKokkos/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include #include "atom_vec_atomic_kokkos.h" #include "atom_kokkos.h" #include "comm_kokkos.h" #include "domain.h" #include "modify.h" #include "fix.h" #include "atom_masks.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; #define DELTA 10000 /* ---------------------------------------------------------------------- */ AtomVecAtomicKokkos::AtomVecAtomicKokkos(LAMMPS *lmp) : AtomVecKokkos(lmp) { molecular = 0; mass_type = 1; 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; } /* ---------------------------------------------------------------------- grow atom arrays n = 0 grows arrays by DELTA n > 0 allocates arrays to size n ------------------------------------------------------------------------- */ void AtomVecAtomicKokkos::grow(int n) { if (n == 0) nmax += DELTA; else nmax = n; atomKK->nmax = nmax; if (nmax < 0 || nmax > MAXSMALLINT) error->one(FLERR,"Per-processor system is too big"); sync(Device,ALL_MASK); modified(Device,ALL_MASK); memory->grow_kokkos(atomKK->k_tag,atomKK->tag,nmax,"atom:tag"); memory->grow_kokkos(atomKK->k_type,atomKK->type,nmax,"atom:type"); memory->grow_kokkos(atomKK->k_mask,atomKK->mask,nmax,"atom:mask"); memory->grow_kokkos(atomKK->k_image,atomKK->image,nmax,"atom:image"); memory->grow_kokkos(atomKK->k_x,atomKK->x,nmax,3,"atom:x"); memory->grow_kokkos(atomKK->k_v,atomKK->v,nmax,3,"atom:v"); memory->grow_kokkos(atomKK->k_f,atomKK->f,nmax,3,"atom:f"); grow_reset(); sync(Host,ALL_MASK); 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 AtomVecAtomicKokkos::grow_reset() { 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; } /* ---------------------------------------------------------------------- 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 struct AtomVecAtomicKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; const typename ArrayTypes::t_int_2d_const _list; const int _iswap; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; const typename ArrayTypes::t_int_1d _mask; X_FLOAT _dx,_dy,_dz; AtomVecAtomicKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, const typename ArrayTypes::t_int_2d_const &list, const int & iswap, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, const typename ArrayTypes::t_int_1d &mask, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): _buf(buf),_list(list),_iswap(iswap), _x(x),_tag(tag),_type(type),_mask(mask), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { const int j = _list(_iswap,i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); _buf(i,2) = _x(j,2); _buf(i,3) = d_ubuf(_tag(j)).d; _buf(i,4) = d_ubuf(_type(j)).d; _buf(i,5) = d_ubuf(_mask(j)).d; } else { _buf(i,0) = _x(j,0) + _dx; _buf(i,1) = _x(j,1) + _dy; _buf(i,2) = _x(j,2) + _dz; _buf(i,3) = d_ubuf(_tag(j)).d; _buf(i,4) = d_ubuf(_type(j)).d; _buf(i,5) = d_ubuf(_mask(j)).d; } } }; /* ---------------------------------------------------------------------- */ int AtomVecAtomicKokkos::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) { X_FLOAT dx,dy,dz; if (pbc_flag != 0) { 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(space==Host) { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), iswap,h_x,h_tag,h_type,h_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), iswap,d_x,d_tag,d_type,d_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } } else { dx = dy = dz = 0; if(space==Host) { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), iswap,h_x,h_tag,h_type,h_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), iswap,d_x,d_tag,d_type,d_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } } return n*6; } /* ---------------------------------------------------------------------- */ 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; const typename ArrayTypes::t_xfloat_2d_const _buf; typename ArrayTypes::t_x_array _x; typename ArrayTypes::t_tagint_1d _tag; typename ArrayTypes::t_int_1d _type; typename ArrayTypes::t_int_1d _mask; int _first; AtomVecAtomicKokkos_UnpackBorder( const typename ArrayTypes::t_xfloat_2d_const &buf, typename ArrayTypes::t_x_array &x, typename ArrayTypes::t_tagint_1d &tag, typename ArrayTypes::t_int_1d &type, typename ArrayTypes::t_int_1d &mask, const int& first): _buf(buf),_x(x),_tag(tag),_type(type),_mask(mask),_first(first){ }; KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { _x(i+_first,0) = _buf(i,0); _x(i+_first,1) = _buf(i,1); _x(i+_first,2) = _buf(i,2); _tag(i+_first) = (tagint) d_ubuf(_buf(i,3)).i; _type(i+_first) = (int) d_ubuf(_buf(i,4)).i; _mask(i+_first) = (int) d_ubuf(_buf(i,5)).i; // printf("%i %i %lf %lf %lf %i BORDER\n",_tag(i+_first),i+_first,_x(i+_first,0),_x(i+_first,1),_x(i+_first,2),_type(i+_first)); } }; /* ---------------------------------------------------------------------- */ void AtomVecAtomicKokkos::unpack_border_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf,ExecutionSpace space) { modified(space,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK); while (first+n >= nmax) grow(0); modified(space,X_MASK|TAG_MASK|TYPE_MASK|MASK_MASK); if(space==Host) { struct AtomVecAtomicKokkos_UnpackBorder f(buf.view(),h_x,h_tag,h_type,h_mask,first); Kokkos::parallel_for(n,f); } else { struct AtomVecAtomicKokkos_UnpackBorder f(buf.view(),d_x,d_tag,d_type,d_mask,first); Kokkos::parallel_for(n,f); } } /* ---------------------------------------------------------------------- */ void AtomVecAtomicKokkos::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); modified(Host,X_MASK|TAG_MASK|TYPE_MASK|MASK_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; } 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; for (i = first; i < last; i++) { if (i == nmax) grow(0); modified(Host,X_MASK|V_MASK|TAG_MASK|TYPE_MASK|MASK_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_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]); } /* ---------------------------------------------------------------------- */ template struct AtomVecAtomicKokkos_PackExchangeFunctor { typedef DeviceType device_type; typedef ArrayTypes AT; typename AT::t_x_array_randomread _x; typename AT::t_v_array_randomread _v; typename AT::t_tagint_1d_randomread _tag; typename AT::t_int_1d_randomread _type; typename AT::t_int_1d_randomread _mask; typename AT::t_imageint_1d_randomread _image; typename AT::t_x_array _xw; typename AT::t_v_array _vw; typename AT::t_tagint_1d _tagw; typename AT::t_int_1d _typew; typename AT::t_int_1d _maskw; typename AT::t_imageint_1d _imagew; typename AT::t_xfloat_2d_um _buf; typename AT::t_int_1d_const _sendlist; typename AT::t_int_1d_const _copylist; int _nlocal,_dim; X_FLOAT _lo,_hi; AtomVecAtomicKokkos_PackExchangeFunctor( const AtomKokkos* atom, const typename AT::tdual_xfloat_2d buf, typename AT::tdual_int_1d sendlist, typename AT::tdual_int_1d copylist,int nlocal, int dim, X_FLOAT lo, X_FLOAT hi): _x(atom->k_x.view()), _v(atom->k_v.view()), _tag(atom->k_tag.view()), _type(atom->k_type.view()), _mask(atom->k_mask.view()), _image(atom->k_image.view()), _xw(atom->k_x.view()), _vw(atom->k_v.view()), _tagw(atom->k_tag.view()), _typew(atom->k_type.view()), _maskw(atom->k_mask.view()), _imagew(atom->k_image.view()), _sendlist(sendlist.template view()), _copylist(copylist.template view()), _nlocal(nlocal),_dim(dim), _lo(lo),_hi(hi){ const size_t elements = 11; const int maxsendlist = (buf.template view().dimension_0()*buf.template view().dimension_1())/elements; buffer_view(_buf,buf,maxsendlist,elements); } KOKKOS_INLINE_FUNCTION void operator() (const int &mysend) const { const int i = _sendlist(mysend); _buf(mysend,0) = 11; _buf(mysend,1) = _x(i,0); _buf(mysend,2) = _x(i,1); _buf(mysend,3) = _x(i,2); _buf(mysend,4) = _v(i,0); _buf(mysend,5) = _v(i,1); _buf(mysend,6) = _v(i,2); _buf(mysend,7) = d_ubuf(_tag[i]).d; _buf(mysend,8) = d_ubuf(_type[i]).d; _buf(mysend,9) = d_ubuf(_mask[i]).d; _buf(mysend,10) = d_ubuf(_image[i]).d; const int j = _copylist(mysend); if(j>-1) { _xw(i,0) = _x(j,0); _xw(i,1) = _x(j,1); _xw(i,2) = _x(j,2); _vw(i,0) = _v(j,0); _vw(i,1) = _v(j,1); _vw(i,2) = _v(j,2); _tagw[i] = _tag(j); _typew[i] = _type(j); _maskw[i] = _mask(j); _imagew[i] = _image(j); } } }; /* ---------------------------------------------------------------------- */ int AtomVecAtomicKokkos::pack_exchange_kokkos(const int &nsend,DAT::tdual_xfloat_2d &k_buf, DAT::tdual_int_1d k_sendlist,DAT::tdual_int_1d k_copylist,ExecutionSpace space,int dim,X_FLOAT lo,X_FLOAT hi ) { if(nsend > (int) (k_buf.view().dimension_0()*k_buf.view().dimension_1())/11) { int newsize = nsend*11/k_buf.view().dimension_1()+1; k_buf.resize(newsize,k_buf.view().dimension_1()); } if(space == Host) { AtomVecAtomicKokkos_PackExchangeFunctor f(atomKK,k_buf,k_sendlist,k_copylist,atom->nlocal,dim,lo,hi); Kokkos::parallel_for(nsend,f); return nsend*11; } else { AtomVecAtomicKokkos_PackExchangeFunctor f(atomKK,k_buf,k_sendlist,k_copylist,atom->nlocal,dim,lo,hi); Kokkos::parallel_for(nsend,f); return nsend*11; } } /* ---------------------------------------------------------------------- */ 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; typedef ArrayTypes AT; typename AT::t_x_array _x; typename AT::t_v_array _v; typename AT::t_tagint_1d _tag; typename AT::t_int_1d _type; typename AT::t_int_1d _mask; typename AT::t_imageint_1d _image; typename AT::t_xfloat_2d_um _buf; typename AT::t_int_1d _nlocal; int _dim; X_FLOAT _lo,_hi; AtomVecAtomicKokkos_UnpackExchangeFunctor( const AtomKokkos* atom, const typename AT::tdual_xfloat_2d buf, typename AT::tdual_int_1d nlocal, int dim, X_FLOAT lo, X_FLOAT hi): _x(atom->k_x.view()), _v(atom->k_v.view()), _tag(atom->k_tag.view()), _type(atom->k_type.view()), _mask(atom->k_mask.view()), _image(atom->k_image.view()), _nlocal(nlocal.template view()),_dim(dim), _lo(lo),_hi(hi){ const size_t elements = 11; const int maxsendlist = (buf.template view().dimension_0()*buf.template view().dimension_1())/elements; buffer_view(_buf,buf,maxsendlist,elements); } KOKKOS_INLINE_FUNCTION void operator() (const int &myrecv) const { X_FLOAT x = _buf(myrecv,_dim+1); if (x >= _lo && x < _hi) { int i = Kokkos::atomic_fetch_add(&_nlocal(0),1); _x(i,0) = _buf(myrecv,1); _x(i,1) = _buf(myrecv,2); _x(i,2) = _buf(myrecv,3); _v(i,0) = _buf(myrecv,4); _v(i,1) = _buf(myrecv,5); _v(i,2) = _buf(myrecv,6); _tag[i] = (tagint) d_ubuf(_buf(myrecv,7)).i; _type[i] = (int) d_ubuf(_buf(myrecv,8)).i; _mask[i] = (int) d_ubuf(_buf(myrecv,9)).i; _image[i] = (imageint) d_ubuf(_buf(myrecv,10)).i; } } }; /* ---------------------------------------------------------------------- */ int AtomVecAtomicKokkos::unpack_exchange_kokkos(DAT::tdual_xfloat_2d &k_buf,int nrecv,int nlocal,int dim,X_FLOAT lo,X_FLOAT hi,ExecutionSpace space) { if(space == Host) { k_count.h_view(0) = nlocal; AtomVecAtomicKokkos_UnpackExchangeFunctor f(atomKK,k_buf,k_count,dim,lo,hi); Kokkos::parallel_for(nrecv/11,f); return k_count.h_view(0); } else { k_count.h_view(0) = nlocal; k_count.modify(); k_count.sync(); AtomVecAtomicKokkos_UnpackExchangeFunctor f(atomKK,k_buf,k_count,dim,lo,hi); Kokkos::parallel_for(nrecv/11,f); k_count.modify(); k_count.sync(); return k_count.h_view(0); } } /* ---------------------------------------------------------------------- */ int AtomVecAtomicKokkos::unpack_exchange(double *buf) { int nlocal = atom->nlocal; if (nlocal == nmax) grow(0); 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) { 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"); } 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, tagint imagetmp, char **values) { int nlocal = atom->nlocal; if (nlocal == nmax) grow(0); h_tag[nlocal] = atoi(values[0]); h_type[nlocal] = atoi(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 ------------------------------------------------------------------------- */ bigint AtomVecAtomicKokkos::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); return bytes; } /* ---------------------------------------------------------------------- */ void AtomVecAtomicKokkos::sync(ExecutionSpace space, unsigned int mask) { if (space == Device) { if (mask & X_MASK) atomKK->k_x.sync(); if (mask & V_MASK) atomKK->k_v.sync(); if (mask & F_MASK) atomKK->k_f.sync(); if (mask & TAG_MASK) atomKK->k_tag.sync(); if (mask & TYPE_MASK) atomKK->k_type.sync(); if (mask & MASK_MASK) atomKK->k_mask.sync(); if (mask & IMAGE_MASK) atomKK->k_image.sync(); } else { if (mask & X_MASK) atomKK->k_x.sync(); if (mask & V_MASK) atomKK->k_v.sync(); if (mask & F_MASK) atomKK->k_f.sync(); if (mask & TAG_MASK) atomKK->k_tag.sync(); if (mask & TYPE_MASK) atomKK->k_type.sync(); if (mask & MASK_MASK) atomKK->k_mask.sync(); if (mask & IMAGE_MASK) atomKK->k_image.sync(); } } /* ---------------------------------------------------------------------- */ void AtomVecAtomicKokkos::sync_overlapping_device(ExecutionSpace space, unsigned int mask) { if (space == Device) { if ((mask & X_MASK) && atomKK->k_x.need_sync()) perform_async_copy(atomKK->k_x,space); if ((mask & V_MASK) && atomKK->k_v.need_sync()) perform_async_copy(atomKK->k_v,space); if ((mask & F_MASK) && atomKK->k_f.need_sync()) perform_async_copy(atomKK->k_f,space); if ((mask & TAG_MASK) && atomKK->k_tag.need_sync()) perform_async_copy(atomKK->k_tag,space); if ((mask & TYPE_MASK) && atomKK->k_type.need_sync()) perform_async_copy(atomKK->k_type,space); if ((mask & MASK_MASK) && atomKK->k_mask.need_sync()) perform_async_copy(atomKK->k_mask,space); if ((mask & IMAGE_MASK) && atomKK->k_image.need_sync()) perform_async_copy(atomKK->k_image,space); } else { if ((mask & X_MASK) && atomKK->k_x.need_sync()) perform_async_copy(atomKK->k_x,space); if ((mask & V_MASK) && atomKK->k_v.need_sync()) perform_async_copy(atomKK->k_v,space); if ((mask & F_MASK) && atomKK->k_f.need_sync()) perform_async_copy(atomKK->k_f,space); if ((mask & TAG_MASK) && atomKK->k_tag.need_sync()) perform_async_copy(atomKK->k_tag,space); if ((mask & TYPE_MASK) && atomKK->k_type.need_sync()) perform_async_copy(atomKK->k_type,space); if ((mask & MASK_MASK) && atomKK->k_mask.need_sync()) perform_async_copy(atomKK->k_mask,space); if ((mask & IMAGE_MASK) && atomKK->k_image.need_sync()) perform_async_copy(atomKK->k_image,space); } } /* ---------------------------------------------------------------------- */ void AtomVecAtomicKokkos::modified(ExecutionSpace space, unsigned int mask) { if (space == Device) { if (mask & X_MASK) atomKK->k_x.modify(); if (mask & V_MASK) atomKK->k_v.modify(); if (mask & F_MASK) atomKK->k_f.modify(); if (mask & TAG_MASK) atomKK->k_tag.modify(); if (mask & TYPE_MASK) atomKK->k_type.modify(); if (mask & MASK_MASK) atomKK->k_mask.modify(); if (mask & IMAGE_MASK) atomKK->k_image.modify(); } else { if (mask & X_MASK) atomKK->k_x.modify(); if (mask & V_MASK) atomKK->k_v.modify(); if (mask & F_MASK) atomKK->k_f.modify(); if (mask & TAG_MASK) atomKK->k_tag.modify(); if (mask & TYPE_MASK) atomKK->k_type.modify(); if (mask & MASK_MASK) atomKK->k_mask.modify(); if (mask & IMAGE_MASK) atomKK->k_image.modify(); } }