blocked_range¶
[algorithms.blocked_range]
Class template for a recursively divisible half-open interval.
A blocked_range represents a half-open range [i,*j*) that can be recursively split.
A blocked_range meets the Range requirements.
A blocked_range specifies a grain size of type size_t.
A blocked_range is splittable into two subranges if the size of the range exceeds its grain size.
The ideal grain size depends upon the context of the blocked_range, which is typically as the range argument
to the loop templates parallel_for, parallel_reduce, or parallel_scan.
// Defined in header <tbb/blocked_range.h>
namespace tbb {
template<typename Value>
class blocked_range {
public:
// types
using size_type = size_t;
using const_iterator = Value;
// constructors
blocked_range( Value begin, Value end, size_type grainsize=1 );
blocked_range( blocked_range& r, split );
blocked_range( blocked_range& r, proportional_split& proportion );
// capacity
size_type size() const;
bool empty() const;
// access
size_type grainsize() const;
bool is_divisible() const;
// iterators
const_iterator begin() const;
const_iterator end() const;
};
}
Requirements:
The
Valuetype shall meet the BlockedRangeValue requirements.
Member functions¶
-
type
size_type¶ The type for measuring the size of a
blocked_range. The type is always asize_t.
-
type
const_iterator¶ The type of a value in the range. Despite its name, the type
const_iteratoris not necessarily an STL iterator; it merely needs to meet the BlockedRangeValue requirements. However, it is convenient to call itconst_iteratorso that if it is a const_iterator, then theblocked_rangebehaves like a read-only STL container.
-
blocked_range(Value begin, Value end, size_type grainsize = 1)¶ Requirements: The parameter
grainsizemust be positive. The debug version of the library raises an assertion failure if this requirement is not met.Effects: Constructs a
blocked_rangerepresenting the half-open interval[begin, end)with the givengrainsize.Example: The statement
"blocked_range<int> r(5, 14, 2);"constructs a range ofintthat contains the values 5 through 13 inclusive, with the grain size of 2. Afterwards,r.begin()==5andr.end()==14.
-
blocked_range(blocked_range &range, split)¶ Basic splitting constructor.
Requirements:
is_divisible()is true.Effects: Partitions
rangeinto two subranges. The newly constructedblocked_rangeis approximately the second half of the originalrange, andrangeis updated to be the remainder. Each subrange has the samegrainsizeas the original range.Example: Let
rbe ablocked_rangethat represents a half-open interval[i, j)with a grain sizeg. Running the statementblocked_range<int> s(r, split);subsequently causes r to represent[i, i+(j-i)/2)andsto represent[i+(j-i)/2, j), both with grain sizeg.
-
blocked_range(blocked_range &range, proportional_split proportion)¶ Proportional splitting constructor.
Requirements:
is_divisible()is true.Effects: Partitions
rangeinto two subranges such that the ratio of their sizes is close to the ratio ofproportion.left()toproportion.right(). The newly constructedblocked_rangeis the subrange at the right, andrangeis updated to be the subrange at the left.Example: Let
rbe ablocked_rangethat represents a half-open interval[i, j)with a grain sizeg. Running the statementblocked_range<int> s(r, proportional_split(2, 3));subsequently causesrto represent[i, i+2*(j-i)/(2+3))andsto represent[i+2*(j-i)/(2+3), j), both with grain sizeg.
-
size_type
size() const¶ Requirements:
end()<begin()is false.Effects: Determines size of range.
Returns:
end()-begin().
-
bool
empty() const¶ Effects: Determines if range is empty.
Returns:
!(begin()<end())
-
bool
is_divisible() const¶ Requirements:
end()<begin()is false.Effects: Determines if range can be split into subranges.
Returns: True if
size()>grainsize();false otherwise.
-
const_iterator
begin() const¶ Returns: Inclusive lower bound on range.
-
const_iterator
end() const¶ Returns: Exclusive upper bound on range.
See also: