~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to lib/kokkos/core/src/Kokkos_OpenMP.hpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
//@HEADER
 
3
// ************************************************************************
 
4
//
 
5
//                             Kokkos
 
6
//         Manycore Performance-Portable Multidimensional Arrays
 
7
//
 
8
//              Copyright (2012) Sandia Corporation
 
9
//
 
10
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
 
11
// the U.S. Government retains certain rights in this software.
 
12
//
 
13
// Redistribution and use in source and binary forms, with or without
 
14
// modification, are permitted provided that the following conditions are
 
15
// met:
 
16
//
 
17
// 1. Redistributions of source code must retain the above copyright
 
18
// notice, this list of conditions and the following disclaimer.
 
19
//
 
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.
 
23
//
 
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.
 
27
//
 
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.
 
39
//
 
40
// Questions?  Contact  H. Carter Edwards (hcedwar@sandia.gov)
 
41
//
 
42
// ************************************************************************
 
43
//@HEADER
 
44
*/
 
45
 
 
46
#ifndef KOKKOS_OPENMP_HPP
 
47
#define KOKKOS_OPENMP_HPP
 
48
 
 
49
#include <Kokkos_Core_fwd.hpp>
 
50
 
 
51
#if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP )
 
52
 
 
53
#include <omp.h>
 
54
 
 
55
#include <cstddef>
 
56
#include <iosfwd>
 
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>
 
62
 
 
63
/*--------------------------------------------------------------------------*/
 
64
 
 
65
namespace Kokkos {
 
66
 
 
67
/// \class OpenMP
 
68
/// \brief Kokkos device for multicore processors in the host memory space.
 
69
class OpenMP {
 
70
public:
 
71
  //------------------------------------
 
72
  //! \name Type declarations that all Kokkos devices must provide.
 
73
  //@{
 
74
 
 
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 ;
 
80
 
 
81
  typedef ScratchMemorySpace< OpenMP > scratch_memory_space ;
 
82
 
 
83
  //! For backward compatibility
 
84
  typedef OpenMP                device_type ;
 
85
  //@}
 
86
  //------------------------------------
 
87
  //! \name Functions that all Kokkos devices must implement.
 
88
  //@{
 
89
 
 
90
  inline static bool in_parallel() { return omp_in_parallel(); }
 
91
 
 
92
  /** \brief  Set the device in a "sleep" state. A noop for OpenMP.  */
 
93
  static bool sleep();
 
94
 
 
95
  /** \brief Wake the device from the 'sleep' state. A noop for OpenMP. */
 
96
  static bool wake();
 
97
 
 
98
  /** \brief Wait until all dispatched functors complete. A noop for OpenMP. */
 
99
  static void fence() {}
 
100
 
 
101
  /// \brief Print configuration information to the given output stream.
 
102
  static void print_configuration( std::ostream & , const bool detail = false );
 
103
 
 
104
  /// \brief Free any resources being consumed by the device.
 
105
  static void finalize();
 
106
 
 
107
  /** \brief  Initialize the device.
 
108
   *
 
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.
 
112
   *
 
113
   *  2) Allocate a HostThread for each OpenMP thread to hold its
 
114
   *     topology and fan in/out data.
 
115
   */
 
116
  static void initialize( unsigned thread_count = 0 ,
 
117
                          unsigned use_numa_count = 0 ,
 
118
                          unsigned use_cores_per_numa = 0 );
 
119
 
 
120
  static int is_initialized();
 
121
  //@}
 
122
  //------------------------------------
 
123
  /** \brief  This execution space has a topological thread pool which can be queried.
 
124
   *
 
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.
 
129
   */
 
130
  inline static int thread_pool_size( int depth = 0 );
 
131
 
 
132
  /** \brief  The rank of the executing thread in this thread pool */
 
133
  KOKKOS_INLINE_FUNCTION static int thread_pool_rank();
 
134
 
 
135
  //------------------------------------
 
136
 
 
137
  inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
 
138
 
 
139
  KOKKOS_INLINE_FUNCTION static
 
140
  unsigned hardware_thread_id() { return thread_pool_rank(); }
 
141
};
 
142
 
 
143
} // namespace Kokkos
 
144
 
 
145
/*--------------------------------------------------------------------------*/
 
146
/*--------------------------------------------------------------------------*/
 
147
 
 
148
namespace Kokkos {
 
149
namespace Impl {
 
150
 
 
151
template<>
 
152
struct VerifyExecutionCanAccessMemorySpace
 
153
  < Kokkos::OpenMP::memory_space
 
154
  , Kokkos::OpenMP::scratch_memory_space
 
155
  >
 
156
{
 
157
  enum { value = true };
 
158
  inline static void verify( void ) { }
 
159
  inline static void verify( const void * ) { }
 
160
};
 
161
 
 
162
} // namespace Impl
 
163
} // namespace Kokkos
 
164
 
 
165
/*--------------------------------------------------------------------------*/
 
166
/*--------------------------------------------------------------------------*/
 
167
 
 
168
#include <OpenMP/Kokkos_OpenMPexec.hpp>
 
169
#include <OpenMP/Kokkos_OpenMP_Parallel.hpp>
 
170
 
 
171
/*--------------------------------------------------------------------------*/
 
172
 
 
173
#endif /* #if defined( KOKKOS_HAVE_OPENMP ) && defined( _OPENMP ) */
 
174
#endif /* #ifndef KOKKOS_OPENMP_HPP */
 
175
 
 
176