Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
blocked_range.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef __TBB_blocked_range_H
18 #define __TBB_blocked_range_H
19 
20 #include "tbb_stddef.h"
21 
22 namespace tbb {
23 
24 namespace internal {
25 
26 // blocked_rangeNd_impl forward declaration in tbb::internal namespace to
27 // name it as a friend for a tbb::blocked_range.
28 template<typename Value, unsigned int N, typename>
30 
31 } // namespace internal
32 
42 
44 template<typename Value>
46 public:
48 
50  typedef Value const_iterator;
51 
53  typedef std::size_t size_type;
54 
55 #if __TBB_DEPRECATED_BLOCKED_RANGE_DEFAULT_CTOR
56 
59 #endif
60 
62  blocked_range( Value begin_, Value end_, size_type grainsize_=1 ) :
63  my_end(end_), my_begin(begin_), my_grainsize(grainsize_)
64  {
65  __TBB_ASSERT( my_grainsize>0, "grainsize must be positive" );
66  }
67 
69  const_iterator begin() const {return my_begin;}
70 
72  const_iterator end() const {return my_end;}
73 
75 
76  size_type size() const {
77  __TBB_ASSERT( !(end()<begin()), "size() unspecified if end()<begin()" );
78  return size_type(my_end-my_begin);
79  }
80 
82  size_type grainsize() const {return my_grainsize;}
83 
84  //------------------------------------------------------------------------
85  // Methods that implement Range concept
86  //------------------------------------------------------------------------
87 
89  bool empty() const {return !(my_begin<my_end);}
90 
92 
93  bool is_divisible() const {return my_grainsize<size();}
94 
96 
99  my_end(r.my_end),
100  my_begin(do_split(r, split())),
102  {
103  // only comparison 'less than' is required from values of blocked_range objects
104  __TBB_ASSERT( !(my_begin < r.my_end) && !(r.my_end < my_begin), "blocked_range has been split incorrectly" );
105  }
106 
107 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
108  static const bool is_splittable_in_proportion = true;
110 
112 
115  my_end(r.my_end),
116  my_begin(do_split(r, proportion)),
118  {
119  // only comparison 'less than' is required from values of blocked_range objects
120  __TBB_ASSERT( !(my_begin < r.my_end) && !(r.my_end < my_begin), "blocked_range has been split incorrectly" );
121  }
122 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
123 
124 private:
126  Value my_end;
127  Value my_begin;
129 
131  static Value do_split( blocked_range& r, split )
132  {
133  __TBB_ASSERT( r.is_divisible(), "cannot split blocked_range that is not divisible" );
134  Value middle = r.my_begin + (r.my_end - r.my_begin) / 2u;
135  r.my_end = middle;
136  return middle;
137  }
138 
139 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
140  static Value do_split( blocked_range& r, proportional_split& proportion )
141  {
142  __TBB_ASSERT( r.is_divisible(), "cannot split blocked_range that is not divisible" );
143 
144  // usage of 32-bit floating point arithmetic is not enough to handle ranges of
145  // more than 2^24 iterations accurately. However, even on ranges with 2^64
146  // iterations the computational error approximately equals to 0.000001% which
147  // makes small impact on uniform distribution of such range's iterations (assuming
148  // all iterations take equal time to complete). See 'test_partitioner_whitebox'
149  // for implementation of an exact split algorithm
150  size_type right_part = size_type(float(r.size()) * float(proportion.right())
151  / float(proportion.left() + proportion.right()) + 0.5f);
152  return r.my_end = Value(r.my_end - right_part);
153  }
154 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
155 
156  template<typename RowValue, typename ColValue>
157  friend class blocked_range2d;
158 
159  template<typename RowValue, typename ColValue, typename PageValue>
160  friend class blocked_range3d;
161 
162  template<typename DimValue, unsigned int N, typename>
164 };
165 
166 } // namespace tbb
167 
168 #endif /* __TBB_blocked_range_H */
bool empty() const
True if range is empty.
Definition: blocked_range.h:89
std::size_t size_type
Type for size of a range.
Definition: blocked_range.h:53
size_t right() const
Definition: tbb_stddef.h:431
A 3-dimensional range that models the Range concept.
Type enables transmission of splitting proportion from partitioners to range objects.
Definition: tbb_stddef.h:426
size_type my_grainsize
blocked_range(blocked_range &r, split)
Split range.
Definition: blocked_range.h:98
size_type grainsize() const
The grain size for this range.
Definition: blocked_range.h:82
static Value do_split(blocked_range &r, split)
Auxiliary function used by the splitting constructor.
const_iterator begin() const
Beginning of range.
Definition: blocked_range.h:69
Value const_iterator
Type of a value.
Definition: blocked_range.h:50
blocked_range(Value begin_, Value end_, size_type grainsize_=1)
Construct range over half-open interval [begin,end), with the given grainsize.
Definition: blocked_range.h:62
size_type size() const
Size of the range.
Definition: blocked_range.h:76
blocked_range(blocked_range &r, proportional_split &proportion)
Split range.
A 2-dimensional range that models the Range concept.
Dummy type that distinguishes splitting constructor from copy constructor.
Definition: tbb_stddef.h:416
static const bool is_splittable_in_proportion
Static field to support proportional split.
A range over which to iterate.
Definition: blocked_range.h:45
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
size_t left() const
Definition: tbb_stddef.h:430
const_iterator end() const
One past last value in range.
Definition: blocked_range.h:72
The graph class.
bool is_divisible() const
True if range is divisible.
Definition: blocked_range.h:93
static Value do_split(blocked_range &r, proportional_split &proportion)

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.