Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:51

0001 /*
0002     Copyright (c) 2005-2020 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 #ifndef __TBB_blocked_range2d_H
0018 #define __TBB_blocked_range2d_H
0019 
0020 #include "tbb_stddef.h"
0021 #include "blocked_range.h"
0022 
0023 namespace tbb {
0024 
0025 //! A 2-dimensional range that models the Range concept.
0026 /** @ingroup algorithms */
0027 template<typename RowValue, typename ColValue=RowValue>
0028 class blocked_range2d {
0029 public:
0030     //! Type for size of an iteration range
0031     typedef blocked_range<RowValue> row_range_type;
0032     typedef blocked_range<ColValue> col_range_type;
0033 
0034 private:
0035     row_range_type my_rows;
0036     col_range_type my_cols;
0037 
0038 public:
0039 
0040     blocked_range2d( RowValue row_begin, RowValue row_end, typename row_range_type::size_type row_grainsize,
0041                      ColValue col_begin, ColValue col_end, typename col_range_type::size_type col_grainsize ) :
0042         my_rows(row_begin,row_end,row_grainsize),
0043         my_cols(col_begin,col_end,col_grainsize)
0044     {}
0045 
0046     blocked_range2d( RowValue row_begin, RowValue row_end,
0047                      ColValue col_begin, ColValue col_end ) :
0048         my_rows(row_begin,row_end),
0049         my_cols(col_begin,col_end)
0050     {}
0051 
0052     //! True if range is empty
0053     bool empty() const {
0054         // Range is empty if at least one dimension is empty.
0055         return my_rows.empty() || my_cols.empty();
0056     }
0057 
0058     //! True if range is divisible into two pieces.
0059     bool is_divisible() const {
0060         return my_rows.is_divisible() || my_cols.is_divisible();
0061     }
0062 
0063     blocked_range2d( blocked_range2d& r, split ) :
0064         my_rows(r.my_rows),
0065         my_cols(r.my_cols)
0066     {
0067         split split_obj;
0068         do_split(r, split_obj);
0069     }
0070 
0071 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
0072     //! Static field to support proportional split
0073     static const bool is_splittable_in_proportion = true;
0074 
0075     blocked_range2d( blocked_range2d& r, proportional_split& proportion ) :
0076         my_rows(r.my_rows),
0077         my_cols(r.my_cols)
0078     {
0079         do_split(r, proportion);
0080     }
0081 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
0082 
0083     //! The rows of the iteration space
0084     const row_range_type& rows() const {return my_rows;}
0085 
0086     //! The columns of the iteration space
0087     const col_range_type& cols() const {return my_cols;}
0088 
0089 private:
0090 
0091     template <typename Split>
0092     void do_split( blocked_range2d& r, Split& split_obj )
0093     {
0094         if( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) {
0095             my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
0096         } else {
0097             my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj);
0098         }
0099     }
0100 };
0101 
0102 } // namespace tbb
0103 
0104 #endif /* __TBB_blocked_range2d_H */