Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:58:26

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_range3d_H
0018 #define __TBB_blocked_range3d_H
0019 
0020 #include "tbb_stddef.h"
0021 #include "blocked_range.h"
0022 
0023 namespace tbb {
0024 
0025 //! A 3-dimensional range that models the Range concept.
0026 /** @ingroup algorithms */
0027 template<typename PageValue, typename RowValue=PageValue, typename ColValue=RowValue>
0028 class blocked_range3d {
0029 public:
0030     //! Type for size of an iteration range
0031     typedef blocked_range<PageValue> page_range_type;
0032     typedef blocked_range<RowValue>  row_range_type;
0033     typedef blocked_range<ColValue>  col_range_type;
0034 
0035 private:
0036     page_range_type my_pages;
0037     row_range_type  my_rows;
0038     col_range_type  my_cols;
0039 
0040 public:
0041 
0042     blocked_range3d( PageValue page_begin, PageValue page_end,
0043                      RowValue  row_begin,  RowValue row_end,
0044                      ColValue  col_begin,  ColValue col_end ) :
0045         my_pages(page_begin,page_end),
0046         my_rows(row_begin,row_end),
0047         my_cols(col_begin,col_end)
0048     {}
0049 
0050     blocked_range3d( PageValue page_begin, PageValue page_end, typename page_range_type::size_type page_grainsize,
0051                      RowValue  row_begin,  RowValue row_end,   typename row_range_type::size_type row_grainsize,
0052                      ColValue  col_begin,  ColValue col_end,   typename col_range_type::size_type col_grainsize ) :
0053         my_pages(page_begin,page_end,page_grainsize),
0054         my_rows(row_begin,row_end,row_grainsize),
0055         my_cols(col_begin,col_end,col_grainsize)
0056     {}
0057 
0058     //! True if range is empty
0059     bool empty() const {
0060         // Range is empty if at least one dimension is empty.
0061         return my_pages.empty() || my_rows.empty() || my_cols.empty();
0062     }
0063 
0064     //! True if range is divisible into two pieces.
0065     bool is_divisible() const {
0066         return  my_pages.is_divisible() || my_rows.is_divisible() || my_cols.is_divisible();
0067     }
0068 
0069     blocked_range3d( blocked_range3d& r, split ) :
0070         my_pages(r.my_pages),
0071         my_rows(r.my_rows),
0072         my_cols(r.my_cols)
0073     {
0074         split split_obj;
0075         do_split(r, split_obj);
0076     }
0077 
0078 #if __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
0079     //! Static field to support proportional split
0080     static const bool is_splittable_in_proportion = true;
0081 
0082     blocked_range3d( blocked_range3d& r, proportional_split& proportion ) :
0083         my_pages(r.my_pages),
0084         my_rows(r.my_rows),
0085         my_cols(r.my_cols)
0086     {
0087         do_split(r, proportion);
0088     }
0089 #endif /* __TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES */
0090 
0091     //! The pages of the iteration space
0092     const page_range_type& pages() const {return my_pages;}
0093 
0094     //! The rows of the iteration space
0095     const row_range_type& rows() const {return my_rows;}
0096 
0097     //! The columns of the iteration space
0098     const col_range_type& cols() const {return my_cols;}
0099 
0100 private:
0101 
0102     template <typename Split>
0103     void do_split( blocked_range3d& r, Split& split_obj)
0104     {
0105         if ( my_pages.size()*double(my_rows.grainsize()) < my_rows.size()*double(my_pages.grainsize()) ) {
0106             if ( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) {
0107                 my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
0108             } else {
0109                 my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj);
0110             }
0111         } else {
0112             if ( my_pages.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_pages.grainsize()) ) {
0113                 my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
0114             } else {
0115                 my_pages.my_begin = page_range_type::do_split(r.my_pages, split_obj);
0116             }
0117         }
0118     }
0119 };
0120 
0121 } // namespace tbb
0122 
0123 #endif /* __TBB_blocked_range3d_H */