BRE12
blocked_range3d.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_range3d_H
22 #define __TBB_blocked_range3d_H
23 
24 #include "tbb_stddef.h"
25 #include "blocked_range.h"
26 
27 namespace tbb {
28 
30 
31 template<typename PageValue, typename RowValue=PageValue, typename ColValue=RowValue>
33 public:
38 
39 private:
40  page_range_type my_pages;
41  row_range_type my_rows;
42  col_range_type my_cols;
43 
44 public:
45 
46  blocked_range3d( PageValue page_begin, PageValue page_end,
47  RowValue row_begin, RowValue row_end,
48  ColValue col_begin, ColValue col_end ) :
49  my_pages(page_begin,page_end),
50  my_rows(row_begin,row_end),
51  my_cols(col_begin,col_end)
52  {
53  }
54 
55  blocked_range3d( PageValue page_begin, PageValue page_end, typename page_range_type::size_type page_grainsize,
56  RowValue row_begin, RowValue row_end, typename row_range_type::size_type row_grainsize,
57  ColValue col_begin, ColValue col_end, typename col_range_type::size_type col_grainsize ) :
58  my_pages(page_begin,page_end,page_grainsize),
59  my_rows(row_begin,row_end,row_grainsize),
60  my_cols(col_begin,col_end,col_grainsize)
61  {
62  }
63 
65  bool empty() const {
66  // Yes, it is a logical OR here, not AND.
67  return my_pages.empty() || my_rows.empty() || my_cols.empty();
68  }
69 
71  bool is_divisible() const {
72  return my_pages.is_divisible() || my_rows.is_divisible() || my_cols.is_divisible();
73  }
74 
75  blocked_range3d( blocked_range3d& r, split ) :
76  my_pages(r.my_pages),
77  my_rows(r.my_rows),
78  my_cols(r.my_cols)
79  {
80  split split_obj;
81  do_split(r, split_obj);
82  }
83 
84 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
85  static const bool is_splittable_in_proportion = true;
87 
88  blocked_range3d( blocked_range3d& r, proportional_split& proportion ) :
89  my_pages(r.my_pages),
90  my_rows(r.my_rows),
91  my_cols(r.my_cols)
92  {
93  do_split(r, proportion);
94  }
95 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
96 
97  template <typename Split>
98  void do_split( blocked_range3d& r, Split& split_obj)
99  {
100  if ( my_pages.size()*double(my_rows.grainsize()) < my_rows.size()*double(my_pages.grainsize()) ) {
101  if ( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) {
102  my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
103  } else {
104  my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj);
105  }
106  } else {
107  if ( my_pages.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_pages.grainsize()) ) {
108  my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
109  } else {
110  my_pages.my_begin = page_range_type::do_split(r.my_pages, split_obj);
111  }
112  }
113  }
114 
116  const page_range_type& pages() const {return my_pages;}
117 
119  const row_range_type& rows() const {return my_rows;}
120 
122  const col_range_type& cols() const {return my_cols;}
123 
124 };
125 
126 } // namespace tbb
127 
128 #endif /* __TBB_blocked_range3d_H */
A 3-dimensional range that models the Range concept.
Definition: blocked_range3d.h:32
blocked_range< PageValue > page_range_type
Type for size of an iteration range.
Definition: blocked_range3d.h:35
static const bool is_splittable_in_proportion
Static field to support proportional split.
Definition: blocked_range3d.h:86
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
const page_range_type & pages() const
The pages of the iteration space.
Definition: blocked_range3d.h:116
const col_range_type & cols() const
The columns of the iteration space.
Definition: blocked_range3d.h:122
size_type grainsize() const
The grain size for this range.
Definition: blocked_range.h:75
const row_range_type & rows() const
The rows of the iteration space.
Definition: blocked_range3d.h:119
bool empty() const
True if range is empty.
Definition: blocked_range3d.h:65
size_type size() const
Size of the range.
Definition: blocked_range.h:69
bool is_divisible() const
True if range is divisible into two pieces.
Definition: blocked_range3d.h:71
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