DDC 0.11.0
Loading...
Searching...
No Matches
print.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 <algorithm>
8#include <array>
9#include <cstdlib>
10#include <ostream>
11#include <sstream>
12#include <type_traits>
13#include <typeinfo>
14#include <utility>
15
16#include <Kokkos_Core.hpp>
17
18#include "chunk_span.hpp"
20
21namespace ddc {
22namespace detail {
23class ChunkPrinter
24{
25 static constexpr int const s_threshold = 10;
26 // If this ever becomes modifiable by the user, we need to ensure that
27 // s_edgeitems < (s_threshold / 2) stays true.
28 static constexpr int const s_edgeitems = 3;
29
30 std::stringstream m_ss;
31
32 static std::ostream& alignment(std::ostream& os, int level)
33 {
34 for (int i = 0; i <= level; ++i) {
35 os << ' ';
36 }
37 return os;
38 }
39
40 template <class T>
41 std::size_t get_element_width(T const& elem)
42 {
43 m_ss.seekp(0);
44 m_ss << elem;
45 return m_ss.tellp();
46 }
47
48 template <class T>
49 void display_aligned_element(std::ostream& os, T const& elem, std::size_t largest_element)
50 {
51 std::size_t const elem_width = get_element_width(elem);
52
53 for (std::size_t i = 0; i < largest_element - elem_width; ++i) {
54 os << " ";
55 }
56 os << elem;
57 }
58
59 template <class ElementType, class Extents, class Layout, class Accessor>
60 std::ostream& base_case_display(
61 std::ostream& os,
62 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s,
63 std::size_t largest_element,
64 std::size_t beginning,
65 std::size_t end,
66 std::size_t extent)
67 {
68 for (std::size_t i0 = beginning; i0 < end; ++i0) {
69 display_aligned_element(os, s[i0], largest_element);
70 if (i0 < extent - 1) {
71 os << " ";
72 }
73 }
74 return os;
75 }
76
77 template <class ElementType, class Extents, class Layout, class Accessor, std::size_t... Is>
78 std::ostream& recursive_display(
79 std::ostream& os,
80 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s,
81 int level,
82 std::size_t largest_element,
83 std::size_t beginning,
84 std::size_t end,
85 std::index_sequence<Is...>)
86 {
87 for (std::size_t i0 = beginning; i0 < end; ++i0) {
88 print_impl(
89 os,
90 Kokkos::submdspan(s, i0, ((void)Is, Kokkos::full_extent)...),
91 level + 1,
92 largest_element,
93 std::make_index_sequence<sizeof...(Is)>());
94 if (i0 < end - 1) {
95 for (int ndims = 0; ndims < sizeof...(Is); ++ndims) {
96 os << '\n';
97 }
98 alignment(os, level);
99 }
100 }
101
102 return os;
103 }
104
105public:
106 // 0D chunk span
107 template <class ElementType, class Extents, class Layout, class Accessor>
108 std::ostream& print_impl(
109 std::ostream& os,
110 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s,
111 int /*level*/,
112 std::size_t /*largest_element*/,
113 std::index_sequence<>)
114 {
115 return os << *s.data_handle();
116 }
117
118 // Recursively parse the chunk to print it
119 template <
120 class ElementType,
121 class Extents,
122 class Layout,
123 class Accessor,
124 std::size_t I0,
125 std::size_t... Is>
126 std::ostream& print_impl(
127 std::ostream& os,
128 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s,
129 int level,
130 std::size_t largest_element,
131 std::index_sequence<I0, Is...>)
132 {
133 auto extent = s.extent(I0);
134 if constexpr (sizeof...(Is) > 0) {
135 os << '[';
136 if (extent < s_threshold) {
137 recursive_display(
138 os,
139 s,
140 level,
141 largest_element,
142 0,
143 extent,
144 std::make_index_sequence<sizeof...(Is)>());
145 } else {
146 recursive_display(
147 os,
148 s,
149 level,
150 largest_element,
151 0,
152 s_edgeitems,
153 std::make_index_sequence<sizeof...(Is)>());
154 for (int ndims = 0; ndims < sizeof...(Is); ++ndims) {
155 os << '\n';
156 }
157 alignment(os, level);
158 os << "...";
159 for (int ndims = 0; ndims < sizeof...(Is); ++ndims) {
160 os << '\n';
161 }
162 alignment(os, level);
163 recursive_display(
164 os,
165 s,
166 level,
167 largest_element,
168 extent - s_edgeitems,
169 extent,
170 std::make_index_sequence<sizeof...(Is)>());
171 }
172 os << "]";
173 } else {
174 os << "[";
175 if (extent < s_threshold) {
176 base_case_display(os, s, largest_element, 0, extent, extent);
177 } else {
178 base_case_display(os, s, largest_element, 0, s_edgeitems, extent);
179 os << "... ";
180 base_case_display(os, s, largest_element, extent - s_edgeitems, extent, extent);
181 }
182 os << "]";
183 }
184
185 return os;
186 }
187
188 // 0D, we don't need the element size in this case so the actual returned value can be anything.
189 template <class ElementType, class Extents, class Layout, class Accessor>
190 std::size_t find_largest_displayed_element(
191 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const&,
192 std::index_sequence<>)
193 {
194 return 0;
195 }
196
197 // Find the largest element we have to print to allow alignment (it ignore
198 // element that will be elided).
199 template <
200 class ElementType,
201 class Extents,
202 class Layout,
203 class Accessor,
204 std::size_t I0,
205 std::size_t... Is>
206 std::size_t find_largest_displayed_element(
207 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s,
208 std::index_sequence<I0, Is...>)
209 {
210 std::size_t ret = 0;
211 auto extent = s.extent(I0);
212 if constexpr (sizeof...(Is) > 0) {
213 if (extent < s_threshold) {
214 for (std::size_t i0 = 0; i0 < extent; ++i0) {
215 ret = std::max(
216 ret,
217 find_largest_displayed_element(
218 Kokkos::submdspan(s, i0, ((void)Is, Kokkos::full_extent)...),
219 std::make_index_sequence<sizeof...(Is)>()));
220 }
221 } else {
222 for (std::size_t i0 = 0; i0 < s_edgeitems; ++i0) {
223 ret = std::max(
224 ret,
225 find_largest_displayed_element(
226 Kokkos::submdspan(s, i0, ((void)Is, Kokkos::full_extent)...),
227 std::make_index_sequence<sizeof...(Is)>()));
228 }
229 for (std::size_t i0 = extent - s_edgeitems; i0 < extent; ++i0) {
230 ret = std::max(
231 ret,
232 find_largest_displayed_element(
233 Kokkos::submdspan(s, i0, ((void)Is, Kokkos::full_extent)...),
234 std::make_index_sequence<sizeof...(Is)>()));
235 }
236 }
237 } else {
238 if (extent < s_threshold) {
239 for (std::size_t i0 = 0; i0 < extent; ++i0) {
240 ret = std::max(ret, get_element_width(s[i0]));
241 }
242 } else {
243 for (std::size_t i0 = 0; i0 < s_edgeitems; ++i0) {
244 ret = std::max(ret, get_element_width(s[i0]));
245 }
246 for (std::size_t i0 = extent - s_edgeitems; i0 < extent; ++i0) {
247 ret = std::max(ret, get_element_width(s[i0]));
248 }
249 }
250 }
251
252 return ret;
253 }
254
255 explicit ChunkPrinter(std::ostream const& os)
256 {
257 m_ss.copyfmt(os);
258 }
259};
260
261void print_demangled_type_name(std::ostream& os, char const* mangled_name);
262
263void print_dim_name(
264 std::ostream& os,
265 char const* const* dims,
266 DiscreteVectorElement const* sizes,
267 std::size_t n);
268
269template <class... Dims>
270void print_dim_name(std::ostream& os, DiscreteVector<Dims...> const& dd)
271{
272 std::array<char const*, sizeof...(Dims)> const names {typeid(Dims).name()...};
273 std::array const std_dd = detail::array(dd);
274 print_dim_name(os, names.data(), std_dd.data(), std_dd.size());
275}
276
277} // namespace detail
278
279template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
280std::ostream& print_content(
281 std::ostream& os,
282 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
283{
284 auto h_chunk_span = create_mirror_view_and_copy(Kokkos::HostSpace(), chunk_span);
285
286 using chunkspan_type = std::remove_cv_t<std::remove_reference_t<decltype(h_chunk_span)>>;
287 using mdspan_type = typename chunkspan_type::allocation_mdspan_type;
288 using extents = typename mdspan_type::extents_type;
289
290 mdspan_type const allocated_mdspan = h_chunk_span.allocation_mdspan();
291
292 ddc::detail::ChunkPrinter printer(os);
293 std::size_t const largest_element = printer.find_largest_displayed_element(
294 allocated_mdspan,
295 std::make_index_sequence<extents::rank()>());
296
297 printer.print_impl(
298 os,
299 allocated_mdspan,
300 0,
301 largest_element,
302 std::make_index_sequence<extents::rank()>());
303
304 return os;
305}
306
307template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
308std::ostream& print_type_info(
309 std::ostream& os,
310 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
311{
312 ddc::detail::print_dim_name(os, chunk_span.extents());
313 os << '\n';
314 ddc::detail::print_demangled_type_name(os, typeid(chunk_span).name());
315 os << '\n';
316
317 return os;
318}
319
320template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
321std::ostream& print(
322 std::ostream& os,
323 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
324{
325 print_type_info(os, chunk_span);
326 print_content(os, chunk_span);
327
328 return os;
329}
330
331
332template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
333std::ostream& operator<<(
334 std::ostream& os,
335 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
336{
337 return print(os, chunk_span);
338}
339
340} // 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(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(int, char **&)
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_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
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 SparseDiscreteDomain(DDoms const &... domains)
Construct a SparseDiscreteDomain by copies and merge of domains.
SparseDiscreteDomain(Kokkos::View< DiscreteElement< DDims > *, Kokkos::SharedSpace > const &... views)
Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
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 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 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 auto end() const
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION auto begin() 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 auto cend() const
KOKKOS_FUNCTION constexpr StridedDiscreteDomain(DDoms const &... domains)
Construct a StridedDiscreteDomain by copies and merge of domains.
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 auto begin() const
KOKKOS_FUNCTION auto end() 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_DEFAULTED_FUNCTION StridedDiscreteDomain(StridedDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr bool operator==(StridedDiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
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
The top-level namespace of DDC.
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, Real > step() noexcept
Spacing step of the mesh.
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, Coordinate< typename DDim::continuous_dimension_type > > origin() noexcept
Lower bound index of the mesh.
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 Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(SparseDiscreteDomain< DDims... > const &domain) noexcept
auto parallel_transform(ExecSpace const &execution_space, ChunkDst &&dst, UnaryTransformOp &&transform)
Transform a borrowed chunk with a given transform functor.
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(StridedDiscreteDomain< DDims... > const &domain) noexcept
bool is_discrete_space_initialized() noexcept
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.
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)
std::ostream & print_content(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Definition print.hpp:280
T host_transform_reduce(Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain in serial.
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(StridedDiscreteDomain< DDims... > const &domain) noexcept
constexpr bool is_uniform_point_sampling_v
KOKKOS_FUNCTION std::enable_if_t< is_uniform_point_sampling_v< DDim >, DiscreteElement< DDim > > front() noexcept
Lower bound index of the mesh.
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.
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:73
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &) noexcept
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
std::enable_if_t< Kokkos::is_execution_space_v< ExecSpace > > parallel_for_each(ExecSpace const &execution_space, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
KOKKOS_FUNCTION constexpr auto replace_dim_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &DDom_b) noexcept
KOKKOS_FUNCTION T device_transform_reduce(Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain in serial.
KOKKOS_FUNCTION std::enable_if_t< is_uniform_point_sampling_v< DDim >, Coordinate< typename DDim::continuous_dimension_type > > origin() noexcept
Lower bound index of the mesh.
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.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rlength(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_left(DiscreteElement< DDim > i)
constexpr bool is_strided_discrete_domain_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmin(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION DiscreteVector< ODDims... > prod(DiscreteVector< ODDims... > const &lhs, DiscreteVector< ODDims... > const &rhs) noexcept
std::ostream & print(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Definition print.hpp:321
constexpr bool is_periodic_sampling_v
KOKKOS_FUNCTION constexpr auto replace_dim_of(StridedDiscreteDomain< DDimsA... > const &DDom_a, StridedDiscreteDomain< DDimsB... > const &DDom_b) noexcept
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, DiscreteElement< DDim > > front() noexcept
Lower bound index of the mesh.
constexpr bool is_sparse_discrete_domain_v
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 constexpr Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
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
std::enable_if_t< Kokkos::is_execution_space_v< ExecSpace >, 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 std::enable_if_t< is_uniform_point_sampling_v< DDim >, Real > step() noexcept
Spacing step of the mesh.
Arg0 init_discrete_space(std::tuple< DDimImpl, Arg0 > &&a)
Move construct a global singleton discrete space and pass through the other argument.
std::ostream & print_type_info(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Definition print.hpp:308
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:83
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_right(DiscreteElement< DDim > i)
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.
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)
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:66
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:78
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:90
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:42
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:54
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:114
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:102
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:126
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:30
KOKKOS_FUNCTION constexpr value_type operator()(value_type const &lhs, value_type const &rhs) const noexcept
Definition reducer.hpp:18