Kokkos Core Kernels Package  Version of the Day
Kokkos_Threads.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_THREADS_HPP
45 #define KOKKOS_THREADS_HPP
46 
47 #include <Kokkos_Core_fwd.hpp>
48 
49 #if defined( KOKKOS_HAVE_PTHREAD )
50 
51 #include <cstddef>
52 #include <iosfwd>
53 #include <Kokkos_HostSpace.hpp>
54 #include <Kokkos_ScratchSpace.hpp>
55 #include <Kokkos_Layout.hpp>
56 #include <Kokkos_MemoryTraits.hpp>
57 #include <impl/Kokkos_Tags.hpp>
58 
59 /*--------------------------------------------------------------------------*/
60 
61 namespace Kokkos {
62 namespace Impl {
63 class ThreadsExec ;
64 } // namespace Impl
65 } // namespace Kokkos
66 
67 /*--------------------------------------------------------------------------*/
68 
69 namespace Kokkos {
70 
72 class Threads {
73 public:
75 
76  typedef Threads execution_space ;
78  typedef Kokkos::HostSpace memory_space ;
79 
82 
83  typedef Kokkos::LayoutRight array_layout ;
84  typedef memory_space::size_type size_type ;
85 
86  typedef ScratchMemorySpace< Threads > scratch_memory_space ;
87 
88 
90  /*------------------------------------------------------------------------*/
92 
93 
96  static int in_parallel();
97 
109  static bool sleep();
110 
116  static bool wake();
117 
124  static void fence();
125 
129  static void finalize();
130 
132  static void print_configuration( std::ostream & , const bool detail = false );
133 
135  /*------------------------------------------------------------------------*/
136  /*------------------------------------------------------------------------*/
138 
139 
157  static void initialize( unsigned threads_count = 0 ,
158  unsigned use_numa_count = 0 ,
159  unsigned use_cores_per_numa = 0 ,
160  bool allow_asynchronous_threadpool = false );
161 
162  static int is_initialized();
163 
165  static int concurrency();
166 
167  static Threads & instance( int = 0 );
168 
169  //----------------------------------------
170 
171  static int thread_pool_size( int depth = 0 );
172 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
173  static int thread_pool_rank();
174 #else
175  KOKKOS_INLINE_FUNCTION static int thread_pool_rank() { return 0 ; }
176 #endif
177 
178  inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
179  KOKKOS_INLINE_FUNCTION static unsigned hardware_thread_id() { return thread_pool_rank(); }
180 
182  //----------------------------------------
183 };
184 
185 } // namespace Kokkos
186 
187 /*--------------------------------------------------------------------------*/
188 
189 namespace Kokkos {
190 namespace Impl {
191 
192 template<>
193 struct VerifyExecutionCanAccessMemorySpace
194  < Kokkos::Threads::memory_space
195  , Kokkos::Threads::scratch_memory_space
196  >
197 {
198  enum { value = true };
199  inline static void verify( void ) { }
200  inline static void verify( const void * ) { }
201 };
202 
203 } // namespace Impl
204 } // namespace Kokkos
205 
206 /*--------------------------------------------------------------------------*/
207 
208 #include <Kokkos_ExecPolicy.hpp>
209 #include <Kokkos_Parallel.hpp>
210 #include <Threads/Kokkos_ThreadsExec.hpp>
211 #include <Threads/Kokkos_ThreadsTeam.hpp>
212 #include <Threads/Kokkos_Threads_Parallel.hpp>
213 
214 #include <KokkosExp_MDRangePolicy.hpp>
215 
216 //----------------------------------------------------------------------------
217 //----------------------------------------------------------------------------
218 
219 #endif /* #if defined( KOKKOS_HAVE_PTHREAD ) */
220 #endif /* #define KOKKOS_THREADS_HPP */
221 
222 
Memory space for main process and CPU execution spaces.
Memory management for host memory.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.