DDC 0.16.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 <cassert>
8#include <cstddef>
9#include <string>
10#include <type_traits>
11#include <utility>
12
13#include <Kokkos_Core.hpp>
14
15#include "chunk_traits.hpp"
18#include "reducer.hpp"
19
20namespace ddc {
21
22namespace detail {
23
24template <class Reducer, class MemorySpace>
25struct DdcToKokkosReducer
26{
27};
28
29template <class T, class MemorySpace>
30struct DdcToKokkosReducer<reducer::sum<T>, MemorySpace>
31{
32 using type = Kokkos::Sum<T, MemorySpace>;
33};
34
35template <class T, class MemorySpace>
36struct DdcToKokkosReducer<reducer::prod<T>, MemorySpace>
37{
38 using type = Kokkos::Prod<T, MemorySpace>;
39};
40
41template <class T, class MemorySpace>
42struct DdcToKokkosReducer<reducer::land<T>, MemorySpace>
43{
44 using type = Kokkos::LAnd<T, MemorySpace>;
45};
46
47template <class T, class MemorySpace>
48struct DdcToKokkosReducer<reducer::lor<T>, MemorySpace>
49{
50 using type = Kokkos::LOr<T, MemorySpace>;
51};
52
53template <class T, class MemorySpace>
54struct DdcToKokkosReducer<reducer::band<T>, MemorySpace>
55{
56 using type = Kokkos::BAnd<T, MemorySpace>;
57};
58
59template <class T, class MemorySpace>
60struct DdcToKokkosReducer<reducer::bor<T>, MemorySpace>
61{
62 using type = Kokkos::BOr<T, MemorySpace>;
63};
64
65template <class T, class MemorySpace>
66struct DdcToKokkosReducer<reducer::bxor<T>, MemorySpace>
67{
68 static_assert(std::is_same_v<T, T>, "This reducer is not yet implemented");
69};
70
71template <class T, class MemorySpace>
72struct DdcToKokkosReducer<reducer::min<T>, MemorySpace>
73{
74 using type = Kokkos::Min<T, MemorySpace>;
75};
76
77template <class T, class MemorySpace>
78struct DdcToKokkosReducer<reducer::max<T>, MemorySpace>
79{
80 using type = Kokkos::Max<T, MemorySpace>;
81};
82
83template <class T, class MemorySpace>
84struct DdcToKokkosReducer<reducer::minmax<T>, MemorySpace>
85{
86 using type = Kokkos::MinMax<T, MemorySpace>;
87};
88
89/// Alias template to transform a DDC reducer type to a Kokkos reducer type
90template <class Reducer, class MemorySpace = Kokkos::HostSpace>
91using ddc_to_kokkos_reducer_t = DdcToKokkosReducer<Reducer, MemorySpace>::type;
92
93template <class Reducer, class Functor, class Support, class IndexSequence>
94class TransformReducerKokkosLambdaAdapter
95{
96};
97
98template <class Reducer, class Functor, class Support, std::size_t... Idx>
99class TransformReducerKokkosLambdaAdapter<Reducer, Functor, Support, std::index_sequence<Idx...>>
100{
101 template <std::size_t I>
102 using index_type = DiscreteVectorElement;
103
104 Reducer m_reducer;
105
106 Functor m_functor;
107
108 Support m_support;
109
110public:
111 TransformReducerKokkosLambdaAdapter(Reducer const& r, Functor const& f, Support const& support)
112 : m_reducer(r)
113 , m_functor(f)
114 , m_support(support)
115 {
116 }
117
118 KOKKOS_FUNCTION void operator()(index_type<0> /*id*/, Reducer::value_type& a) const
119 requires(sizeof...(Idx) == 0)
120 {
121 a = m_reducer(a, m_functor(m_support(typename Support::discrete_vector_type())));
122 }
123
124 KOKKOS_FUNCTION void operator()(index_type<Idx>... ids, Reducer::value_type& a) const
125 requires(sizeof...(Idx) > 0)
126 {
127 a = m_reducer(a, m_functor(m_support(typename Support::discrete_vector_type(ids...))));
128 }
129};
130
131template <class Reducer, class Functor, class Support>
132TransformReducerKokkosLambdaAdapter(Reducer const& r, Functor const& f, Support const& support)
133 -> TransformReducerKokkosLambdaAdapter<
134 Reducer,
135 Functor,
136 Support,
137 std::make_index_sequence<Support::rank()>>;
138
139/** A parallel reduction over a nD domain using the default Kokkos execution space
140 * @param[in] label name for easy identification of the parallel_for_each algorithm
141 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
142 * @param[in] domain the range over which to apply the algorithm
143 * @param[in] neutral the neutral element of the reduction operation
144 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
145 * results of transform, the results of other reduce and neutral.
146 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
147 * range. The return type must be acceptable as input to reduce
148 */
149template <class ExecSpace, class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
150T transform_reduce_kokkos(
151 std::string const& label,
152 ExecSpace const& execution_space,
153 Support const& domain,
154 T neutral,
155 BinaryReductionOp const& reduce,
156 UnaryTransformOp const& transform) noexcept
157{
158 T result = neutral;
159 Kokkos::parallel_reduce(
160 label,
161 ddc_to_kokkos_execution_policy(execution_space, detail::array(domain.extents())),
162 TransformReducerKokkosLambdaAdapter(reduce, transform, domain),
163 ddc_to_kokkos_reducer_t<BinaryReductionOp>(result));
164 return result;
165}
166
167} // namespace detail
168
169/** A reduction over a nD domain using a given `Kokkos` execution space
170 * @param[in] label name for easy identification of the parallel_for_each algorithm
171 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
172 * @param[in] domain the range over which to apply the algorithm
173 * @param[in] neutral the neutral element of the reduction operation
174 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
175 * results of transform, the results of other reduce and neutral.
176 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
177 * range. The return type must be acceptable as input to reduce
178 */
179template <class ExecSpace, class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
181 std::string const& label,
182 ExecSpace const& execution_space,
183 Support const& domain,
184 T neutral,
185 BinaryReductionOp&& reduce,
186 UnaryTransformOp&& transform) noexcept
187{
188 return detail::transform_reduce_kokkos(
189 label,
190 execution_space,
191 domain,
192 neutral,
193 std::forward<BinaryReductionOp>(reduce),
194 std::forward<UnaryTransformOp>(transform));
195}
196
197/** A reduction over a nD domain using a given `Kokkos` execution space
198 * @param[in] execution_space a Kokkos execution space where the loop will be executed on
199 * @param[in] domain the range over which to apply the algorithm
200 * @param[in] neutral the neutral element of the reduction operation
201 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
202 * results of transform, the results of other reduce and neutral.
203 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
204 * range. The return type must be acceptable as input to reduce
205 */
206template <class ExecSpace, class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
208 ExecSpace const& execution_space,
209 Support const& domain,
210 T neutral,
211 BinaryReductionOp&& reduce,
212 UnaryTransformOp&& transform) noexcept
213 requires(Kokkos::is_execution_space_v<ExecSpace>)
214{
215 return detail::transform_reduce_kokkos(
216 "ddc_parallel_transform_reduce_default",
217 execution_space,
218 domain,
219 neutral,
220 std::forward<BinaryReductionOp>(reduce),
221 std::forward<UnaryTransformOp>(transform));
222}
223
224/** A reduction over a nD domain using the `Kokkos` default execution space
225 * @param[in] label name for easy identification of the parallel_for_each algorithm
226 * @param[in] domain the range over which to apply the algorithm
227 * @param[in] neutral the neutral element of the reduction operation
228 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
229 * results of transform, the results of other reduce and neutral.
230 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
231 * range. The return type must be acceptable as input to reduce
232 */
233template <class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
235 std::string const& label,
236 Support const& domain,
237 T neutral,
238 BinaryReductionOp&& reduce,
239 UnaryTransformOp&& transform) noexcept
240{
241 return parallel_transform_reduce(
242 label,
243 Kokkos::DefaultExecutionSpace(),
244 domain,
245 neutral,
246 std::forward<BinaryReductionOp>(reduce),
247 std::forward<UnaryTransformOp>(transform));
248}
249
250/** A reduction over a nD domain using the `Kokkos` default execution space
251 * @param[in] domain the range over which to apply the algorithm
252 * @param[in] neutral the neutral element of the reduction operation
253 * @param[in] reduce a binary FunctionObject that will be applied in unspecified order to the
254 * results of transform, the results of other reduce and neutral.
255 * @param[in] transform a unary FunctionObject that will be applied to each element of the input
256 * range. The return type must be acceptable as input to reduce
257 */
258template <class Support, class T, class BinaryReductionOp, class UnaryTransformOp>
260 Support const& domain,
261 T neutral,
262 BinaryReductionOp&& reduce,
263 UnaryTransformOp&& transform) noexcept
264{
265 return parallel_transform_reduce(
266 "ddc_parallel_transform_reduce_default",
267 Kokkos::DefaultExecutionSpace(),
268 domain,
269 neutral,
270 std::forward<BinaryReductionOp>(reduce),
271 std::forward<UnaryTransformOp>(transform));
272}
273
274namespace experimental {
275
276namespace detail {
277
278template <class Reducer, class Functor, class Support, class DElem, class IndexSequence>
279class TransformReducerChunkKokkosLambdaAdapter
280{
281};
282
283template <class Reducer, class Functor, class Support, class DElem, std::size_t... Idx>
284class TransformReducerChunkKokkosLambdaAdapter<
285 Reducer,
286 Functor,
287 Support,
288 DElem,
289 std::index_sequence<Idx...>>
290{
291 template <std::size_t I>
292 using index_type = DiscreteVectorElement;
293
294 Reducer m_reducer;
295
296 Functor m_functor;
297
298 Support m_support;
299
300 DElem m_delem;
301
302public:
303 TransformReducerChunkKokkosLambdaAdapter(
304 Reducer const& r,
305 Functor const& f,
306 Support const& support,
307 DElem const& delem)
308 : m_reducer(r)
309 , m_functor(f)
310 , m_support(support)
311 , m_delem(delem)
312 {
313 }
314
315 KOKKOS_FUNCTION void operator()(
316 [[maybe_unused]] index_type<0> unused_id,
317 Reducer::value_type& a) const
318 requires(sizeof...(Idx) == 0)
319 {
320 a = m_reducer(a, m_functor(m_delem, m_support(typename Support::discrete_vector_type())));
321 }
322
323 KOKKOS_FUNCTION void operator()(index_type<Idx>... ids, Reducer::value_type& a) const
324 requires(sizeof...(Idx) > 0)
325 {
326 a = m_reducer(
327 a,
328 m_functor(m_delem, m_support(typename Support::discrete_vector_type(ids...))));
329 }
330};
331
332template <class Reducer, class Functor, class Support, class DElem, std::size_t... Idx>
333TransformReducerChunkKokkosLambdaAdapter(
334 Reducer const& r,
335 Functor const& f,
336 Support const& support,
337 DElem const& delem)
338 -> TransformReducerChunkKokkosLambdaAdapter<
339 Reducer,
340 Functor,
341 Support,
342 DElem,
343 std::make_index_sequence<Support::rank()>>;
344
345} // namespace detail
346
347/** Performs a parallel transform-reduce over an nD domain using a Kokkos execution space.
348 *
349 * For each element of `out`, a reduction is performed over the dimensions of
350 * `domain` that are not present in `out.domain()`. The reduction combines the
351 * values obtained by applying `transform` to each element of the corresponding
352 * subdomain.
353 *
354 * @param[in] label name used to identify the Kokkos kernel.
355 * @param[in] execution_space Kokkos execution space on which the reductions are executed.
356 * @param[in] domain full domain over which the transform-reduce is defined.
357 * @param[out] out chunk receiving the reduction result for each point of
358 * `out.domain()`. Its domain must be a subdomain of `domain`.
359 * @param[in] reduce binary reduction operator used to combine transformed values.
360 * It must be compatible with the value type stored in `out`.
361 * @param[in] transform unary function applied to each element of the reduction
362 * subdomain. Its return type must be accepted by `reduce`.
363 */
364template <
365 class ExecSpace,
366 class Support,
367 concepts::borrowed_chunk ChunkDst,
368 class BinaryReductionOp,
369 class UnaryTransformOp>
371 std::string const& label,
372 ExecSpace const& execution_space,
373 Support const& domain,
374 ChunkDst&& out,
375 BinaryReductionOp const& reduce,
376 UnaryTransformOp const& transform) noexcept
377{
378 using DDomOut = std::remove_cvref_t<ChunkDst>::discrete_domain_type;
379 using DElemOut = DDomOut::discrete_element_type;
380 using MemorySpaceOut = std::remove_cvref_t<ChunkDst>::memory_space;
381 assert(out.domain() == DDomOut(domain));
382
383 auto ddom_interest = remove_dims_of(domain, out.domain());
384 host_for_each(out.domain(), [&](DElemOut iout) {
385 Kokkos::parallel_reduce(
386 label,
387 ddc::detail::ddc_to_kokkos_execution_policy(
388 execution_space,
389 ddc::detail::array(ddom_interest.extents())),
390 detail::TransformReducerChunkKokkosLambdaAdapter(
391 reduce,
392 transform,
393 ddom_interest,
394 iout),
395 ddc::detail::ddc_to_kokkos_reducer_t<BinaryReductionOp, MemorySpaceOut>(
396 out[iout].allocation_kokkos_view()));
397 });
398}
399
400} // namespace experimental
401
402} // 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 bool operator==(SparseDiscreteDomain< ODDims... > const &other) const
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 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 bool operator==(StridedDiscreteDomain< ODDims... > const &other) const
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
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.
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:60
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:70
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)
A compile-time sequence of types.
Definition type_seq.hpp:30
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)