DDC 0.14.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 <limits>
11#include <mutex>
12#include <ostream>
13#include <sstream>
14#include <type_traits>
15#include <typeinfo>
16#include <utility>
17
18#include <Kokkos_Core.hpp>
19
20#include "chunk_span.hpp"
23
24namespace ddc {
25
26struct PrinterOptions
27{
28 std::size_t threshold {10};
29 std::size_t edgeitems {3};
30
31 bool operator==(PrinterOptions const& rhs) const noexcept;
32};
33
34namespace detail {
35
36/**
37 * This class is a singleton, as it contains global printing option
38 */
39struct ChunkPrinter
40{
41 /*
42 * We use a global lock because we do not care about performance for
43 * printing and it ensure that output doesn't get mangled if trying to
44 * print from different threads.
45 */
46 std::recursive_mutex m_global_lock;
47
48 PrinterOptions m_options;
49
50 // Copy of the stream format, used to compute how much space each element of the mdspan will take when printed
51 std::stringstream m_ss;
52
53 ChunkPrinter(ChunkPrinter& rhs) = delete;
54
55 ChunkPrinter(ChunkPrinter&& rhs) = delete;
56
57 ~ChunkPrinter();
58
59 ChunkPrinter& operator=(ChunkPrinter&& rhs) = delete;
60
61 ChunkPrinter& operator=(ChunkPrinter& rhs) = delete;
62
63private:
64 ChunkPrinter();
65
66 /**
67 * Print the spaces needed to align value to os
68 */
69 static std::ostream& align(std::ostream& os, int level);
70
71 /**
72 * Returns the size of the elem that needs to be printed
73 */
74 template <class T>
75 std::size_t get_element_width(T const& elem)
76 {
77 m_ss.seekp(0);
78 m_ss << elem;
79 return m_ss.tellp();
80 }
81
82 /**
83 * Print an element with enough leading spaces to ensure it is aligned with the others
84 */
85 template <class T>
86 void display_aligned_element(std::ostream& os, T const& elem, std::size_t largest_element)
87 {
88 std::size_t const elem_width = get_element_width(elem);
89
90 for (std::size_t i = 0; i < largest_element - elem_width; ++i) {
91 os << " ";
92 }
93 os << elem;
94 }
95
96 /**
97 * Displays the elements from the smallest dimension of a chunk span
98 */
99 template <class ElementType, class Extents, class Layout, class Accessor>
100 std::ostream& base_case_display(
101 std::ostream& os,
102 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& span,
103 std::size_t largest_element,
104 std::size_t beginning,
105 std::size_t end,
106 std::size_t extent)
107 {
108 for (std::size_t i0 = beginning; i0 < end; ++i0) {
109 display_aligned_element(os, span[i0], largest_element);
110 if (i0 < extent - 1) {
111 os << " ";
112 }
113 }
114 return os;
115 }
116
117 /**
118 * Recursively print the highest dimensions information of a chunk span (mostly '[' and ']'), and call base_case_display to print the smallest dimension
119 */
120 template <class ElementType, class Extents, class Layout, class Accessor, std::size_t... Is>
121 std::ostream& recursive_display(
122 std::ostream& os,
123 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& span,
124 int level,
125 std::size_t largest_element,
126 std::size_t beginning,
127 std::size_t end,
128 std::index_sequence<Is...>)
129 {
130 for (std::size_t i0 = beginning; i0 < end; ++i0) {
131 print_impl(
132 os,
133 Kokkos::submdspan(span, i0, ((void)Is, Kokkos::full_extent)...),
134 level + 1,
135 largest_element,
136 std::make_index_sequence<sizeof...(Is)>());
137 if (i0 < end - 1) {
138 for (int ndims = 0; ndims < sizeof...(Is); ++ndims) {
139 os << '\n';
140 }
141 align(os, level);
142 }
143 }
144
145 return os;
146 }
147
148public:
149 static ChunkPrinter& get_instance();
150
151 // 0D chunk span
152 template <class ElementType, class Extents, class Layout, class Accessor>
153 std::ostream& print_impl(
154 std::ostream& os,
155 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& span,
156 int /*level*/,
157 std::size_t /*largest_element*/,
158 std::index_sequence<>)
159 {
160 return os << *span.data_handle();
161 }
162
163 // Recursively parse the chunk to print it
164 template <
165 class ElementType,
166 class Extents,
167 class Layout,
168 class Accessor,
169 std::size_t I0,
170 std::size_t... Is>
171 std::ostream& print_impl(
172 std::ostream& os,
173 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& span,
174 int level,
175 std::size_t largest_element,
176 std::index_sequence<I0, Is...>)
177 {
178 auto extent = span.extent(I0);
179 if constexpr (sizeof...(Is) > 0) {
180 os << '[';
181 if (extent < m_options.threshold) {
182 recursive_display(
183 os,
184 span,
185 level,
186 largest_element,
187 0,
188 extent,
189 std::make_index_sequence<sizeof...(Is)>());
190 } else {
191 recursive_display(
192 os,
193 span,
194 level,
195 largest_element,
196 0,
197 m_options.edgeitems,
198 std::make_index_sequence<sizeof...(Is)>());
199 for (int ndims = 0; ndims < sizeof...(Is); ++ndims) {
200 os << '\n';
201 }
202 align(os, level);
203 os << "...";
204 for (int ndims = 0; ndims < sizeof...(Is); ++ndims) {
205 os << '\n';
206 }
207 align(os, level);
208 recursive_display(
209 os,
210 span,
211 level,
212 largest_element,
213 extent - m_options.edgeitems,
214 extent,
215 std::make_index_sequence<sizeof...(Is)>());
216 }
217 os << "]";
218 } else {
219 os << "[";
220 if (extent < m_options.threshold) {
221 base_case_display(os, span, largest_element, 0, extent, extent);
222 } else {
223 base_case_display(os, span, largest_element, 0, m_options.edgeitems, extent);
224 os << "... ";
225 base_case_display(
226 os,
227 span,
228 largest_element,
229 extent - m_options.edgeitems,
230 extent,
231 extent);
232 }
233 os << "]";
234 }
235
236 return os;
237 }
238
239 // 0D, we don't need the element size in this case so the actual returned value can be anything.
240 template <class ElementType, class Extents, class Layout, class Accessor>
241 std::size_t find_largest_displayed_element(
242 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const&,
243 std::index_sequence<>)
244 {
245 return 0;
246 }
247
248 // Find the largest element we have to print to allow alignment (it ignore
249 // element that will be elided).
250 template <
251 class ElementType,
252 class Extents,
253 class Layout,
254 class Accessor,
255 std::size_t I0,
256 std::size_t... Is>
257 std::size_t find_largest_displayed_element(
258 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& span,
259 std::index_sequence<I0, Is...>)
260 {
261 std::size_t ret = 0;
262 auto extent = span.extent(I0);
263 if constexpr (sizeof...(Is) > 0) {
264 if (extent < m_options.threshold) {
265 for (std::size_t i0 = 0; i0 < extent; ++i0) {
266 ret = std::max(
267 ret,
268 find_largest_displayed_element(
269 Kokkos::submdspan(span, i0, ((void)Is, Kokkos::full_extent)...),
270 std::make_index_sequence<sizeof...(Is)>()));
271 }
272 } else {
273 for (std::size_t i0 = 0; i0 < m_options.edgeitems; ++i0) {
274 ret = std::max(
275 ret,
276 find_largest_displayed_element(
277 Kokkos::submdspan(span, i0, ((void)Is, Kokkos::full_extent)...),
278 std::make_index_sequence<sizeof...(Is)>()));
279 }
280 for (std::size_t i0 = extent - m_options.edgeitems; i0 < extent; ++i0) {
281 ret = std::max(
282 ret,
283 find_largest_displayed_element(
284 Kokkos::submdspan(span, i0, ((void)Is, Kokkos::full_extent)...),
285 std::make_index_sequence<sizeof...(Is)>()));
286 }
287 }
288 } else {
289 if (extent < m_options.threshold) {
290 for (std::size_t i0 = 0; i0 < extent; ++i0) {
291 ret = std::max(ret, get_element_width(span[i0]));
292 }
293 } else {
294 for (std::size_t i0 = 0; i0 < m_options.edgeitems; ++i0) {
295 ret = std::max(ret, get_element_width(span[i0]));
296 }
297 for (std::size_t i0 = extent - m_options.edgeitems; i0 < extent; ++i0) {
298 ret = std::max(ret, get_element_width(span[i0]));
299 }
300 }
301 }
302
303 return ret;
304 }
305
306 /*
307 * Save the format that will be used in order to measure the size of the element we need to display
308 */
309 void saveformat(std::ostream& os);
310};
311
312/*
313 * Print the demangled name of a type into a standard ostream.
314 */
315void print_demangled_type_name(std::ostream& os, char const* mangled_name);
316
317void print_dim_name(
318 std::ostream& os,
319 char const* const* dims,
320 DiscreteVectorElement const* sizes,
321 std::size_t n);
322
323template <class... Dims>
324void print_dim_name(std::ostream& os, DiscreteVector<Dims...> const& dd)
325{
326 std::array<char const*, sizeof...(Dims)> const names {typeid(Dims).name()...};
327 std::array const std_dd = detail::array(dd);
328 print_dim_name(os, names.data(), std_dd.data(), std_dd.size());
329}
330
331} // namespace detail
332
333/**
334 * Try to set the options for the printer, returns the old format (or the
335 * current format if the option passed are invalid).
336 * option is invalid if m_edgeitems >= (m_threshold / 2), in this case the
337 * format isn't changed.
338 */
340
341/**
342 * Return the currently used format options
343 */
345
346/**
347 * Print the content of a ChunkSpan
348 */
349template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
350std::ostream& print_content(
351 std::ostream& os,
352 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
353{
354 auto chunk_span_right = detail::create_layout_right_view_and_copy(chunk_span);
355 auto chunk_span_right_host
356 = create_mirror_view_and_copy(Kokkos::HostSpace(), chunk_span_right.span_view());
357
358 using chunkspan_type
359 = std::remove_cv_t<std::remove_reference_t<decltype(chunk_span_right_host)>>;
360 using mdspan_type = chunkspan_type::allocation_mdspan_type;
361 using extents = mdspan_type::extents_type;
362
363 mdspan_type const allocated_mdspan = chunk_span_right_host.allocation_mdspan();
364
365 ddc::detail::ChunkPrinter& printer = ddc::detail::ChunkPrinter::get_instance();
366 std::scoped_lock const lock(printer.m_global_lock);
367
368 printer.saveformat(os);
369
370 std::size_t const largest_element = printer.find_largest_displayed_element(
371 allocated_mdspan,
372 std::make_index_sequence<extents::rank()>());
373
374 printer.print_impl(
375 os,
376 allocated_mdspan,
377 0 /*level*/,
378 largest_element,
379 std::make_index_sequence<extents::rank()>());
380
381 return os;
382}
383
384/**
385 * Print the metadata of a ChunkSpan (size, dimension name, ...)
386 */
387template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
388std::ostream& print_type_info(
389 std::ostream& os,
390 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
391{
392 ddc::detail::ChunkPrinter& printer = ddc::detail::ChunkPrinter::get_instance();
393 std::scoped_lock const lock(printer.m_global_lock);
394
395 ddc::detail::print_dim_name(os, chunk_span.extents());
396 os << '\n';
397 ddc::detail::print_demangled_type_name(os, typeid(chunk_span).name());
398 os << '\n';
399
400 return os;
401}
402
403/**
404 * Print metadata and content of a ChunkSpan
405 */
406template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
407std::ostream& print(
408 std::ostream& os,
409 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
410{
411 ddc::detail::ChunkPrinter& printer = ddc::detail::ChunkPrinter::get_instance();
412 std::scoped_lock const lock(printer.m_global_lock);
413
414 print_type_info(os, chunk_span);
415 print_content(os, chunk_span);
416
417 return os;
418}
419
420/**
421 * Print metadata and content of a ChunkSpan
422 * Always print without elision, regardless of options set
423 */
424template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
425std::ostream& print_full(
426 std::ostream& os,
427 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
428{
429 ddc::detail::ChunkPrinter& printer = ddc::detail::ChunkPrinter::get_instance();
430 std::scoped_lock const lock(printer.m_global_lock);
431
432 PrinterOptions const old_options
433 = set_print_options({.threshold = std::numeric_limits<size_t>::max(), .edgeitems = 1});
434
435 print_type_info(os, chunk_span);
436 print_content(os, chunk_span);
437
438 set_print_options(old_options);
439
440 return os;
441}
442
443template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
444std::ostream& operator<<(
445 std::ostream& os,
446 ChunkSpan<ElementType, SupportType, LayoutStridedPolicy, MemorySpace> const& chunk_span)
447{
448 return print(os, chunk_span);
449}
450
451} // 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
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)
std::ostream & print_content(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Print the content of a ChunkSpan.
Definition print.hpp:350
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
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:73
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 T device_transform_reduce(Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain in serial.
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
std::ostream & print(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Print metadata and content of a ChunkSpan.
Definition print.hpp:407
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()
PrinterOptions get_print_options()
Return the currently used format options.
Definition print.cpp:121
std::ostream & print_full(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Print metadata and content of a ChunkSpan Always print without elision, regardless of options set.
Definition print.hpp:425
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
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)
Print the metadata of a ChunkSpan (size, dimension name, ...)
Definition print.hpp:388
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
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.
PrinterOptions set_print_options(PrinterOptions options=PrinterOptions())
Try to set the options for the printer, returns the old format (or the current format if the option p...
Definition print.cpp:100
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
std::size_t threshold
Definition print.hpp:28
bool operator==(PrinterOptions const &rhs) const noexcept
Definition print.cpp:23
std::size_t edgeitems
Definition print.hpp:29
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