Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Kokkos_Serial.hpp
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //   Kokkos: Manycore Performance-Portable Multidimensional Arrays
00006 //              Copyright (2012) Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions?  Contact  H. Carter Edwards (hcedwar@sandia.gov)
00039 //
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00046 
00047 #ifndef KOKKOS_SERIAL_HPP
00048 #define KOKKOS_SERIAL_HPP
00049 
00050 #include <cstddef>
00051 #include <iosfwd>
00052 #include <Kokkos_Parallel.hpp>
00053 #include <Kokkos_Layout.hpp>
00054 #include <Kokkos_HostSpace.hpp>
00055 #include <Kokkos_ScratchSpace.hpp>
00056 #include <Kokkos_MemoryTraits.hpp>
00057 #include <impl/Kokkos_Tags.hpp>
00058 
00059 /*--------------------------------------------------------------------------*/
00060 
00061 namespace Kokkos {
00062 
00075 class Serial {
00076 public:
00078 
00079 
00081   typedef Impl::ExecutionSpaceTag  kokkos_tag ;
00082 
00084   typedef Serial                device_type ;
00085   typedef Serial                execution_space ;
00087   typedef HostSpace::size_type  size_type ;
00089   typedef HostSpace             memory_space ;
00091   typedef LayoutRight           array_layout ;
00096   typedef Serial                host_mirror_device_type ;
00097 
00099   typedef ScratchMemorySpace< Kokkos::Serial >  scratch_memory_space ;
00100 
00102 
00109   inline static int in_parallel() { return false ; }
00110 
00122   static bool sleep();
00123 
00129   static bool wake();
00130 
00137   static void fence() {}
00138 
00139   static void initialize( unsigned threads_count = 1 ,
00140                           unsigned use_numa_count = 0 ,
00141                           unsigned use_cores_per_numa = 0 ,
00142                           bool allow_asynchronous_threadpool = false) {
00143     (void) threads_count;
00144     (void) use_numa_count;
00145     (void) use_cores_per_numa;
00146     (void) allow_asynchronous_threadpool;
00147   }
00148 
00149   static int is_initialized() { return 1 ; }
00150 
00152   static void finalize() {}
00153 
00155   static void print_configuration( std::ostream & , const bool detail = false );
00156 
00157   //--------------------------------------------------------------------------
00158 
00159   inline static int thread_pool_size( int = 0 ) { return 1 ; }
00160   KOKKOS_INLINE_FUNCTION static int thread_pool_rank() { return 0 ; }
00161 
00162   //--------------------------------------------------------------------------
00163 
00164   KOKKOS_INLINE_FUNCTION static unsigned hardware_thread_id() { return thread_pool_rank(); }
00165   inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
00166 
00167   static inline int team_max()         { return thread_pool_size(1) ; }
00168   static inline int team_recommended() { return thread_pool_size(2); }
00169 
00170   //--------------------------------------------------------------------------
00171 
00172   static void * scratch_memory_resize( unsigned reduce_size , unsigned shared_size );
00173 
00174   //--------------------------------------------------------------------------
00175 };
00176 
00177 } // namespace Kokkos
00178 
00179 /*--------------------------------------------------------------------------*/
00180 /*--------------------------------------------------------------------------*/
00181 
00182 namespace Kokkos {
00183 namespace Impl {
00184 
00185 template<>
00186 struct VerifyExecutionCanAccessMemorySpace
00187   < Kokkos::Serial::memory_space
00188   , Kokkos::Serial::scratch_memory_space
00189   >
00190 {
00191   inline static void verify( void ) { }
00192   inline static void verify( const void * ) { }
00193 };
00194 
00195 namespace SerialImpl {
00196 
00197 struct Sentinel {
00198 
00199   void *   m_scratch ;
00200   unsigned m_reduce_end ;
00201   unsigned m_shared_end ;
00202 
00203   Sentinel();
00204   ~Sentinel();
00205   static Sentinel & singleton();
00206 };
00207 
00208 inline
00209 unsigned align( unsigned n );
00210 }
00211 } // namespace Impl
00212 } // namespace Kokkos
00213 
00214 /*--------------------------------------------------------------------------*/
00215 /*--------------------------------------------------------------------------*/
00216 
00217 namespace Kokkos {
00218 namespace Impl {
00219 
00220 class SerialTeamMember {
00221 private:
00222   typedef Kokkos::ScratchMemorySpace< Kokkos::Serial > scratch_memory_space ;
00223   const scratch_memory_space  m_space ;
00224   const int                   m_league_rank ;
00225   const int                   m_league_size ;
00226 
00227   SerialTeamMember & operator = ( const SerialTeamMember & );
00228 
00229 public:
00230 
00231   KOKKOS_INLINE_FUNCTION
00232   const scratch_memory_space & team_shmem() const { return m_space ; }
00233 
00234   KOKKOS_INLINE_FUNCTION int league_rank() const { return m_league_rank ; }
00235   KOKKOS_INLINE_FUNCTION int league_size() const { return m_league_size ; }
00236   KOKKOS_INLINE_FUNCTION int team_rank() const { return 0 ; }
00237   KOKKOS_INLINE_FUNCTION int team_size() const { return 1 ; }
00238 
00239   KOKKOS_INLINE_FUNCTION void team_barrier() const {}
00240 
00241   template< class JoinOp >
00242   typename JoinOp::value_type team_reduce( const typename JoinOp::value_type & value
00243                                          , const JoinOp & ) const
00244     { return value ; }
00245 
00255   template< typename Type >
00256   KOKKOS_INLINE_FUNCTION Type team_scan( const Type & value , Type * const global_accum ) const
00257     {
00258       const Type tmp = global_accum ? *global_accum : Type(0) ;
00259       if ( global_accum ) { *global_accum += value ; }
00260       return tmp ;
00261     }
00262 
00268   template< typename Type >
00269   KOKKOS_INLINE_FUNCTION Type team_scan( const Type & ) const
00270     { return Type(0); }
00271 
00272 #ifdef KOKKOS_HAVE_CXX11
00273 
00277   template< typename iType, class Operation>
00278   KOKKOS_INLINE_FUNCTION void team_par_for(const iType n, const Operation & op) const {
00279     for(int i=0; i<n ; i++) {
00280       op(i);
00281     }
00282   }
00283 
00284 #endif
00285 
00286   //----------------------------------------
00287   // Execution space specific:
00288 
00289   SerialTeamMember( int arg_league_rank
00290                   , int arg_league_size 
00291                   , int arg_shared_size
00292                   );
00293 };
00294 
00295 template<unsigned int VectorLength>
00296 class SerialTeamVectorMember {
00297 private:
00298   typedef Kokkos::ScratchMemorySpace< Kokkos::Serial > scratch_memory_space ;
00299   const scratch_memory_space  m_space ;
00300   const int                   m_league_rank ;
00301   const int                   m_league_size ;
00302 
00303   SerialTeamVectorMember & operator = ( const SerialTeamVectorMember & );
00304 
00305 public:
00306 
00307   KOKKOS_INLINE_FUNCTION
00308   const scratch_memory_space & team_shmem() const { return m_space ; }
00309 
00310   KOKKOS_INLINE_FUNCTION int league_rank() const { return m_league_rank ; }
00311   KOKKOS_INLINE_FUNCTION int league_size() const { return m_league_size ; }
00312   KOKKOS_INLINE_FUNCTION int team_rank() const { return 0 ; }
00313   KOKKOS_INLINE_FUNCTION int team_size() const { return 1 ; }
00314 
00315   KOKKOS_INLINE_FUNCTION void team_barrier() const {}
00316 
00317   template< class JoinOp >
00318   typename JoinOp::value_type team_reduce( const typename JoinOp::value_type & value
00319                                          , const JoinOp & ) const
00320     { return value ; }
00321 
00331   template< typename Type >
00332   KOKKOS_INLINE_FUNCTION Type team_scan( const Type & value , Type * const global_accum ) const
00333     {
00334       const Type tmp = global_accum ? *global_accum : Type(0) ;
00335       if ( global_accum ) { *global_accum += value ; }
00336       return tmp ;
00337     }
00338 
00344   template< typename Type >
00345   KOKKOS_INLINE_FUNCTION Type team_scan( const Type & ) const
00346     { return Type(0); }
00347 
00348 #ifdef KOKKOS_HAVE_CXX11
00349 
00353   template< typename iType, class Operation>
00354   KOKKOS_INLINE_FUNCTION void team_par_for(const iType n, const Operation & op) const {
00355     for(int i=0; i<n ; i++) {
00356       op(i);
00357     }
00358   }
00359 
00361   template< class Operation >
00362   KOKKOS_INLINE_FUNCTION void vector_single(const Operation & op) const {
00363     op();
00364   }
00365 
00367   template< class Operation , typename ValueType>
00368   KOKKOS_INLINE_FUNCTION void vector_single(const Operation & op, ValueType& bcast) const {
00369     op();
00370   }
00371 
00376   template< typename iType, class Operation >
00377   KOKKOS_INLINE_FUNCTION void vector_par_for(const iType n, const Operation & op) const {
00378     #ifdef KOKKOS_HAVE_PRAGMA_IVDEP
00379     #pragma ivdep
00380     #endif
00381     for(int i=0; i<n ; i++) {
00382       op(i);
00383     }
00384   }
00385 
00390   template< typename iType, class Operation, typename ValueType >
00391   KOKKOS_INLINE_FUNCTION void vector_par_reduce(const iType n, const Operation & op, ValueType& result) const {
00392 
00393     result = ValueType();
00394 
00395 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP
00396 #pragma ivdep
00397 #endif
00398     for(int i=0; i<n ; i++) {
00399       ValueType tmp = ValueType();
00400       op(i,tmp);
00401       result+=tmp;
00402     }
00403   }
00404 
00412   template< typename iType, class Operation, typename ValueType, class JoinType >
00413   KOKKOS_INLINE_FUNCTION void vector_par_reduce(const iType n, const Operation & op, ValueType& init_result, const JoinType & join) const {
00414 
00415     ValueType result = init_result;
00416 
00417 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP
00418 #pragma ivdep
00419 #endif
00420     for(int i=0; i<n ; i++) {
00421       ValueType tmp = init_result;
00422       op(i,tmp);
00423       join(result,tmp);
00424     }
00425     init_result = result;
00426   }
00427 
00428 
00439   template< typename iType, class Operation, typename ValueType >
00440   KOKKOS_INLINE_FUNCTION  void vector_par_scan(const iType n, const Operation & op, ValueType& scan_val) const {
00441 
00442     scan_val = ValueType();
00443 
00444 #ifdef KOKKOS_HAVE_PRAGMA_IVDEP
00445 #pragma ivdep
00446 #endif
00447     for(int i=0; i<n ; i++) {
00448       op(i,scan_val,true);
00449     }
00450   }
00451 #endif
00452   //----------------------------------------
00453   // Execution space specific:
00454 
00455   SerialTeamVectorMember( int arg_league_rank
00456                   , int arg_league_size
00457                   , int arg_shared_size
00458                   )
00459   : m_space( ((char *) SerialImpl::Sentinel::singleton().m_scratch) + SerialImpl::Sentinel::singleton().m_reduce_end
00460            , arg_shared_size )
00461   , m_league_rank( arg_league_rank )
00462   , m_league_size( arg_league_size )
00463   {}
00464 };
00465 } // namespace Impl
00466 } // namespace Kokkos
00467 
00468 /*--------------------------------------------------------------------------*/
00469 /*--------------------------------------------------------------------------*/
00470 
00471 namespace Kokkos {
00472 
00473 /* 
00474  * < Kokkos::Serial , WorkArgTag >
00475  * < WorkArgTag , Impl::enable_if< Impl::is_same< Kokkos::Serial , Kokkos::DefaultExecutionSpace >::value >::type >
00476  *
00477  */
00478 template< class Arg0 , class Arg1 >
00479 class TeamPolicy< Arg0 , Arg1 , Kokkos::Serial >
00480 {
00481 private:
00482 
00483   const int m_league_size ;
00484 
00485 public:
00486 
00487   typedef Impl::ExecutionPolicyTag   kokkos_tag ;       
00488   typedef TeamPolicy                 execution_policy ; 
00489   typedef Kokkos::Serial             execution_space ;  
00490 
00491   typedef typename
00492     Impl::if_c< ! Impl::is_same< Kokkos::Serial , Arg0 >::value , Arg0 , Arg1 >::type
00493       work_tag ;
00494 
00495   inline int team_size() const { return 1 ; }
00496   inline int league_size() const { return m_league_size ; }
00497 
00499   TeamPolicy( execution_space & , int league_size_request , int /* team_size_request */ )
00500     : m_league_size( league_size_request )
00501     { }
00502 
00503   TeamPolicy( int league_size_request , int /* team_size_request */ )
00504     : m_league_size( league_size_request )
00505     { }
00506 
00507   template< class FunctorType >
00508   static
00509   int team_size_max( const FunctorType & ) { return 1 ; }
00510 
00511   typedef Impl::SerialTeamMember  member_type ;
00512 };
00513 
00514 } /* namespace Kokkos */
00515 
00516 /*--------------------------------------------------------------------------*/
00517 /*--------------------------------------------------------------------------*/
00518 
00519 namespace Kokkos {
00520 
00521 template< unsigned int VectorLength , class Arg0 , class Arg1 >
00522 class TeamVectorPolicy< VectorLength , Arg0 , Arg1 , Kokkos::Serial >
00523 {
00524 private:
00525 
00526   const int m_league_size ;
00527 
00528 public:
00529 
00530   typedef Impl::ExecutionPolicyTag   kokkos_tag ;       
00531   typedef TeamVectorPolicy           execution_policy ; 
00532   typedef Kokkos::Serial             execution_space ;  
00533 
00534   typedef typename
00535     Impl::if_c< ! Impl::is_same< Kokkos::Serial , Arg0 >::value , Arg0 , Arg1 >::type
00536       work_tag ;
00537 
00538   inline int team_size() const { return 1 ; }
00539   inline int league_size() const { return m_league_size ; }
00540 
00542   TeamVectorPolicy( execution_space & , int league_size_request , int /* team_size_request */ )
00543     : m_league_size( league_size_request )
00544     { }
00545 
00546   TeamVectorPolicy( int league_size_request , int /* team_size_request */ )
00547     : m_league_size( league_size_request )
00548     { }
00549 
00550   template< class FunctorType >
00551   static
00552   int team_size_max( const FunctorType & ) { return 1 ; }
00553 
00554   typedef Impl::SerialTeamVectorMember<VectorLength>  member_type ;
00555 };
00556 
00557 } /* namespace Kokkos */
00558 
00559 /*--------------------------------------------------------------------------*/
00560 /*--------------------------------------------------------------------------*/
00561 
00562 namespace Kokkos {
00563 namespace Impl {
00564 
00565 template< class FunctorType , class Arg0 , class Arg1 , class Arg2 >
00566 class ParallelFor< FunctorType , Kokkos::RangePolicy< Arg0 , Arg1 , Arg2 , Kokkos::Serial > >
00567 {
00568 private:
00569 
00570   typedef Kokkos::RangePolicy< Arg0 , Arg1 , Arg2 , Kokkos::Serial > Policy ;
00571 
00572 public:
00573   // work tag is void
00574   template< class PType >
00575   inline
00576   ParallelFor( typename Impl::enable_if<
00577                  ( Impl::is_same< PType , Policy >::value &&
00578                    Impl::is_same< typename PType::work_tag , void >::value
00579                  ), const FunctorType & >::type functor
00580              , const PType & policy )
00581     {
00582       const typename PType::member_type e = policy.end();
00583       for ( typename PType::member_type i = policy.begin() ; i < e ; ++i ) {
00584         functor( i );
00585       }
00586     }
00587 
00588   // work tag is non-void
00589   template< class PType >
00590   inline
00591   ParallelFor( typename Impl::enable_if<
00592                  ( Impl::is_same< PType , Policy >::value &&
00593                    ! Impl::is_same< typename PType::work_tag , void >::value
00594                  ), const FunctorType & >::type functor
00595              , const PType & policy )
00596     {
00597       const typename PType::member_type e = policy.end();
00598       for ( typename PType::member_type i = policy.begin() ; i < e ; ++i ) {
00599         functor( typename PType::work_tag() , i );
00600       }
00601     }
00602 };
00603 
00604 template< class FunctorType , class Arg0 , class Arg1 , class Arg2 >
00605 class ParallelReduce< FunctorType , Kokkos::RangePolicy< Arg0 , Arg1 , Arg2 , Kokkos::Serial > >
00606 {
00607 public:
00608   typedef Kokkos::RangePolicy< Arg0 , Arg1 , Arg2 , Kokkos::Serial > Policy ;
00609 
00610   typedef ReduceAdapter< FunctorType >  Reduce ;
00611   typedef typename Reduce::pointer_type pointer_type ;
00612 
00613   // Work tag is void
00614   template< class ViewType , class PType >
00615   ParallelReduce( typename Impl::enable_if<
00616                     ( Impl::is_view< ViewType >::value &&
00617                       Impl::is_same< typename ViewType::memory_space , HostSpace >::value &&
00618                       Impl::is_same< PType , Policy >::value &&
00619                       Impl::is_same< typename PType::work_tag , void >::value
00620                     ), const FunctorType & >::type functor
00621                 , const PType     & policy
00622                 , const ViewType  & result
00623                 )
00624     {
00625       pointer_type result_ptr = result.ptr_on_device();
00626 
00627       if ( ! result_ptr ) {
00628         result_ptr = (pointer_type)
00629           Kokkos::Serial::scratch_memory_resize( Reduce::value_size( functor ) , 0 );
00630       }
00631 
00632       typename Reduce::reference_type update = Reduce::init( functor , result_ptr );
00633       
00634       const typename PType::member_type e = policy.end();
00635       for ( typename PType::member_type i = policy.begin() ; i < e ; ++i ) {
00636         functor( i , update );
00637       }
00638 
00639       Reduce::final( functor , result_ptr );
00640     }
00641 
00642   // Work tag is non-void
00643   template< class ViewType , class PType >
00644   ParallelReduce( typename Impl::enable_if<
00645                     ( Impl::is_view< ViewType >::value &&
00646                       Impl::is_same< typename ViewType::memory_space , HostSpace >::value &&
00647                       Impl::is_same< PType , Policy >::value &&
00648                       ! Impl::is_same< typename PType::work_tag , void >::value
00649                     ), const FunctorType & >::type functor
00650                 , const PType     & policy
00651                 , const ViewType  & result
00652                 )
00653     {
00654       pointer_type result_ptr = result.ptr_on_device();
00655 
00656       if ( ! result_ptr ) {
00657         result_ptr = (pointer_type)
00658           Kokkos::Serial::scratch_memory_resize( Reduce::value_size( functor ) , 0 );
00659       }
00660 
00661       typename Reduce::reference_type update = Reduce::init( functor , result_ptr );
00662       
00663       const typename PType::member_type e = policy.end();
00664       for ( typename PType::member_type i = policy.begin() ; i < e ; ++i ) {
00665         functor( typename PType::work_tag() , i , update );
00666       }
00667 
00668       Reduce::final( functor , result_ptr );
00669     }
00670 };
00671 
00672 template< class FunctorType , class Arg0 , class Arg1 , class Arg2 >
00673 class ParallelScan< FunctorType , Kokkos::RangePolicy< Arg0 , Arg1 , Arg2 , Kokkos::Serial > >
00674 {
00675 private:
00676 
00677   typedef Kokkos::RangePolicy< Arg0 , Arg1 , Arg2 , Kokkos::Serial > Policy ;
00678   typedef ReduceAdapter< FunctorType >  Reduce ;
00679 
00680 public:
00681 
00682   typedef typename Reduce::pointer_type pointer_type ;
00683 
00684   // work tag is void
00685   template< class PType >
00686   inline
00687   ParallelScan( typename Impl::enable_if<
00688                  ( Impl::is_same< PType , Policy >::value &&
00689                    Impl::is_same< typename PType::work_tag , void >::value
00690                  ), const FunctorType & >::type functor
00691              , const PType & policy )
00692     {
00693       pointer_type result_ptr = (pointer_type)
00694         Kokkos::Serial::scratch_memory_resize( Reduce::value_size( functor ) , 0 );
00695 
00696       typename Reduce::reference_type update = Reduce::init( functor , result_ptr );
00697       
00698       const typename PType::member_type e = policy.end();
00699       for ( typename PType::member_type i = policy.begin() ; i < e ; ++i ) {
00700         functor( i , update , true );
00701       }
00702 
00703       Reduce::final( functor , result_ptr );
00704     }
00705 
00706   // work tag is non-void
00707   template< class PType >
00708   inline
00709   ParallelScan( typename Impl::enable_if<
00710                  ( Impl::is_same< PType , Policy >::value &&
00711                    ! Impl::is_same< typename PType::work_tag , void >::value
00712                  ), const FunctorType & >::type functor
00713              , const PType & policy )
00714     {
00715       pointer_type result_ptr = (pointer_type)
00716         Kokkos::Serial::scratch_memory_resize( Reduce::value_size( functor ) , 0 );
00717 
00718       typename Reduce::reference_type update = Reduce::init( functor , result_ptr );
00719       
00720       const typename PType::member_type e = policy.end();
00721       for ( typename PType::member_type i = policy.begin() ; i < e ; ++i ) {
00722         functor( typename PType::work_tag() , i , update , true );
00723       }
00724 
00725       Reduce::final( functor , result_ptr );
00726     }
00727 };
00728 
00729 } // namespace Impl
00730 } // namespace Kokkos
00731 
00732 /*--------------------------------------------------------------------------*/
00733 /*--------------------------------------------------------------------------*/
00734 
00735 namespace Kokkos {
00736 namespace Impl {
00737 
00738 template< class FunctorType , class Arg0 , class Arg1 >
00739 class ParallelFor< FunctorType , Kokkos::TeamPolicy< Arg0 , Arg1 , Kokkos::Serial > >
00740 {
00741 private:
00742 
00743   typedef Kokkos::TeamPolicy< Arg0 , Arg1 , Kokkos::Serial > Policy ;
00744 
00745   template< class TagType >
00746   KOKKOS_FORCEINLINE_FUNCTION static
00747   void driver( typename Impl::enable_if< Impl::is_same< TagType , void >::value ,
00748                  const FunctorType & >::type functor
00749              , const typename Policy::member_type & member )
00750     { functor( member ); }
00751 
00752   template< class TagType >
00753   KOKKOS_FORCEINLINE_FUNCTION static
00754   void driver( typename Impl::enable_if< ! Impl::is_same< TagType , void >::value ,
00755                  const FunctorType & >::type functor
00756              , const typename Policy::member_type & member )
00757     { functor( TagType() , member ); }
00758 
00759 public:
00760 
00761   ParallelFor( const FunctorType & functor
00762              , const Policy      & policy )
00763     {
00764       const int shared_size = FunctorTeamShmemSize< FunctorType >::value( functor , policy.team_size() );
00765 
00766       Kokkos::Serial::scratch_memory_resize( 0 , shared_size );
00767 
00768       for ( int ileague = 0 ; ileague < policy.league_size() ; ++ileague ) {
00769         ParallelFor::template driver< typename Policy::work_tag >
00770           ( functor , typename Policy::member_type(ileague,policy.league_size(),shared_size) );
00771         // functor( typename Policy::member_type(ileague,policy.league_size(),shared_size) );
00772       }
00773     }
00774 };
00775 
00776 template< unsigned int VectorLength , class FunctorType , class Arg0 , class Arg1 >
00777 class ParallelFor< FunctorType , Kokkos::TeamVectorPolicy< VectorLength , Arg0 , Arg1 , Kokkos::Serial > >
00778 {
00779 private:
00780 
00781   typedef Kokkos::TeamVectorPolicy< VectorLength , Arg0 , Arg1 , Kokkos::Serial > Policy ;
00782 
00783   template< class TagType >
00784   KOKKOS_FORCEINLINE_FUNCTION static
00785   void driver( typename Impl::enable_if< Impl::is_same< TagType , void >::value ,
00786                  const FunctorType & >::type functor
00787              , const typename Policy::member_type & member )
00788     { functor( member ); }
00789 
00790   template< class TagType >
00791   KOKKOS_FORCEINLINE_FUNCTION static
00792   void driver( typename Impl::enable_if< ! Impl::is_same< TagType , void >::value ,
00793                  const FunctorType & >::type functor
00794              , const typename Policy::member_type & member )
00795     { functor( TagType() , member ); }
00796 
00797 public:
00798 
00799   ParallelFor( const FunctorType & functor
00800              , const Policy      & policy )
00801     {
00802       const int shared_size = FunctorTeamShmemSize< FunctorType >::value( functor , policy.team_size() );
00803 
00804       Kokkos::Serial::scratch_memory_resize( 0 , shared_size );
00805 
00806       for ( int ileague = 0 ; ileague < policy.league_size() ; ++ileague ) {
00807         ParallelFor::template driver< typename Policy::work_tag >
00808           ( functor , typename Policy::member_type(ileague,policy.league_size(),shared_size) );
00809         // functor( typename Policy::member_type(ileague,policy.league_size(),shared_size) );
00810       }
00811     }
00812 };
00813 
00814 template< class FunctorType , class Arg0 , class Arg1 >
00815 class ParallelReduce< FunctorType , Kokkos::TeamPolicy< Arg0 , Arg1 , Kokkos::Serial > > 
00816 {
00817 private:
00818 
00819   typedef Kokkos::TeamPolicy< Arg0 , Arg1 , Kokkos::Serial > Policy ;
00820   typedef ReduceAdapter< FunctorType >  Reduce ;
00821 
00822   template< class TagType >
00823   KOKKOS_FORCEINLINE_FUNCTION static
00824   void driver( typename Impl::enable_if< Impl::is_same< TagType , void >::value ,
00825                  const FunctorType & >::type functor
00826              , const typename Policy::member_type  & member
00827              ,       typename Reduce::reference_type update )
00828     { functor( member , update ); }
00829 
00830   template< class TagType >
00831   KOKKOS_FORCEINLINE_FUNCTION static
00832   void driver( typename Impl::enable_if< ! Impl::is_same< TagType , void >::value ,
00833                  const FunctorType & >::type functor
00834              , const typename Policy::member_type  & member 
00835              ,       typename Reduce::reference_type update )
00836     { functor( TagType() , member , update ); }
00837 
00838 public:
00839 
00840   typedef typename Reduce::pointer_type pointer_type ;
00841 
00842   template< class ViewType >
00843   ParallelReduce( const FunctorType  & functor
00844                 , const Policy       & policy
00845                 , const ViewType     & result
00846                 )
00847     {
00848       const int reduce_size = Reduce::value_size( functor );
00849       const int shared_size = FunctorTeamShmemSize< FunctorType >::value( functor , policy.team_size() );
00850       void * const scratch_reduce = Kokkos::Serial::scratch_memory_resize( reduce_size , shared_size );
00851 
00852       const pointer_type result_ptr =
00853         result.ptr_on_device() ? result.ptr_on_device() 
00854                                : (pointer_type) scratch_reduce ;
00855 
00856       typename Reduce::reference_type update = Reduce::init( functor , result_ptr );
00857       
00858       for ( int ileague = 0 ; ileague < policy.league_size() ; ++ileague ) {
00859         ParallelReduce::template driver< typename Policy::work_tag >
00860           ( functor , typename Policy::member_type(ileague,policy.league_size(),shared_size) , update );
00861       }
00862 
00863       Reduce::final( functor , result_ptr );
00864     }
00865 };
00866 
00867 } // namespace Impl
00868 } // namespace Kokkos
00869 
00870 #endif /* #define KOKKOS_SERIAL_HPP */
00871 
00872 //----------------------------------------------------------------------------
00873 //----------------------------------------------------------------------------
00874 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends