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_Macros.hpp>
48 #if defined( KOKKOS_ENABLE_OPENMP)
49 
50 #if !defined(_OPENMP)
51 #error "You enabled Kokkos OpenMP support without enabling OpenMP in the compiler!"
52 #endif
53 
54 #include <Kokkos_Core_fwd.hpp>
55 
56 #include <cstddef>
57 #include <iosfwd>
58 #include <Kokkos_HostSpace.hpp>
59 
60 #ifdef KOKKOS_ENABLE_HBWSPACE
61 #include <Kokkos_HBWSpace.hpp>
62 #endif
63 
64 #include <Kokkos_ScratchSpace.hpp>
65 #include <Kokkos_Parallel.hpp>
66 #include <Kokkos_TaskScheduler.hpp>
67 #include <Kokkos_Layout.hpp>
68 #include <impl/Kokkos_Tags.hpp>
69 
70 /*--------------------------------------------------------------------------*/
71 
72 namespace Kokkos {
73 
76 class OpenMP {
77 public:
78  //------------------------------------
80 
81 
83  using execution_space = OpenMP;
84  #ifdef KOKKOS_ENABLE_HBWSPACE
85  using memory_space = Experimental::HBWSpace;
86  #else
87  using memory_space = HostSpace;
88  #endif
91 
92  using array_layout = LayoutRight;
93  using size_type = memory_space::size_type;
94 
95  using scratch_memory_space = ScratchMemorySpace< OpenMP >;
96 
98  //------------------------------------
100 
101 
102  inline static bool in_parallel();
103 
105  static bool sleep();
106 
108  static bool wake();
109 
111  static void fence() {}
112 
114  static void print_configuration( std::ostream & , const bool detail = false );
115 
117  static void finalize();
118 
128  static void initialize( unsigned thread_count = 0 ,
129  unsigned use_numa_count = 0 ,
130  unsigned use_cores_per_numa = 0 );
131 
132  static int is_initialized();
133 
135  static int concurrency();
136 
138  //------------------------------------
146  inline static int thread_pool_size( int depth = 0 );
147 
149  KOKKOS_INLINE_FUNCTION static int thread_pool_rank();
150 
151  //------------------------------------
152 
153  inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
154 
155  KOKKOS_INLINE_FUNCTION static
156  unsigned hardware_thread_id() { return thread_pool_rank(); }
157 
158  static const char* name();
159 };
160 
161 } // namespace Kokkos
162 
163 /*--------------------------------------------------------------------------*/
164 /*--------------------------------------------------------------------------*/
165 
166 namespace Kokkos {
167 namespace Impl {
168 
169 template<>
170 struct MemorySpaceAccess
171  < Kokkos::OpenMP::memory_space
172  , Kokkos::OpenMP::scratch_memory_space
173  >
174 {
175  enum { assignable = false };
176  enum { accessible = true };
177  enum { deepcopy = false };
178 };
179 
180 template<>
181 struct VerifyExecutionCanAccessMemorySpace
182  < Kokkos::OpenMP::memory_space
183  , Kokkos::OpenMP::scratch_memory_space
184  >
185 {
186  enum { value = true };
187  inline static void verify( void ) { }
188  inline static void verify( const void * ) { }
189 };
190 
191 } // namespace Impl
192 } // namespace Kokkos
193 
194 /*--------------------------------------------------------------------------*/
195 /*--------------------------------------------------------------------------*/
196 
197 #include <OpenMP/Kokkos_OpenMP_Exec.hpp>
198 #include <OpenMP/Kokkos_OpenMP_Parallel.hpp>
199 #include <OpenMP/Kokkos_OpenMP_Task.hpp>
200 
201 #include <KokkosExp_MDRangePolicy.hpp>
202 /*--------------------------------------------------------------------------*/
203 
204 #endif /* #if defined( KOKKOS_ENABLE_OPENMP ) && defined( _OPENMP ) */
205 #endif /* #ifndef KOKKOS_OPENMP_HPP */
206 
void print_configuration(std::ostream &, const bool detail=false)
Print "Bill of Materials".
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.