24#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
26#include <Cabana_VerletList.hpp>
34template <
class MemorySpace,
class AlgorithmTag,
class LayoutTag,
35 class BuildTag = Cabana::TeamVectorOpTag>
37 LayoutTag, BuildTag> {
41 std::size_t
const max_neigh) {
56 KOKKOS_INLINE_FUNCTION
58 std::size_t
const max_neigh) {
61 Kokkos::ViewAllocateWithoutInitializing(
"neighbors"), num_particles,
66 KOKKOS_INLINE_FUNCTION
68 std::size_t
const max_neigh) {
69 Kokkos::realloc(
counts, num_particles);
70 Kokkos::realloc(Kokkos::WithoutInitializing,
neighbors, num_particles,
75 KOKKOS_INLINE_FUNCTION
78 auto count_n =
counts(nid);
80 if (count > count_n) {
83 count = Kokkos::atomic_fetch_add(&
counts(pid), 1);
93 KOKKOS_INLINE_FUNCTION
95 auto const count =
counts(pid);
107 KOKKOS_INLINE_FUNCTION
110 auto count_n =
counts(nid);
112 if (count > count_n) {
126 KOKKOS_INLINE_FUNCTION
128 Kokkos::parallel_for(
"custom_verlet_list::sort_neighbors",
129 Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(
130 std::size_t{0},
counts.size()),
131 [&](std::size_t
const i) {
132 auto const count =
counts(i);
134 std::sort(ptr, ptr + count);
140 KOKKOS_INLINE_FUNCTION
142 auto max_counts = 0l;
143 auto ave_counts = 0l;
144 auto ave_sq_counts = 0l;
145 for (
int pid = 0; pid <
counts.extent(0); ++pid) {
146 auto const count =
static_cast<long>(
counts(pid));
147 if (max_counts < count)
150 ave_sq_counts += count * count;
152 if (
counts.extent(0) != 0) {
153 ave_counts /=
static_cast<long>(
counts.extent(0));
154 ave_sq_counts /=
static_cast<long>(
counts.extent(0));
155 ave_sq_counts -= ave_counts * ave_counts;
157 ostream <<
"max:" << max_counts <<
" ave:" << ave_counts
158 <<
" var:" << ave_sq_counts << std::endl;
159 return static_cast<int>(max_counts);
162 KOKKOS_INLINE_FUNCTION
165 Kokkos::Max<int> max_reduce(max_counts);
166 Kokkos::parallel_reduce(
167 "custom_verlet_list::reduce_max",
168 Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(std::size_t{0},
170 [&](std::size_t
const i,
int &value) {
182 KOKKOS_INLINE_FUNCTION
void setOverflow() {
overflow =
true; }
185template <
class MemorySpace,
class AlgorithmTag,
class BuildTag>
187 Cabana::VerletLayout2D, BuildTag>> {
193 Cabana::VerletLayout2D, BuildTag>;
196 KOKKOS_INLINE_FUNCTION
198 std::size_t
const num_p = list.
counts.size();
199 std::size_t total_n = 0;
200 for (std::size_t i = 0; i < num_p; ++i)
201 total_n += list.
counts(i);
206 KOKKOS_INLINE_FUNCTION
213 KOKKOS_INLINE_FUNCTION
215 std::size_t
const particle_index) {
216 return list.
counts(particle_index);
221 KOKKOS_INLINE_FUNCTION
223 std::size_t
const particle_index,
224 std::size_t
const count) {
225 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