Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Kokkos_OpenMP.hpp
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //                             Kokkos
00006 //         Manycore Performance-Portable Multidimensional Arrays
00007 //
00008 //              Copyright (2012) Sandia Corporation
00009 //
00010 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00011 // the U.S. Government retains certain rights in this software.
00012 //
00013 // Redistribution and use in source and binary forms, with or without
00014 // modification, are permitted provided that the following conditions are
00015 // met:
00016 //
00017 // 1. Redistributions of source code must retain the above copyright
00018 // notice, this list of conditions and the following disclaimer.
00019 //
00020 // 2. Redistributions in binary form must reproduce the above copyright
00021 // notice, this list of conditions and the following disclaimer in the
00022 // documentation and/or other materials provided with the distribution.
00023 //
00024 // 3. Neither the name of the Corporation nor the names of the
00025 // contributors may be used to endorse or promote products derived from
00026 // this software without specific prior written permission.
00027 //
00028 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00029 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00031 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00032 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00033 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00034 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00035 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00036 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00037 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 //
00040 // Questions?  Contact  H. Carter Edwards (hcedwar@sandia.gov)
00041 //
00042 // ************************************************************************
00043 //@HEADER
00044 */
00045 
00046 #ifndef KOKKOS_OPENMP_HPP
00047 #define KOKKOS_OPENMP_HPP
00048 
00049 #include <Kokkos_Core_fwd.hpp>
00050 
00051 #if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP )
00052 
00053 #include <omp.h>
00054 
00055 #include <cstddef>
00056 #include <iosfwd>
00057 #include <Kokkos_HostSpace.hpp>
00058 #include <Kokkos_ScratchSpace.hpp>
00059 #include <Kokkos_Parallel.hpp>
00060 #include <Kokkos_Layout.hpp>
00061 #include <impl/Kokkos_Tags.hpp>
00062 
00063 /*--------------------------------------------------------------------------*/
00064 
00065 namespace Kokkos {
00066 
00069 class OpenMP {
00070 public:
00071   //------------------------------------
00073 
00074 
00076   typedef Impl::ExecutionSpaceTag  kokkos_tag ;
00077   typedef OpenMP                device_type ;
00078   typedef OpenMP                execution_space ;
00079   typedef HostSpace::size_type  size_type ;
00080   typedef HostSpace             memory_space ;
00081   typedef LayoutRight           array_layout ;
00082   typedef OpenMP                host_mirror_device_type ;
00083 
00084   typedef ScratchMemorySpace< OpenMP > scratch_memory_space ;
00085 
00087   //------------------------------------
00089 
00090 
00091   inline static bool in_parallel() { return omp_in_parallel(); }
00092 
00094   static bool sleep();
00095 
00097   static bool wake();
00098 
00100   static void fence() {}
00101 
00103   static void print_configuration( std::ostream & , const bool detail = false );
00104 
00106   static void finalize();
00107 
00117   static void initialize( unsigned thread_count = 0 ,
00118                           unsigned use_numa_count = 0 ,
00119                           unsigned use_cores_per_numa = 0 );
00120 
00121   static int is_initialized();
00123   //------------------------------------
00131   inline static int thread_pool_size( int depth = 0 );
00132 
00134   KOKKOS_INLINE_FUNCTION static int thread_pool_rank();
00135 
00136   //------------------------------------
00137 
00138   inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
00139   inline static unsigned team_max()             { return thread_pool_size(1); }
00140   inline static unsigned team_recommended()     { return thread_pool_size(2); }
00141 
00142   KOKKOS_INLINE_FUNCTION static
00143   unsigned hardware_thread_id() { return thread_pool_rank(); }
00144 };
00145 
00146 } // namespace Kokkos
00147 
00148 /*--------------------------------------------------------------------------*/
00149 /*--------------------------------------------------------------------------*/
00150 
00151 namespace Kokkos {
00152 namespace Impl {
00153 
00154 template<>
00155 struct VerifyExecutionCanAccessMemorySpace
00156   < Kokkos::OpenMP::memory_space
00157   , Kokkos::OpenMP::scratch_memory_space
00158   >
00159 {
00160   inline static void verify( void ) { }
00161   inline static void verify( const void * ) { }
00162 };
00163 
00164 } // namespace Impl
00165 } // namespace Kokkos
00166 
00167 /*--------------------------------------------------------------------------*/
00168 /*--------------------------------------------------------------------------*/
00169 
00170 #include <OpenMP/Kokkos_OpenMPexec.hpp>
00171 #include <OpenMP/Kokkos_OpenMP_Parallel.hpp>
00172 
00173 /*--------------------------------------------------------------------------*/
00174 
00175 #endif /* #if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP ) */
00176 #endif /* #ifndef KOKKOS_OPENMP_HPP */
00177 
00178 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends