3#include <AMReX_Config.H>
25 template <
class T, std::
size_t N>
41 template <
class T,
unsigned int N>
53#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
65#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
75 const T*
data () const noexcept {
return arr; }
81 T*
data () noexcept {
return arr; }
88 static constexpr unsigned int size () noexcept {
return N; }
95 const T*
begin () const noexcept {
return arr; }
102 const T*
end () const noexcept {
return arr + N; }
109 T*
begin () noexcept {
return arr; }
116 T*
end () noexcept {
return arr + N; }
125 void fill (
const T& value )
noexcept
126 {
for (
unsigned int i = 0; i < N; ++i) { arr[i] = value; } }
132 constexpr T
sum () const noexcept
135 for (
unsigned int i = 0; i < N; ++i) { s += arr[i]; }
146 for (
unsigned int i = 0; i < N; ++i) { p *= arr[i]; }
153 for (
unsigned int i = 0; i < N; ++i) {
159#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
160#if defined(AMREX_USE_HIP)
165 static void index_assert (
int i)
167 if (i < 0 ||
static_cast<unsigned int>(i) >= N) {
174 std::stringstream ss;
175 ss << " (" << i << ") is out of bound (0:" << N-1 <<")";
202 template <
class T,
int XLO,
int XHI>
210 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1); }
217 static constexpr int lo () noexcept {
return XLO; }
223 static constexpr int hi () noexcept {
return XHI; }
230 static constexpr unsigned int len () noexcept {
return (XHI-XLO+1); }
237 const T*
begin () const noexcept {
return arr; }
244 const T*
end () const noexcept {
return arr + XHI-XLO+1; }
251 T*
begin () noexcept {
return arr; }
258 T*
end () noexcept {
return arr + XHI-XLO+1; }
265 const T& operator() (
int i)
const noexcept {
266#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
277 T& operator() (
int i)
noexcept {
278#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
288 constexpr T
sum () const noexcept
291 for (
int i = XLO; i <= XHI; ++i) { s += arr[i-XLO]; }
302 for (
int i = 0; i < (XHI-XLO+1); ++i) {
307#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
308#if defined(AMREX_USE_HIP)
313 static void index_assert (
int i)
315 if (i<XLO || i>XHI) {
322 std::stringstream ss;
323 ss << " (" << i << ") is out of bound ("
324 << XLO << ":" << XHI << ")";
325 amrex::Abort(ss.str());
354 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
355 Order ORDER = Order::F>
363 static constexpr unsigned int size() noexcept {
return (XHI-XLO+1)*(YHI-YLO+1); }
371 static constexpr int xlo () noexcept {
return XLO; }
378 static constexpr int xhi () noexcept {
return XHI; }
386 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
394 static constexpr int ylo () noexcept {
return YLO; }
401 static constexpr int yhi () noexcept {
return YHI; }
409 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
416 const T*
begin () const noexcept {
return arr; }
423 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
430 T*
begin () noexcept {
return arr; }
437 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
447 const T& operator() (
int i,
int j)
const noexcept {
448#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
451 if constexpr (ORDER == Order::F) {
452 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
454 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
466 T& operator() (
int i,
int j)
noexcept {
467#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
470 if constexpr (ORDER == Order::F) {
471 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
473 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
482 constexpr T
sum () const noexcept
485 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
520 constexpr T
sum (
int axis,
int loc)
const noexcept
525 for (
int i = XLO; i <= XHI; ++i) {
526 s += this->operator()(i,j);
528 }
else if (axis == 1) {
530 for (
int j = YLO; j <= YHI; ++j) {
531 s += this->operator()(i,j);
545 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
581 constexpr T
product (
int axis,
int loc)
const noexcept
586 for (
int i = XLO; i <= XHI; ++i) {
587 p *= this->operator()(i,j);
589 }
else if (axis == 1) {
591 for (
int j = YLO; j <= YHI; ++j) {
592 p *= this->operator()(i,j);
597#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
598#if defined(AMREX_USE_HIP)
603 static void index_assert (
int i,
int j)
605 if (i<XLO || i>XHI || j<YLO || j>YHI) {
608 i, j, XLO, XHI, YLO, YHI);
612 std::stringstream ss;
613 ss << " (" << i << "," << j
614 << ") is out of bound ("
615 << XLO << ":" << XHI << ","
616 << YLO << ":" << YHI << ")";
617 amrex::Abort(ss.str());
624 T arr[(XHI-XLO+1)*(YHI-YLO+1)];
649 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
int ZLO,
int ZHI,
650 Order ORDER=Order::F>
658 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
666 static constexpr int xlo () noexcept {
return XLO; }
673 static constexpr int xhi () noexcept {
return XHI; }
680 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
688 static constexpr int ylo () noexcept {
return YLO; }
695 static constexpr int yhi () noexcept {
return YHI; }
703 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
711 static constexpr int zlo () noexcept {
return ZLO; }
718 static constexpr int zhi () noexcept {
return ZHI; }
725 static constexpr unsigned int zlen () noexcept {
return (ZHI-ZLO+1); }
732 const T*
begin () const noexcept {
return arr; }
739 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
746 T*
begin () noexcept {
return arr; }
753 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
764 const T& operator() (
int i,
int j,
int k)
const noexcept {
765#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
766 index_assert(i, j, k);
768 if constexpr (ORDER == Order::F) {
769 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
770 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
772 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
773 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
786 T& operator() (
int i,
int j,
int k)
noexcept {
787#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
788 index_assert(i, j, k);
790 if constexpr (ORDER == Order::F) {
791 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
792 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
794 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
795 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
804 constexpr T
sum () const noexcept
807 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
848 constexpr T
sum (
int axis,
int loc0,
int loc1)
const noexcept
854 for (
int i = XLO; i <= XHI; ++i) {
855 s += this->operator()(i,j,k);
857 }
else if (axis == 1) {
860 for (
int j = YLO; j <= YHI; ++j) {
861 s += this->operator()(i,j,k);
863 }
else if (axis == 2) {
866 for (
int k = ZLO; k <= ZHI; ++k) {
867 s += this->operator()(i,j,k);
881 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
923 constexpr T
product (
const int axis,
const int loc0,
const int loc1)
const noexcept
929 for (
int i = XLO; i <= XHI; ++i) {
930 p *= this->operator()(i,j,k);
932 }
else if (axis == 1) {
935 for (
int j = YLO; j <= YHI; ++j) {
936 p *= this->operator()(i,j,k);
938 }
else if (axis == 2) {
941 for (
int k = ZLO; k <= ZHI; ++k) {
942 p *= this->operator()(i,j,k);
948#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
949#if defined(AMREX_USE_HIP)
954 static void index_assert (
int i,
int j,
int k)
956 if (i<XLO || i>XHI || j<YLO || j>YHI || k<ZLO || k>ZHI) {
959 i, j, k, XLO, XHI, YLO, YHI, ZLO, ZHI);
963 std::stringstream ss;
964 ss << " (" << i << "," << j << "," << k
965 << ") is out of bound ("
966 << XLO << ":" << XHI << ","
967 << YLO << ":" << YHI << ","
968 << ZLO << ":" << ZHI << ")";
969 amrex::Abort(ss.str());
976 T arr[(XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1)];
1000 template <
class T,
typename =
typename T::FABType>
1001 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a)
noexcept
1003 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1024 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1047 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T,AMREX_SPACEDIM>& a)
noexcept
1049 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1059 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T*,AMREX_SPACEDIM>& a)
noexcept
1083 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1094#if (AMREX_SPACEDIM == 1)
1095 return XDim3{a[0], 0., 0.};
1096#elif (AMREX_SPACEDIM == 2)
1097 return XDim3{a[0], a[1], 0.};
1099 return XDim3{a[0], a[1], a[2]};
#define AMREX_NO_INLINE
Definition AMReX_Extension.H:136
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_DEVICE_PRINTF(...)
Definition AMReX_GpuPrint.H:21
#define AMREX_IF_ON_DEVICE(CODE)
Definition AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
std::array< T, N > Array
Definition AMReX_Array.H:26
Definition AMReX_Amr.cpp:49
Array< int, 3 > IntArray
Definition AMReX_Array.H:29
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Create an array of const-qualified pointers from an array of objects.
Definition AMReX_Array.H:1047
XDim3 makeXDim3(const Array< Real, 3 > &a) noexcept
Definition AMReX_Array.H:1092
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Create an array of pointers from an array of objects.
Definition AMReX_Array.H:1001
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:44
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
Array< Real, 3 > RealArray
Definition AMReX_Array.H:28
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get I'th element of IntVectND<dim>
Definition AMReX_IntVect.H:1230
A GPU-compatible one-dimensional array.
Definition AMReX_Array.H:204
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:210
__host__ static __device__ constexpr int hi() noexcept
Definition AMReX_Array.H:223
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:244
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:237
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:258
__host__ static __device__ constexpr unsigned int len() noexcept
Definition AMReX_Array.H:230
__host__ static __device__ constexpr int lo() noexcept
Definition AMReX_Array.H:217
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:288
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:251
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:299
A GPU-compatible two-dimensional array.
Definition AMReX_Array.H:357
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:409
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:401
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:437
__host__ __device__ constexpr T sum(int axis, int loc) const noexcept
Definition AMReX_Array.H:520
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:386
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:371
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:416
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:482
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:430
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:394
__host__ __device__ constexpr T product(int axis, int loc) const noexcept
Definition AMReX_Array.H:581
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:542
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:423
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:378
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:363
A GPU-compatible three-dimensional array.
Definition AMReX_Array.H:652
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:666
__host__ static __device__ constexpr int zhi() noexcept
Definition AMReX_Array.H:718
__host__ __device__ constexpr T product(const int axis, const int loc0, const int loc1) const noexcept
Definition AMReX_Array.H:923
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:680
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:804
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:732
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:753
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:746
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:878
__host__ __device__ constexpr T sum(int axis, int loc0, int loc1) const noexcept
Definition AMReX_Array.H:848
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:658
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:673
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:703
__host__ static __device__ constexpr int zlo() noexcept
Definition AMReX_Array.H:711
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:739
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:695
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:688
__host__ static __device__ constexpr unsigned int zlen() noexcept
Definition AMReX_Array.H:725
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:43
T & reference_type
Definition AMReX_Array.H:45
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:132
T value_type
Definition AMReX_Array.H:44
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:102
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:116
__host__ __device__ const T * data() const noexcept
Definition AMReX_Array.H:75
__host__ __device__ void fill(const T &value) noexcept
Definition AMReX_Array.H:125
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:109
__host__ __device__ T product() const noexcept
Definition AMReX_Array.H:143
__host__ __device__ T * data() noexcept
Definition AMReX_Array.H:81
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:95
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:88
__host__ __device__ const T & operator[](int i) const noexcept
Definition AMReX_Array.H:52
__host__ __device__ GpuArray< T, N > & operator+=(GpuArray< T, N > const &a) noexcept
Definition AMReX_Array.H:151
Definition AMReX_Dim3.H:13