Kokkos Core Kernels Package  Version of the Day
Kokkos_OpenMP.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_OPENMP_HPP
45 #define KOKKOS_OPENMP_HPP
46 
47 #include <Kokkos_Core_fwd.hpp>
48 
49 #if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP )
50 
51 #include <omp.h>
52 
53 #include <cstddef>
54 #include <iosfwd>
55 #include <Kokkos_HostSpace.hpp>
56 #ifdef KOKKOS_HAVE_HBWSPACE
57 #include <Kokkos_HBWSpace.hpp>
58 #endif
59 #include <Kokkos_ScratchSpace.hpp>
60 #include <Kokkos_Parallel.hpp>
61 #include <Kokkos_TaskScheduler.hpp>
62 #include <Kokkos_Layout.hpp>
63 #include <impl/Kokkos_Tags.hpp>
64 
65 #include <KokkosExp_MDRangePolicy.hpp>
66 /*--------------------------------------------------------------------------*/
67 
68 namespace Kokkos {
69 
72 class OpenMP {
73 public:
74  //------------------------------------
76 
77 
79  typedef OpenMP execution_space ;
80  #ifdef KOKKOS_HAVE_HBWSPACE
81  typedef Experimental::HBWSpace memory_space ;
82  #else
83  typedef HostSpace memory_space ;
84  #endif
87 
88  typedef LayoutRight array_layout ;
89  typedef memory_space::size_type size_type ;
90 
91  typedef ScratchMemorySpace< OpenMP > scratch_memory_space ;
92 
94  //------------------------------------
96 
97 
98  inline static bool in_parallel() { return omp_in_parallel(); }
99 
101  static bool sleep();
102 
104  static bool wake();
105 
107  static void fence() {}
108 
110  static void print_configuration( std::ostream & , const bool detail = false );
111 
113  static void finalize();
114 
124  static void initialize( unsigned thread_count = 0 ,
125  unsigned use_numa_count = 0 ,
126  unsigned use_cores_per_numa = 0 );
127 
128  static int is_initialized();
129 
131  static int concurrency();
132 
134  //------------------------------------
142  inline static int thread_pool_size( int depth = 0 );
143 
145  KOKKOS_INLINE_FUNCTION static int thread_pool_rank();
146 
147  //------------------------------------
148 
149  inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
150 
151  KOKKOS_INLINE_FUNCTION static
152  unsigned hardware_thread_id() { return thread_pool_rank(); }
153 };
154 
155 } // namespace Kokkos
156 
157 /*--------------------------------------------------------------------------*/
158 /*--------------------------------------------------------------------------*/
159 
160 namespace Kokkos {
161 namespace Impl {
162 
163 template<>
164 struct VerifyExecutionCanAccessMemorySpace
165  < Kokkos::OpenMP::memory_space
166  , Kokkos::OpenMP::scratch_memory_space
167  >
168 {
169  enum { value = true };
170  inline static void verify( void ) { }
171  inline static void verify( const void * ) { }
172 };
173 
174 } // namespace Impl
175 } // namespace Kokkos
176 
177 /*--------------------------------------------------------------------------*/
178 /*--------------------------------------------------------------------------*/
179 
180 #include <OpenMP/Kokkos_OpenMPexec.hpp>
181 #include <OpenMP/Kokkos_OpenMP_Parallel.hpp>
182 #include <OpenMP/Kokkos_OpenMP_Task.hpp>
183 
184 /*--------------------------------------------------------------------------*/
185 
186 #endif /* #if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP ) */
187 #endif /* #ifndef KOKKOS_OPENMP_HPP */
188 
189 
Memory space for main process and CPU execution spaces.
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.