3
// ************************************************************************
6
// Manycore Performance-Portable Multidimensional Arrays
8
// Copyright (2012) Sandia Corporation
10
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
11
// the U.S. Government retains certain rights in this software.
13
// Redistribution and use in source and binary forms, with or without
14
// modification, are permitted provided that the following conditions are
17
// 1. Redistributions of source code must retain the above copyright
18
// notice, this list of conditions and the following disclaimer.
20
// 2. Redistributions in binary form must reproduce the above copyright
21
// notice, this list of conditions and the following disclaimer in the
22
// documentation and/or other materials provided with the distribution.
24
// 3. Neither the name of the Corporation nor the names of the
25
// contributors may be used to endorse or promote products derived from
26
// this software without specific prior written permission.
28
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
29
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
35
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
36
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
42
// ************************************************************************
46
#ifndef KOKKOS_OPENMP_HPP
47
#define KOKKOS_OPENMP_HPP
49
#include <Kokkos_Core_fwd.hpp>
51
#if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP )
57
#include <Kokkos_HostSpace.hpp>
58
#include <Kokkos_ScratchSpace.hpp>
59
#include <Kokkos_Parallel.hpp>
60
#include <Kokkos_Layout.hpp>
61
#include <impl/Kokkos_Tags.hpp>
63
/*--------------------------------------------------------------------------*/
68
/// \brief Kokkos device for multicore processors in the host memory space.
71
//------------------------------------
72
//! \name Type declarations that all Kokkos devices must provide.
75
//! Tag this class as a kokkos execution space
76
typedef OpenMP execution_space ;
77
typedef HostSpace memory_space ;
78
typedef LayoutRight array_layout ;
79
typedef HostSpace::size_type size_type ;
81
typedef ScratchMemorySpace< OpenMP > scratch_memory_space ;
83
//! For backward compatibility
84
typedef OpenMP device_type ;
86
//------------------------------------
87
//! \name Functions that all Kokkos devices must implement.
90
inline static bool in_parallel() { return omp_in_parallel(); }
92
/** \brief Set the device in a "sleep" state. A noop for OpenMP. */
95
/** \brief Wake the device from the 'sleep' state. A noop for OpenMP. */
98
/** \brief Wait until all dispatched functors complete. A noop for OpenMP. */
99
static void fence() {}
101
/// \brief Print configuration information to the given output stream.
102
static void print_configuration( std::ostream & , const bool detail = false );
104
/// \brief Free any resources being consumed by the device.
105
static void finalize();
107
/** \brief Initialize the device.
109
* 1) If the hardware locality library is enabled and OpenMP has not
110
* already bound threads then bind OpenMP threads to maximize
111
* core utilization and group for memory hierarchy locality.
113
* 2) Allocate a HostThread for each OpenMP thread to hold its
114
* topology and fan in/out data.
116
static void initialize( unsigned thread_count = 0 ,
117
unsigned use_numa_count = 0 ,
118
unsigned use_cores_per_numa = 0 );
120
static int is_initialized();
122
//------------------------------------
123
/** \brief This execution space has a topological thread pool which can be queried.
125
* All threads within a pool have a common memory space for which they are cache coherent.
126
* depth = 0 gives the number of threads in the whole pool.
127
* depth = 1 gives the number of threads in a NUMA region, typically sharing L3 cache.
128
* depth = 2 gives the number of threads at the finest granularity, typically sharing L1 cache.
130
inline static int thread_pool_size( int depth = 0 );
132
/** \brief The rank of the executing thread in this thread pool */
133
KOKKOS_INLINE_FUNCTION static int thread_pool_rank();
135
//------------------------------------
137
inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
139
KOKKOS_INLINE_FUNCTION static
140
unsigned hardware_thread_id() { return thread_pool_rank(); }
143
} // namespace Kokkos
145
/*--------------------------------------------------------------------------*/
146
/*--------------------------------------------------------------------------*/
152
struct VerifyExecutionCanAccessMemorySpace
153
< Kokkos::OpenMP::memory_space
154
, Kokkos::OpenMP::scratch_memory_space
157
enum { value = true };
158
inline static void verify( void ) { }
159
inline static void verify( const void * ) { }
163
} // namespace Kokkos
165
/*--------------------------------------------------------------------------*/
166
/*--------------------------------------------------------------------------*/
168
#include <OpenMP/Kokkos_OpenMPexec.hpp>
169
#include <OpenMP/Kokkos_OpenMP_Parallel.hpp>
171
/*--------------------------------------------------------------------------*/
173
#endif /* #if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP ) */
174
#endif /* #ifndef KOKKOS_OPENMP_HPP */