24#include <Cabana_VerletList.hpp>
30template <
class MemorySpace,
class ListAlgorithm,
class Layout,
class BuildTag>
33template <
class MemorySpace,
class AlgorithmTag,
class BuildTag>
40template <
class MemorySpace,
class AlgorithmTag,
class LayoutTag,
41 class BuildTag = Cabana::TeamVectorOpTag>
43 LayoutTag, BuildTag> {
47 std::size_t
const max_neigh) {
51 Kokkos::View<int *, MemorySpace>
counts;
52 Kokkos::View<int **, Kokkos::LayoutRight, MemorySpace>
neighbors;
62 KOKKOS_INLINE_FUNCTION
64 std::size_t
const max_neigh) {
65 counts = Kokkos::View<int *, MemorySpace>(
"num_neighbors", num_particles);
66 neighbors = Kokkos::View<int **, Kokkos::LayoutRight, MemorySpace>(
67 Kokkos::ViewAllocateWithoutInitializing(
"neighbors"), num_particles,
72 KOKKOS_INLINE_FUNCTION
74 std::size_t
const max_neigh) {
75 Kokkos::realloc(
counts, num_particles);
76 Kokkos::realloc(Kokkos::WithoutInitializing,
neighbors, num_particles,
81 KOKKOS_INLINE_FUNCTION
84 auto count_n =
counts(nid);
86 if (count > count_n) {
89 count = Kokkos::atomic_fetch_add(&
counts(pid), 1);
99 KOKKOS_INLINE_FUNCTION
101 auto const count =
counts(pid);
113 KOKKOS_INLINE_FUNCTION
116 auto count_n =
counts(nid);
118 if (count > count_n) {
132 KOKKOS_INLINE_FUNCTION
134 Kokkos::parallel_for(
"custom_verlet_list::sort_neighbors",
135 Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(
136 std::size_t{0},
counts.size()),
137 [&](std::size_t
const i) {
138 auto const count =
counts(i);
140 std::sort(ptr, ptr + count);
146 KOKKOS_INLINE_FUNCTION
148 auto max_counts = 0l;
149 auto ave_counts = 0l;
150 auto ave_sq_counts = 0l;
151 for (
int pid = 0; pid <
counts.extent(0); ++pid) {
152 auto const count =
static_cast<long>(
counts(pid));
153 if (max_counts < count)
156 ave_sq_counts += count * count;
158 if (
counts.extent(0) != 0) {
159 ave_counts /=
static_cast<long>(
counts.extent(0));
160 ave_sq_counts /=
static_cast<long>(
counts.extent(0));
161 ave_sq_counts -= ave_counts * ave_counts;
163 ostream <<
"max:" << max_counts <<
" ave:" << ave_counts
164 <<
" var:" << ave_sq_counts << std::endl;
165 return static_cast<int>(max_counts);
168 KOKKOS_INLINE_FUNCTION
171 Kokkos::Max<int> max_reduce(max_counts);
172 Kokkos::parallel_reduce(
173 "custom_verlet_list::reduce_max",
174 Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(std::size_t{0},
176 [&](std::size_t
const i,
int &value) {
188 KOKKOS_INLINE_FUNCTION
void setOverflow() {
overflow =
true; }
191template <
class MemorySpace,
class AlgorithmTag,
class BuildTag>
193 Cabana::VerletLayout2D, BuildTag>> {
199 Cabana::VerletLayout2D, BuildTag>;
202 KOKKOS_INLINE_FUNCTION
204 std::size_t
const num_p = list.
counts.size();
205 std::size_t total_n = 0;
206 for (std::size_t i = 0; i < num_p; ++i)
207 total_n += list.
counts(i);
212 KOKKOS_INLINE_FUNCTION
218 KOKKOS_INLINE_FUNCTION
220 std::size_t
const particle_index) {
221 return list.
counts(particle_index);
226 KOKKOS_INLINE_FUNCTION
228 std::size_t
const particle_index,
229 std::size_t
const count) {
230 return list.
neighbors(particle_index, count);
static KOKKOS_INLINE_FUNCTION std::size_t getNeighbor(list_type const &list, std::size_t const particle_index, std::size_t const count)
Get the id for a neighbor for a given particle index and the index of the neighbor relative to the pa...
static KOKKOS_INLINE_FUNCTION std::size_t totalNeighbor(list_type const &list)
Get the total number of neighbors across all particles.
static KOKKOS_INLINE_FUNCTION std::size_t maxNeighbor(list_type const &list)
Get the maximum number of neighbors per particle.
static KOKKOS_INLINE_FUNCTION std::size_t numNeighbor(list_type const &list, std::size_t const particle_index)
Get the number of neighbors for a given particle index.
MemorySpace memory_space
Kokkos memory space.
KOKKOS_INLINE_FUNCTION void addNeighborLB(int pid, int nid)
KOKKOS_INLINE_FUNCTION void sortNeighbors()
KOKKOS_INLINE_FUNCTION auto get_max_counts()
CustomVerletList(std::size_t const begin, std::size_t const end, std::size_t const max_neigh)
KOKKOS_INLINE_FUNCTION void addNeighborAtomicLB(int pid, int nid)
KOKKOS_INLINE_FUNCTION void initializeData(std::size_t const num_particles, std::size_t const max_neigh)
KOKKOS_INLINE_FUNCTION void reallocData(std::size_t const num_particles, std::size_t const max_neigh)
KOKKOS_INLINE_FUNCTION void addNeighbor(int pid, int nid)
CustomVerletList()=default
Kokkos::View< int **, Kokkos::LayoutRight, MemorySpace > neighbors
KOKKOS_INLINE_FUNCTION auto get_variance_max_counts(auto &ostream)
Kokkos::View< int *, MemorySpace > counts
KOKKOS_INLINE_FUNCTION bool hasOverflow() const