DDC 0.15.0
Loading...
Searching...
No Matches
parallel_transform_reduce.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <cstddef>
8#include <string>
9#include <type_traits>
10#include <utility>
11
12#include <Kokkos_Core.hpp>
13
14#include "chunk_traits.hpp"
17#include "reducer.hpp"
18
19namespace ddc {
20
21namespace detail {
22
23template <class Reducer, class MemorySpace>
24struct DdcToKokkosReducer
25{
26};
27
28template <class T, class MemorySpace>
29struct DdcToKokkosReducer<reducer::sum<T>, MemorySpace>
30{
31 using type = Kokkos::Sum<T, MemorySpace>;
32};
33
34template <class T, class MemorySpace>
35struct DdcToKokkosReducer<reducer::prod<T>, MemorySpace>
36{
37 using type = Kokkos::Prod<T, MemorySpace>;
38};
39
40template <class T, class MemorySpace>
41struct DdcToKokkosReducer<reducer::land<T>, MemorySpace>
42{
43 using type = Kokkos::LAnd<T, MemorySpace>;
44};
45
46template <class T, class MemorySpace>
47struct DdcToKokkosReducer<reducer::lor<T>, MemorySpace>
48{
49 using type = Kokkos::LOr<T, MemorySpace>;
50};
51
52template <class T, class MemorySpace>
53struct DdcToKokkosReducer<reducer::band<T>, MemorySpace>
54{
55 using type = Kokkos::BAnd<T, MemorySpace>;
56};
57
58template <class T, class MemorySpace>
59struct DdcToKokkosReducer<reducer::bor<T>, MemorySpace>
60{
61 using type = Kokkos::BOr<T, MemorySpace>;
62};
63
64template <class T, class MemorySpace>
65struct DdcToKokkosReducer<reducer::bxor<T>, MemorySpace>
66{
67 static_assert(std::is_same_v<T, T>, "This reducer is not yet implemented");
68};
69
70template <class T, class MemorySpace>
71struct DdcToKokkosReducer<reducer::min<T>, MemorySpace>
72{
73 using type = Kokkos::Min<T, MemorySpace>;
74};
75
76template <class T, class MemorySpace>
77struct DdcToKokkosReducer<reducer::max<T>, MemorySpace>
78{
79 using type = Kokkos::Max<T, MemorySpace>;
80};
81
82template <class T, class MemorySpace>
83struct DdcToKokkosReducer<reducer::minmax<T>, MemorySpace>
84{
85 using type = Kokkos::MinMax<T, MemorySpace>;
86};
87
88/// Alias template to transform a DDC reducer type to a Kokkos reducer type
89template <class Reducer, class MemorySpace = Kokkos::HostSpace>
90using ddc_to_kokkos_reducer_t = DdcToKokkosReducer<Reducer, MemorySpace>::type;
91
92template <class Reducer, class Functor, class Support, class IndexSequence>
93class TransformReducerKokkosLambdaAdapter
94{
95};
96
97template <class Reducer, class Functor, class Support, std::size_t... Idx>
98class TransformReducerKokkosLambdaAdapter<Reducer, Functor, Support, std::index_sequence<Idx...>>
99{
100 template <std::size_t I>
101 using index_type = DiscreteVectorElement;
102
103 Reducer m_reducer;
104
105 Functor m_functor;
106
107 Support m_support;
108
109public:
110 TransformReducerKokkosLambdaAdapter(Reducer const& r, Functor const& f, Support const& support)
111 : m_reducer(r)
112 , m_functor(f)
113 , m_support(support)
114 {
115 }
116
117 KOKKOS_FUNCTION void operator()(index_type<0> /*id*/, Reducer::value_type& a) const
118 requires(sizeof...(Idx) == 0)
119 {
120 a = m_reducer(a, m_functor(m_support(typename Support::discrete_vector_type())));
121 }
122
123 KOKKOS_FUNCTION void operator()(index_type<Idx>... ids, Reducer::value_type& a) const
124 requires(sizeof...(Idx) > 0)
125 {
126 a = m_reducer(a, m_functor(m_support(typename Support::discrete_vector_type(ids...))));
127 }
128};
129
130template <class Reducer, class Functor, class Support>
131TransformReducerKokkosLambdaAdapter(Reducer const& r, Functor const& f, Support const& support)
132 -> TransformReducerKokkosLambdaAdapter<
133 Reducer,
134 Functor,
135 Support,
136 std::make_index_sequence<Support::rank()>>;
137
138/** A parallel reduction over a nD domain using the default Kokkos execution space
139 * @param[in] label name for easy identification of the parallel_for_each algorithm
140 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
141 * @param[in] domain the range over which to apply the algorithm
142 * @param[in] neutral the neutral element of the reduction operation
143 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
144 * results of transform, the results of other reduce and neutral.
145 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
146 * range. The return type must be acceptable as input to reduce
147 */
148template <class ExecSpace, class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
149T transform_reduce_kokkos(
150 std::string const& label,
151 ExecSpace const& execution_space,
152 Support const& domain,
153 T neutral,
154 BinaryReductionOp const& reduce,
155 UnaryTransformOp const& transform) noexcept
156{
157 T result = neutral;
158 Kokkos::parallel_reduce(
159 label,
160 ddc_to_kokkos_execution_policy(execution_space, detail::array(domain.extents())),
161 TransformReducerKokkosLambdaAdapter(reduce, transform, domain),
162 ddc_to_kokkos_reducer_t<BinaryReductionOp>(result));
163 return result;
164}
165
166} // namespace detail
167
168/** A reduction over a nD domain using a given `Kokkos` execution space
169 * @param[in] label name for easy identification of the parallel_for_each algorithm
170 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
171 * @param[in] domain the range over which to apply the algorithm
172 * @param[in] neutral the neutral element of the reduction operation
173 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
174 * results of transform, the results of other reduce and neutral.
175 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
176 * range. The return type must be acceptable as input to reduce
177 */
178template <class ExecSpace, class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
180 std::string const& label,
181 ExecSpace const& execution_space,
182 Support const& domain,
183 T neutral,
184 BinaryReductionOp&& reduce,
185 UnaryTransformOp&& transform) noexcept
186{
187 return detail::transform_reduce_kokkos(
188 label,
189 execution_space,
190 domain,
191 neutral,
192 std::forward<BinaryReductionOp>(reduce),
193 std::forward<UnaryTransformOp>(transform));
194}
195
196/** A reduction over a nD domain using a given `Kokkos` execution space
197 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
198 * @param[in] domain the range over which to apply the algorithm
199 * @param[in] neutral the neutral element of the reduction operation
200 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
201 * results of transform, the results of other reduce and neutral.
202 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
203 * range. The return type must be acceptable as input to reduce
204 */
205template <class ExecSpace, class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
207 ExecSpace const& execution_space,
208 Support const& domain,
209 T neutral,
210 BinaryReductionOp&& reduce,
211 UnaryTransformOp&& transform) noexcept
212 requires(Kokkos::is_execution_space_v<ExecSpace>)
213{
214 return detail::transform_reduce_kokkos(
215 "ddc_parallel_transform_reduce_default",
216 execution_space,
217 domain,
218 neutral,
219 std::forward<BinaryReductionOp>(reduce),
220 std::forward<UnaryTransformOp>(transform));
221}
222
223/** A reduction over a nD domain using the `Kokkos` default execution space
224 * @param[in] label name for easy identification of the parallel_for_each algorithm
225 * @param[in] domain the range over which to apply the algorithm
226 * @param[in] neutral the neutral element of the reduction operation
227 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
228 * results of transform, the results of other reduce and neutral.
229 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
230 * range. The return type must be acceptable as input to reduce
231 */
232template <class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
234 std::string const& label,
235 Support const& domain,
236 T neutral,
237 BinaryReductionOp&& reduce,
238 UnaryTransformOp&& transform) noexcept
239{
240 return parallel_transform_reduce(
241 label,
242 Kokkos::DefaultExecutionSpace(),
243 domain,
244 neutral,
245 std::forward<BinaryReductionOp>(reduce),
246 std::forward<UnaryTransformOp>(transform));
247}
248
249/** A reduction over a nD domain using the `Kokkos` default execution space
250 * @param[in] domain the range over which to apply the algorithm
251 * @param[in] neutral the neutral element of the reduction operation
252 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
253 * results of transform, the results of other reduce and neutral.
254 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
255 * range. The return type must be acceptable as input to reduce
256 */
257template <class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
259 Support const& domain,
260 T neutral,
261 BinaryReductionOp&& reduce,
262 UnaryTransformOp&& transform) noexcept
263{
264 return parallel_transform_reduce(
265 "ddc_parallel_transform_reduce_default",
266 Kokkos::DefaultExecutionSpace(),
267 domain,
268 neutral,
269 std::forward<BinaryReductionOp>(reduce),
270 std::forward<UnaryTransformOp>(transform));
271}
272
273namespace experimental {
274
275namespace detail {
276
277template <class Reducer, class Functor, class Support, class DElem, class IndexSequence>
278class TransformReducerChunkKokkosLambdaAdapter
279{
280};
281
282template <class Reducer, class Functor, class Support, class DElem, std::size_t... Idx>
283class TransformReducerChunkKokkosLambdaAdapter<
284 Reducer,
285 Functor,
286 Support,
287 DElem,
288 std::index_sequence<Idx...>>
289{
290 template <std::size_t I>
291 using index_type = DiscreteVectorElement;
292
293 Reducer m_reducer;
294
295 Functor m_functor;
296
297 Support m_support;
298
299 DElem m_delem;
300
301public:
302 TransformReducerChunkKokkosLambdaAdapter(
303 Reducer const& r,
304 Functor const& f,
305 Support const& support,
306 DElem const& delem)
307 : m_reducer(r)
308 , m_functor(f)
309 , m_support(support)
310 , m_delem(delem)
311 {
312 }
313
314 KOKKOS_FUNCTION void operator()(
315 [[maybe_unused]] index_type<0> unused_id,
316 Reducer::value_type& a) const
317 requires(sizeof...(Idx) == 0)
318 {
319 a = m_reducer(a, m_functor(m_delem, m_support(typename Support::discrete_vector_type())));
320 }
321
322 KOKKOS_FUNCTION void operator()(index_type<Idx>... ids, Reducer::value_type& a) const
323 requires(sizeof...(Idx) > 0)
324 {
325 a = m_reducer(
326 a,
327 m_functor(m_delem, m_support(typename Support::discrete_vector_type(ids...))));
328 }
329};
330
331template <class Reducer, class Functor, class Support, class DElem, std::size_t... Idx>
332TransformReducerChunkKokkosLambdaAdapter(
333 Reducer const& r,
334 Functor const& f,
335 Support const& support,
336 DElem const& delem)
337 -> TransformReducerChunkKokkosLambdaAdapter<
338 Reducer,
339 Functor,
340 Support,
341 DElem,
342 std::make_index_sequence<Support::rank()>>;
343
344} // namespace detail
345
346/** Performs a parallel transform-reduce over an nD domain using a Kokkos execution space.
347 *
348 * For each element of `out`, a reduction is performed over the dimensions of
349 * `domain` that are not present in `out.domain()`. The reduction combines the
350 * values obtained by applying `transform` to each element of the corresponding
351 * subdomain.
352 *
353 * @param[in] label name used to identify the Kokkos kernel.
354 * @param[in] execution_space Kokkos execution space on which the reductions are executed.
355 * @param[in] domain full domain over which the transform-reduce is defined.
356 * @param[out] out chunk receiving the reduction result for each point of
357 * `out.domain()`. Its domain must be a subdomain of `domain`.
358 * @param[in] reduce binary reduction operator used to combine transformed values.
359 * It must be compatible with the value type stored in `out`.
360 * @param[in] transform unary function applied to each element of the reduction
361 * subdomain. Its return type must be accepted by `reduce`.
362 */
363template <
364 class ExecSpace,
365 class Support,
366 concepts::borrowed_chunk ChunkDst,
367 class BinaryReductionOp,
368 class UnaryTransformOp>
370 std::string const& label,
371 ExecSpace const& execution_space,
372 Support const& domain,
373 ChunkDst&& out,
374 BinaryReductionOp const& reduce,
375 UnaryTransformOp const& transform) noexcept
376{
377 using DDomOut = std::remove_cvref_t<ChunkDst>::discrete_domain_type;
378 using DElemOut = DDomOut::discrete_element_type;
379 using MemorySpaceOut = std::remove_cvref_t<ChunkDst>::memory_space;
380 assert(out.domain() == DDomOut(domain));
381
382 auto ddom_interest = remove_dims_of(domain, out.domain());
383 host_for_each(out.domain(), [&](DElemOut iout) {
384 Kokkos::parallel_reduce(
385 label,
386 ddc::detail::ddc_to_kokkos_execution_policy(
387 execution_space,
388 ddc::detail::array(ddom_interest.extents())),
389 detail::TransformReducerChunkKokkosLambdaAdapter(
390 reduce,
391 transform,
392 ddom_interest,
393 iout),
394 ddc::detail::ddc_to_kokkos_reducer_t<BinaryReductionOp, MemorySpaceOut>(
395 out[iout].allocation_kokkos_view()));
396 });
397}
398
399} // namespace experimental
400
401} // namespace ddc
friend class ChunkSpan
friend class DiscreteDomain
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
KOKKOS_FUNCTION std::size_t size() const
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Impl & operator=(Impl &&x)=default
Impl & operator=(Impl const &x)=delete
Impl(InputIt const points_begin, InputIt const points_end)
Construct a NonUniformPointSampling using a pair of iterators.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
Impl(InputRange const &points)
Construct a NonUniformPointSampling using a C++20 "common range".
Impl(std::initializer_list< Coordinate< CDim > > const points)
Construct a NonUniformPointSampling using a brace-list, i.e. NonUniformPointSampling mesh({0....
NonUniformPointSampling models a non-uniform discretization of the CDim segment .
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(InputRange const &non_uniform_points)
Construct an Impl<Kokkos::HostSpace> and associated discrete_domain_type from a range containing the ...
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(InputRange const &domain_r, InputRange const &pre_ghost_r, InputRange const &post_ghost_r)
Construct 4 non-uniform DiscreteDomain and an Impl<Kokkos::HostSpace> from 3 ranges containing the po...
Impl & operator=(Impl &&x)=default
KOKKOS_FUNCTION Coordinate< CDim > origin() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl const &)=delete
KOKKOS_FUNCTION std::size_t n_period() const
Number of steps in a period.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Impl(Coordinate< CDim > origin, Real step, std::size_t n_period)
Construct a Impl from a point and a spacing step.
KOKKOS_FUNCTION Real step() const
Spacing step of the mesh.
Impl & operator=(Impl const &x)=delete
PeriodicSampling models a periodic discretization of the provided continuous dimension.
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period)
Construct a Impl<Kokkos::HostSpace> and associated discrete_domain_type from a segment and a number ...
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period, DiscreteVector< DDim > n_ghosts_before, DiscreteVector< DDim > n_ghosts_after)
Construct a periodic DiscreteDomain from a segment and a number of points n.
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period, DiscreteVector< DDim > n_ghosts)
Construct a periodic DiscreteDomain from a segment and a number of points n.
ScopeGuard & operator=(ScopeGuard const &x)=delete
~ScopeGuard() noexcept
ScopeGuard(int argc, char **&argv)
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(ScopeGuard const &x)=delete
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteElement operator()(DiscreteVector<> const &) const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type) const
static KOKKOS_FUNCTION DiscreteVector distance_from_front() noexcept
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
static KOKKOS_FUNCTION DiscreteVector distance_from_front(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const &) const
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
static KOKKOS_FUNCTION bool contains() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type) const
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain()=default
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain(SparseDiscreteDomain< ODDims... > const &)
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type n) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_FUNCTION DiscreteVector< DDims... > distance_from_front(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr auto discrete_elements() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
SparseDiscreteDomain(Kokkos::View< DiscreteElement< DDims > *, Kokkos::SharedSpace > const &... views)
Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr std::size_t size() const
KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain(DDoms const &... domains)
Construct a SparseDiscreteDomain by copies and merge of domains.
KOKKOS_FUNCTION constexpr DiscreteElement< DDims... > operator()(DiscreteVector< DDims... > const &dvect) const noexcept
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain()=default
static KOKKOS_FUNCTION DiscreteVector distance_from_front() noexcept
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain & operator=(StridedDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr StridedDiscreteDomain take_first(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr std::size_t size()
KOKKOS_FUNCTION constexpr StridedDiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size, discrete_vector_type const &strides)
Construct a StridedDiscreteDomain starting from element_begin with size points.
KOKKOS_FUNCTION constexpr StridedDiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_FUNCTION constexpr StridedDiscreteDomain take_last(discrete_vector_type) const
KOKKOS_FUNCTION constexpr bool operator==(StridedDiscreteDomain const &) const
KOKKOS_FUNCTION constexpr StridedDiscreteDomain remove_first(discrete_vector_type) const
static KOKKOS_FUNCTION bool contains() noexcept
KOKKOS_FUNCTION constexpr StridedDiscreteDomain remove_last(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain(StridedDiscreteDomain &&x)=default
static KOKKOS_FUNCTION DiscreteVector distance_from_front(DiscreteElement<>) noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr StridedDiscreteDomain()=default
KOKKOS_FUNCTION constexpr operator bool()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain(StridedDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteElement operator()(DiscreteVector<> const &) const noexcept
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
KOKKOS_FUNCTION constexpr StridedDiscreteDomain(StridedDiscreteDomain< ODDims... > const &)
KOKKOS_DEFAULTED_FUNCTION ~StridedDiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain & operator=(StridedDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain & operator=(StridedDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr StridedDiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr std::size_t size() const
KOKKOS_FUNCTION DiscreteVector< DDims... > distance_from_front(DElems const &... delems) const noexcept
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain(StridedDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_vector_type strides() const noexcept
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain & operator=(StridedDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr StridedDiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr StridedDiscreteDomain remove_first(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteElement< DDims... > operator()(DiscreteVector< DDims... > const &dvect) const noexcept
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_FUNCTION constexpr StridedDiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr StridedDiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION ~StridedDiscreteDomain()=default
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomain(StridedDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr bool operator==(StridedDiscreteDomain< ODims... > const &other) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr StridedDiscreteDomain(DDoms const &... domains)
Construct a StridedDiscreteDomain by copies and merge of domains.
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr StridedDiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &extents, discrete_vector_type const &strides)
Construct a StridedDiscreteDomain starting from element_begin with size points.
Impl(Coordinate< CDim > origin, Real step)
Construct a Impl from a point and a spacing step.
Impl & operator=(Impl const &x)=delete
KOKKOS_FUNCTION Coordinate< CDim > origin() const noexcept
Lower bound index of the mesh.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION Real step() const
Spacing step of the mesh.
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl & operator=(Impl &&x)=default
Impl(Impl const &)=delete
UniformPointSampling models a uniform discretization of the provided continuous dimension.
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n)
Construct a Impl<Kokkos::HostSpace> and associated discrete_domain_type from a segment and a number ...
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_ghosts)
Construct a uniform DiscreteDomain from a segment and a number of points n.
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_ghosts_before, DiscreteVector< DDim > n_ghosts_after)
Construct a uniform DiscreteDomain from a segment and a number of points n.
#define DDC_BUILD_DEPRECATED_CODE
Definition config.hpp:7
void parallel_transform_reduce(std::string const &label, ExecSpace const &execution_space, Support const &domain, ChunkDst &&out, BinaryReductionOp const &reduce, UnaryTransformOp const &transform) noexcept
Performs a parallel transform-reduce over an nD domain using a Kokkos execution space.
The top-level namespace of DDC.
auto parallel_fill(ExecSpace const &execution_space, ChunkDst &&dst, T const &value)
Fill a borrowed chunk with a given value.
constexpr bool is_non_uniform_point_sampling_v
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(SparseDiscreteDomain< DDims... > const &domain) noexcept
T parallel_transform_reduce(ExecSpace const &execution_space, Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain using a given Kokkos execution space.
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(StridedDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rlength(DiscreteDomain< DDim > const &d)
bool is_discrete_space_initialized() noexcept
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_left(DiscreteElement< DDim > i)
T parallel_transform_reduce(Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain using the Kokkos default execution space.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > origin() noexcept
Lower bound index of the mesh.
T parallel_transform_reduce(std::string const &label, ExecSpace const &execution_space, Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain using a given Kokkos execution space.
auto parallel_deepcopy(ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
void parallel_for_each(std::string const &label, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using the Kokkos default execution space
void parallel_for_each(Support const &domain, Functor &&f) noexcept
iterates over a nD domain using the Kokkos default execution space
KOKKOS_FUNCTION constexpr SparseDiscreteDomain< QueryDDims... > select(SparseDiscreteDomain< DDims... > const &domain)
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(StridedDiscreteDomain< DDims... > const &domain) noexcept
auto parallel_transform(std::string const &label, ChunkDst &&dst, UnaryTransformOp &&transform)
Transform a borrowed chunk with a given transform functor.
constexpr bool is_uniform_point_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmin(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(StridedDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr StridedDiscreteDomain< QueryDDims... > select(StridedDiscreteDomain< DDims... > const &domain)
KOKKOS_FUNCTION constexpr auto remove_dims_of(StridedDiscreteDomain< DDimsA... > const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_right(DiscreteElement< DDim > i)
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
KOKKOS_FUNCTION constexpr auto remove_dims_of(StridedDiscreteDomain< DDimsA... > const &DDom_a, StridedDiscreteDomain< DDimsB... > const &) noexcept
constexpr DiscreteElement< DDim > init_trivial_half_bounded_space() noexcept
Construct a half bounded dimension without attributes.
void host_for_each(Support const &domain, Functor &&f) noexcept
iterates over a nD domain in serial
Definition for_each.hpp:75
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &) noexcept
void host_for_each_block(Support const &domain, std::size_t nb_blocks, Functor const &f) noexcept
Iterate over blocks of a domain using a total number of blocks.
constexpr DiscreteDomain< DDim > init_trivial_bounded_space(DiscreteVector< DDim > const n) noexcept
Construct a bounded dimension without attributes.
detail::ddim_impl_t< DDim, Kokkos::HostSpace > const & host_discrete_space()
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(SparseDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr auto replace_dim_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &DDom_b) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(SparseDiscreteDomain< DDims... > const &domain) noexcept
auto parallel_fill(ChunkDst &&dst, T const &value)
Fill a borrowed chunk with a given value.
constexpr bool is_strided_discrete_domain_v
KOKKOS_FUNCTION DiscreteVector< ODDims... > prod(DiscreteVector< ODDims... > const &lhs, DiscreteVector< ODDims... > const &rhs) noexcept
void parallel_for_each(ExecSpace const &execution_space, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
constexpr bool is_periodic_sampling_v
auto parallel_transform(std::string const &label, ExecSpace const &execution_space, ChunkDst &&dst, UnaryTransformOp &&transform)
Transform a borrowed chunk with a given transform functor.
KOKKOS_FUNCTION Real step() noexcept
Spacing step of the mesh.
KOKKOS_FUNCTION constexpr auto replace_dim_of(StridedDiscreteDomain< DDimsA... > const &DDom_a, StridedDiscreteDomain< DDimsB... > const &DDom_b) noexcept
auto parallel_transform(ExecSpace const &execution_space, ChunkDst &&dst, UnaryTransformOp &&transform)
Transform a borrowed chunk with a given transform functor.
constexpr bool is_sparse_discrete_domain_v
void host_for_each_block(Support const &domain, typename Support::discrete_vector_type nb_blocks_per_dim, Functor const &f) noexcept
Iterate over blocks of a domain using a per-dimension block specification.
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
T parallel_transform_reduce(std::string const &label, Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain using the Kokkos default execution space.
KOKKOS_FUNCTION DiscreteElement< DDim > front() noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION detail::ddim_impl_t< DDim, MemorySpace > const & discrete_space()
auto parallel_deepcopy(ExecSpace const &execution_space, ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
void parallel_for_each(std::string const &label, ExecSpace const &execution_space, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
auto parallel_copy(ExecSpace const &execution_space, ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
Arg0 init_discrete_space(std::tuple< DDimImpl, Arg0 > &&a)
Move construct a global singleton discrete space and pass through the other argument.
auto parallel_transform(ChunkDst &&dst, UnaryTransformOp &&transform)
Transform a borrowed chunk with a given transform functor.
KOKKOS_FUNCTION void device_for_each(Support const &domain, Functor &&f) noexcept
iterates over a nD domain in serial
Definition for_each.hpp:85
std::tuple< Arg0, Arg1, Args... > init_discrete_space(std::tuple< DDimImpl, Arg0, Arg1, Args... > &&a)
Move construct a global singleton discrete space and pass through remaining arguments.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
friend KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator operator-(StridedDiscreteDomainIterator i, difference_type n)
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator*() const noexcept
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator & operator++()
friend KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator operator+(difference_type n, StridedDiscreteDomainIterator i)
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator & operator-=(difference_type n)
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator operator++(int)
friend KOKKOS_FUNCTION constexpr bool operator<(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)
KOKKOS_DEFAULTED_FUNCTION StridedDiscreteDomainIterator()=default
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator operator--(int)
friend KOKKOS_FUNCTION constexpr bool operator==(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator(DiscreteElement< DDim > value, DiscreteVector< DDim > stride)
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator & operator+=(difference_type n)
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator[](difference_type n) const
friend KOKKOS_FUNCTION constexpr difference_type operator-(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator & operator--()
friend KOKKOS_FUNCTION constexpr bool operator>=(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr StridedDiscreteDomainIterator operator+(StridedDiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr bool operator>(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator!=(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator<=(StridedDiscreteDomainIterator const &xx, StridedDiscreteDomainIterator const &yy)