Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/oneapi/tbb/blocked_range2d.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright (c) 2005-2021 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 <cstddef>
0021 
0022 #include "detail/_config.h"
0023 #include "detail/_namespace_injection.h"
0024 #include "detail/_range_common.h"
0025 
0026 #include "blocked_range.h"
0027 
0028 namespace tbb {
0029 namespace detail {
0030 namespace d1 {
0031 
0032 //! A 2-dimensional range that models the Range concept.
0033 /** @ingroup algorithms */
0034 template<typename RowValue, typename ColValue = RowValue>
0035     __TBB_requires(blocked_range_value<RowValue> &&
0036                    blocked_range_value<ColValue>)
0037 class blocked_range2d {
0038 public:
0039     //! Type for size of an iteration range
0040     using row_range_type = blocked_range<RowValue>;
0041     using col_range_type = blocked_range<ColValue>;
0042 
0043 private:
0044     row_range_type my_rows;
0045     col_range_type my_cols;
0046 
0047 public:
0048     blocked_range2d( RowValue row_begin, RowValue row_end, typename row_range_type::size_type row_grainsize,
0049                      ColValue col_begin, ColValue col_end, typename col_range_type::size_type col_grainsize ) :
0050         my_rows(row_begin,row_end,row_grainsize),
0051         my_cols(col_begin,col_end,col_grainsize)
0052     {}
0053 
0054     blocked_range2d( RowValue row_begin, RowValue row_end,
0055                      ColValue col_begin, ColValue col_end ) :
0056         my_rows(row_begin,row_end),
0057         my_cols(col_begin,col_end)
0058     {}
0059 
0060     //! True if range is empty
0061     bool empty() const {
0062         // Range is empty if at least one dimension is empty.
0063         return my_rows.empty() || my_cols.empty();
0064     }
0065 
0066     //! True if range is divisible into two pieces.
0067     bool is_divisible() const {
0068         return my_rows.is_divisible() || my_cols.is_divisible();
0069     }
0070 
0071     blocked_range2d( blocked_range2d& r, split ) :
0072         my_rows(r.my_rows),
0073         my_cols(r.my_cols)
0074     {
0075         split split_obj;
0076         do_split(r, split_obj);
0077     }
0078 
0079     blocked_range2d( blocked_range2d& r, proportional_split& proportion ) :
0080         my_rows(r.my_rows),
0081         my_cols(r.my_cols)
0082     {
0083         do_split(r, proportion);
0084     }
0085 
0086     //! The rows of the iteration space
0087     const row_range_type& rows() const { return my_rows; }
0088 
0089     //! The columns of the iteration space
0090     const col_range_type& cols() const { return my_cols; }
0091 
0092 private:
0093     template <typename Split>
0094     void do_split( blocked_range2d& r, Split& split_obj ) {
0095         if ( my_rows.size()*double(my_cols.grainsize()) < my_cols.size()*double(my_rows.grainsize()) ) {
0096             my_cols.my_begin = col_range_type::do_split(r.my_cols, split_obj);
0097         } else {
0098             my_rows.my_begin = row_range_type::do_split(r.my_rows, split_obj);
0099         }
0100     }
0101 };
0102 
0103 } // namespace d1
0104 } // namespace detail
0105 
0106 inline namespace v1 {
0107 using detail::d1::blocked_range2d;
0108 } // namespace v1
0109 } // namespace tbb
0110 
0111 #endif /* __TBB_blocked_range2d_H */