Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
Kokkos_OpenMP.hpp
1//@HEADER
2// ************************************************************************
3//
4// Kokkos v. 4.0
5// Copyright (2022) National Technology & Engineering
6// Solutions of Sandia, LLC (NTESS).
7//
8// Under the terms of Contract DE-NA0003525 with NTESS,
9// the U.S. Government retains certain rights in this software.
10//
11// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12// See https://kokkos.org/LICENSE for license information.
13// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14//
15//@HEADER
16
17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
19static_assert(false,
20 "Including non-public Kokkos header files is not allowed.");
21#endif
22#ifndef KOKKOS_OPENMP_HPP
23#define KOKKOS_OPENMP_HPP
24
25#include <Kokkos_Macros.hpp>
26#if defined(KOKKOS_ENABLE_OPENMP)
27
28#include <Kokkos_Core_fwd.hpp>
29
30#include <cstddef>
31#include <iosfwd>
32#include <Kokkos_HostSpace.hpp>
33
34#ifdef KOKKOS_ENABLE_HBWSPACE
35#include <Kokkos_HBWSpace.hpp>
36#endif
37
38#include <Kokkos_ScratchSpace.hpp>
39#include <Kokkos_Parallel.hpp>
40#include <Kokkos_TaskScheduler.hpp>
41#include <Kokkos_Layout.hpp>
42#include <impl/Kokkos_HostSharedPtr.hpp>
43#include <impl/Kokkos_Profiling_Interface.hpp>
44#include <impl/Kokkos_InitializationSettings.hpp>
45
46#include <vector>
47
48/*--------------------------------------------------------------------------*/
49
50namespace Kokkos {
51
52namespace Impl {
53class OpenMPInternal;
54}
55
58class OpenMP {
59 public:
61 using execution_space = OpenMP;
62
63 using memory_space =
64#ifdef KOKKOS_ENABLE_HBWSPACE
65 Experimental::HBWSpace;
66#else
67 HostSpace;
68#endif
69
71 using device_type = Kokkos::Device<execution_space, memory_space>;
72 using array_layout = LayoutRight;
73 using size_type = memory_space::size_type;
74 using scratch_memory_space = ScratchMemorySpace<OpenMP>;
75
76 OpenMP();
77
78 OpenMP(int pool_size);
79
81 void print_configuration(std::ostream& os, bool verbose = false) const;
82
84 inline static bool in_parallel(OpenMP const& = OpenMP()) noexcept;
85
89 static void impl_static_fence(std::string const& name);
90
91 void fence(std::string const& name =
92 "Kokkos::OpenMP::fence: Unnamed Instance Fence") const;
93
98 inline static bool is_asynchronous(OpenMP const& = OpenMP()) noexcept;
99
100#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
106 template <typename F>
107 KOKKOS_DEPRECATED static void partition_master(
108 F const& f, int requested_num_partitions = 0,
109 int requested_partition_size = 0);
110#endif
111
112 static int concurrency(OpenMP const& = OpenMP());
113
114 static void impl_initialize(InitializationSettings const&);
115
118 static bool impl_is_initialized() noexcept;
119
121 static void impl_finalize();
122
123 inline static int impl_thread_pool_size(OpenMP const& = OpenMP()) noexcept;
124
126 inline static int impl_thread_pool_rank() noexcept;
127
128 inline static int impl_thread_pool_size(int depth, OpenMP const& = OpenMP());
129
130 // use UniqueToken
131 inline static int impl_max_hardware_threads() noexcept;
132
133 // use UniqueToken
134 KOKKOS_INLINE_FUNCTION
135 static int impl_hardware_thread_id() noexcept;
136
137 static int impl_get_current_max_threads() noexcept;
138
139 Impl::OpenMPInternal* impl_internal_space_instance() const {
140 return m_space_instance.get();
141 }
142
143 static constexpr const char* name() noexcept { return "OpenMP"; }
144 uint32_t impl_instance_id() const noexcept { return 1; }
145
146 private:
147 friend bool operator==(OpenMP const& lhs, OpenMP const& rhs) {
148 return lhs.impl_internal_space_instance() ==
149 rhs.impl_internal_space_instance();
150 }
151 friend bool operator!=(OpenMP const& lhs, OpenMP const& rhs) {
152 return !(lhs == rhs);
153 }
154 Kokkos::Impl::HostSharedPtr<Impl::OpenMPInternal> m_space_instance;
155};
156
157namespace Tools {
158namespace Experimental {
159template <>
160struct DeviceTypeTraits<OpenMP> {
161 static constexpr DeviceType id = DeviceType::OpenMP;
162 static int device_id(const OpenMP&) { return 0; }
163};
164} // namespace Experimental
165} // namespace Tools
166} // namespace Kokkos
167
168/*--------------------------------------------------------------------------*/
169/*--------------------------------------------------------------------------*/
170
171namespace Kokkos {
172namespace Impl {
173
174template <>
175struct MemorySpaceAccess<Kokkos::OpenMP::memory_space,
176 Kokkos::OpenMP::scratch_memory_space> {
177 enum : bool { assignable = false };
178 enum : bool { accessible = true };
179 enum : bool { deepcopy = false };
180};
181
182} // namespace Impl
183} // namespace Kokkos
184
185/*--------------------------------------------------------------------------*/
186/*--------------------------------------------------------------------------*/
187
188#include <OpenMP/Kokkos_OpenMP_Instance.hpp>
189#include <OpenMP/Kokkos_OpenMP_Team.hpp>
190#include <OpenMP/Kokkos_OpenMP_Parallel.hpp>
191#include <OpenMP/Kokkos_OpenMP_Task.hpp>
192
193#include <KokkosExp_MDRangePolicy.hpp>
194/*--------------------------------------------------------------------------*/
195
196#endif /* #if defined( KOKKOS_ENABLE_OPENMP ) && defined( _OPENMP ) */
197#endif /* #ifndef KOKKOS_OPENMP_HPP */
Declaration of various MemoryLayout options.
Declaration of parallel operators.