1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef __TBB_test_common_parallel_reduce_common_H 18 #define __TBB_test_common_parallel_reduce_common_H 19 20 #include "test.h" 21 #include "utils.h" 22 #include "utils_report.h" 23 #include "utils_concurrency_limit.h" 24 25 #include "oneapi/tbb/parallel_reduce.h" 26 #include "oneapi/tbb/blocked_range.h" 27 #include "oneapi/tbb/global_control.h" 28 29 //! Type-tag for testing algorithm with default partitioner 30 struct utils_default_partitioner {}; 31 32 template <typename Range, typename Body, typename Partitioner> 33 void reduce_invoker(const Range& range, Body& body, Partitioner& partiotioner) { 34 tbb::parallel_reduce( range, body, partiotioner ); 35 } 36 37 template <typename Range, typename Body> 38 void reduce_invoker(const Range& range, Body& body, utils_default_partitioner&) { 39 tbb::parallel_reduce( range, body ); 40 } 41 42 template <typename ResultType, typename Range, typename Func, typename Reduction, typename Partitioner> 43 ResultType reduce_invoker(const Range& range, const Func& func, const Reduction& reduction, Partitioner& partiotioner) { 44 return tbb::parallel_reduce( range, ResultType(), func, reduction, partiotioner ); 45 } 46 47 template <typename ResultType, typename Range, typename Func, typename Reduction> 48 ResultType reduce_invoker(const Range& range, const Func& func, const Reduction& reduction, utils_default_partitioner&) { 49 return tbb::parallel_reduce( range, ResultType(), func, reduction ); 50 } 51 52 template <typename Range, typename Body, typename Partitioner> 53 void deterministic_reduce_invoker(const Range& range, Body& body, const Partitioner& partiotioner) { 54 tbb::parallel_deterministic_reduce( range, body, partiotioner ); 55 } 56 57 template <typename Range, typename Body> 58 void deterministic_reduce_invoker(const Range& range, Body& body, const utils_default_partitioner&) { 59 tbb::parallel_deterministic_reduce( range, body ); 60 } 61 62 template <typename ResultType, typename Range, typename Func, typename Reduction, typename Partitioner> 63 ResultType deterministic_reduce_invoker(const Range& range, const Func& func, 64 const Reduction& reduction, const Partitioner& partiotioner) { 65 return tbb::parallel_deterministic_reduce( range, ResultType(), func, reduction, partiotioner ); 66 } 67 68 template <typename ResultType, typename Range, typename Func, typename Reduction> 69 ResultType deterministic_reduce_invoker(const Range& range, const Func& func, 70 const Reduction& reduction, const utils_default_partitioner&) { 71 return tbb::parallel_deterministic_reduce( range, ResultType(), func, reduction ); 72 } 73 74 #endif // __TBB_test_common_parallel_reduce_common_H 75