Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_Qthreads.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 Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_QTHREADS_HPP
45 #define KOKKOS_QTHREADS_HPP
46 
47 #include <Kokkos_Macros.hpp>
48 #if defined( KOKKOS_ENABLE_QTHREADS )
49 
50 #include <Kokkos_Core_fwd.hpp>
51 
52 // Defines to enable experimental Qthreads functionality.
53 #define QTHREAD_LOCAL_PRIORITY
54 #define CLONED_TASKS
55 
56 #include <qthread.h>
57 
58 #include <cstddef>
59 #include <iosfwd>
60 
61 #include <Kokkos_HostSpace.hpp>
62 #include <Kokkos_ScratchSpace.hpp>
63 #include <Kokkos_Parallel.hpp>
64 //#include <Kokkos_MemoryTraits.hpp>
65 //#include <Kokkos_ExecPolicy.hpp>
66 //#include <Kokkos_TaskScheduler.hpp> // Uncomment when Tasking working.
67 #include <Kokkos_Layout.hpp>
68 #include <impl/Kokkos_Tags.hpp>
69 #include <KokkosExp_MDRangePolicy.hpp>
70 
71 /*--------------------------------------------------------------------------*/
72 
73 namespace Kokkos {
74 
75 namespace Impl {
76 
77 class QthreadsExec;
78 
79 } // namespace Impl
80 
81 } // namespace Kokkos
82 
83 /*--------------------------------------------------------------------------*/
84 
85 namespace Kokkos {
86 
88 class Qthreads {
89 public:
91 
92 
94  typedef Qthreads execution_space;
95  typedef Kokkos::HostSpace memory_space;
97  typedef Kokkos::Device< execution_space, memory_space > device_type;
98 
99  typedef Kokkos::LayoutRight array_layout;
100  typedef memory_space::size_type size_type;
101 
102  typedef ScratchMemorySpace< Qthreads > scratch_memory_space;
103 
105  /*------------------------------------------------------------------------*/
106 
108  static Qthreads & instance( int = 0 );
109 
119  bool sleep();
120 
126  static bool wake();
127 
135  static void fence();
136 
137  /*------------------------------------------------------------------------*/
138 
139  static int in_parallel();
140 
141  static int is_initialized();
142 
144  static int concurrency();
145 
146  static void initialize( int thread_count );
147  static void finalize();
148 
150  static void print_configuration( std::ostream &, const bool detail = false );
151 
152  int shepherd_size() const;
153  int shepherd_worker_size() const;
154 
155  static const char* name();
156 };
157 
158 } // namespace Kokkos
159 
160 /*--------------------------------------------------------------------------*/
161 
162 namespace Kokkos {
163 
164 namespace Impl {
165 
166 template<>
167 struct MemorySpaceAccess
168  < Kokkos::Qthreads::memory_space
169  , Kokkos::Qthreads::scratch_memory_space
170  >
171 {
172  enum { assignable = false };
173  enum { accessible = true };
174  enum { deepcopy = false };
175 };
176 
177 template<>
178 struct VerifyExecutionCanAccessMemorySpace
179  < Kokkos::Qthreads::memory_space
180  , Kokkos::Qthreads::scratch_memory_space
181  >
182 {
183  enum { value = true };
184  inline static void verify( void ) {}
185  inline static void verify( const void * ) {}
186 };
187 
188 } // namespace Impl
189 
190 } // namespace Kokkos
191 
192 /*--------------------------------------------------------------------------*/
193 
194 #include <Qthreads/Kokkos_QthreadsExec.hpp>
195 #include <Qthreads/Kokkos_Qthreads_Parallel.hpp>
196 //#include <Qthreads/Kokkos_Qthreads_Task.hpp> // Uncomment when Tasking working.
197 //#include <Qthreads/Kokkos_Qthreads_TaskQueue.hpp> // Uncomment when Tasking working.
198 
199 #endif // #define KOKKOS_ENABLE_QTHREADS
200 #endif // #define KOKKOS_QTHREADS_HPP
201 
void print_configuration(std::ostream &, const bool detail=false)
Print &quot;Bill of Materials&quot;.
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.