Warning, file /include/oneapi/tbb/blocked_rangeNd.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB_blocked_rangeNd_H
0018 #define __TBB_blocked_rangeNd_H
0019
0020 #if !TBB_PREVIEW_BLOCKED_RANGE_ND
0021 #error Set TBB_PREVIEW_BLOCKED_RANGE_ND to include blocked_rangeNd.h
0022 #endif
0023
0024 #include <algorithm> // std::any_of
0025 #include <array>
0026 #include <cstddef>
0027 #include <type_traits> // std::is_same, std::enable_if
0028
0029 #include "detail/_config.h"
0030 #include "detail/_template_helpers.h" // index_sequence, make_index_sequence
0031 #include "detail/_range_common.h"
0032
0033 #include "blocked_range.h"
0034
0035 namespace tbb {
0036 namespace detail {
0037 namespace d1 {
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 template<typename Value, unsigned int N, typename = detail::make_index_sequence<N>>
0053 __TBB_requires(blocked_range_value<Value>)
0054 class blocked_rangeNd_impl;
0055
0056 template<typename Value, unsigned int N, std::size_t... Is>
0057 __TBB_requires(blocked_range_value<Value>)
0058 class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {
0059 public:
0060
0061 using value_type = Value;
0062
0063 private:
0064
0065 template<std::size_t>
0066 using dim_type_helper = tbb::blocked_range<value_type>;
0067
0068 public:
0069 blocked_rangeNd_impl() = delete;
0070
0071
0072 blocked_rangeNd_impl(const dim_type_helper<Is>&... args) : my_dims{ {args...} } {}
0073
0074
0075 static constexpr unsigned int ndims() { return N; }
0076
0077
0078 const tbb::blocked_range<value_type>& dim(unsigned int dimension) const {
0079 __TBB_ASSERT(dimension < N, "out of bound");
0080 return my_dims[dimension];
0081 }
0082
0083
0084
0085
0086
0087
0088 bool empty() const {
0089 return std::any_of(my_dims.begin(), my_dims.end(), [](const tbb::blocked_range<value_type>& d) {
0090 return d.empty();
0091 });
0092 }
0093
0094
0095 bool is_divisible() const {
0096 return std::any_of(my_dims.begin(), my_dims.end(), [](const tbb::blocked_range<value_type>& d) {
0097 return d.is_divisible();
0098 });
0099 }
0100
0101 blocked_rangeNd_impl(blocked_rangeNd_impl& r, proportional_split proportion) : my_dims(r.my_dims) {
0102 do_split(r, proportion);
0103 }
0104
0105 blocked_rangeNd_impl(blocked_rangeNd_impl& r, split proportion) : my_dims(r.my_dims) {
0106 do_split(r, proportion);
0107 }
0108
0109 private:
0110 static_assert(N != 0, "zero dimensional blocked_rangeNd can't be constructed");
0111
0112
0113 std::array<tbb::blocked_range<value_type>, N> my_dims;
0114
0115 template<typename split_type>
0116 void do_split(blocked_rangeNd_impl& r, split_type proportion) {
0117 static_assert((std::is_same<split_type, split>::value || std::is_same<split_type, proportional_split>::value), "type of split object is incorrect");
0118 __TBB_ASSERT(r.is_divisible(), "can't split not divisible range");
0119
0120 auto my_it = std::max_element(my_dims.begin(), my_dims.end(), [](const tbb::blocked_range<value_type>& first, const tbb::blocked_range<value_type>& second) {
0121 return (first.size() * second.grainsize() < second.size() * first.grainsize());
0122 });
0123
0124 auto r_it = r.my_dims.begin() + (my_it - my_dims.begin());
0125
0126 my_it->my_begin = tbb::blocked_range<value_type>::do_split(*r_it, proportion);
0127
0128
0129
0130 __TBB_ASSERT(!(my_it->my_begin < r_it->my_end) && !(r_it->my_end < my_it->my_begin),
0131 "blocked_range has been split incorrectly");
0132 }
0133 };
0134
0135 template<typename Value, unsigned int N>
0136 using blocked_rangeNd = blocked_rangeNd_impl<Value, N>;
0137
0138 }
0139 }
0140
0141 inline namespace v1 {
0142 using detail::d1::blocked_rangeNd;
0143 }
0144 }
0145
0146 #endif
0147