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
68 template<
class Scalar,
class Space>
73 typedef typename std::remove_cv<Scalar>::type value_type;
82 KOKKOS_INLINE_FUNCTION
83 Sum(value_type& value_): value(&value_) {}
85 KOKKOS_INLINE_FUNCTION
86 Sum(
const result_view_type& value_): value(value_.data()) {}
89 KOKKOS_INLINE_FUNCTION
90 void join(value_type& dest,
const value_type& src)
const {
94 KOKKOS_INLINE_FUNCTION
95 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
99 KOKKOS_INLINE_FUNCTION
100 void init( value_type& val)
const {
101 val = reduction_identity<value_type>::sum();
104 KOKKOS_INLINE_FUNCTION
105 value_type& reference()
const {
109 KOKKOS_INLINE_FUNCTION
110 result_view_type view()
const {
111 return result_view_type(value);
115 template<
class Scalar,
class Space>
119 typedef Prod reducer;
120 typedef typename std::remove_cv<Scalar>::type value_type;
129 KOKKOS_INLINE_FUNCTION
130 Prod(value_type& value_): value(&value_) {}
132 KOKKOS_INLINE_FUNCTION
133 Prod(
const result_view_type& value_): value(value_.data()) {}
136 KOKKOS_INLINE_FUNCTION
137 void join(value_type& dest,
const value_type& src)
const {
141 KOKKOS_INLINE_FUNCTION
142 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
146 KOKKOS_INLINE_FUNCTION
147 void init( value_type& val)
const {
148 val = reduction_identity<value_type>::prod();
151 KOKKOS_INLINE_FUNCTION
152 value_type& reference()
const {
156 KOKKOS_INLINE_FUNCTION
157 result_view_type view()
const {
158 return result_view_type(value);
162 template<
class Scalar,
class Space>
167 typedef typename std::remove_cv<Scalar>::type value_type;
176 KOKKOS_INLINE_FUNCTION
177 Min(value_type& value_): value(&value_) {}
179 KOKKOS_INLINE_FUNCTION
180 Min(
const result_view_type& value_): value(value_.data()) {}
183 KOKKOS_INLINE_FUNCTION
184 void join(value_type& dest,
const value_type& src)
const {
189 KOKKOS_INLINE_FUNCTION
190 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
195 KOKKOS_INLINE_FUNCTION
196 void init( value_type& val)
const {
197 val = reduction_identity<value_type>::min();
200 KOKKOS_INLINE_FUNCTION
201 value_type& reference()
const {
205 KOKKOS_INLINE_FUNCTION
206 result_view_type view()
const {
207 return result_view_type(value);
211 template<
class Scalar,
class Space>
216 typedef typename std::remove_cv<Scalar>::type value_type;
225 KOKKOS_INLINE_FUNCTION
226 Max(value_type& value_): value(&value_) {}
228 KOKKOS_INLINE_FUNCTION
229 Max(
const result_view_type& value_): value(value_.data()) {}
232 KOKKOS_INLINE_FUNCTION
233 void join(value_type& dest,
const value_type& src)
const {
238 KOKKOS_INLINE_FUNCTION
239 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
245 KOKKOS_INLINE_FUNCTION
246 void init( value_type& val)
const {
247 val = reduction_identity<value_type>::max();
250 KOKKOS_INLINE_FUNCTION
251 value_type& reference()
const {
255 KOKKOS_INLINE_FUNCTION
256 result_view_type view()
const {
257 return result_view_type(value);
261 template<
class Scalar,
class Space>
265 typedef LAnd reducer;
266 typedef typename std::remove_cv<Scalar>::type value_type;
275 KOKKOS_INLINE_FUNCTION
276 LAnd(value_type& value_): value(&value_) {}
278 KOKKOS_INLINE_FUNCTION
279 LAnd(
const result_view_type& value_): value(value_.data()) {}
281 KOKKOS_INLINE_FUNCTION
282 void join(value_type& dest,
const value_type& src)
const {
286 KOKKOS_INLINE_FUNCTION
287 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
291 KOKKOS_INLINE_FUNCTION
292 void init( value_type& val)
const {
293 val = reduction_identity<value_type>::land();
296 KOKKOS_INLINE_FUNCTION
297 value_type& reference()
const {
301 KOKKOS_INLINE_FUNCTION
302 result_view_type view()
const {
303 return result_view_type(value);
307 template<
class Scalar,
class Space>
312 typedef typename std::remove_cv<Scalar>::type value_type;
321 KOKKOS_INLINE_FUNCTION
322 LOr(value_type& value_): value(&value_) {}
324 KOKKOS_INLINE_FUNCTION
325 LOr(
const result_view_type& value_): value(value_.data()) {}
328 KOKKOS_INLINE_FUNCTION
329 void join(value_type& dest,
const value_type& src)
const {
333 KOKKOS_INLINE_FUNCTION
334 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
338 KOKKOS_INLINE_FUNCTION
339 void init( value_type& val)
const {
340 val = reduction_identity<value_type>::lor();
343 KOKKOS_INLINE_FUNCTION
344 value_type& reference()
const {
348 KOKKOS_INLINE_FUNCTION
349 result_view_type view()
const {
350 return result_view_type(value);
354 template<
class Scalar,
class Space>
358 typedef BAnd reducer;
359 typedef typename std::remove_cv<Scalar>::type value_type;
368 KOKKOS_INLINE_FUNCTION
369 BAnd(value_type& value_): value(&value_) {}
371 KOKKOS_INLINE_FUNCTION
372 BAnd(
const result_view_type& value_): value(value_.data()) {}
375 KOKKOS_INLINE_FUNCTION
376 void join(value_type& dest,
const value_type& src)
const {
380 KOKKOS_INLINE_FUNCTION
381 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
385 KOKKOS_INLINE_FUNCTION
386 void init( value_type& val)
const {
387 val = reduction_identity<value_type>::band();
390 KOKKOS_INLINE_FUNCTION
391 value_type& reference()
const {
395 KOKKOS_INLINE_FUNCTION
396 result_view_type view()
const {
397 return result_view_type(value);
401 template<
class Scalar,
class Space>
406 typedef typename std::remove_cv<Scalar>::type value_type;
415 KOKKOS_INLINE_FUNCTION
416 BOr(value_type& value_): value(&value_) {}
418 KOKKOS_INLINE_FUNCTION
419 BOr(
const result_view_type& value_): value(value_.data()) {}
422 KOKKOS_INLINE_FUNCTION
423 void join(value_type& dest,
const value_type& src)
const {
427 KOKKOS_INLINE_FUNCTION
428 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
432 KOKKOS_INLINE_FUNCTION
433 void init( value_type& val)
const {
434 val = reduction_identity<value_type>::bor();
437 KOKKOS_INLINE_FUNCTION
438 value_type& reference()
const {
442 KOKKOS_INLINE_FUNCTION
443 result_view_type view()
const {
444 return result_view_type(value);
448 template<
class Scalar,
class Index>
449 struct ValLocScalar {
453 KOKKOS_INLINE_FUNCTION
454 void operator = (
const ValLocScalar& rhs) {
459 KOKKOS_INLINE_FUNCTION
460 void operator = (
const volatile ValLocScalar& rhs)
volatile {
466 template<
class Scalar,
class Index,
class Space>
469 typedef typename std::remove_cv<Scalar>::type scalar_type;
470 typedef typename std::remove_cv<Index>::type index_type;
474 typedef MinLoc reducer;
475 typedef ValLocScalar<scalar_type,index_type> value_type;
484 KOKKOS_INLINE_FUNCTION
485 MinLoc(value_type& value_): value(&value_) {}
487 KOKKOS_INLINE_FUNCTION
488 MinLoc(
const result_view_type& value_): value(value_.data()) {}
492 KOKKOS_INLINE_FUNCTION
493 void join(value_type& dest,
const value_type& src)
const {
494 if ( src.val < dest.val )
498 KOKKOS_INLINE_FUNCTION
499 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
500 if ( src.val < dest.val )
504 KOKKOS_INLINE_FUNCTION
505 void init( value_type& val)
const {
506 val.val = reduction_identity<scalar_type>::min();
507 val.loc = reduction_identity<index_type>::min();
510 KOKKOS_INLINE_FUNCTION
511 value_type& reference() {
515 KOKKOS_INLINE_FUNCTION
516 result_view_type view()
const {
517 return result_view_type(value);
521 template<
class Scalar,
class Index,
class Space>
524 typedef typename std::remove_cv<Scalar>::type scalar_type;
525 typedef typename std::remove_cv<Index>::type index_type;
529 typedef MaxLoc reducer;
530 typedef ValLocScalar<scalar_type,index_type> value_type;
539 KOKKOS_INLINE_FUNCTION
540 MaxLoc(value_type& value_): value(&value_) {}
542 KOKKOS_INLINE_FUNCTION
543 MaxLoc(
const result_view_type& value_): value(value_.data()) {}
546 KOKKOS_INLINE_FUNCTION
547 void join(value_type& dest,
const value_type& src)
const {
548 if ( src.val > dest.val )
552 KOKKOS_INLINE_FUNCTION
553 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
554 if ( src.val > dest.val )
558 KOKKOS_INLINE_FUNCTION
559 void init( value_type& val)
const {
560 val.val = reduction_identity<scalar_type>::max();;
561 val.loc = reduction_identity<index_type>::min();
564 KOKKOS_INLINE_FUNCTION
565 value_type& reference() {
569 KOKKOS_INLINE_FUNCTION
570 result_view_type view()
const {
571 return result_view_type(value);
575 template<
class Scalar>
576 struct MinMaxScalar {
577 Scalar min_val,max_val;
579 KOKKOS_INLINE_FUNCTION
580 void operator = (
const MinMaxScalar& rhs) {
581 min_val = rhs.min_val;
582 max_val = rhs.max_val;
585 KOKKOS_INLINE_FUNCTION
586 void operator = (
const volatile MinMaxScalar& rhs)
volatile {
587 min_val = rhs.min_val;
588 max_val = rhs.max_val;
592 template<
class Scalar,
class Space>
595 typedef typename std::remove_cv<Scalar>::type scalar_type;
599 typedef MinMax reducer;
600 typedef MinMaxScalar<scalar_type> value_type;
609 KOKKOS_INLINE_FUNCTION
610 MinMax(value_type& value_): value(&value_) {}
612 KOKKOS_INLINE_FUNCTION
613 MinMax(
const result_view_type& value_): value(value_.data()) {}
616 KOKKOS_INLINE_FUNCTION
617 void join(value_type& dest,
const value_type& src)
const {
618 if ( src.min_val < dest.min_val ) {
619 dest.min_val = src.min_val;
621 if ( src.max_val > dest.max_val ) {
622 dest.max_val = src.max_val;
626 KOKKOS_INLINE_FUNCTION
627 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
628 if ( src.min_val < dest.min_val ) {
629 dest.min_val = src.min_val;
631 if ( src.max_val > dest.max_val ) {
632 dest.max_val = src.max_val;
636 KOKKOS_INLINE_FUNCTION
637 void init( value_type& val)
const {
638 val.max_val = reduction_identity<scalar_type>::max();;
639 val.min_val = reduction_identity<scalar_type>::min();
642 KOKKOS_INLINE_FUNCTION
643 value_type& reference() {
647 KOKKOS_INLINE_FUNCTION
648 result_view_type view()
const {
649 return result_view_type(value);
653 template<
class Scalar,
class Index>
654 struct MinMaxLocScalar {
655 Scalar min_val,max_val;
656 Index min_loc,max_loc;
658 KOKKOS_INLINE_FUNCTION
659 void operator = (
const MinMaxLocScalar& rhs) {
660 min_val = rhs.min_val;
661 min_loc = rhs.min_loc;
662 max_val = rhs.max_val;
663 max_loc = rhs.max_loc;
666 KOKKOS_INLINE_FUNCTION
667 void operator = (
const volatile MinMaxLocScalar& rhs)
volatile {
668 min_val = rhs.min_val;
669 min_loc = rhs.min_loc;
670 max_val = rhs.max_val;
671 max_loc = rhs.max_loc;
675 template<
class Scalar,
class Index,
class Space>
678 typedef typename std::remove_cv<Scalar>::type scalar_type;
679 typedef typename std::remove_cv<Index>::type index_type;
683 typedef MinMaxLoc reducer;
684 typedef MinMaxLocScalar<scalar_type,index_type> value_type;
693 KOKKOS_INLINE_FUNCTION
694 MinMaxLoc(value_type& value_): value(&value_) {}
696 KOKKOS_INLINE_FUNCTION
697 MinMaxLoc(
const result_view_type& value_): value(value_.data()) {}
700 KOKKOS_INLINE_FUNCTION
701 void join(value_type& dest,
const value_type& src)
const {
702 if ( src.min_val < dest.min_val ) {
703 dest.min_val = src.min_val;
704 dest.min_loc = src.min_loc;
706 if ( src.max_val > dest.max_val ) {
707 dest.max_val = src.max_val;
708 dest.max_loc = src.max_loc;
712 KOKKOS_INLINE_FUNCTION
713 void join(
volatile value_type& dest,
const volatile value_type& src)
const {
714 if ( src.min_val < dest.min_val ) {
715 dest.min_val = src.min_val;
716 dest.min_loc = src.min_loc;
718 if ( src.max_val > dest.max_val ) {
719 dest.max_val = src.max_val;
720 dest.max_loc = src.max_loc;
724 KOKKOS_INLINE_FUNCTION
725 void init( value_type& val)
const {
726 val.max_val = reduction_identity<scalar_type>::max();;
727 val.min_val = reduction_identity<scalar_type>::min();
728 val.max_loc = reduction_identity<index_type>::min();
729 val.min_loc = reduction_identity<index_type>::min();
732 KOKKOS_INLINE_FUNCTION
733 value_type& reference() {
737 KOKKOS_INLINE_FUNCTION
738 result_view_type view()
const {
739 return result_view_type(value);
749 template<
class T,
class ReturnType ,
class ValueTraits>
750 struct ParallelReduceReturnValue;
752 template<
class ReturnType ,
class FunctorType >
753 struct ParallelReduceReturnValue<typename std::enable_if<Kokkos::is_view<ReturnType>::value>::type,
ReturnType, FunctorType> {
755 typedef InvalidType reducer_type;
757 typedef typename return_type::value_type value_type_scalar;
758 typedef typename return_type::value_type*
const value_type_array;
760 typedef typename if_c<return_type::rank==0,value_type_scalar,value_type_array>::type value_type;
762 static return_type& return_value(
ReturnType& return_val,
const FunctorType&) {
767 template<
class ReturnType ,
class FunctorType>
768 struct ParallelReduceReturnValue<typename std::enable_if<
769 !Kokkos::is_view<ReturnType>::value &&
770 (!std::is_array<ReturnType>::value && !std::is_pointer<ReturnType>::value) &&
771 !Kokkos::is_reducer_type<ReturnType>::value
775 , Kokkos::MemoryUnmanaged
778 typedef InvalidType reducer_type;
780 typedef typename return_type::value_type value_type;
782 static return_type return_value(ReturnType& return_val,
const FunctorType&) {
783 return return_type(&return_val);
787 template<
class ReturnType ,
class FunctorType>
788 struct ParallelReduceReturnValue<typename std::enable_if<
789 (is_array<ReturnType>::value || std::is_pointer<ReturnType>::value)
793 , Kokkos::MemoryUnmanaged
796 typedef InvalidType reducer_type;
798 typedef typename return_type::value_type value_type[];
800 static return_type return_value(
ReturnType& return_val,
801 const FunctorType& functor) {
802 return return_type(return_val,functor.value_count);
806 template<
class ReturnType ,
class FunctorType>
807 struct ParallelReduceReturnValue<typename std::enable_if<
808 Kokkos::is_reducer_type<ReturnType>::value
812 typedef typename return_type::value_type value_type;
814 static return_type return_value(
ReturnType& return_val,
815 const FunctorType& functor) {
822 template<
class T,
class ReturnType ,
class FunctorType>
823 struct ParallelReducePolicyType;
825 template<
class PolicyType ,
class FunctorType >
826 struct ParallelReducePolicyType<typename std::enable_if<Kokkos::Impl::is_execution_policy<PolicyType>::value>::type, PolicyType,FunctorType> {
828 typedef PolicyType policy_type;
829 static PolicyType policy(
const PolicyType& policy_) {
834 template<
class PolicyType ,
class FunctorType >
835 struct ParallelReducePolicyType<typename std::enable_if<std::is_integral<PolicyType>::value>::type, PolicyType,FunctorType> {
837 Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
842 static policy_type policy(
const PolicyType& policy_) {
843 return policy_type(0,policy_);
850 template<
class FunctorType,
class ExecPolicy,
class ValueType,
class ExecutionSpace>
851 struct ParallelReduceFunctorType {
852 typedef FunctorType functor_type;
853 static const functor_type& functor(
const functor_type& functor) {
861 template<
class PolicyType,
class FunctorType,
class ReturnType >
862 struct ParallelReduceAdaptor {
863 typedef Impl::ParallelReduceReturnValue<void,ReturnType,FunctorType> return_value_adapter;
864 #ifdef KOKKOS_IMPL_NEED_FUNCTOR_WRAPPER 865 typedef Impl::ParallelReduceFunctorType<FunctorType,PolicyType,
866 typename return_value_adapter::value_type,
867 typename PolicyType::execution_space> functor_adaptor;
870 void execute(
const std::string& label,
871 const PolicyType& policy,
872 const FunctorType& functor,
874 #if defined(KOKKOS_ENABLE_PROFILING) 876 if(Kokkos::Profiling::profileLibraryLoaded()) {
877 Kokkos::Profiling::beginParallelReduce(
"" == label ?
typeid(FunctorType).name() : label, 0, &kpID);
881 Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
882 #ifdef KOKKOS_IMPL_NEED_FUNCTOR_WRAPPER 883 Impl::ParallelReduce<typename functor_adaptor::functor_type, PolicyType, typename return_value_adapter::reducer_type >
884 closure(functor_adaptor::functor(functor),
886 return_value_adapter::return_value(return_value,functor));
888 Impl::ParallelReduce<FunctorType, PolicyType, typename return_value_adapter::reducer_type >
891 return_value_adapter::return_value(return_value,functor));
893 Kokkos::Impl::shared_allocation_tracking_release_and_enable();
896 #if defined(KOKKOS_ENABLE_PROFILING) 897 if(Kokkos::Profiling::profileLibraryLoaded()) {
898 Kokkos::Profiling::endParallelReduce(kpID);
914 template<
class OutType ,
class InType >
916 typename std::enable_if
917 < std::is_same< OutType , InType >::value , InType
const & >::type
918 forward_execution_policy( InType
const & p ) {
return p ; }
920 template<
class OutType ,
class InType >
922 typename std::enable_if
923 < ! std::is_same< OutType , InType >::value , OutType >::type
924 forward_execution_policy( InType
const & p ) {
return OutType(p); }
927 template<
class OutType ,
class InType >
929 typename std::enable_if
930 < std::is_same< OutType , InType >::value , InType
const & >::type
931 forward_reducer( InType
const & r ) {
return r ; }
933 template<
class OutType ,
class InType >
935 typename std::enable_if< Kokkos::is_view< InType >::value , OutType >::type
936 forward_reducer( InType
const & v )
937 {
return OutType( v.data() ); }
939 template<
class OutType >
942 forward_reducer(
typename OutType::reference ref )
943 {
return OutType( ref ); }
951 template<
class PolicyType ,
class ClosureType ,
class ReduceType >
953 typename std::enable_if< Kokkos::is_reducer< ReduceType >::value >::type
955 , PolicyType && arg_policy
956 , ClosureType && arg_closure
957 , ReduceType && arg_reduce
962 using input_policy_type =
963 typename std::remove_const<
964 typename std::remove_reference< PolicyType >::type >::type ;
966 using input_reduce_type =
967 typename std::remove_const<
968 typename std::remove_reference< ReduceType >::type >::type ;
970 using Analysis = Kokkos::Impl::FunctorAnalysis
971 < Kokkos::Impl::FunctorPatternInterface::REDUCE
980 enum { is_policy = Kokkos::is_execution_policy< input_policy_type >::value };
981 enum { is_intval = std::is_integral< input_policy_type >::value };
983 static_assert( is_policy || is_intval ,
984 "Kokkos::parallel_reduce 2nd argument must be execution policy or integral value" );
986 using policy_type =
typename std::conditional
987 < is_policy , input_policy_type
994 enum { is_reducer = Kokkos::is_reducer< input_reduce_type >::value };
995 enum { is_view = Kokkos::is_view< input_reduce_type >::value };
996 enum { is_ref = std::is_same< ReduceType
997 ,
typename Analysis::reference_type
1000 static_assert( is_reducer || is_view || is_ref ,
1001 "Kokkos::parallel_reduce 4th argument must be reducer, output View, or output variable" );
1006 using has_space =
typename std::conditional
1009 using memory_space =
typename has_space::memory_space ;
1011 using reduce_type =
typename std::conditional
1012 < is_reducer , input_reduce_type
1013 ,
typename Analysis::Reducer< memory_space >
1018 #if (KOKKOS_ENABLE_PROFILING) 1020 if(Kokkos::Profiling::profileLibraryLoaded()) {
1021 Kokkos::Profiling::beginParallelReduce(arg_label, 0, &kpID);
1028 Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
1031 ,
typename Analysis::execution_space >
1032 closure( arg_closure
1033 , forward_execution_policy< policy_type >( arg_policy )
1034 , forward_reducer< reduce_type >( arg_reduce ) );
1036 Kokkos::Impl::shared_allocation_tracking_release_and_enable();
1044 #if (KOKKOS_ENABLE_PROFILING) 1045 if(Kokkos::Profiling::profileLibraryLoaded()) {
1046 Kokkos::Profiling::endParallelReduce(kpID);
1054 template<
class PolicyType ,
class ClosureType ,
class ReduceType >
1056 typename std::enable_if
1057 < Kokkos::is_execution_policy<
1058 typename std::remove_const<
1059 typename std::remove_reference< PolicyType >::type >::type
1063 typename std::remove_const<
1064 typename std::remove_reference< PolicyType >::type >::type
1068 , ClosureType && arg_closure
1069 , ReduceType && arg_reduce
1073 , std::forward< PolicyType >( arg_policy )
1074 , std::forward< ClosureType >( arg_closure )
1075 , std::forward< ReduceType >( arg_reduce ) );
1080 template<
class PolicyType ,
class ClosureType >
1084 , PolicyType && arg_policy
1085 , ClosureType && arg_closure
1090 using input_policy_type =
1091 typename std::remove_const<
1092 typename std::remove_reference< PolicyType >::type >::type ;
1094 using Analysis = Kokkos::Impl::FunctorAnalysis
1095 < Kokkos::Impl::FunctorPatternInterface::REDUCE
1100 static_assert( Analysis::has_final_member_function ,
1101 "Kokkos::parallel_reduce functor does not have a final member function" );
1104 , std::forward< PolicyType >( arg_policy )
1105 , std::forward< ClosureType >( arg_closure )
1106 ,
typename Analysis::Reducer<>() );
1113 template<
class PolicyType ,
class ClosureType >
1116 , ClosureType && arg_closure )
1120 using input_policy_type =
1121 typename std::remove_const<
1122 typename std::remove_reference< PolicyType >::type >::type ;
1124 using Analysis = Kokkos::Impl::FunctorAnalysis
1125 < Kokkos::Impl::FunctorPatternInterface::REDUCE
1130 static_assert( Analysis::has_final_member_function ,
1131 "Kokkos::parallel_reduce functor does not have a final member function" );
1134 , std::forward< PolicyType >( arg_policy )
1135 , std::forward< ClosureType >( arg_closure )
1136 ,
typename Analysis::Reducer<>() );
1192 template<
class PolicyType,
class FunctorType,
class ReturnType >
1195 const PolicyType& policy,
1196 const FunctorType& functor,
1198 typename Impl::enable_if<
1199 Kokkos::Impl::is_execution_policy<PolicyType>::value
1201 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(label,policy,functor,return_value);
1204 template<
class PolicyType,
class FunctorType,
class ReturnType >
1207 const FunctorType& functor,
1209 typename Impl::enable_if<
1210 Kokkos::Impl::is_execution_policy<PolicyType>::value
1212 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(
"",policy,functor,return_value);
1215 template<
class FunctorType,
class ReturnType >
1218 const FunctorType& functor,
1220 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1221 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(
"",policy_type(0,policy),functor,return_value);
1224 template<
class FunctorType,
class ReturnType >
1227 const size_t& policy,
1228 const FunctorType& functor,
1230 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1231 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(label,policy_type(0,policy),functor,return_value);
1236 template<
class PolicyType,
class FunctorType,
class ReturnType >
1239 const PolicyType& policy,
1240 const FunctorType& functor,
1242 typename Impl::enable_if<
1243 Kokkos::Impl::is_execution_policy<PolicyType>::value
1245 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,const ReturnType>::execute(label,policy,functor,return_value);
1248 template<
class PolicyType,
class FunctorType,
class ReturnType >
1251 const FunctorType& functor,
1253 typename Impl::enable_if<
1254 Kokkos::Impl::is_execution_policy<PolicyType>::value
1257 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,ReturnType>::execute(
"",policy,functor,return_value_impl);
1260 template<
class FunctorType,
class ReturnType >
1263 const FunctorType& functor,
1265 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1267 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(
"",policy_type(0,policy),functor,return_value_impl);
1270 template<
class FunctorType,
class ReturnType >
1273 const size_t& policy,
1274 const FunctorType& functor,
1276 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1278 Impl::ParallelReduceAdaptor<policy_type,FunctorType,ReturnType>::execute(label,policy_type(0,policy),functor,return_value_impl);
1283 template<
class PolicyType,
class FunctorType>
1286 const PolicyType& policy,
1287 const FunctorType& functor,
1288 typename Impl::enable_if<
1289 Kokkos::Impl::is_execution_policy<PolicyType>::value
1291 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1292 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1293 ,
typename ValueTraits::value_type
1294 ,
typename ValueTraits::pointer_type
1295 >::type value_type ;
1299 , Kokkos::MemoryUnmanaged
1301 result_view_type result_view ;
1303 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,result_view_type>::execute(label,policy,functor,result_view);
1306 template<
class PolicyType,
class FunctorType >
1309 const FunctorType& functor,
1310 typename Impl::enable_if<
1311 Kokkos::Impl::is_execution_policy<PolicyType>::value
1313 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1314 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1315 ,
typename ValueTraits::value_type
1316 ,
typename ValueTraits::pointer_type
1317 >::type value_type ;
1321 , Kokkos::MemoryUnmanaged
1323 result_view_type result_view ;
1325 Impl::ParallelReduceAdaptor<PolicyType,FunctorType,result_view_type>::execute(
"",policy,functor,result_view);
1328 template<
class FunctorType >
1331 const FunctorType& functor) {
1332 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1333 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1334 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1335 ,
typename ValueTraits::value_type
1336 ,
typename ValueTraits::pointer_type
1337 >::type value_type ;
1341 , Kokkos::MemoryUnmanaged
1343 result_view_type result_view ;
1345 Impl::ParallelReduceAdaptor<policy_type,FunctorType,result_view_type>::execute(
"",policy_type(0,policy),functor,result_view);
1348 template<
class FunctorType>
1351 const size_t& policy,
1352 const FunctorType& functor) {
1353 typedef typename Impl::ParallelReducePolicyType<void,size_t,FunctorType>::policy_type policy_type;
1354 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1355 typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
1356 ,
typename ValueTraits::value_type
1357 ,
typename ValueTraits::pointer_type
1358 >::type value_type ;
1362 , Kokkos::MemoryUnmanaged
1364 result_view_type result_view ;
1366 Impl::ParallelReduceAdaptor<policy_type,FunctorType,result_view_type>::execute(label,policy_type(0,policy),functor,result_view);
1371 #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.
View to an array of data.
Memory management for host memory.
Execution policy for work over a range of an integral type.
Implementation detail of parallel_reduce.