deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\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: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2022 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_arborx_distributed_tree_h
14#define dealii_arborx_distributed_tree_h
15
16#include <deal.II/base/config.h>
17
18#if defined(DEAL_II_ARBORX_WITH_MPI) && defined(DEAL_II_WITH_MPI)
20
21# include <deal.II/base/mpi.h>
22
23# include <ArborX_DistributedTree.hpp>
24# include <Kokkos_Core.hpp>
25
26#endif
27
29
30#if defined(DEAL_II_ARBORX_WITH_MPI) && defined(DEAL_II_WITH_MPI)
31namespace ArborXWrappers
32{
37# if ARBORX_VERSION_MAJOR < 2
39 {
40 public:
45 template <int dim, typename Number>
47 const MPI_Comm comm,
48 const std::vector<BoundingBox<dim, Number>> &bounding_boxes);
49
54 template <int dim, typename Number>
56 const std::vector<Point<dim, Number>> &points);
57
72 template <typename QueryType>
73 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
74 query(const QueryType &queries);
75
76 private:
80 ArborX::DistributedTree<Kokkos::HostSpace> distributed_tree;
81 };
82
83
84
85 template <int dim, typename Number>
87 const MPI_Comm comm,
88 const std::vector<BoundingBox<dim, Number>> &bounding_boxes)
89 : distributed_tree(comm,
90 Kokkos::DefaultHostExecutionSpace{},
91 bounding_boxes)
92 {}
93
94
95
96 template <int dim, typename Number>
98 const MPI_Comm comm,
99 const std::vector<Point<dim, Number>> &points)
100 : distributed_tree(comm, Kokkos::DefaultHostExecutionSpace{}, points)
101 {}
102
103
104
105 template <typename QueryType>
106 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
107 DistributedTree::query(const QueryType &queries)
108 {
109 Kokkos::View<int *, Kokkos::HostSpace> offsets("offsets", 0);
110 Kokkos::View<Kokkos::pair<int, int> *, Kokkos::HostSpace> indices_ranks(
111 "indices_ranks", 0);
112 distributed_tree.query(Kokkos::DefaultHostExecutionSpace{},
113 queries,
114 indices_ranks,
115 offsets);
116
117 std::vector<std::pair<int, int>> indices_ranks_vector;
118 for (unsigned int i = 0; i < indices_ranks.extent(0); ++i)
119 {
120 indices_ranks_vector.emplace_back(indices_ranks(i).first,
121 indices_ranks(i).second);
122 }
123
124 std::vector<int> offsets_vector;
125 offsets_vector.insert(offsets_vector.begin(),
126 offsets.data(),
127 offsets.data() + offsets.extent(0));
128
129 return {indices_ranks_vector, offsets_vector};
130 }
131# else
132 template <typename Value>
133 class DistributedTree
134 {
135 public:
141 DistributedTree(const MPI_Comm comm, const std::vector<Value> &values);
142
157 template <typename QueryType>
158 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
159 query(const QueryType &queries);
160
161 private:
165 ArborX::DistributedTree<Kokkos::HostSpace,
166 ArborX::PairValueIndex<Value, unsigned int>,
167 internal::IndexableGetter>
173 internal::ExtractIndexRank callback;
174 };
175
176
177
178 template <typename Value>
180 const std::vector<Value> &values)
181 : distributed_tree(comm,
182 Kokkos::DefaultHostExecutionSpace{},
183 ArborX::Experimental::attach_indices(values),
184 internal::IndexableGetter{})
185 , callback{Utilities::MPI::this_mpi_process(comm)}
186 {}
187
188 template <typename Value>
189 template <typename QueryType>
190 std::pair<std::vector<std::pair<int, int>>, std::vector<int>>
191 DistributedTree<Value>::query(const QueryType &queries)
192 {
193 Kokkos::View<int *, Kokkos::HostSpace> offsets("offsets", 0);
194 Kokkos::View<Kokkos::pair<unsigned int, unsigned int> *, Kokkos::HostSpace>
195 indices_ranks("indices_ranks", 0);
196 if constexpr (QueryType::is_nearest)
197 {
198 distributed_tree.query(
199 Kokkos::DefaultHostExecutionSpace{},
200 queries,
201 ArborX::Experimental::declare_callback_constrained(callback),
202 indices_ranks,
203 offsets);
204 }
205 else
206 {
207 distributed_tree.query(Kokkos::DefaultHostExecutionSpace{},
208 queries,
209 callback,
210 indices_ranks,
211 offsets);
212 }
213
214 std::vector<std::pair<int, int>> indices_ranks_vector;
215 for (unsigned int i = 0; i < indices_ranks.extent(0); ++i)
216 {
217 indices_ranks_vector.emplace_back(indices_ranks(i).first,
218 indices_ranks(i).second);
219 }
220
221 std::vector<int> offsets_vector;
222 offsets_vector.insert(offsets_vector.begin(),
223 offsets.data(),
224 offsets.data() + offsets.extent(0));
225
226 return {indices_ranks_vector, offsets_vector};
227 }
228
229# endif
230} // namespace ArborXWrappers
231
232#endif
233
235#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:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
const MPI_Comm comm
Definition mpi.cc:912