3#include <AMReX_Config.H>
30 template <
class T, std::
size_t N>
50 template <
class T,
unsigned int N>
64#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
78#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
90 const T*
data () const noexcept {
return arr; }
98 T*
data () noexcept {
return arr; }
105 static constexpr unsigned int size () noexcept {
return N; }
112 const T*
begin () const noexcept {
return arr; }
119 const T*
end () const noexcept {
return arr + N; }
128 T*
begin () noexcept {
return arr; }
137 T*
end () noexcept {
return arr + N; }
146 void fill (
const T& value )
noexcept
147 {
for (
unsigned int i = 0; i < N; ++i) { arr[i] = value; } }
153 constexpr T
sum () const noexcept
156 for (
unsigned int i = 0; i < N; ++i) { s += arr[i]; }
167 for (
unsigned int i = 0; i < N; ++i) { p *= arr[i]; }
180 for (
unsigned int i = 0; i < N; ++i) {
186#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
187#if defined(AMREX_USE_HIP)
197 static void index_assert (
int i)
199 if (i < 0 ||
static_cast<unsigned int>(i) >= N) {
206 std::stringstream ss;
207 ss << " (" << i << ") is out of bound (0:" << N-1 <<")";
234 template <
class T,
int XLO,
int XHI>
242 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1); }
249 static constexpr int lo () noexcept {
return XLO; }
255 static constexpr int hi () noexcept {
return XHI; }
262 static constexpr unsigned int len () noexcept {
return (XHI-XLO+1); }
269 const T*
begin () const noexcept {
return arr; }
276 const T*
end () const noexcept {
return arr + XHI-XLO+1; }
283 T*
begin () noexcept {
return arr; }
290 T*
end () noexcept {
return arr + XHI-XLO+1; }
297 const T& operator() (
int i)
const noexcept {
298#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
309 T& operator() (
int i)
noexcept {
310#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
320 constexpr T
sum () const noexcept
323 for (
int i = XLO; i <= XHI; ++i) { s += arr[i-XLO]; }
334 for (
int i = 0; i < (XHI-XLO+1); ++i) {
339#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
340#if defined(AMREX_USE_HIP)
345 static void index_assert (
int i)
347 if (i<XLO || i>XHI) {
354 std::stringstream ss;
355 ss << " (" << i << ") is out of bound ("
356 << XLO << ":" << XHI << ")";
357 amrex::Abort(ss.str());
386 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
387 Order ORDER = Order::F>
395 static constexpr unsigned int size() noexcept {
return (XHI-XLO+1)*(YHI-YLO+1); }
403 static constexpr int xlo () noexcept {
return XLO; }
410 static constexpr int xhi () noexcept {
return XHI; }
418 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
426 static constexpr int ylo () noexcept {
return YLO; }
433 static constexpr int yhi () noexcept {
return YHI; }
441 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
448 const T*
begin () const noexcept {
return arr; }
455 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
462 T*
begin () noexcept {
return arr; }
469 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1); }
479 const T& operator() (
int i,
int j)
const noexcept {
480#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
483 if constexpr (ORDER == Order::F) {
484 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
486 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
498 T& operator() (
int i,
int j)
noexcept {
499#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
502 if constexpr (ORDER == Order::F) {
503 return arr[i+j*(XHI-XLO+1)-(YLO*(XHI-XLO+1)+XLO)];
505 return arr[j+i*(YHI-YLO+1)-(XLO*(YHI-YLO+1)+YLO)];
514 constexpr T
sum () const noexcept
517 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
552 constexpr T
sum (
int axis,
int loc)
const noexcept
557 for (
int i = XLO; i <= XHI; ++i) {
558 s += this->operator()(i,j);
560 }
else if (axis == 1) {
562 for (
int j = YLO; j <= YHI; ++j) {
563 s += this->operator()(i,j);
577 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1); ++i) {
613 constexpr T
product (
int axis,
int loc)
const noexcept
618 for (
int i = XLO; i <= XHI; ++i) {
619 p *= this->operator()(i,j);
621 }
else if (axis == 1) {
623 for (
int j = YLO; j <= YHI; ++j) {
624 p *= this->operator()(i,j);
629#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
630#if defined(AMREX_USE_HIP)
635 static void index_assert (
int i,
int j)
637 if (i<XLO || i>XHI || j<YLO || j>YHI) {
640 i, j, XLO, XHI, YLO, YHI);
644 std::stringstream ss;
645 ss << " (" << i << "," << j
646 << ") is out of bound ("
647 << XLO << ":" << XHI << ","
648 << YLO << ":" << YHI << ")";
649 amrex::Abort(ss.str());
656 T arr[(XHI-XLO+1)*(YHI-YLO+1)];
681 template <
class T,
int XLO,
int XHI,
int YLO,
int YHI,
int ZLO,
int ZHI,
682 Order ORDER=Order::F>
690 static constexpr unsigned int size () noexcept {
return (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
698 static constexpr int xlo () noexcept {
return XLO; }
705 static constexpr int xhi () noexcept {
return XHI; }
712 static constexpr unsigned int xlen () noexcept {
return (XHI-XLO+1); }
720 static constexpr int ylo () noexcept {
return YLO; }
727 static constexpr int yhi () noexcept {
return YHI; }
735 static constexpr unsigned int ylen () noexcept {
return (YHI-YLO+1); }
743 static constexpr int zlo () noexcept {
return ZLO; }
750 static constexpr int zhi () noexcept {
return ZHI; }
757 static constexpr unsigned int zlen () noexcept {
return (ZHI-ZLO+1); }
764 const T*
begin () const noexcept {
return arr; }
771 const T*
end () const noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
778 T*
begin () noexcept {
return arr; }
785 T*
end () noexcept {
return arr + (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); }
796 const T& operator() (
int i,
int j,
int k)
const noexcept {
797#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
798 index_assert(i, j, k);
800 if constexpr (ORDER == Order::F) {
801 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
802 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
804 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
805 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
818 T& operator() (
int i,
int j,
int k)
noexcept {
819#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
820 index_assert(i, j, k);
822 if constexpr (ORDER == Order::F) {
823 return arr[i+j*(XHI-XLO+1)+k*((XHI-XLO+1)*(YHI-YLO+1))
824 -(ZLO*((XHI-XLO+1)*(YHI-YLO+1))+YLO*(XHI-XLO+1)+XLO)];
826 return arr[k+j*(ZHI-ZLO+1)+i*((ZHI-ZLO+1)*(YHI-YLO+1))
827 -(XLO*((ZHI-ZLO+1)*(YHI-YLO+1))+YLO*(ZHI-ZLO+1)+ZLO)];
836 constexpr T
sum () const noexcept
839 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
880 constexpr T
sum (
int axis,
int loc0,
int loc1)
const noexcept
886 for (
int i = XLO; i <= XHI; ++i) {
887 s += this->operator()(i,j,k);
889 }
else if (axis == 1) {
892 for (
int j = YLO; j <= YHI; ++j) {
893 s += this->operator()(i,j,k);
895 }
else if (axis == 2) {
898 for (
int k = ZLO; k <= ZHI; ++k) {
899 s += this->operator()(i,j,k);
913 for (
int i = 0; i < (XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1); ++i) {
955 constexpr T
product (
const int axis,
const int loc0,
const int loc1)
const noexcept
961 for (
int i = XLO; i <= XHI; ++i) {
962 p *= this->operator()(i,j,k);
964 }
else if (axis == 1) {
967 for (
int j = YLO; j <= YHI; ++j) {
968 p *= this->operator()(i,j,k);
970 }
else if (axis == 2) {
973 for (
int k = ZLO; k <= ZHI; ++k) {
974 p *= this->operator()(i,j,k);
980#if defined(AMREX_DEBUG) || defined(AMREX_BOUND_CHECK)
981#if defined(AMREX_USE_HIP)
986 static void index_assert (
int i,
int j,
int k)
988 if (i<XLO || i>XHI || j<YLO || j>YHI || k<ZLO || k>ZHI) {
991 i, j, k, XLO, XHI, YLO, YHI, ZLO, ZHI);
995 std::stringstream ss;
996 ss << " (" << i << "," << j << "," << k
997 << ") is out of bound ("
998 << XLO << ":" << XHI << ","
999 << YLO << ":" << YHI << ","
1000 << ZLO << ":" << ZHI << ")";
1001 amrex::Abort(ss.str());
1008 T arr[(XHI-XLO+1)*(YHI-YLO+1)*(ZHI-ZLO+1)];
1032 template <
class T,
typename =
typename T::FABType>
1033 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (std::array<T,AMREX_SPACEDIM>& a)
noexcept
1035 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1056 std::array<T*,AMREX_SPACEDIM>
GetArrOfPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1079 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T,AMREX_SPACEDIM>& a)
noexcept
1081 return {{
AMREX_D_DECL(a.data(), a.data()+1, a.data()+2)}};
1091 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<T*,AMREX_SPACEDIM>& a)
noexcept
1115 std::array<T const*,AMREX_SPACEDIM>
GetArrOfConstPtrs (
const std::array<std::unique_ptr<T>,AMREX_SPACEDIM>& a)
noexcept
1134#if (AMREX_SPACEDIM == 1)
1135 return XDim3{.
x = a[0], .y = 0., .z = 0.};
1136#elif (AMREX_SPACEDIM == 2)
1137 return XDim3{.
x = a[0], .y = a[1], .z = 0.};
1139 return XDim3{.
x = a[0], .y = a[1], .z = a[2]};
Runtime initialization/finalization helpers and global diagnostics.
General-purpose algorithm utilities available on both host and device.
Assertion macros used across AMReX for runtime consistency checks.
Simple structs for 3-component integer and real-valued tuples.
#define AMREX_NO_INLINE
Definition AMReX_Extension.H:141
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#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
Array< int, 3 > IntArray
Definition AMReX_Array.H:38
Array< Real, 3 > RealArray
Definition AMReX_Array.H:35
std::array< T, N > Array
Definition AMReX_Array.H:31
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:53
Definition AMReX_Amr.cpp:50
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:1079
XDim3 makeXDim3(const Array< Real, 3 > &a) noexcept
Convert an AMReX dimension-sized coordinate array into an XDim3, padding unused components with zeros...
Definition AMReX_Array.H:1132
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:1033
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:241
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get I'th element of IntVectND<dim>
Definition AMReX_IntVect.H:1334
A GPU-compatible one-dimensional array.
Definition AMReX_Array.H:236
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:242
__host__ static __device__ constexpr int hi() noexcept
Definition AMReX_Array.H:255
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:276
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:269
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:290
__host__ static __device__ constexpr unsigned int len() noexcept
Definition AMReX_Array.H:262
__host__ static __device__ constexpr int lo() noexcept
Definition AMReX_Array.H:249
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:320
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:283
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:331
A GPU-compatible two-dimensional array.
Definition AMReX_Array.H:389
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:441
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:433
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:469
__host__ __device__ constexpr T sum(int axis, int loc) const noexcept
Definition AMReX_Array.H:552
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:418
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:403
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:448
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:514
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:462
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:426
__host__ __device__ constexpr T product(int axis, int loc) const noexcept
Definition AMReX_Array.H:613
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:574
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:455
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:410
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:395
A GPU-compatible three-dimensional array.
Definition AMReX_Array.H:684
__host__ static __device__ constexpr int xlo() noexcept
Definition AMReX_Array.H:698
__host__ static __device__ constexpr int zhi() noexcept
Definition AMReX_Array.H:750
__host__ __device__ constexpr T product(const int axis, const int loc0, const int loc1) const noexcept
Definition AMReX_Array.H:955
__host__ static __device__ constexpr unsigned int xlen() noexcept
Definition AMReX_Array.H:712
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:836
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:764
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:785
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:778
__host__ __device__ constexpr T product() const noexcept
Definition AMReX_Array.H:910
__host__ __device__ constexpr T sum(int axis, int loc0, int loc1) const noexcept
Definition AMReX_Array.H:880
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:690
__host__ static __device__ constexpr int xhi() noexcept
Definition AMReX_Array.H:705
__host__ static __device__ constexpr unsigned int ylen() noexcept
Definition AMReX_Array.H:735
__host__ static __device__ constexpr int zlo() noexcept
Definition AMReX_Array.H:743
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:771
__host__ static __device__ constexpr int yhi() noexcept
Definition AMReX_Array.H:727
__host__ static __device__ constexpr int ylo() noexcept
Definition AMReX_Array.H:720
__host__ static __device__ constexpr unsigned int zlen() noexcept
Definition AMReX_Array.H:757
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
T & reference_type
Definition AMReX_Array.H:54
__host__ __device__ constexpr T sum() const noexcept
Definition AMReX_Array.H:153
T value_type
Definition AMReX_Array.H:53
__host__ __device__ const T * end() const noexcept
Definition AMReX_Array.H:119
__host__ __device__ T * end() noexcept
Definition AMReX_Array.H:137
__host__ __device__ const T * data() const noexcept
Definition AMReX_Array.H:90
__host__ __device__ void fill(const T &value) noexcept
Definition AMReX_Array.H:146
__host__ __device__ T * begin() noexcept
Definition AMReX_Array.H:128
__host__ __device__ T product() const noexcept
Definition AMReX_Array.H:164
__host__ __device__ T * data() noexcept
Definition AMReX_Array.H:98
__host__ __device__ const T * begin() const noexcept
Definition AMReX_Array.H:112
__host__ static __device__ constexpr unsigned int size() noexcept
Definition AMReX_Array.H:105
__host__ __device__ const T & operator[](int i) const noexcept
Definition AMReX_Array.H:63
__host__ __device__ GpuArray< T, N > & operator+=(GpuArray< T, N > const &a) noexcept
Perform element-wise accumulation from another GpuArray.
Definition AMReX_Array.H:178
A simple struct holding 3 Real values for a 3D coordinate.
Definition AMReX_Dim3.H:32
Real x
Definition AMReX_Dim3.H:32