1 #ifndef OMEGA_H_ARRAY_HPP
2 #define OMEGA_H_ARRAY_HPP
4 #include <Omega_h_defines.hpp>
5 #include <Omega_h_fail.hpp>
6 #include <initializer_list>
7 #ifdef OMEGA_H_USE_KOKKOS
8 #include <Omega_h_kokkos.hpp>
9 #include <Omega_h_pool_kokkos.hpp>
10 #include <Omega_h_memory.hpp>
12 #include <Omega_h_shared_alloc.hpp>
25 #ifdef OMEGA_H_USE_KOKKOS
27 class KokkosViewWrapper {
29 KokkosViewWrapper(
size_t n,
const std::string& name_in)
30 : view_(KokkosPool::getGlobalPool().allocateView<T>(n)),
33 [[nodiscard]]
auto label() const -> std::
string {
return label_; }
35 [[nodiscard]]
auto getView() const -> const View<T*>& {
39 ~KokkosViewWrapper() {
40 KokkosPool::getGlobalPool().deallocateView<T>(view_);
51 #ifdef OMEGA_H_USE_KOKKOS
60 OMEGA_H_INLINE
Write();
61 #ifdef OMEGA_H_USE_KOKKOS
62 Write(View<T*> view_in);
64 Write(LO size_in, std::string
const& name =
"");
65 Write(LO size_in, T value, std::string
const& name =
"");
66 Write(LO size_in, T offset, T stride, std::string
const& name =
"");
67 Write(std::initializer_list<T> l, std::string
const& name =
"");
69 OMEGA_H_INLINE LO size()
const OMEGA_H_NOEXCEPT;
70 OMEGA_H_DEVICE T& operator[](LO i)
const OMEGA_H_NOEXCEPT;
71 OMEGA_H_INLINE T* data()
const noexcept;
72 #ifdef OMEGA_H_USE_KOKKOS
73 OMEGA_H_INLINE View<T*>
const& view()
const {
return view_; }
75 void set(LO i, T value)
const;
77 long use_count()
const;
78 OMEGA_H_INLINE
bool exists()
const noexcept;
79 #ifdef OMEGA_H_USE_KOKKOS
80 std::string name()
const;
82 std::string
const& name()
const;
84 OMEGA_H_INLINE T* begin()
const noexcept {
return data(); }
85 OMEGA_H_INLINE T* end()
const OMEGA_H_NOEXCEPT {
return data() + size(); }
94 OMEGA_H_INLINE
Read() {}
96 Read(LO size, T value, std::string
const& name =
"");
97 Read(LO size, T offset, T stride, std::string
const& name =
"");
98 Read(std::initializer_list<T> l, std::string
const& name =
"");
99 OMEGA_H_INLINE LO size()
const OMEGA_H_NOEXCEPT {
return write_.size(); }
100 OMEGA_H_DEVICE T
const& operator[](LO i)
const OMEGA_H_NOEXCEPT {
101 #ifdef OMEGA_H_CHECK_BOUNDS
102 OMEGA_H_CHECK_OP(0, <=, i);
103 OMEGA_H_CHECK_OP(i, <, size());
107 OMEGA_H_INLINE T
const* data()
const OMEGA_H_NOEXCEPT {
108 return write_.data();
110 #ifdef OMEGA_H_USE_KOKKOS
111 View<const T*> view()
const;
116 OMEGA_H_INLINE
bool exists()
const OMEGA_H_NOEXCEPT {
117 return write_.exists();
119 std::string name()
const {
return write_.name(); }
120 OMEGA_H_INLINE T
const* begin()
const noexcept {
return data(); }
121 OMEGA_H_INLINE T
const* end()
const noexcept {
return data() + size(); }
124 template <
typename T>
129 using Bytes = Read<Byte>;
130 using LOs = Read<LO>;
131 using GOs = Read<GO>;
132 using Reals = Read<Real>;
134 template <
typename T>
137 #if defined(OMEGA_H_USE_KOKKOS)
138 typename Kokkos::View<const T*, Kokkos::HostSpace> mirror_;
141 using value_type = T;
145 inline T
const& operator[](LO i)
const OMEGA_H_NOEXCEPT;
146 T
const* data()
const;
149 T
const* begin()
const noexcept {
return data(); }
150 T
const* end()
const noexcept {
return data() + size(); }
153 template <
typename T>
156 #ifdef OMEGA_H_USE_KOKKOS
157 typename View<T*>::host_mirror_type mirror_;
160 using value_type = T;
162 HostWrite(LO size_in, std::string
const& name =
"");
176 HostWrite(LO size_in, T offset, T stride, std::string
const& name =
"");
179 HostWrite(std::initializer_list<T> l, std::string
const& name =
"");
181 LO size()
const OMEGA_H_NOEXCEPT;
182 inline T& operator[](LO i)
const OMEGA_H_NOEXCEPT;
184 OMEGA_H_INLINE
bool exists()
const OMEGA_H_NOEXCEPT {
185 return write_.exists();
187 void set(LO i, T value);
189 T* begin()
const noexcept {
return data(); }
190 T* end()
const OMEGA_H_NOEXCEPT {
return data() + size(); }
193 template <
typename T>
195 template <
typename T>
196 void fill_linear(
Write<T> a, T offset, T stride);
203 #define OMEGA_H_EXPL_INST_DECL(T) \
204 extern template T* nonnull(T*); \
205 extern template T const* nonnull(T const*); \
206 extern template class Read<T>; \
207 extern template class Write<T>; \
208 extern template class HostRead<T>; \
209 extern template class HostWrite<T>; \
210 extern template void fill(Write<T> a, T val); \
211 extern template void fill_linear(Write<T> a, T, T); \
212 extern template void copy_into(Read<T> a, Write<T> b); \
213 extern template Write<T> deep_copy(Read<T> a, std::string const&);
214 OMEGA_H_EXPL_INST_DECL(I8)
215 OMEGA_H_EXPL_INST_DECL(I32)
216 OMEGA_H_EXPL_INST_DECL(I64)
217 OMEGA_H_EXPL_INST_DECL(Real)
218 #undef OMEGA_H_EXPL_INST_DECL
223 #ifdef OMEGA_H_USE_KOKKOS
224 #include "Omega_h_array_kokkos.hpp"
226 #include "Omega_h_array_default.hpp"
Definition: Omega_h_array.hpp:135
Definition: Omega_h_array.hpp:154
Definition: Omega_h_array.hpp:89
Definition: Omega_h_memory.hpp:9
Definition: Omega_h_array.hpp:50
Definition: amr_mpi_test.cpp:6
Definition: Omega_h_shared_alloc.hpp:51
Definition: Omega_h_rbtree.hpp:1013