deal.II version 9.7.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
distributed_tree.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2022 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_arborx_distributed_tree_h
16#define dealii_arborx_distributed_tree_h
17
18#include <deal.II/base/config.h>
19
20#if defined(DEAL_II_ARBORX_WITH_MPI) && defined(DEAL_II_WITH_MPI)
22
23# include <deal.II/base/mpi.h>
24
25# include <ArborX_DistributedTree.hpp>
26# include <Kokkos_Core.hpp>
27
29
30namespace ArborXWrappers
31{
36# if ARBORX_VERSION_MAJOR < 2
38 {
39 public:
44 template <int dim, typename Number>
46 const MPI_Comm comm,
47 const std::vector<BoundingBox<dim, Number>> &bounding_boxes);
48
53 template <int dim, typename Number>
55 const std::vector<Point<dim, Number>> &points);
56
71 template <typename QueryType>
72 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
73 query(const QueryType &queries);
74
75 private:
79 ArborX::DistributedTree<Kokkos::HostSpace> distributed_tree;
80 };
81
82
83
84 template <int dim, typename Number>
86 const MPI_Comm comm,
87 const std::vector<BoundingBox<dim, Number>> &bounding_boxes)
89 Kokkos::DefaultHostExecutionSpace{},
90 bounding_boxes)
91 {}
92
93
94
95 template <int dim, typename Number>
97 const MPI_Comm comm,
98 const std::vector<Point<dim, Number>> &points)
99 : distributed_tree(comm, Kokkos::DefaultHostExecutionSpace{}, points)
100 {}
101
102
103
104 template <typename QueryType>
105 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
106 DistributedTree::query(const QueryType &queries)
107 {
108 Kokkos::View<int *, Kokkos::HostSpace> offsets("offsets", 0);
109 Kokkos::View<Kokkos::pair<int, int> *, Kokkos::HostSpace> indices_ranks(
110 "indices_ranks", 0);
111 distributed_tree.query(Kokkos::DefaultHostExecutionSpace{},
112 queries,
113 indices_ranks,
114 offsets);
115
116 std::vector<std::pair<int, int>> indices_ranks_vector;
117 for (unsigned int i = 0; i < indices_ranks.extent(0); ++i)
118 {
119 indices_ranks_vector.emplace_back(indices_ranks(i).first,
120 indices_ranks(i).second);
121 }
122
123 std::vector<int> offsets_vector;
124 offsets_vector.insert(offsets_vector.begin(),
125 offsets.data(),
126 offsets.data() + offsets.extent(0));
127
128 return {indices_ranks_vector, offsets_vector};
129 }
130# else
131 template <typename Value>
132 class DistributedTree
133 {
134 public:
140 DistributedTree(const MPI_Comm comm, const std::vector<Value> &values);
141
156 template <typename QueryType>
157 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
158 query(const QueryType &queries);
159
160 private:
164 ArborX::DistributedTree<Kokkos::HostSpace,
165 ArborX::PairValueIndex<Value, unsigned int>,
166 internal::IndexableGetter>
172 internal::ExtractIndexRank callback;
173 };
174
175
176
177 template <typename Value>
179 const std::vector<Value> &values)
180 : distributed_tree(comm,
181 Kokkos::DefaultHostExecutionSpace{},
182 ArborX::Experimental::attach_indices(values),
183 internal::IndexableGetter{})
184 , callback{Utilities::MPI::this_mpi_process(comm)}
185 {}
186
187 template <typename Value>
188 template <typename QueryType>
189 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
190 DistributedTree<Value>::query(const QueryType &queries)
191 {
192 Kokkos::View<int *, Kokkos::HostSpace> offsets("offsets", 0);
193 Kokkos::View<Kokkos::pair<unsigned int, unsigned int> *, Kokkos::HostSpace>
194 indices_ranks("indices_ranks", 0);
195 if constexpr (QueryType::is_nearest)
196 {
197 distributed_tree.query(
198 Kokkos::DefaultHostExecutionSpace{},
199 queries,
200 ArborX::Experimental::declare_callback_constrained(callback),
201 indices_ranks,
202 offsets);
203 }
204 else
205 {
206 distributed_tree.query(Kokkos::DefaultHostExecutionSpace{},
207 queries,
208 callback,
209 indices_ranks,
210 offsets);
211 }
212
213 std::vector<std::pair<int, int>> indices_ranks_vector;
214 for (unsigned int i = 0; i < indices_ranks.extent(0); ++i)
215 {
216 indices_ranks_vector.emplace_back(indices_ranks(i).first,
217 indices_ranks(i).second);
218 }
219
220 std::vector<int> offsets_vector;
221 offsets_vector.insert(offsets_vector.begin(),
222 offsets.data(),
223 offsets.data() + offsets.extent(0));
224
225 return {indices_ranks_vector, offsets_vector};
226 }
227
228# endif
229} // namespace ArborXWrappers
230
232
233#else
234
235// Make sure the scripts that create the C++20 module input files have
236// something to latch on if the preprocessor #ifdef above would
237// otherwise lead to an empty content of the file.
240
241#endif
242#endif
ArborX::DistributedTree< Kokkos::HostSpace > distributed_tree
std::pair< std::vector< std::pair< int, int > >, std::vector< int > > query(const QueryType &queries)
DistributedTree(const MPI_Comm comm, const std::vector< BoundingBox< dim, Number > > &bounding_boxes)
Definition point.h:113
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
*braid_SplitCommworld & comm