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-2019 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 
18 
19 */
20 
21 #ifndef __TBB_blocked_range_H
22 #define __TBB_blocked_range_H
23 
24 #include "tbb_stddef.h"
25 
26 namespace tbb {
27 
28 namespace internal {
29 
30 // blocked_rangeNd_impl forward declaration in tbb::internal namespace to
31 // name it as a friend for a tbb::blocked_range.
32 template<typename Value, unsigned int N, typename>
34 
35 } // namespace internal
36 
46 
48 template<typename Value>
50 public:
52 
54  typedef Value const_iterator;
55 
57  typedef std::size_t size_type;
58 
59 #if __TBB_DEPRECATED_BLOCKED_RANGE_DEFAULT_CTOR
60 
62  blocked_range() : my_end(), my_begin(), my_grainsize() {}
63 #endif
64 
66  blocked_range( Value begin_, Value end_, size_type grainsize_=1 ) :
67  my_end(end_), my_begin(begin_), my_grainsize(grainsize_)
68  {
69  __TBB_ASSERT( my_grainsize>0, "grainsize must be positive" );
70  }
71 
73  const_iterator begin() const {return my_begin;}
74 
76  const_iterator end() const {return my_end;}
77 
79 
80  size_type size() const {
81  __TBB_ASSERT( !(end()<begin()), "size() unspecified if end()<begin()" );
82  return size_type(my_end-my_begin);
83  }
84 
86  size_type grainsize() const {return my_grainsize;}
87 
88  //------------------------------------------------------------------------
89  // Methods that implement Range concept
90  //------------------------------------------------------------------------
91 
93  bool empty() const {return !(my_begin<my_end);}
94 
96 
97  bool is_divisible() const {return my_grainsize<size();}
98 
100 
103  my_end(r.my_end),
104  my_begin(do_split(r, split())),
105  my_grainsize(r.my_grainsize)
106  {
107  // only comparison 'less than' is required from values of blocked_range objects
108  __TBB_ASSERT( !(my_begin < r.my_end) && !(r.my_end < my_begin), "blocked_range has been split incorrectly" );
109  }
110 
111 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
112  static const bool is_splittable_in_proportion = true;
114 
116 
119  my_end(r.my_end),
120  my_begin(do_split(r, proportion)),
121  my_grainsize(r.my_grainsize)
122  {
123  // only comparison 'less than' is required from values of blocked_range objects
124  __TBB_ASSERT( !(my_begin < r.my_end) && !(r.my_end < my_begin), "blocked_range has been split incorrectly" );
125  }
126 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
127 
128 private:
130  Value my_end;
131  Value my_begin;
132  size_type my_grainsize;
133 
135  static Value do_split( blocked_range& r, split )
136  {
137  __TBB_ASSERT( r.is_divisible(), "cannot split blocked_range that is not divisible" );
138  Value middle = r.my_begin + (r.my_end - r.my_begin) / 2u;
139  r.my_end = middle;
140  return middle;
141  }
142 
143 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
144  static Value do_split( blocked_range& r, proportional_split& proportion )
145  {
146  __TBB_ASSERT( r.is_divisible(), "cannot split blocked_range that is not divisible" );
147 
148  // usage of 32-bit floating point arithmetic is not enough to handle ranges of
149  // more than 2^24 iterations accurately. However, even on ranges with 2^64
150  // iterations the computational error approximately equals to 0.000001% which
151  // makes small impact on uniform distribution of such range's iterations (assuming
152  // all iterations take equal time to complete). See 'test_partitioner_whitebox'
153  // for implementation of an exact split algorithm
154  size_type right_part = size_type(float(r.size()) * float(proportion.right())
155  / float(proportion.left() + proportion.right()) + 0.5f);
156  return r.my_end = Value(r.my_end - right_part);
157  }
158 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
159 
160  template<typename RowValue, typename ColValue>
161  friend class blocked_range2d;
162 
163  template<typename RowValue, typename ColValue, typename PageValue>
164  friend class blocked_range3d;
165 
166  template<typename DimValue, unsigned int N, typename>
167  friend class internal::blocked_rangeNd_impl;
168 };
169 
170 } // namespace tbb
171 
172 #endif /* __TBB_blocked_range_H */
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
const_iterator end() const
One past last value in range.
Definition: blocked_range.h:76
A 2-dimensional range that models the Range concept.
const_iterator begin() const
Beginning of range.
Definition: blocked_range.h:73
blocked_range(blocked_range &r, split)
Split range.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
size_t right() const
Definition: tbb_stddef.h:414
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp begin
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:66
Type enables transmission of splitting proportion from partitioners to range objects.
Definition: tbb_stddef.h:409
bool is_divisible() const
True if range is divisible.
Definition: blocked_range.h:97
size_t left() const
Definition: tbb_stddef.h:413
blocked_range(blocked_range &r, proportional_split &proportion)
Split range.
std::size_t size_type
Type for size of a range.
Definition: blocked_range.h:57
bool empty() const
True if range is empty.
Definition: blocked_range.h:93
The graph class.
static Value do_split(blocked_range &r, proportional_split &proportion)
size_type grainsize() const
The grain size for this range.
Definition: blocked_range.h:86
A range over which to iterate.
Definition: blocked_range.h:49
size_type my_grainsize
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
Value const_iterator
Type of a value.
Definition: blocked_range.h:54
static Value do_split(blocked_range &r, split)
Auxiliary function used by the splitting constructor.
A 3-dimensional range that models the Range concept.
size_type size() const
Size of the range.
Definition: blocked_range.h:80
Dummy type that distinguishes splitting constructor from copy constructor.
Definition: tbb_stddef.h:399

Copyright © 2005-2019 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.