44 #ifndef KOKKOS_PARALLEL_REDUCE_HPP
45 #define KOKKOS_PARALLEL_REDUCE_HPP
47 #include <Kokkos_NumericTraits.hpp>
51 template<
class T,
class Enable =
void>
52 struct is_reducer_type {
58 struct is_reducer_type<T,typename std::enable_if<
59 std::is_same<typename std::remove_cv<T>::type,
60 typename std::remove_cv<typename T::reducer>::type>::value
65 template<
class Scalar,
class Space>
70 typedef typename std::remove_cv<Scalar>::type value_type;
75 result_view_type value;
76 bool references_scalar_v;
80 KOKKOS_INLINE_FUNCTION
81 Sum(value_type& value_): value(&value_),references_scalar_v(true) {}
83 KOKKOS_INLINE_FUNCTION
84 Sum(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
87 KOKKOS_INLINE_FUNCTION
88 void join(value_type& dest,
const value_type& src)
const {
92 KOKKOS_INLINE_FUNCTION
93 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
97 KOKKOS_INLINE_FUNCTION
98 void init( value_type& val)
const {
99 val = reduction_identity<value_type>::sum();
102 KOKKOS_INLINE_FUNCTION
103 value_type& reference()
const {
104 return *value.data();
107 KOKKOS_INLINE_FUNCTION
108 result_view_type view()
const {
112 KOKKOS_INLINE_FUNCTION
113 bool references_scalar()
const {
114 return references_scalar_v;
118 template<
class Scalar,
class Space>
122 typedef Prod reducer;
123 typedef typename std::remove_cv<Scalar>::type value_type;
128 result_view_type value;
129 bool references_scalar_v;
133 KOKKOS_INLINE_FUNCTION
134 Prod(value_type& value_): value(&value_),references_scalar_v(true) {}
136 KOKKOS_INLINE_FUNCTION
137 Prod(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
140 KOKKOS_INLINE_FUNCTION
141 void join(value_type& dest,
const value_type& src)
const {
145 KOKKOS_INLINE_FUNCTION
146 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
150 KOKKOS_INLINE_FUNCTION
151 void init( value_type& val)
const {
152 val = reduction_identity<value_type>::prod();
155 KOKKOS_INLINE_FUNCTION
156 value_type& reference()
const {
157 return *value.data();
160 KOKKOS_INLINE_FUNCTION
161 result_view_type view()
const {
165 KOKKOS_INLINE_FUNCTION
166 bool references_scalar()
const {
167 return references_scalar_v;
171 template<
class Scalar,
class Space>
176 typedef typename std::remove_cv<Scalar>::type value_type;
181 result_view_type value;
182 bool references_scalar_v;
186 KOKKOS_INLINE_FUNCTION
187 Min(value_type& value_): value(&value_),references_scalar_v(true) {}
189 KOKKOS_INLINE_FUNCTION
190 Min(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
193 KOKKOS_INLINE_FUNCTION
194 void join(value_type& dest,
const value_type& src)
const {
199 KOKKOS_INLINE_FUNCTION
200 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
205 KOKKOS_INLINE_FUNCTION
206 void init( value_type& val)
const {
207 val = reduction_identity<value_type>::min();
210 KOKKOS_INLINE_FUNCTION
211 value_type& reference()
const {
212 return *value.data();
215 KOKKOS_INLINE_FUNCTION
216 result_view_type view()
const {
220 KOKKOS_INLINE_FUNCTION
221 bool references_scalar()
const {
222 return references_scalar_v;
226 template<
class Scalar,
class Space>
231 typedef typename std::remove_cv<Scalar>::type value_type;
236 result_view_type value;
237 bool references_scalar_v;
241 KOKKOS_INLINE_FUNCTION
242 Max(value_type& value_): value(&value_),references_scalar_v(true) {}
244 KOKKOS_INLINE_FUNCTION
245 Max(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
248 KOKKOS_INLINE_FUNCTION
249 void join(value_type& dest,
const value_type& src)
const {
254 KOKKOS_INLINE_FUNCTION
255 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
261 KOKKOS_INLINE_FUNCTION
262 void init( value_type& val)
const {
263 val = reduction_identity<value_type>::max();
266 KOKKOS_INLINE_FUNCTION
267 value_type& reference()
const {
268 return *value.data();
271 KOKKOS_INLINE_FUNCTION
272 result_view_type view()
const {
276 KOKKOS_INLINE_FUNCTION
277 bool references_scalar()
const {
278 return references_scalar_v;
282 template<
class Scalar,
class Space>
286 typedef LAnd reducer;
287 typedef typename std::remove_cv<Scalar>::type value_type;
292 result_view_type value;
293 bool references_scalar_v;
297 KOKKOS_INLINE_FUNCTION
298 LAnd(value_type& value_): value(&value_),references_scalar_v(true) {}
300 KOKKOS_INLINE_FUNCTION
301 LAnd(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
303 KOKKOS_INLINE_FUNCTION
304 void join(value_type& dest,
const value_type& src)
const {
308 KOKKOS_INLINE_FUNCTION
309 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
313 KOKKOS_INLINE_FUNCTION
314 void init( value_type& val)
const {
315 val = reduction_identity<value_type>::land();
318 KOKKOS_INLINE_FUNCTION
319 value_type& reference()
const {
320 return *value.data();
323 KOKKOS_INLINE_FUNCTION
324 result_view_type view()
const {
328 KOKKOS_INLINE_FUNCTION
329 bool references_scalar()
const {
330 return references_scalar_v;
334 template<
class Scalar,
class Space>
339 typedef typename std::remove_cv<Scalar>::type value_type;
344 result_view_type value;
345 bool references_scalar_v;
349 KOKKOS_INLINE_FUNCTION
350 LOr(value_type& value_): value(&value_),references_scalar_v(true) {}
352 KOKKOS_INLINE_FUNCTION
353 LOr(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
356 KOKKOS_INLINE_FUNCTION
357 void join(value_type& dest,
const value_type& src)
const {
361 KOKKOS_INLINE_FUNCTION
362 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
366 KOKKOS_INLINE_FUNCTION
367 void init( value_type& val)
const {
368 val = reduction_identity<value_type>::lor();
371 KOKKOS_INLINE_FUNCTION
372 value_type& reference()
const {
373 return *value.data();
376 KOKKOS_INLINE_FUNCTION
377 result_view_type view()
const {
381 KOKKOS_INLINE_FUNCTION
382 bool references_scalar()
const {
383 return references_scalar_v;
387 template<
class Scalar,
class Space>
391 typedef BAnd reducer;
392 typedef typename std::remove_cv<Scalar>::type value_type;
397 result_view_type value;
398 bool references_scalar_v;
402 KOKKOS_INLINE_FUNCTION
403 BAnd(value_type& value_): value(&value_),references_scalar_v(true) {}
405 KOKKOS_INLINE_FUNCTION
406 BAnd(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
409 KOKKOS_INLINE_FUNCTION
410 void join(value_type& dest,
const value_type& src)
const {
414 KOKKOS_INLINE_FUNCTION
415 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
419 KOKKOS_INLINE_FUNCTION
420 void init( value_type& val)
const {
421 val = reduction_identity<value_type>::band();
424 KOKKOS_INLINE_FUNCTION
425 value_type& reference()
const {
426 return *value.data();
429 KOKKOS_INLINE_FUNCTION
430 result_view_type view()
const {
434 KOKKOS_INLINE_FUNCTION
435 bool references_scalar()
const {
436 return references_scalar_v;
440 template<
class Scalar,
class Space>
445 typedef typename std::remove_cv<Scalar>::type value_type;
450 result_view_type value;
451 bool references_scalar_v;
455 KOKKOS_INLINE_FUNCTION
456 BOr(value_type& value_): value(&value_),references_scalar_v(true) {}
458 KOKKOS_INLINE_FUNCTION
459 BOr(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
462 KOKKOS_INLINE_FUNCTION
463 void join(value_type& dest,
const value_type& src)
const {
467 KOKKOS_INLINE_FUNCTION
468 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
472 KOKKOS_INLINE_FUNCTION
473 void init( value_type& val)
const {
474 val = reduction_identity<value_type>::bor();
477 KOKKOS_INLINE_FUNCTION
478 value_type& reference()
const {
479 return *value.data();
482 KOKKOS_INLINE_FUNCTION
483 result_view_type view()
const {
487 KOKKOS_INLINE_FUNCTION
488 bool references_scalar()
const {
489 return references_scalar_v;
493 template<
class Scalar,
class Index>
494 struct ValLocScalar {
498 KOKKOS_INLINE_FUNCTION
499 void operator = (
const ValLocScalar& rhs) {
504 KOKKOS_INLINE_FUNCTION
505 void operator = (
const volatile ValLocScalar& rhs)
volatile {
511 template<
class Scalar,
class Index,
class Space>
514 typedef typename std::remove_cv<Scalar>::type scalar_type;
515 typedef typename std::remove_cv<Index>::type index_type;
519 typedef MinLoc reducer;
520 typedef ValLocScalar<scalar_type,index_type> value_type;
525 result_view_type value;
526 bool references_scalar_v;
530 KOKKOS_INLINE_FUNCTION
531 MinLoc(value_type& value_): value(&value_),references_scalar_v(true) {}
533 KOKKOS_INLINE_FUNCTION
534 MinLoc(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
538 KOKKOS_INLINE_FUNCTION
539 void join(value_type& dest,
const value_type& src)
const {
540 if ( src.val < dest.val )
544 KOKKOS_INLINE_FUNCTION
545 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
546 if ( src.val < dest.val )
550 KOKKOS_INLINE_FUNCTION
551 void init( value_type& val)
const {
552 val.val = reduction_identity<scalar_type>::min();
553 val.loc = reduction_identity<index_type>::min();
556 KOKKOS_INLINE_FUNCTION
557 value_type& reference()
const {
558 return *value.data();
561 KOKKOS_INLINE_FUNCTION
562 result_view_type view()
const {
566 KOKKOS_INLINE_FUNCTION
567 bool references_scalar()
const {
568 return references_scalar_v;
572 template<
class Scalar,
class Index,
class Space>
575 typedef typename std::remove_cv<Scalar>::type scalar_type;
576 typedef typename std::remove_cv<Index>::type index_type;
580 typedef MaxLoc reducer;
581 typedef ValLocScalar<scalar_type,index_type> value_type;
586 result_view_type value;
587 bool references_scalar_v;
591 KOKKOS_INLINE_FUNCTION
592 MaxLoc(value_type& value_): value(&value_),references_scalar_v(true) {}
594 KOKKOS_INLINE_FUNCTION
595 MaxLoc(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
598 KOKKOS_INLINE_FUNCTION
599 void join(value_type& dest,
const value_type& src)
const {
600 if ( src.val > dest.val )
604 KOKKOS_INLINE_FUNCTION
605 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
606 if ( src.val > dest.val )
610 KOKKOS_INLINE_FUNCTION
611 void init( value_type& val)
const {
612 val.val = reduction_identity<scalar_type>::max();;
613 val.loc = reduction_identity<index_type>::min();
616 KOKKOS_INLINE_FUNCTION
617 value_type& reference()
const {
618 return *value.data();
621 KOKKOS_INLINE_FUNCTION
622 result_view_type view()
const {
626 KOKKOS_INLINE_FUNCTION
627 bool references_scalar()
const {
628 return references_scalar_v;
632 template<
class Scalar>
633 struct MinMaxScalar {
634 Scalar min_val,max_val;
636 KOKKOS_INLINE_FUNCTION
637 void operator = (
const MinMaxScalar& rhs) {
638 min_val = rhs.min_val;
639 max_val = rhs.max_val;
642 KOKKOS_INLINE_FUNCTION
643 void operator = (
const volatile MinMaxScalar& rhs)
volatile {
644 min_val = rhs.min_val;
645 max_val = rhs.max_val;
649 template<
class Scalar,
class Space>
652 typedef typename std::remove_cv<Scalar>::type scalar_type;
656 typedef MinMax reducer;
657 typedef MinMaxScalar<scalar_type> value_type;
662 result_view_type value;
663 bool references_scalar_v;
667 KOKKOS_INLINE_FUNCTION
668 MinMax(value_type& value_): value(&value_),references_scalar_v(true) {}
670 KOKKOS_INLINE_FUNCTION
671 MinMax(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
674 KOKKOS_INLINE_FUNCTION
675 void join(value_type& dest,
const value_type& src)
const {
676 if ( src.min_val < dest.min_val ) {
677 dest.min_val = src.min_val;
679 if ( src.max_val > dest.max_val ) {
680 dest.max_val = src.max_val;
684 KOKKOS_INLINE_FUNCTION
685 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
686 if ( src.min_val < dest.min_val ) {
687 dest.min_val = src.min_val;
689 if ( src.max_val > dest.max_val ) {
690 dest.max_val = src.max_val;
694 KOKKOS_INLINE_FUNCTION
695 void init( value_type& val)
const {
696 val.max_val = reduction_identity<scalar_type>::max();;
697 val.min_val = reduction_identity<scalar_type>::min();
700 KOKKOS_INLINE_FUNCTION
701 value_type& reference()
const {
702 return *value.data();
705 KOKKOS_INLINE_FUNCTION
706 result_view_type view()
const {
710 KOKKOS_INLINE_FUNCTION
711 bool references_scalar()
const {
712 return references_scalar_v;
716 template<
class Scalar,
class Index>
717 struct MinMaxLocScalar {
718 Scalar min_val,max_val;
719 Index min_loc,max_loc;
721 KOKKOS_INLINE_FUNCTION
722 void operator = (
const MinMaxLocScalar& rhs) {
723 min_val = rhs.min_val;
724 min_loc = rhs.min_loc;
725 max_val = rhs.max_val;
726 max_loc = rhs.max_loc;
729 KOKKOS_INLINE_FUNCTION
730 void operator = (
const volatile MinMaxLocScalar& rhs)
volatile {
731 min_val = rhs.min_val;
732 min_loc = rhs.min_loc;
733 max_val = rhs.max_val;
734 max_loc = rhs.max_loc;
738 template<
class Scalar,
class Index,
class Space>
741 typedef typename std::remove_cv<Scalar>::type scalar_type;
742 typedef typename std::remove_cv<Index>::type index_type;
746 typedef MinMaxLoc reducer;
747 typedef MinMaxLocScalar<scalar_type,index_type> value_type;
752 result_view_type value;
753 bool references_scalar_v;
757 KOKKOS_INLINE_FUNCTION
758 MinMaxLoc(value_type& value_): value(&value_),references_scalar_v(true) {}
760 KOKKOS_INLINE_FUNCTION
761 MinMaxLoc(
const result_view_type& value_): value(value_),references_scalar_v(false) {}
764 KOKKOS_INLINE_FUNCTION
765 void join(value_type& dest,
const value_type& src)
const {
766 if ( src.min_val < dest.min_val ) {
767 dest.min_val = src.min_val;
768 dest.min_loc = src.min_loc;
770 if ( src.max_val > dest.max_val ) {
771 dest.max_val = src.max_val;
772 dest.max_loc = src.max_loc;
776 KOKKOS_INLINE_FUNCTION
777 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
778 if ( src.min_val < dest.min_val ) {
779 dest.min_val = src.min_val;
780 dest.min_loc = src.min_loc;
782 if ( src.max_val > dest.max_val ) {
783 dest.max_val = src.max_val;
784 dest.max_loc = src.max_loc;
788 KOKKOS_INLINE_FUNCTION
789 void init( value_type& val)
const {
790 val.max_val = reduction_identity<scalar_type>::max();;
791 val.min_val = reduction_identity<scalar_type>::min();
792 val.max_loc = reduction_identity<index_type>::min();
793 val.min_loc = reduction_identity<index_type>::min();
796 KOKKOS_INLINE_FUNCTION
797 value_type& reference()
const {
798 return *value.data();
801 KOKKOS_INLINE_FUNCTION
802 result_view_type view()
const {
806 KOKKOS_INLINE_FUNCTION
807 bool references_scalar()
const {
808 return references_scalar_v;
815 template<
class T,
class ReturnType ,
class ValueTraits>
816 struct ParallelReduceReturnValue;
818 template<
class ReturnType ,
class FunctorType >
819 struct ParallelReduceReturnValue<typename std::enable_if<Kokkos::is_view<ReturnType>::value>::type,
ReturnType, FunctorType> {
821 typedef InvalidType reducer_type;
823 typedef typename return_type::value_type value_type_scalar;
824 typedef typename return_type::value_type*
const value_type_array;
826 typedef typename if_c<return_type::rank==0,value_type_scalar,value_type_array>::type value_type;
828 static return_type& return_value(
ReturnType& return_val,
const FunctorType&) {
833 template<
class ReturnType ,
class FunctorType>
834 struct ParallelReduceReturnValue<typename std::enable_if<
835 !Kokkos::is_view<ReturnType>::value &&
836 (!std::is_array<ReturnType>::value && !std::is_pointer<ReturnType>::value) &&
837 !Kokkos::is_reducer_type<ReturnType>::value
841 , Kokkos::MemoryUnmanaged
844 typedef InvalidType reducer_type;
846 typedef typename return_type::value_type value_type;
848 static return_type return_value(
ReturnType& return_val,
const FunctorType&) {
849 return return_type(&return_val);
853 template<
class ReturnType ,
class FunctorType>
854 struct ParallelReduceReturnValue<typename std::enable_if<
855 (is_array<ReturnType>::value || std::is_pointer<ReturnType>::value)
859 , Kokkos::MemoryUnmanaged
862 typedef InvalidType reducer_type;
864 typedef typename return_type::value_type value_type[];
866 static return_type return_value(
ReturnType& return_val,
867 const FunctorType& functor) {
868 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
869 return return_type(return_val,functor.value_count);
871 if ( is_array<ReturnType>::value )
872 return return_type(return_val);
874 return return_type(return_val,functor.value_count);
879 template<
class ReturnType ,
class FunctorType>
880 struct ParallelReduceReturnValue<typename std::enable_if<
881 Kokkos::is_reducer_type<ReturnType>::value
885 typedef typename return_type::value_type value_type;
887 static return_type return_value(
ReturnType& return_val,
888 const FunctorType&) {
893 template<
class T,
class ReturnType ,
class FunctorType>
894 struct ParallelReducePolicyType;
896 template<
class PolicyType ,
class FunctorType >
897 struct ParallelReducePolicyType<typename std::enable_if<Kokkos::Impl::is_execution_policy<PolicyType>::value>::type, PolicyType,FunctorType> {
899 typedef PolicyType policy_type;
900 static PolicyType policy(
const PolicyType& policy_) {
905 template<
class PolicyType ,
class FunctorType >
906 struct ParallelReducePolicyType<typename std::enable_if<std::is_integral<PolicyType>::value>::type, PolicyType,FunctorType> {
908 Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
913 static policy_type policy(
const PolicyType& policy_) {
914 return policy_type(0,policy_);
919 template<
class FunctorType,
class ExecPolicy,
class ValueType,
class ExecutionSpace>
920 struct ParallelReduceFunctorType {
921 typedef FunctorType functor_type;
922 static const functor_type& functor(
const functor_type& functor) {
927 template<
class PolicyType,
class FunctorType,
class ReturnType >
928 struct ParallelReduceAdaptor {
929 typedef Impl::ParallelReduceReturnValue<void,ReturnType,FunctorType> return_value_adapter;
930 #ifdef KOKKOS_IMPL_NEED_FUNCTOR_WRAPPER
931 typedef Impl::ParallelReduceFunctorType<FunctorType,PolicyType,
932 typename return_value_adapter::value_type,
933 typename PolicyType::execution_space> functor_adaptor;
936 void execute(
const std::string& label,
937 const PolicyType& policy,
938 const FunctorType& functor,
940 #if defined(KOKKOS_ENABLE_PROFILING)
942 if(Kokkos::Profiling::profileLibraryLoaded()) {
943 Kokkos::Impl::ParallelConstructName<FunctorType, typename PolicyType::work_tag> name(label);
944 Kokkos::Profiling::beginParallelReduce(name.get(), 0, &kpID);
948 Kokkos::Impl::shared_allocation_tracking_disable();
949 #ifdef KOKKOS_IMPL_NEED_FUNCTOR_WRAPPER
950 Impl::ParallelReduce<typename functor_adaptor::functor_type, PolicyType, typename return_value_adapter::reducer_type >
951 closure(functor_adaptor::functor(functor),
953 return_value_adapter::return_value(return_value,functor));
955 Impl::ParallelReduce<FunctorType, PolicyType, typename return_value_adapter::reducer_type >
958 return_value_adapter::return_value(return_value,functor));
960 Kokkos::Impl::shared_allocation_tracking_enable();
963 #if defined(KOKKOS_ENABLE_PROFILING)
964 if(Kokkos::Profiling::profileLibraryLoaded()) {
965 Kokkos::Profiling::endParallelReduce(kpID);
986 template <
typename T>
987 struct ReducerHasTestReferenceFunction
989 template <
typename E>
static std::true_type test_func( decltype(&E::references_scalar) ) ;
990 template <
typename E>
static std::false_type test_func(...);
992 enum { value = std::is_same<std::true_type,decltype(test_func<T>(0))>::value };
995 template<class T, bool is_reducer = ReducerHasTestReferenceFunction<T>::value>
996 struct ParallelReduceFence {
997 static void fence(
const T&) {
1001 template<
class ... Args>
1002 struct ParallelReduceFence<
View<Args...>, false> {
1003 static void fence(
const View<Args...>) {};
1006 struct ParallelReduceFence<T,true> {
1007 static void fence(
const T& reducer) {
1008 if(reducer.references_scalar())
1055 template<
class PolicyType,
class FunctorType,
class ReturnType >
1058 const PolicyType& policy,
1059 const FunctorType& functor,
1061 typename Impl::enable_if<
1062 Kokkos::Impl::is_execution_policy<PolicyType>::value
1064 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(label,policy,functor,return_value);
1065 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1068 template<
class PolicyType,
class FunctorType,
class ReturnType >
1071 const FunctorType& functor,
1073 typename Impl::enable_if<
1074 Kokkos::Impl::is_execution_policy<PolicyType>::value
1076 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(
"",policy,functor,return_value);
1077 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1080 template<
class FunctorType,
class ReturnType >
1083 const FunctorType& functor,
1085 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1086 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(
"",policy_type(0,policy),functor,return_value);
1087 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1090 template<
class FunctorType,
class ReturnType >
1093 const size_t& policy,
1094 const FunctorType& functor,
1096 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1097 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(label,policy_type(0,policy),functor,return_value);
1098 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1103 template<
class PolicyType,
class FunctorType,
class ReturnType >
1106 const PolicyType& policy,
1107 const FunctorType& functor,
1109 typename Impl::enable_if<
1110 Kokkos::Impl::is_execution_policy<PolicyType>::value
1113 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(label,policy,functor,return_value_impl);
1114 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1117 template<
class PolicyType,
class FunctorType,
class ReturnType >
1120 const FunctorType& functor,
1122 typename Impl::enable_if<
1123 Kokkos::Impl::is_execution_policy<PolicyType>::value
1126 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(
"",policy,functor,return_value_impl);
1127 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1130 template<
class FunctorType,
class ReturnType >
1133 const FunctorType& functor,
1135 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1137 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(
"",policy_type(0,policy),functor,return_value_impl);
1138 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1141 template<
class FunctorType,
class ReturnType >
1144 const size_t& policy,
1145 const FunctorType& functor,
1147 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1149 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(label,policy_type(0,policy),functor,return_value_impl);
1150 Impl::ParallelReduceFence<ReturnType>::fence(return_value);
1155 template<
class PolicyType,
class FunctorType>
1158 const PolicyType& policy,
1159 const FunctorType& functor,
1160 typename Impl::enable_if<
1161 Kokkos::Impl::is_execution_policy<PolicyType>::value
1163 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1164 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1165 ,
typename ValueTraits::value_type
1166 ,
typename ValueTraits::pointer_type
1167 >::type value_type ;
1169 static_assert(Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE,PolicyType,FunctorType>::
1170 has_final_member_function,
"Calling parallel_reduce without either return value or final function.");
1174 , Kokkos::MemoryUnmanaged
1176 result_view_type result_view ;
1178 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,result_view_type>::execute(label,policy,functor,result_view);
1181 template<
class PolicyType,
class FunctorType >
1184 const FunctorType& functor,
1185 typename Impl::enable_if<
1186 Kokkos::Impl::is_execution_policy<PolicyType>::value
1188 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1189 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1190 ,
typename ValueTraits::value_type
1191 ,
typename ValueTraits::pointer_type
1192 >::type value_type ;
1194 static_assert(Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE,PolicyType,FunctorType>::
1195 has_final_member_function,
"Calling parallel_reduce without either return value or final function.");
1199 , Kokkos::MemoryUnmanaged
1201 result_view_type result_view ;
1203 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,result_view_type>::execute(
"",policy,functor,result_view);
1206 template<
class FunctorType >
1209 const FunctorType& functor) {
1210 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1211 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1212 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1213 ,
typename ValueTraits::value_type
1214 ,
typename ValueTraits::pointer_type
1215 >::type value_type ;
1217 static_assert(Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE,RangePolicy<>,FunctorType>::
1218 has_final_member_function,
"Calling parallel_reduce without either return value or final function.");
1222 , Kokkos::MemoryUnmanaged
1224 result_view_type result_view ;
1226 Impl::ParallelReduceAdaptor<policy_type,FunctorType,result_view_type>::execute(
"",policy_type(0,policy),functor,result_view);
1229 template<
class FunctorType>
1232 const size_t& policy,
1233 const FunctorType& functor) {
1234 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1235 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1236 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1237 ,
typename ValueTraits::value_type
1238 ,
typename ValueTraits::pointer_type
1239 >::type value_type ;
1241 static_assert(Impl::FunctorAnalysis<Impl::FunctorPatternInterface::REDUCE,RangePolicy<>,FunctorType>::
1242 has_final_member_function,
"Calling parallel_reduce without either return value or final function.");
1246 , Kokkos::MemoryUnmanaged
1248 result_view_type result_view ;
1250 Impl::ParallelReduceAdaptor<policy_type,FunctorType,result_view_type>::execute(label,policy_type(0,policy),functor,result_view);
1255 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1257 namespace Kokkos {
namespace Experimental {
1266 using Kokkos::ValLocScalar;
1267 using Kokkos::MinLoc;
1268 using Kokkos::MaxLoc;
1269 using Kokkos::MinMaxScalar;
1270 using Kokkos::MinMax;
1271 using Kokkos::MinMaxLocScalar;
1272 using Kokkos::MinMaxLoc;
1276 #endif // KOKKOS_PARALLEL_REDUCE_HPP
void parallel_reduce(const std::string &label, const PolicyType &policy, const FunctorType &functor, ReturnType &return_value, typename Impl::enable_if< Kokkos::Impl::is_execution_policy< PolicyType >::value >::type *=0)
Parallel reduction.
Memory management for host memory.
Execution policy for work over a range of an integral type.