omega_h
Reliable mesh adaptation
Omega_h_array_default.hpp
1 //
2 // Created by Matthew McCall on 6/8/23.
3 //
4 
5 #ifndef OMEGA_H_ARRAY_DEFAULT_HPP
6 #define OMEGA_H_ARRAY_DEFAULT_HPP
7 
8 namespace Omega_h {
9 
10 template <typename T>
11 Write<T>::Write() : shared_alloc_() {}
12 
13 template <typename T>
14 LO Write<T>::size() const OMEGA_H_NOEXCEPT {
15 #ifdef OMEGA_H_CHECK_BOUNDS
16  OMEGA_H_CHECK(exists());
17 #endif
18  return static_cast<LO>(shared_alloc_.size() / sizeof(T));
19 }
20 
21 template <typename T>
22 OMEGA_H_DEVICE T& Write<T>::operator[](LO i) const OMEGA_H_NOEXCEPT {
23 #ifdef OMEGA_H_CHECK_BOUNDS
24  OMEGA_H_CHECK_OP(0, <=, i);
25  OMEGA_H_CHECK_OP(i, <, size());
26 #endif
27  return data()[i];
28 }
29 
30 template <typename T>
31 OMEGA_H_INLINE T* Write<T>::data() const noexcept {
32  return static_cast<T*>(shared_alloc_.data());
33 }
34 
35 template <typename T>
36 OMEGA_H_INLINE long Write<T>::use_count() const { return shared_alloc_.alloc->use_count; }
37 
38 template <typename T>
39 OMEGA_H_INLINE bool Write<T>::exists() const noexcept {
40  return shared_alloc_.data() != nullptr;
41 }
42 
43 template <typename T>
44 inline T const& HostRead<T>::operator[](LO i) const OMEGA_H_NOEXCEPT {
45 #ifdef OMEGA_H_CHECK_BOUNDS
46  OMEGA_H_CHECK_OP(0, <=, i);
47  OMEGA_H_CHECK_OP(i, <, size());
48 #endif
49 #ifdef KOKKOS_ENABLE_CUDA
50  return mirror_[i];
51 #else
52  return read_[i];
53 #endif
54 }
55 
56 template <typename T>
57 inline T& HostWrite<T>::operator[](LO i) const OMEGA_H_NOEXCEPT {
58 #ifdef OMEGA_H_CHECK_BOUNDS
59  OMEGA_H_CHECK_OP(0, <=, i);
60  OMEGA_H_CHECK_OP(i, <, size());
61 #endif
62 #ifdef KOKKOS_ENABLE_CUDA
63  return mirror_[i];
64 #else
65  return write_[i];
66 #endif
67 }
68 
69 } // namespace Omega_h
70 
71 #endif // OMEGA_H_ARRAY_DEFAULT_HPP
Definition: amr_mpi_test.cpp:6