BRE12
blocked_range2d.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
19 */
20 
21 #ifndef __TBB_blocked_range2d_H
22 #define __TBB_blocked_range2d_H
23 
24 #include "tbb_stddef.h"
25 #include "blocked_range.h"
26 
27 namespace tbb {
28 
30 
31 template<typename RowValue, typename ColValue=RowValue>
33 public:
37 
38 private:
39  row_range_type my_rows;
40  col_range_type my_cols;
41 
42 public:
43 
44  blocked_range2d( RowValue row_begin, RowValue row_end, typename row_range_type::size_type row_grainsize,
45  ColValue col_begin, ColValue col_end, typename col_range_type::size_type col_grainsize ) :
46  my_rows(row_begin,row_end,row_grainsize),
47  my_cols(col_begin,col_end,col_grainsize)
48  {
49  }
50 
51  blocked_range2d( RowValue row_begin, RowValue row_end,
52  ColValue col_begin, ColValue col_end ) :
53  my_rows(row_begin,row_end),
54  my_cols(col_begin,col_end)
55  {
56  }
57 
59  bool empty() const {
60  // Yes, it is a logical OR here, not AND.
61  return my_rows.empty() || my_cols.empty();
62  }
63 
65  bool is_divisible() const {
66  return my_rows.is_divisible() || my_cols.is_divisible();
67  }
68 
69  blocked_range2d( blocked_range2d& r, split ) :
70  my_rows(r.my_rows),
71  my_cols(r.my_cols)
72  {
73  split split_obj;
74  do_split(r, split_obj);
75  }
76 
77 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
78  static const bool is_splittable_in_proportion = true;
80 
81  blocked_range2d( blocked_range2d& r, proportional_split& proportion ) :
82  my_rows(r.my_rows),
83  my_cols(r.my_cols)
84  {
85  do_split(r, proportion);
86  }
87 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
88 
89  template <typename Split>
90  void do_split( blocked_range2d& r, Split& split_obj )
91  {
92  if( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) {
93  my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
94  } else {
95  my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj);
96  }
97  }
98 
100  const row_range_type& rows() const {return my_rows;}
101 
103  const col_range_type& cols() const {return my_cols;}
104 };
105 
106 } // namespace tbb
107 
108 #endif /* __TBB_blocked_range2d_H */
static const bool is_splittable_in_proportion
Static field to support proportional split.
Definition: blocked_range2d.h:79
const row_range_type & rows() const
The rows of the iteration space.
Definition: blocked_range2d.h:100
bool is_divisible() const
True if range is divisible into two pieces.
Definition: blocked_range2d.h:65
std::size_t size_type
Type for size of a range.
Definition: blocked_range.h:48
bool empty() const
True if range is empty.
Definition: blocked_range.h:82
size_type grainsize() const
The grain size for this range.
Definition: blocked_range.h:75
blocked_range< RowValue > row_range_type
Type for size of an iteration range.
Definition: blocked_range2d.h:35
const col_range_type & cols() const
The columns of the iteration space.
Definition: blocked_range2d.h:103
size_type size() const
Size of the range.
Definition: blocked_range.h:69
bool empty() const
True if range is empty.
Definition: blocked_range2d.h:59
A 2-dimensional range that models the Range concept.
Definition: blocked_range2d.h:32
bool is_divisible() const
True if range is divisible.
Definition: blocked_range.h:86
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44