1 // clang-format off
2 /* ----------------------------------------------------------------------
3 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
4 https://www.lammps.org/, Sandia National Laboratories
5 Steve Plimpton, sjplimp@sandia.gov
6
7 Copyright (2003) Sandia Corporation. Under the terms of Contract
8 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
9 certain rights in this software. This software is distributed under
10 the GNU General Public License.
11
12 See the README file in the top-level LAMMPS directory.
13 ------------------------------------------------------------------------- */
14
15 #include "npair_halffull_kokkos.h"
16
17 #include "atom_kokkos.h"
18 #include "atom_masks.h"
19 #include "atom_vec.h"
20 #include "domain.h"
21 #include "neigh_list_kokkos.h"
22
23 #include <cmath>
24
25 using namespace LAMMPS_NS;
26
27 /* ---------------------------------------------------------------------- */
28
29 template<class DeviceType, int NEWTON>
NPairHalffullKokkos(LAMMPS * lmp)30 NPairHalffullKokkos<DeviceType,NEWTON>::NPairHalffullKokkos(LAMMPS *lmp) : NPair(lmp) {
31 atomKK = (AtomKokkos *) atom;
32 execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
33 }
34
35 /* ----------------------------------------------------------------------
36 build half list from full list
37 pair stored once if i,j are both owned and i < j
38 pair stored by me if j is ghost (also stored by proc owning j)
39 works if full list is a skip list
40 works for owned (non-ghost) list, also for ghost list
41 if ghost, also store neighbors of ghost atoms & set inum,gnum correctly
42 ------------------------------------------------------------------------- */
43
44 template<class DeviceType, int NEWTON>
build(NeighList * list)45 void NPairHalffullKokkos<DeviceType,NEWTON>::build(NeighList *list)
46 {
47 if (NEWTON) {
48 x = atomKK->k_x.view<DeviceType>();
49 atomKK->sync(execution_space,X_MASK);
50 }
51 nlocal = atom->nlocal;
52
53 NeighListKokkos<DeviceType>* k_list_full = static_cast<NeighListKokkos<DeviceType>*>(list->listfull);
54 d_ilist_full = k_list_full->d_ilist;
55 d_numneigh_full = k_list_full->d_numneigh;
56 d_neighbors_full = k_list_full->d_neighbors;
57 int inum_full = list->listfull->inum;
58 if (list->ghost) inum_full += list->listfull->gnum;
59
60 NeighListKokkos<DeviceType>* k_list = static_cast<NeighListKokkos<DeviceType>*>(list);
61 k_list->maxneighs = k_list_full->maxneighs; // simple, but could be made more memory efficient
62 k_list->grow(atom->nmax);
63 d_ilist = k_list->d_ilist;
64 d_numneigh = k_list->d_numneigh;
65 d_neighbors = k_list->d_neighbors;
66
67 // loop over parent full list
68
69 copymode = 1;
70 Kokkos::parallel_for(Kokkos::RangePolicy<DeviceType, TagNPairHalffullCompute>(0,inum_full),*this);
71 copymode = 0;
72
73 list->inum = k_list_full->inum;
74 list->gnum = k_list_full->gnum;
75
76 k_list->k_ilist.template modify<DeviceType>();
77 }
78
79 template<class DeviceType, int NEWTON>
80 KOKKOS_INLINE_FUNCTION
operator ()(TagNPairHalffullCompute,const int & ii) const81 void NPairHalffullKokkos<DeviceType,NEWTON>::operator()(TagNPairHalffullCompute, const int &ii) const {
82 int n = 0;
83
84 const int i = d_ilist_full(ii);
85 F_FLOAT xtmp,ytmp,ztmp;
86 if (NEWTON) {
87 xtmp = x(i,0);
88 ytmp = x(i,1);
89 ztmp = x(i,2);
90 }
91
92 // loop over full neighbor list
93
94 const int jnum = d_numneigh_full(i);
95 const AtomNeighbors neighbors_i = AtomNeighbors(&d_neighbors(i,0),d_numneigh(i),
96 &d_neighbors(i,1)-&d_neighbors(i,0));
97
98 for (int jj = 0; jj < jnum; jj++) {
99 const int joriginal = d_neighbors_full(i,jj);
100 const int j = joriginal & NEIGHMASK;
101 if (NEWTON) {
102 if (j < nlocal) {
103 if (i > j) continue;
104 } else {
105 if (x(j,2) < ztmp) continue;
106 if (x(j,2) == ztmp) {
107 if (x(j,1) < ytmp) continue;
108 if (x(j,1) == ytmp && x(j,0) < xtmp) continue;
109 }
110 }
111 neighbors_i(n++) = joriginal;
112 } else {
113 if (j > i) neighbors_i(n++) = joriginal;
114 }
115 }
116
117 d_numneigh(i) = n;
118 d_ilist(ii) = i;
119 }
120
121 namespace LAMMPS_NS {
122 template class NPairHalffullKokkos<LMPDeviceType,0>;
123 template class NPairHalffullKokkos<LMPDeviceType,1>;
124 #ifdef LMP_KOKKOS_GPU
125 template class NPairHalffullKokkos<LMPHostType,0>;
126 template class NPairHalffullKokkos<LMPHostType,1>;
127 #endif
128 }
129