47 #ifndef KOKKOS_SERIAL_HPP 48 #define KOKKOS_SERIAL_HPP 53 #include <Kokkos_TaskScheduler.hpp> 55 #include <Kokkos_HostSpace.hpp> 56 #include <Kokkos_ScratchSpace.hpp> 57 #include <Kokkos_MemoryTraits.hpp> 58 #include <impl/Kokkos_Tags.hpp> 59 #include <impl/Kokkos_FunctorAdapter.hpp> 60 #include <impl/Kokkos_Profiling_Interface.hpp> 62 #include <KokkosExp_MDRangePolicy.hpp> 64 #if defined( KOKKOS_HAVE_SERIAL ) 86 typedef Serial execution_space ;
88 typedef HostSpace::size_type size_type ;
90 typedef HostSpace memory_space ;
95 typedef LayoutRight array_layout ;
98 typedef ScratchMemorySpace< Kokkos::Serial > scratch_memory_space ;
108 inline static int in_parallel() {
return false ; }
136 static void fence() {}
138 static void initialize(
unsigned threads_count = 1 ,
139 unsigned use_numa_count = 0 ,
140 unsigned use_cores_per_numa = 0 ,
141 bool allow_asynchronous_threadpool =
false) {
142 (void) threads_count;
143 (void) use_numa_count;
144 (void) use_cores_per_numa;
145 (void) allow_asynchronous_threadpool;
148 Impl::init_lock_array_host_space();
149 #if (KOKKOS_ENABLE_PROFILING) 150 Kokkos::Profiling::initialize();
154 static int is_initialized() {
return 1 ; }
157 static int concurrency() {
return 1;};
161 #if (KOKKOS_ENABLE_PROFILING) 162 Kokkos::Profiling::finalize();
167 static void print_configuration( std::ostream & ,
const bool =
false ) {}
171 inline static int thread_pool_size(
int = 0 ) {
return 1 ; }
172 KOKKOS_INLINE_FUNCTION
static int thread_pool_rank() {
return 0 ; }
176 KOKKOS_INLINE_FUNCTION
static unsigned hardware_thread_id() {
return thread_pool_rank(); }
177 inline static unsigned max_hardware_threads() {
return thread_pool_size(0); }
181 static void * scratch_memory_resize(
unsigned reduce_size ,
unsigned shared_size );
195 struct VerifyExecutionCanAccessMemorySpace
196 <
Kokkos::Serial::memory_space
197 , Kokkos::Serial::scratch_memory_space
200 enum { value =
true };
201 inline static void verify(
void ) { }
202 inline static void verify(
const void * ) { }
205 namespace SerialImpl {
210 unsigned m_reduce_end ;
211 unsigned m_shared_end ;
215 static Sentinel & singleton();
219 unsigned align(
unsigned n );
230 class SerialTeamMember {
233 const scratch_memory_space m_space ;
234 const int m_league_rank ;
235 const int m_league_size ;
237 SerialTeamMember & operator = (
const SerialTeamMember & );
241 KOKKOS_INLINE_FUNCTION
242 const scratch_memory_space & team_shmem()
const {
return m_space ; }
244 KOKKOS_INLINE_FUNCTION
245 const scratch_memory_space & team_scratch(
int)
const 248 KOKKOS_INLINE_FUNCTION
249 const scratch_memory_space & thread_scratch(
int)
const 252 KOKKOS_INLINE_FUNCTION
int league_rank()
const {
return m_league_rank ; }
253 KOKKOS_INLINE_FUNCTION
int league_size()
const {
return m_league_size ; }
254 KOKKOS_INLINE_FUNCTION
int team_rank()
const {
return 0 ; }
255 KOKKOS_INLINE_FUNCTION
int team_size()
const {
return 1 ; }
257 KOKKOS_INLINE_FUNCTION
void team_barrier()
const {}
259 template<
class ValueType>
260 KOKKOS_INLINE_FUNCTION
261 void team_broadcast(
const ValueType& ,
const int& )
const {}
263 template<
class ValueType,
class JoinOp >
264 KOKKOS_INLINE_FUNCTION
265 ValueType team_reduce(
const ValueType & value ,
const JoinOp & )
const 279 template<
typename Type >
280 KOKKOS_INLINE_FUNCTION Type team_scan(
const Type & value , Type *
const global_accum )
const 282 const Type tmp = global_accum ? *global_accum : Type(0) ;
283 if ( global_accum ) { *global_accum += value ; }
292 template<
typename Type >
293 KOKKOS_INLINE_FUNCTION Type team_scan(
const Type & )
const 299 SerialTeamMember(
int arg_league_rank
300 ,
int arg_league_size
301 ,
int arg_shared_size
313 template<
class ... Properties >
314 class TeamPolicyInternal<
Kokkos::Serial , Properties ... >:
public PolicyTraits<Properties...>
318 size_t m_team_scratch_size[2] ;
319 size_t m_thread_scratch_size[2] ;
326 typedef TeamPolicyInternal execution_policy ;
328 typedef PolicyTraits<Properties ... > traits;
331 typedef Kokkos::Serial execution_space ;
333 TeamPolicyInternal& operator = (
const TeamPolicyInternal& p) {
334 m_league_size = p.m_league_size;
335 m_team_scratch_size[0] = p.m_team_scratch_size[0];
336 m_thread_scratch_size[0] = p.m_thread_scratch_size[0];
337 m_team_scratch_size[1] = p.m_team_scratch_size[1];
338 m_thread_scratch_size[1] = p.m_thread_scratch_size[1];
339 m_chunk_size = p.m_chunk_size;
345 template<
class FunctorType >
347 int team_size_max(
const FunctorType & ) {
return 1 ; }
349 template<
class FunctorType >
351 int team_size_recommended(
const FunctorType & ) {
return 1 ; }
353 template<
class FunctorType >
355 int team_size_recommended(
const FunctorType & ,
const int& ) {
return 1 ; }
359 inline int team_size()
const {
return 1 ; }
360 inline int league_size()
const {
return m_league_size ; }
361 inline size_t scratch_size(
const int& level,
int = 0)
const {
return m_team_scratch_size[level] + m_thread_scratch_size[level]; }
364 TeamPolicyInternal( execution_space &
365 ,
int league_size_request
368 : m_team_scratch_size { 0 , 0 }
369 , m_thread_scratch_size { 0 , 0 }
370 , m_league_size( league_size_request )
371 , m_chunk_size ( 32 )
374 TeamPolicyInternal( execution_space &
375 ,
int league_size_request
376 ,
const Kokkos::AUTO_t &
378 : m_team_scratch_size { 0 , 0 }
379 , m_thread_scratch_size { 0 , 0 }
380 , m_league_size( league_size_request )
381 , m_chunk_size ( 32 )
384 TeamPolicyInternal(
int league_size_request
387 : m_team_scratch_size { 0 , 0 }
388 , m_thread_scratch_size { 0 , 0 }
389 , m_league_size( league_size_request )
390 , m_chunk_size ( 32 )
393 TeamPolicyInternal(
int league_size_request
394 ,
const Kokkos::AUTO_t &
396 : m_team_scratch_size { 0 , 0 }
397 , m_thread_scratch_size { 0 , 0 }
398 , m_league_size( league_size_request )
399 , m_chunk_size ( 32 )
402 inline int chunk_size()
const {
return m_chunk_size ; }
405 inline TeamPolicyInternal set_chunk_size(
typename traits::index_type chunk_size_)
const {
406 TeamPolicyInternal p = *
this;
407 p.m_chunk_size = chunk_size_;
412 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerTeamValue& per_team)
const {
413 TeamPolicyInternal p = *
this;
414 p.m_team_scratch_size[level] = per_team.value;
419 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerThreadValue& per_thread)
const {
420 TeamPolicyInternal p = *
this;
421 p.m_thread_scratch_size[level] = per_thread.value;
426 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread)
const {
427 TeamPolicyInternal p = *
this;
428 p.m_team_scratch_size[level] = per_team.value;
429 p.m_thread_scratch_size[level] = per_thread.value;
433 typedef Impl::SerialTeamMember member_type ;
448 template<
class FunctorType ,
class ... Traits >
449 class ParallelFor< FunctorType ,
450 Kokkos::RangePolicy< Traits ... > ,
458 const FunctorType m_functor ;
459 const Policy m_policy ;
461 template<
class TagType >
462 typename std::enable_if< std::is_same< TagType , void >::value >::type
465 const typename Policy::member_type e = m_policy.end();
466 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
471 template<
class TagType >
472 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
476 const typename Policy::member_type e = m_policy.end();
477 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
486 { this->
template exec< typename Policy::work_tag >(); }
489 ParallelFor(
const FunctorType & arg_functor
490 ,
const Policy & arg_policy )
491 : m_functor( arg_functor )
492 , m_policy( arg_policy )
498 template<
class FunctorType ,
class ReducerType ,
class ... Traits >
499 class ParallelReduce< FunctorType
500 ,
Kokkos::RangePolicy< Traits ... >
508 typedef typename Policy::work_tag WorkTag ;
510 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
511 typedef typename ReducerConditional::type ReducerTypeFwd;
513 typedef Kokkos::Impl::FunctorValueTraits< ReducerTypeFwd , WorkTag > ValueTraits ;
514 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTag > ValueInit ;
516 typedef typename ValueTraits::pointer_type pointer_type ;
517 typedef typename ValueTraits::reference_type reference_type ;
519 const FunctorType m_functor ;
520 const Policy m_policy ;
521 const ReducerType m_reducer ;
522 const pointer_type m_result_ptr ;
524 template<
class TagType >
526 typename std::enable_if< std::is_same< TagType , void >::value >::type
527 exec( pointer_type ptr )
const 529 reference_type update = ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
531 const typename Policy::member_type e = m_policy.end();
532 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
533 m_functor( i , update );
536 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , TagType >::
537 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
540 template<
class TagType >
542 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
543 exec( pointer_type ptr )
const 546 reference_type update = ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
548 const typename Policy::member_type e = m_policy.end();
549 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
550 m_functor( t , i , update );
553 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , TagType >::
554 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
562 pointer_type ptr = (pointer_type) Kokkos::Serial::scratch_memory_resize
563 ( ValueTraits::value_size( ReducerConditional::select(m_functor , m_reducer) ) , 0 );
565 this->
template exec< WorkTag >( m_result_ptr ? m_result_ptr : ptr );
568 template<
class HostViewType >
569 ParallelReduce(
const FunctorType & arg_functor ,
570 const Policy & arg_policy ,
571 const HostViewType & arg_result_view ,
572 typename std::enable_if<
573 Kokkos::is_view< HostViewType >::value &&
574 !Kokkos::is_reducer_type<ReducerType>::value
575 ,
void*>::type = NULL)
576 : m_functor( arg_functor )
577 , m_policy( arg_policy )
578 , m_reducer( InvalidType() )
579 , m_result_ptr( arg_result_view.ptr_on_device() )
581 static_assert( Kokkos::is_view< HostViewType >::value
582 ,
"Kokkos::Serial reduce result must be a View" );
584 static_assert( std::is_same< typename HostViewType::memory_space , HostSpace >::value
585 ,
"Kokkos::Serial reduce result must be a View in HostSpace" );
589 ParallelReduce(
const FunctorType & arg_functor
591 ,
const ReducerType& reducer )
592 : m_functor( arg_functor )
593 , m_policy( arg_policy )
594 , m_reducer( reducer )
595 , m_result_ptr( reducer.result_view().data() )
605 template<
class FunctorType ,
class ... Traits >
606 class ParallelScan< FunctorType
607 ,
Kokkos::RangePolicy< Traits ... >
614 typedef typename Policy::work_tag WorkTag ;
615 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , WorkTag > ValueTraits ;
616 typedef Kokkos::Impl::FunctorValueInit< FunctorType , WorkTag > ValueInit ;
618 typedef typename ValueTraits::pointer_type pointer_type ;
619 typedef typename ValueTraits::reference_type reference_type ;
621 const FunctorType m_functor ;
622 const Policy m_policy ;
624 template<
class TagType >
626 typename std::enable_if< std::is_same< TagType , void >::value >::type
627 exec( pointer_type ptr )
const 629 reference_type update = ValueInit::init( m_functor , ptr );
631 const typename Policy::member_type e = m_policy.end();
632 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
633 m_functor( i , update ,
true );
637 template<
class TagType >
639 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
640 exec( pointer_type ptr )
const 643 reference_type update = ValueInit::init( m_functor , ptr );
645 const typename Policy::member_type e = m_policy.end();
646 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
647 m_functor( t , i , update ,
true );
656 pointer_type ptr = (pointer_type)
657 Kokkos::Serial::scratch_memory_resize( ValueTraits::value_size( m_functor ) , 0 );
658 this->
template exec< WorkTag >( ptr );
662 ParallelScan(
const FunctorType & arg_functor
663 ,
const Policy & arg_policy
665 : m_functor( arg_functor )
666 , m_policy( arg_policy )
680 template<
class FunctorType ,
class ... Properties >
681 class ParallelFor< FunctorType
682 ,
Kokkos::TeamPolicy< Properties ... >
688 typedef TeamPolicyInternal< Kokkos::Serial , Properties ...> Policy ;
689 typedef typename Policy::member_type Member ;
691 const FunctorType m_functor ;
695 template<
class TagType >
697 typename std::enable_if< std::is_same< TagType , void >::value >::type
700 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
701 m_functor( Member(ileague,m_league,m_shared) );
705 template<
class TagType >
707 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
711 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
712 m_functor( t , Member(ileague,m_league,m_shared) );
721 Kokkos::Serial::scratch_memory_resize( 0 , m_shared );
722 this->
template exec< typename Policy::work_tag >();
725 ParallelFor(
const FunctorType & arg_functor
726 ,
const Policy & arg_policy )
727 : m_functor( arg_functor )
728 , m_league( arg_policy.league_size() )
729 , m_shared( arg_policy.scratch_size(0) + arg_policy.scratch_size(1) + FunctorTeamShmemSize< FunctorType >::value( arg_functor , 1 ) )
735 template<
class FunctorType ,
class ReducerType ,
class ... Properties >
736 class ParallelReduce< FunctorType
737 ,
Kokkos::TeamPolicy< Properties ... >
744 typedef TeamPolicyInternal< Kokkos::Serial, Properties ... > Policy ;
745 typedef typename Policy::member_type Member ;
746 typedef typename Policy::work_tag WorkTag ;
748 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
749 typedef typename ReducerConditional::type ReducerTypeFwd;
751 typedef Kokkos::Impl::FunctorValueTraits< ReducerTypeFwd , WorkTag > ValueTraits ;
752 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTag > ValueInit ;
754 typedef typename ValueTraits::pointer_type pointer_type ;
755 typedef typename ValueTraits::reference_type reference_type ;
757 const FunctorType m_functor ;
759 const ReducerType m_reducer ;
760 pointer_type m_result_ptr ;
763 template<
class TagType >
765 typename std::enable_if< std::is_same< TagType , void >::value >::type
766 exec( pointer_type ptr )
const 768 reference_type update = ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
770 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
771 m_functor( Member(ileague,m_league,m_shared) , update );
774 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , TagType >::
775 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
778 template<
class TagType >
780 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
781 exec( pointer_type ptr )
const 785 reference_type update = ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
787 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
788 m_functor( t , Member(ileague,m_league,m_shared) , update );
791 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , TagType >::
792 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
800 pointer_type ptr = (pointer_type) Kokkos::Serial::scratch_memory_resize
801 ( ValueTraits::value_size( ReducerConditional::select(m_functor , m_reducer) ) , m_shared );
803 this->
template exec< WorkTag >( m_result_ptr ? m_result_ptr : ptr );
806 template<
class ViewType >
807 ParallelReduce(
const FunctorType & arg_functor
808 ,
const Policy & arg_policy
809 ,
const ViewType & arg_result ,
810 typename std::enable_if<
811 Kokkos::is_view< ViewType >::value &&
812 !Kokkos::is_reducer_type<ReducerType>::value
813 ,
void*>::type = NULL)
814 : m_functor( arg_functor )
815 , m_league( arg_policy.league_size() )
816 , m_reducer( InvalidType() )
817 , m_result_ptr( arg_result.ptr_on_device() )
818 , m_shared( arg_policy.scratch_size(0) + arg_policy.scratch_size(1) + FunctorTeamShmemSize< FunctorType >::value( m_functor , 1 ) )
820 static_assert( Kokkos::is_view< ViewType >::value
821 ,
"Reduction result on Kokkos::Serial must be a Kokkos::View" );
823 static_assert( std::is_same<
typename ViewType::memory_space
825 ,
"Reduction result on Kokkos::Serial must be a Kokkos::View in HostSpace" );
829 ParallelReduce(
const FunctorType & arg_functor
831 ,
const ReducerType& reducer )
832 : m_functor( arg_functor )
833 , m_league( arg_policy.league_size() )
834 , m_reducer( reducer )
835 , m_result_ptr( reducer.result_view().data() )
836 , m_shared( arg_policy.scratch_size(0) + arg_policy.scratch_size(1) + FunctorTeamShmemSize< FunctorType >::value( arg_functor , arg_policy.team_size() ) )
855 template<
typename iType>
856 struct TeamThreadRangeBoundariesStruct<iType,SerialTeamMember> {
857 typedef iType index_type;
860 enum {increment = 1};
861 const SerialTeamMember& thread;
863 KOKKOS_INLINE_FUNCTION
864 TeamThreadRangeBoundariesStruct (
const SerialTeamMember& arg_thread,
const iType& arg_count)
870 KOKKOS_INLINE_FUNCTION
871 TeamThreadRangeBoundariesStruct (
const SerialTeamMember& arg_thread,
const iType& arg_begin,
const iType & arg_end )
874 , thread( arg_thread )
878 template<
typename iType>
879 struct ThreadVectorRangeBoundariesStruct<iType,SerialTeamMember> {
880 typedef iType index_type;
883 enum {increment = 1};
885 KOKKOS_INLINE_FUNCTION
886 ThreadVectorRangeBoundariesStruct (
const SerialTeamMember& thread,
const iType& count):
893 template<
typename iType >
894 KOKKOS_INLINE_FUNCTION
895 Impl::TeamThreadRangeBoundariesStruct<iType,Impl::SerialTeamMember>
896 TeamThreadRange(
const Impl::SerialTeamMember& thread,
const iType & count )
898 return Impl::TeamThreadRangeBoundariesStruct< iType, Impl::SerialTeamMember >( thread, count );
901 template<
typename iType1,
typename iType2 >
902 KOKKOS_INLINE_FUNCTION
903 Impl::TeamThreadRangeBoundariesStruct< typename std::common_type< iType1, iType2 >::type,
904 Impl::SerialTeamMember >
905 TeamThreadRange(
const Impl::SerialTeamMember& thread,
const iType1 & begin,
const iType2 & end )
907 typedef typename std::common_type< iType1, iType2 >::type iType;
908 return Impl::TeamThreadRangeBoundariesStruct< iType, Impl::SerialTeamMember >( thread, iType(begin), iType(end) );
911 template<
typename iType>
912 KOKKOS_INLINE_FUNCTION
913 Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::SerialTeamMember >
915 return Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::SerialTeamMember >(thread,count);
918 KOKKOS_INLINE_FUNCTION
919 Impl::ThreadSingleStruct<Impl::SerialTeamMember> PerTeam(
const Impl::SerialTeamMember& thread) {
920 return Impl::ThreadSingleStruct<Impl::SerialTeamMember>(thread);
923 KOKKOS_INLINE_FUNCTION
924 Impl::VectorSingleStruct<Impl::SerialTeamMember> PerThread(
const Impl::SerialTeamMember& thread) {
925 return Impl::VectorSingleStruct<Impl::SerialTeamMember>(thread);
936 template<
typename iType,
class Lambda>
937 KOKKOS_INLINE_FUNCTION
938 void parallel_for(
const Impl::TeamThreadRangeBoundariesStruct<iType,Impl::SerialTeamMember>& loop_boundaries,
const Lambda& lambda) {
939 for( iType i = loop_boundaries.begin; i < loop_boundaries.end; i+=loop_boundaries.increment)
947 template<
typename iType,
class Lambda,
typename ValueType >
948 KOKKOS_INLINE_FUNCTION
949 void parallel_reduce(
const Impl::TeamThreadRangeBoundariesStruct<iType,Impl::SerialTeamMember>& loop_boundaries,
950 const Lambda & lambda, ValueType& result) {
952 result = ValueType();
954 for( iType i = loop_boundaries.begin; i < loop_boundaries.end; i+=loop_boundaries.increment) {
955 ValueType tmp = ValueType();
960 result = loop_boundaries.thread.team_reduce(result,Impl::JoinAdd<ValueType>());
970 template<
typename iType,
class Lambda,
typename ValueType,
class JoinType >
971 KOKKOS_INLINE_FUNCTION
972 void parallel_reduce(
const Impl::TeamThreadRangeBoundariesStruct<iType,Impl::SerialTeamMember>& loop_boundaries,
973 const Lambda & lambda,
const JoinType& join, ValueType& init_result) {
975 ValueType result = init_result;
977 for( iType i = loop_boundaries.begin; i < loop_boundaries.end; i+=loop_boundaries.increment) {
978 ValueType tmp = ValueType();
983 init_result = loop_boundaries.thread.team_reduce(result,Impl::JoinLambdaAdapter<ValueType,JoinType>(join));
993 template<
typename iType,
class Lambda>
994 KOKKOS_INLINE_FUNCTION
995 void parallel_for(
const Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::SerialTeamMember >&
996 loop_boundaries,
const Lambda& lambda) {
997 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP 1000 for( iType i = loop_boundaries.start; i < loop_boundaries.end; i+=loop_boundaries.increment)
1008 template<
typename iType,
class Lambda,
typename ValueType >
1009 KOKKOS_INLINE_FUNCTION
1010 void parallel_reduce(
const Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::SerialTeamMember >&
1011 loop_boundaries,
const Lambda & lambda, ValueType& result) {
1012 result = ValueType();
1013 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP 1016 for( iType i = loop_boundaries.start; i < loop_boundaries.end; i+=loop_boundaries.increment) {
1017 ValueType tmp = ValueType();
1030 template<
typename iType,
class Lambda,
typename ValueType,
class JoinType >
1031 KOKKOS_INLINE_FUNCTION
1032 void parallel_reduce(
const Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::SerialTeamMember >&
1033 loop_boundaries,
const Lambda & lambda,
const JoinType& join, ValueType& init_result) {
1035 ValueType result = init_result;
1036 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP 1039 for( iType i = loop_boundaries.start; i < loop_boundaries.end; i+=loop_boundaries.increment) {
1040 ValueType tmp = ValueType();
1044 init_result = result;
1057 template<
typename iType,
class FunctorType >
1058 KOKKOS_INLINE_FUNCTION
1059 void parallel_scan(
const Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::SerialTeamMember >&
1060 loop_boundaries,
const FunctorType & lambda) {
1062 typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
1063 typedef typename ValueTraits::value_type value_type ;
1065 value_type scan_val = value_type();
1067 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP 1070 for( iType i = loop_boundaries.start; i < loop_boundaries.end; i+=loop_boundaries.increment) {
1071 lambda(i,scan_val,
true);
1079 template<
class FunctorType>
1080 KOKKOS_INLINE_FUNCTION
1081 void single(
const Impl::VectorSingleStruct<Impl::SerialTeamMember>& ,
const FunctorType& lambda) {
1085 template<
class FunctorType>
1086 KOKKOS_INLINE_FUNCTION
1087 void single(
const Impl::ThreadSingleStruct<Impl::SerialTeamMember>& ,
const FunctorType& lambda) {
1091 template<
class FunctorType,
class ValueType>
1092 KOKKOS_INLINE_FUNCTION
1093 void single(
const Impl::VectorSingleStruct<Impl::SerialTeamMember>& ,
const FunctorType& lambda, ValueType& val) {
1097 template<
class FunctorType,
class ValueType>
1098 KOKKOS_INLINE_FUNCTION
1099 void single(
const Impl::ThreadSingleStruct<Impl::SerialTeamMember>& ,
const FunctorType& lambda, ValueType& val) {
1106 #include <impl/Kokkos_Serial_Task.hpp> 1108 #endif // defined( KOKKOS_HAVE_SERIAL ) Scratch memory space associated with an execution space.
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.
KOKKOS_INLINE_FUNCTION Impl::TeamThreadRangeBoundariesStruct< iType, TeamMemberType > TeamThreadRange(const TeamMemberType &, const iType &count)
Execution policy for parallel work over a threads within a team.
Memory space for main process and CPU execution spaces.
Memory management for host memory.
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< ! Impl::is_integral< ExecPolicy >::value >::type *=0)
Execute functor in parallel according to the execution policy.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.
KOKKOS_INLINE_FUNCTION Impl::ThreadVectorRangeBoundariesStruct< iType, TeamMemberType > ThreadVectorRange(const TeamMemberType &, const iType &count)
Execution policy for a vector parallel loop.
Execution policy for work over a range of an integral type.