9 #ifndef _COMPADRE_NEIGHBORLISTS_HPP_
10 #define _COMPADRE_NEIGHBORLISTS_HPP_
13 #include <Kokkos_Core.hpp>
18 template <
typename view_type>
54 NeighborLists(view_type cr_neighbor_lists, view_type number_of_neighbors_list,
57 "cr_neighbor_lists and number_neighbors_list and neighbor_lists_row_offsets must be a 1D Kokkos view.");
82 &&
"neighbor_lists is not large enough to store all neighbors.");
90 NeighborLists(view_type cr_neighbor_lists, view_type number_of_neighbors_list) {
92 &&
"cr_neighbor_lists and number_neighbors_list must be a 1D Kokkos view.");
114 &&
"neighbor_lists is not large enough to store all neighbors.");
125 &&
"cr_neighbor_lists and number_neighbors_list must be a 1D Kokkos view.");
156 KOKKOS_INLINE_FUNCTION
170 Kokkos::parallel_reduce(
"max number of neighbors",
172 KOKKOS_LAMBDA(
const int i,
int& t_max_num_neighbors) {
173 t_max_num_neighbors = (number_of_neighbors_list(i) > t_max_num_neighbors) ? number_of_neighbors_list(i) : t_max_num_neighbors;
185 Kokkos::parallel_reduce(
"min number of neighbors",
187 KOKKOS_LAMBDA(
const int i,
int& t_min_num_neighbors) {
188 t_min_num_neighbors = (number_of_neighbors_list(i) < t_min_num_neighbors) ? number_of_neighbors_list(i) : t_min_num_neighbors;
198 Kokkos::parallel_scan(
"number of neighbors offsets",
201 row_offsets(i) = lsum;
202 lsum += number_of_neighbors_list(i);
230 KOKKOS_INLINE_FUNCTION
242 KOKKOS_INLINE_FUNCTION
255 KOKKOS_INLINE_FUNCTION
265 &&
"Stale information in host_cr_neighbor_lists. Call CopyDeviceDataToHost() to refresh.");
267 &&
"neighor_num exceeds number of neighbors for this target_index.");
272 KOKKOS_INLINE_FUNCTION
275 &&
"neighor_num exceeds number of neighbors for this target_index.");
281 KOKKOS_INLINE_FUNCTION
288 KOKKOS_INLINE_FUNCTION
304 KOKKOS_INLINE_FUNCTION
313 template <
typename view_type>
319 template <
typename view_type>
325 template <
typename view_type>
331 template <
typename view_type_2d,
typename view_type_1d = Kokkos::View<
int*,
typename view_type_2d::memory_space,
typename view_type_2d::memory_traits> >
337 Kokkos::parallel_reduce(
"total number of neighbors over all lists", Kokkos::RangePolicy<typename view_type_2d::execution_space>(0, neighbor_lists.extent(0)),
339 t_total_num_neighbors += neighbor_lists(i,0);
340 }, Kokkos::Sum<global_index_type>(total_storage_size));
344 view_type_1d new_cr_neighbor_lists(
"compressed row neighbor lists", total_storage_size);
345 view_type_1d new_number_of_neighbors_list(
"number of neighbors list", neighbor_lists.extent(0));
349 auto d_neighbor_lists = create_mirror_view(
typename view_type_1d::execution_space(), neighbor_lists);
350 Kokkos::deep_copy(d_neighbor_lists, neighbor_lists);
352 Kokkos::parallel_for(
"copy number of neighbors to compressed row",
353 Kokkos::RangePolicy<typename view_type_1d::execution_space>(0, neighbor_lists.extent(0)),
354 KOKKOS_LAMBDA(
const int i) {
355 new_number_of_neighbors_list(i) = d_neighbor_lists(i,0);
362 auto cr_data = nla.getNeighborLists();
365 if (Kokkos::SpaceAccessibility<device_execution_space, typename view_type_1d::memory_space>::accessible==1) {
366 Kokkos::parallel_for(
"copy neighbor lists to compressed row", Kokkos::RangePolicy<typename view_type_1d::execution_space>(0, neighbor_lists.extent(0)),
367 KOKKOS_LAMBDA(
const int i) {
368 for (
int j=0; j<d_neighbor_lists(i,0); ++j) {
369 cr_data(nla.getRowOffsetDevice(i)+j) = d_neighbor_lists(i,j+1);
373 nla.copyDeviceDataToHost();
379 Kokkos::parallel_for(
"copy neighbor lists to compressed row", Kokkos::RangePolicy<host_execution_space>(0, neighbor_lists.extent(0)),
380 KOKKOS_LAMBDA(
const int i) {
381 for (
int j=0; j<neighbor_lists(i,0); ++j) {
382 cr_data(nla.getRowOffsetHost(i)+j) = d_neighbor_lists(i,j+1);
void computeRowOffsets()
Calculate the row offsets for each target's neighborhood (host)
int getNumberOfNeighborsHost(int target_index) const
Get number of neighbors for a given target (host)
NeighborLists(view_type number_of_neighbors_list)
Constructor for when number_of_neighbors_list is already populated. Will allocate space for compresse...
std::size_t global_index_type
view_type _number_of_neighbors_list
KOKKOS_INLINE_FUNCTION int getNumberOfNeighborsDevice(int target_index) const
Get number of neighbors for a given target (device)
#define compadre_assert_extreme_debug(condition)
compadre_kernel_assert_debug is similar to compadre_assert_debug, but is a call on the device...
KOKKOS_INLINE_FUNCTION int getNumberOfTargets() const
Get number of total targets having neighborhoods (host/device).
#define compadre_kernel_assert_extreme_debug(condition)
internal_row_offsets_view_type _row_offsets
global_index_type getRowOffsetHost(int target_index) const
Get offset into compressed row neighbor lists (host)
KOKKOS_INLINE_FUNCTION int getMinNumNeighbors() const
Get the minimum number of neighbors of all targets' neighborhoods (host/device)
KOKKOS_INLINE_FUNCTION void setNeighborDevice(int target_index, int neighbor_num, int new_value)
Setter function for N(i,j) indexing where N(i,j) is the index of the jth neighbor of i...
view_type internal_view_type
NeighborLists(view_type cr_neighbor_lists, view_type number_of_neighbors_list, internal_row_offsets_view_type neighbor_lists_row_offsets, bool compute_max=true)
Constructor for when compressed row cr_neighbor_lists is preallocated/populated, number_of_neighbors_...
NeighborLists< view_type > CreateNeighborLists(view_type number_of_neighbors_list)
CreateNeighborLists allows for the construction of an object of type NeighborLists with template dedu...
view_type getNeighborLists() const
Device view into neighbor lists data (use with caution)
NeighborLists(view_type cr_neighbor_lists, view_type number_of_neighbors_list)
Constructor for when compressed row cr_neighbor_lists is preallocated/populated, and number_of_neighb...
void computeMinNumNeighbors()
Calculate the minimum number of neighbors of all targets' neighborhoods (host)
internal_row_offsets_view_type::HostMirror _host_row_offsets
void computeMaxNumNeighbors()
Calculate the maximum number of neighbors of all targets' neighborhoods (host)
global_index_type getTotalNeighborsOverAllListsHost() const
Get the sum of the number of neighbors of all targets' neighborhoods (host)
#define TO_GLOBAL(variable)
Kokkos::View< global_index_type *, typename view_type::array_layout, typename view_type::memory_space, typename view_type::memory_traits > internal_row_offsets_view_type
KOKKOS_INLINE_FUNCTION global_index_type getTotalNeighborsOverAllListsDevice() const
Get the sum of the number of neighbors of all targets' neighborhoods (device)
view_type _cr_neighbor_lists
KOKKOS_INLINE_FUNCTION int getMaxNumNeighbors() const
Get the maximum number of neighbors of all targets' neighborhoods (host/device)
void copyDeviceDataToHost()
Sync the host from the device (copy device data to host)
NeighborLists()
Constructor for the purpose of classes who have NeighborLists as a member object. ...
int _max_neighbor_list_row_storage_size
int getNeighborHost(int target_index, int neighbor_num) const
Offers N(i,j) indexing where N(i,j) is the index of the jth neighbor of i (host)
view_type::HostMirror _host_cr_neighbor_lists
#define compadre_assert_debug(condition)
compadre_assert_debug is used for assertions that are checked in loops, as these significantly impact...
view_type getNumberOfNeighborsList() const
Device view into number of neighbors list (use with caution)
KOKKOS_INLINE_FUNCTION int getNeighborDevice(int target_index, int neighbor_num) const
Offers N(i,j) indexing where N(i,j) is the index of the jth neighbor of i (device) ...
NeighborLists< view_type_1d > Convert2DToCompressedRowNeighborLists(view_type_2d neighbor_lists)
Converts 2D neighbor lists to compressed row neighbor lists.
NeighborLists assists in accessing entries of compressed row neighborhood lists.
KOKKOS_INLINE_FUNCTION global_index_type getRowOffsetDevice(int target_index) const
Get offset into compressed row neighbor lists (device)
view_type::HostMirror _host_number_of_neighbors_list
#define compadre_assert_release(condition)
compadre_assert_release is used for assertions that should always be checked, but generally are not e...
int _min_neighbor_list_row_storage_size
#define compadre_kernel_assert_debug(condition)