1#ifndef AMREX_BASEFAB_H_
2#define AMREX_BASEFAB_H_
3#include <AMReX_Config.H>
47extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs;
48extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs_hwm;
49extern std::atomic<Long> atomic_total_cells_allocated_in_fabs;
50extern std::atomic<Long> atomic_total_cells_allocated_in_fabs_hwm;
51extern Long private_total_bytes_allocated_in_fabs;
52extern Long private_total_bytes_allocated_in_fabs_hwm;
53extern Long private_total_cells_allocated_in_fabs;
54extern Long private_total_cells_allocated_in_fabs_hwm;
56#pragma omp threadprivate(private_total_bytes_allocated_in_fabs)
57#pragma omp threadprivate(private_total_bytes_allocated_in_fabs_hwm)
58#pragma omp threadprivate(private_total_cells_allocated_in_fabs)
59#pragma omp threadprivate(private_total_cells_allocated_in_fabs_hwm)
122inline void check_array4_index_range (
Box const& bx)
124#if defined(AMREX_USE_GPU) && !defined(AMREX_ARRAY4_64BIT_INDEX)
126 "BaseFab: box has too many points for 32-bit Array4 indexing; "
127 "build with USE_ARRAY4_64BIT_INDEX=TRUE (GNU Make) or AMReX_ARRAY4_64BIT_INDEX=ON (CMake)");
155 if constexpr (!std::is_trivially_default_constructible_v<T>) {
176 if constexpr (!std::is_trivially_destructible_v<T>) {
261 bool shared = false,
Arena* ar =
nullptr);
340 requires (std::is_trivially_destructible_v<U>)
353 [[nodiscard]] std::
size_t nBytes () const noexcept {
return this->
truesize*
sizeof(T); }
360 [[nodiscard]] std::size_t
nBytes (
const Box& bx,
int ncomps)
const noexcept
361 {
return bx.numPts() *
sizeof(T) * ncomps; }
364 [[nodiscard]]
int nComp () const noexcept {
return this->
nvar; }
367 [[nodiscard]]
const int*
nCompPtr() const noexcept {
368 return &(this->
nvar);
378 [[nodiscard]]
const Box&
box () const noexcept {
return this->
domain; }
403 [[nodiscard]]
const int*
loVect () const noexcept {
return this->
domain.loVect(); }
413 [[nodiscard]]
const int*
hiVect () const noexcept {
return this->
domain.hiVect(); }
439 [[nodiscard]] T*
dataPtr (
int n = 0) noexcept {
441 return &(this->
dptr[n*this->
domain.numPts()]);
448 [[nodiscard]]
const T*
dataPtr (
int n = 0) const noexcept {
450 return &(this->
dptr[n*this->
domain.numPts()]);
622 void getVal (T* data,
const IntVect& pos,
int N,
int numcomp)
const noexcept;
626 template <RunOn run_on AMREX_DEFAULT_RUNON>
627 requires (std::is_same_v<T,float> || std::is_same_v<T,double>)
636 template <RunOn run_on AMREX_DEFAULT_RUNON>
637 void setVal (T
const&
x,
const Box& bx,
int dcomp,
int ncomp)
noexcept;
639 template <RunOn run_on AMREX_DEFAULT_RUNON>
674 const
Box& destbox,
int destcomp,
int numcomp) noexcept;
684 int numcomp = 1) noexcept;
697 int numcomp,
void* dst) const noexcept;
702 int numcomp, const
void* src) noexcept;
707 int numcomp, const
void* src) noexcept;
744 [[nodiscard]]
Real norm (
int p,
int scomp = 0,
int numcomp = 1) const;
748 [[nodiscard]]
Real norm (const
Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const;
754 void abs (
int comp,
int numcomp=1) noexcept;
759 void abs (const
Box& subbox,
int comp = 0,
int numcomp=1) noexcept;
764 [[nodiscard]] T
min (
int comp = 0) const noexcept;
769 [[nodiscard]] T
min (const
Box& subbox,
int comp = 0) const noexcept;
774 [[nodiscard]] T
max (
int comp = 0) const noexcept;
779 [[nodiscard]] T
max (const
Box& subbox,
int comp = 0) const noexcept;
784 [[nodiscard]] std::pair<T,T>
minmax (
int comp = 0) const noexcept;
789 [[nodiscard]] std::pair<T,T>
minmax (const
Box& subbox,
int comp = 0) const noexcept;
794 [[nodiscard]] T
maxabs (
int comp = 0) const noexcept;
799 [[nodiscard]] T
maxabs (const
Box& subbox,
int comp = 0) const noexcept;
845 [[nodiscard]] T
sum (
int comp,
int numcomp = 1) const noexcept;
848 [[nodiscard]] T
sum (const
Box& subbox,
int comp,
int numcomp = 1) const noexcept;
892 int srccomp,
int destcomp,
int numcomp=1) noexcept;
912 int numcomp=1) noexcept;
919 int srccomp,
int destcomp,
int numcomp=1) noexcept;
928 int srccomp,
int destcomp,
int numcomp) noexcept;
933 int srccomp,
int destcomp,
int numcomp=1) noexcept;
941 int srccomp,
int destcomp,
int numcomp=1) noexcept;
946 const
BaseFab<T>& src1,
int comp1,
947 const
BaseFab<T>& src2,
int comp2) noexcept;
963 int numcomp=1) noexcept;
970 int srccomp,
int destcomp,
int numcomp=1) noexcept;
994 int numcomp=1) noexcept;
1002 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1027 int numcomp=1) noexcept;
1034 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1059 int numcomp=1) noexcept;
1068 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1082 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
1084 const
Box& b,
int comp,
int numcomp = 1) noexcept;
1089 const
BaseFab<T>& f2,
int comp2,
1091 const
Box& b,
int comp,
int numcomp = 1) noexcept;
1104 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
1106 int comp,
int numcomp = 1) noexcept;
1111 int numcomp = 1) const noexcept;
1116 int numcomp) const noexcept;
1126 template <RunOn run_on AMREX_DEFAULT_RUNON>
1130 template <RunOn run_on AMREX_DEFAULT_RUNON>
1133 template <RunOn run_on AMREX_DEFAULT_RUNON>
1137 template <RunOn run_on AMREX_DEFAULT_RUNON>
1140 template <RunOn run_on AMREX_DEFAULT_RUNON>
1144 template <RunOn run_on AMREX_DEFAULT_RUNON>
1148 template <RunOn run_on AMREX_DEFAULT_RUNON>
1156 template <RunOn run_on AMREX_DEFAULT_RUNON>
1160 template <RunOn run_on AMREX_DEFAULT_RUNON>
1164 template <RunOn run_on AMREX_DEFAULT_RUNON>
1167 template <RunOn run_on AMREX_DEFAULT_RUNON>
1171 template <RunOn run_on AMREX_DEFAULT_RUNON>
1178 template <RunOn run_on AMREX_DEFAULT_RUNON>
1181 template <RunOn run_on AMREX_DEFAULT_RUNON>
1185 template <RunOn run_on AMREX_DEFAULT_RUNON>
1189 template <RunOn run_on AMREX_DEFAULT_RUNON>
1192 template <RunOn run_on AMREX_DEFAULT_RUNON>
1196 template <RunOn run_on AMREX_DEFAULT_RUNON>
1203 template <RunOn run_on AMREX_DEFAULT_RUNON>
1206 template <RunOn run_on AMREX_DEFAULT_RUNON>
1210 template <RunOn run_on AMREX_DEFAULT_RUNON>
1214 template <RunOn run_on AMREX_DEFAULT_RUNON>
1217 template <RunOn run_on AMREX_DEFAULT_RUNON>
1221 template <RunOn run_on AMREX_DEFAULT_RUNON>
1228 template <RunOn run_on AMREX_DEFAULT_RUNON>
1231 template <RunOn run_on AMREX_DEFAULT_RUNON>
1235 template <RunOn run_on AMREX_DEFAULT_RUNON>
1239 template <RunOn run_on AMREX_DEFAULT_RUNON>
1242 template <RunOn run_on AMREX_DEFAULT_RUNON>
1246 template <RunOn run_on AMREX_DEFAULT_RUNON>
1253 template <RunOn run_on AMREX_DEFAULT_RUNON>
1256 template <RunOn run_on AMREX_DEFAULT_RUNON>
1260 template <RunOn run_on AMREX_DEFAULT_RUNON>
1264 template <RunOn run_on AMREX_DEFAULT_RUNON>
1287 [[nodiscard]] T
dot (const
Box& bx,
int destcomp,
int numcomp) const noexcept;
1344 if (this->
arena()->isManaged()) {
1345#if defined(AMREX_USE_SYCL)
1350#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1352 std::size_t s =
sizeof(T)*this->
nvar*this->
domain.numPts();
1353#if defined(CUDART_VERSION) && (CUDART_VERSION >= 13000)
1354 cudaMemLocation location = {};
1355 location.type = cudaMemLocationTypeHost;
1364#elif defined(AMREX_USE_HIP)
1376 if (this->
arena()->isManaged()) {
1377#if defined(AMREX_USE_SYCL)
1378 std::size_t s =
sizeof(T)*this->
nvar*this->
domain.numPts();
1379 auto& q = Gpu::Device::streamQueue();
1380 q.submit([&] (sycl::handler& h) { h.prefetch(this->
dptr, s); });
1381#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1383 std::size_t s =
sizeof(T)*this->
nvar*this->
domain.numPts();
1384#if defined(CUDART_VERSION) && (CUDART_VERSION >= 13000)
1385 cudaMemLocation location = {};
1386 location.type = cudaMemLocationTypeDevice;
1396#elif defined(AMREX_USE_HIP)
1456 int numcomp)
const noexcept
1464 for (
int k = 0; k < numcomp; k++) {
1465 data[k] = this->
dptr[loc+(n+k)*sz];
1472 const IntVect& pos)
const noexcept
1489 this->
domain.shift(idir,n_cell);
1497 this->
domain.shiftHalf(v);
1505 this->
domain.shiftHalf(idir,n_cell);
1510template <RunOn run_on>
1511requires (std::is_same_v<T,float> || std::is_same_v<T,double>)
1519template <RunOn run_on>
1527template <RunOn run_on>
1535template <RunOn run_on>
1543template <RunOn run_on>
1551template <RunOn run_on>
1554 const Box& destbox,
int destcomp,
int numcomp)
noexcept
1560 AMREX_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
1567 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
1571 d(i,j,k,n+destcomp) = s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
1578template <RunOn run_on>
1586template <RunOn run_on>
1600 if (this->
nvar == 0) {
return; }
1602 detail::check_array4_index_range(this->
domain);
1606 this->
dptr =
static_cast<T*
>(this->
alloc(n*
sizeof(T)));
1618 if constexpr (std::is_same_v<T,float> || std::is_same_v<T,double>) {
1662 this->
dptr =
nullptr;
1683 detail::check_array4_index_range(bx);
1690 detail::check_array4_index_range(bx);
1711 :
dptr(
const_cast<T*
>(a.p)),
1719 :
dptr(
const_cast<T*
>(a.p)),
1734 dptr(rhs.dptr), domain(rhs.domain),
1735 nvar(rhs.nvar), truesize(rhs.truesize),
1736 ptr_owner(rhs.ptr_owner), shared_memory(rhs.shared_memory)
1738 , alloc_stream(rhs.alloc_stream)
1742 rhs.ptr_owner =
false;
1751 DataAllocator::operator=(rhs);
1763 rhs.ptr_owner =
false;
1769template <RunOn run_on>
1787 dcells = new_cells - old_cells;
1796 if (ar ==
nullptr) {
1800 detail::check_array4_index_range(b);
1810 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1813 this->
dptr =
nullptr;
1816 else if (this->
nvar*this->
domain.numPts() > this->truesize
1823 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1838requires (std::is_trivially_destructible_v<U>)
1846 if (o && this->
dptr) {
1847 if (this->
nvar > 0) {
1872 amrex::Abort(
"BaseFab::clear: BaseFab cannot be owner of shared memory");
1884 if (this->
nvar > 0) {
1891 this->
dptr =
nullptr;
1897std::unique_ptr<T,DataDeleter>
1902 r.reset(this->
dptr);
1904 if (this->
nvar > 0) {
1914template <RunOn run_on>
1919 void* dst)
const noexcept
1930 d(i,j,k,n) = s(i,j,k,n+srccomp);
1932 return sizeof(T)*d.
size();
1941template <RunOn run_on,
typename BUF>
1946 const void* src)
noexcept
1958 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1960 return sizeof(BUF)*s.
size();
1969template <RunOn run_on,
typename BUF>
1974 const void* src)
noexcept
1986 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1988 return sizeof(BUF)*s.
size();
1997template <RunOn run_on>
2005template <RunOn run_on>
2013template <RunOn run_on>
2021template <RunOn run_on>
2028 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
2036template <
typename Op,
typename T,
typename F>
2038T basefab_reduce_cpu (
Box const& bx,
int ncomp, T
const& init,
F const& f)
noexcept
2042 Reduce::detail::Lanes<Tup> acc;
2043 Reduce::detail::lanes_set<0>(acc, rem);
2046 for (
int n = 0; n < ncomp; ++n) {
2047 for (
int k = lo.z; k <= hi.z; ++k) {
2048 for (
int j = lo.y; j <= hi.y; ++j) {
2049 Reduce::detail::reduce_row<Op>(lo.x, hi.x, acc, rem,
2050 [&] (
int i) { return Tup{static_cast<T>(f(i,j,k,n))}; });
2052 Reduce::detail::lanes_fold<0,Tup,Op>(acc, rem);
2059template <RunOn run_on>
2062 int scomp,
int ncomp)
const noexcept
2075 reduce_op.
eval(subbox, reduce_data,
2080 for (
int n = 0; n < ncomp; ++n) {
2086 ReduceTuple hv = reduce_data.
value(reduce_op);
2091 r = detail::basefab_reduce_cpu<ReduceOpMax>(subbox, ncomp,
Real(0.0),
2092 [=] (
int i,
int j,
int k,
int n)
noexcept
2094 auto const t = a(i,j,k,n+scomp);
2095 return static_cast<Real>(m(i,j,k) ? std::abs(t) : T(0));
2102template <RunOn run_on>
2110template <RunOn run_on>
2125 reduce_op.
eval(subbox, reduce_data,
2129 for (
int n = 0; n < numcomp; ++n) {
2134 ReduceTuple hv = reduce_data.
value(reduce_op);
2136 }
else if (
p == 1) {
2140 reduce_op.
eval(subbox, reduce_data,
2144 for (
int n = 0; n < numcomp; ++n) {
2145 t +=
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
2149 ReduceTuple hv = reduce_data.
value(reduce_op);
2151 }
else if (
p == 2) {
2155 reduce_op.
eval(subbox, reduce_data,
2159 for (
int n = 0; n < numcomp; ++n) {
2160 t +=
static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
2164 ReduceTuple hv = reduce_data.
value(reduce_op);
2173 nrm = detail::basefab_reduce_cpu<ReduceOpMax>(subbox, numcomp,
Real(0.0),
2174 [=] (
int i,
int j,
int k,
int n)
noexcept
2176 return static_cast<Real>(std::abs(a(i,j,k,n+comp)));
2178 }
else if (
p == 1) {
2179 nrm = detail::basefab_reduce_cpu<ReduceOpSum>(subbox, numcomp,
Real(0.0),
2180 [=] (
int i,
int j,
int k,
int n)
noexcept
2182 return static_cast<Real>(std::abs(a(i,j,k,n+comp)));
2184 }
else if (
p == 2) {
2185 nrm = detail::basefab_reduce_cpu<ReduceOpSum>(subbox, numcomp,
Real(0.0),
2186 [=] (
int i,
int j,
int k,
int n)
noexcept
2188 return static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
2199template <RunOn run_on>
2207template <RunOn run_on>
2216 using ReduceTuple =
typename decltype(reduce_data)::Type;
2217 reduce_op.
eval(subbox, reduce_data,
2220 return { a(i,j,k) };
2222 ReduceTuple hv = reduce_data.
value(reduce_op);
2227 return detail::basefab_reduce_cpu<ReduceOpMin>(subbox, 1, std::numeric_limits<T>::max(),
2228 [=] (
int i,
int j,
int k,
int)
noexcept
2236template <RunOn run_on>
2244template <RunOn run_on>
2253 using ReduceTuple =
typename decltype(reduce_data)::Type;
2254 reduce_op.
eval(subbox, reduce_data,
2257 return { a(i,j,k) };
2259 ReduceTuple hv = reduce_data.
value(reduce_op);
2264 return detail::basefab_reduce_cpu<ReduceOpMax>(subbox, 1, std::numeric_limits<T>::lowest(),
2265 [=] (
int i,
int j,
int k,
int)
noexcept
2273template <RunOn run_on>
2281template <RunOn run_on>
2290 using ReduceTuple =
typename decltype(reduce_data)::Type;
2291 reduce_op.
eval(subbox, reduce_data,
2294 auto const x = a(i,j,k);
2297 ReduceTuple hv = reduce_data.
value(reduce_op);
2303 MM rem{std::numeric_limits<T>::max(), std::numeric_limits<T>::lowest()};
2304 Reduce::detail::Lanes<MM> acc;
2305 Reduce::detail::lanes_set<0>(acc, rem);
2308 for (
int k = lo.z; k <= hi.z; ++k) {
2309 for (
int j = lo.y; j <= hi.y; ++j) {
2310 Reduce::detail::reduce_row<ReduceOpMin,ReduceOpMax>(lo.x, hi.x, acc, rem,
2311 [&] (
int i) { auto const x = a(i,j,k); return MM{x,x}; });
2313 Reduce::detail::lanes_fold<0,MM,ReduceOpMin,ReduceOpMax>(acc, rem);
2319template <RunOn run_on>
2327template <RunOn run_on>
2336 using ReduceTuple =
typename decltype(reduce_data)::Type;
2337 reduce_op.
eval(subbox, reduce_data,
2340 return { std::abs(a(i,j,k)) };
2342 ReduceTuple hv = reduce_data.
value(reduce_op);
2347 return detail::basefab_reduce_cpu<ReduceOpMax>(subbox, 1, T(0),
2348 [=] (
int i,
int j,
int k,
int)
noexcept
2350 return std::abs(a(i,j,k));
2357template <RunOn run_on>
2365 std::numeric_limits<int>::lowest(),
2366 std::numeric_limits<int>::lowest())};
2373 if ((*flag == 0) && (a(i,j,k) == value)) {
2396template <RunOn run_on>
2404template <RunOn run_on>
2413template <RunOn run_on>
2422template <RunOn run_on>
2430template <RunOn run_on>
2439template <RunOn run_on>
2448template <RunOn run_on>
2458template <RunOn run_on>
2461 int srccomp,
int destcomp,
int numcomp)
noexcept
2468 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2475 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2478 d(i,j,k,n+destcomp) += a * s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
2485template <RunOn run_on>
2495template <RunOn run_on>
2498 const Box& srcbox,
const Box& destbox,
2499 int srccomp,
int destcomp,
int numcomp)
noexcept
2506 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2513 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2516 d(i,j,k,n+destcomp) = s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp) + a*d(i,j,k,n+destcomp);
2523template <RunOn run_on>
2531 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2532 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2540 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2547template <RunOn run_on>
2552 int comp,
int numcomp)
noexcept
2562 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2563 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2572 const Dim3 off1{.x = slo1.x-dlo.x, .y = slo1.y-dlo.y, .z = slo1.z-dlo.z};
2573 const Dim3 off2{.x = slo2.x-dlo.x, .y = slo2.y-dlo.y, .z = slo2.z-dlo.z};
2577 d(i,j,k,n+comp) = alpha*s1(i+off1.
x,j+off1.
y,k+off1.
z,n+comp1)
2578 + beta*s2(i+off2.
x,j+off2.
y,k+off2.
z,n+comp2);
2584template <RunOn run_on>
2588 int numcomp)
const noexcept
2595 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2601 const Dim3 offset{.x = ylo.x-xlo.x, .y = ylo.y-xlo.y, .z = ylo.z-xlo.z};
2609 using ReduceTuple =
typename decltype(reduce_data)::Type;
2610 reduce_op.
eval(xbx, reduce_data,
2614 for (
int n = 0; n < numcomp; ++n) {
2615 t += xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp);
2619 ReduceTuple hv = reduce_data.
value(reduce_op);
2624 r = detail::basefab_reduce_cpu<ReduceOpSum>(xbx, numcomp, T(0),
2625 [=] (
int i,
int j,
int k,
int n)
noexcept
2627 return xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp);
2635template <RunOn run_on>
2639 int numcomp)
const noexcept
2646 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2652 const Dim3 offset{.x = ylo.x-xlo.x, .y = ylo.y-xlo.y, .z = ylo.z-xlo.z};
2662 using ReduceTuple =
typename decltype(reduce_data)::Type;
2663 reduce_op.
eval(xbx, reduce_data,
2666 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2668 for (
int n = 0; n < numcomp; ++n) {
2669 t += xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp) * m;
2673 ReduceTuple hv = reduce_data.
value(reduce_op);
2678 r = detail::basefab_reduce_cpu<ReduceOpSum>(xbx, numcomp, T(0),
2679 [=] (
int i,
int j,
int k,
int n)
noexcept
2681 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2682 return xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp) * m;
2690template <RunOn run_on>
2698template <RunOn run_on>
2706template <RunOn run_on>
2714template <RunOn run_on>
2722template <RunOn run_on>
2730template <RunOn run_on>
2738template <RunOn run_on>
2746template <RunOn run_on>
2754template <RunOn run_on>
2762template <RunOn run_on>
2768 return ovlp.
ok() ? this->
atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2772template <RunOn run_on>
2775 int numcomp)
noexcept
2781template <RunOn run_on>
2784 int numcomp)
noexcept
2789 return ovlp.
ok() ? this->
atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2793template <RunOn run_on>
2796 int srccomp,
int destcomp,
int numcomp)
noexcept
2802 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2809 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2812 d(i,j,k,n+destcomp) += s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
2821template <RunOn run_on,
typename T>
2824 const Box& srcbox,
const Box& destbox,
2825 int srccomp,
int destcomp,
int numcomp)
noexcept
2831 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2834 T*
p = d.
ptr(i,j,k,n+destcomp);
2835 HostDevice::Atomic::Add(
p, s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp));
2839template <RunOn run_on,
typename T>
2840requires (!HasAtomicAdd<T>::value)
2841void basefab_atomic_add (BaseFab<T>& dfab,
const BaseFab<T>& sfab,
2842 const Box& srcbox,
const Box& destbox,
2843 int srccomp,
int destcomp,
int numcomp)
2852template <RunOn run_on>
2855 int srccomp,
int destcomp,
int numcomp)
noexcept
2861 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2864 detail::basefab_atomic_add<run_on>(*
this, src, srcbox, destbox,
2865 srccomp, destcomp, numcomp);
2871template <RunOn run_on>
2874 int srccomp,
int destcomp,
int numcomp)
noexcept
2876#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
2877#if defined(AMREX_USE_GPU)
2884 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2893 Dim3 const offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2911 for (
int ip = 0; ip < nplanes; ++ip) {
2916 int planes_left = nplanes;
2917 while (planes_left > 0) {
2919 auto const m = mm + plo;
2920 auto* lock = OpenMP::get_lock(m);
2921 if (omp_test_lock(lock))
2925 if (planedim == 1) {
2933 for (
int n = 0; n < numcomp; ++n) {
2934 for (
int k = lo.z; k <= hi.z; ++k) {
2935 for (
int j = lo.y; j <= hi.y; ++j) {
2936 auto * pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
2937 auto const* psrc = s.
ptr(slo.x,j+offset.
y,k+offset.
z,n+ srccomp);
2939 for (
int ii = 0; ii < len.x; ++ii) {
2940 pdst[ii] += psrc[ii];
2948 omp_unset_lock(lock);
2949 if (planes_left == 0) {
break; }
2953 for (
int ip = 0; ip < nplanes; ++ip) {
2954 int new_mm = (mm+ip) % nplanes;
2955 if ( ! mask[new_mm] ) {
2966#if defined(AMREX_USE_GPU)
2968 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2972 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2977template <RunOn run_on>
2985template <RunOn run_on>
2993template <RunOn run_on>
2996 int srccomp,
int destcomp,
int numcomp)
noexcept
3002 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3009 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3012 d(i,j,k,n+destcomp) -= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3019template <RunOn run_on>
3027template <RunOn run_on>
3035template <RunOn run_on>
3043template <RunOn run_on>
3051template <RunOn run_on>
3054 int srccomp,
int destcomp,
int numcomp)
noexcept
3060 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3067 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3070 d(i,j,k,n+destcomp) *= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3077template <RunOn run_on>
3085template <RunOn run_on>
3093template <RunOn run_on>
3101template <RunOn run_on>
3109template <RunOn run_on>
3112 int srccomp,
int destcomp,
int numcomp)
noexcept
3118 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3125 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3128 d(i,j,k,n+destcomp) /= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3135template <RunOn run_on>
3145template <RunOn run_on>
3155template <RunOn run_on>
3158 int numcomp)
noexcept
3167template <RunOn run_on>
3170 int srccomp,
int destcomp,
int numcomp)
noexcept
3176 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3183 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3186 if (s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp) != 0) {
3187 d(i,j,k,n+destcomp) /= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3205template <RunOn run_on>
3210 const Box& b,
int comp,
int numcomp)
noexcept
3217 Real alpha = (t2-t)/(t2-t1);
3218 Real beta = (t-t1)/(t2-t1);
3219 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,b,comp,numcomp);
3224template <RunOn run_on>
3229 const Box& b,
int comp,
int numcomp)
noexcept
3236 Real alpha = (t2-t)/(t2-t1);
3237 Real beta = (t-t1)/(t2-t1);
3238 return linComb<run_on>(f1,b,comp1,f2,b,comp2,alpha,beta,b,comp,numcomp);
3247template <RunOn run_on>
3255template <RunOn run_on>
3259 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3263 a(i,j,k,n+dcomp.i) = x;
3268template <RunOn run_on>
3276template <RunOn run_on>
3280 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3285 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3290template <RunOn run_on>
3298template <RunOn run_on>
3302 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3307 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3312template <RunOn run_on>
3322 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3331 for (
auto const& b : b_lst) {
3338template <RunOn run_on>
3347template <RunOn run_on>
3353 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3354 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3362 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3369template <RunOn run_on>
3377template <RunOn run_on>
3385template <RunOn run_on>
3389 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3394 a(i,j,k,n+dcomp.i) += val;
3401template <RunOn run_on>
3409template <RunOn run_on>
3417template <RunOn run_on>
3423 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3424 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3432 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3439template <RunOn run_on>
3447template <RunOn run_on>
3455template <RunOn run_on>
3459 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3464 a(i,j,k,n+dcomp.i) -= val;
3471template <RunOn run_on>
3479template <RunOn run_on>
3487template <RunOn run_on>
3493 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3494 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3502 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3509template <RunOn run_on>
3517template <RunOn run_on>
3525template <RunOn run_on>
3529 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3534 a(i,j,k,n+dcomp.i) *= val;
3541template <RunOn run_on>
3549template <RunOn run_on>
3557template <RunOn run_on>
3563 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3564 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3572 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3579template <RunOn run_on>
3587template <RunOn run_on>
3595template <RunOn run_on>
3599 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3604 a(i,j,k,n+dcomp.i) /= val;
3611template <RunOn run_on>
3619template <RunOn run_on>
3627template <RunOn run_on>
3633 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3634 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3642 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3649template <RunOn run_on>
3657template <RunOn run_on>
3661 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3666 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3673template <RunOn run_on>
3681template <RunOn run_on>
3685 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3690 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3697template <RunOn run_on>
3701 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3709 using ReduceTuple =
typename decltype(reduce_data)::Type;
3710 reduce_op.
eval(bx, reduce_data,
3714 for (
int n = 0; n < ncomp.n; ++n) {
3715 t += a(i,j,k,n+dcomp.i);
3719 ReduceTuple hv = reduce_data.
value(reduce_op);
3724 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
3725 [=] (
int i,
int j,
int k,
int n)
noexcept
3727 return a(i,j,k,n+dcomp.i);
3735template <RunOn run_on>
3740 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3741 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3750 using ReduceTuple =
typename decltype(reduce_data)::Type;
3751 reduce_op.
eval(bx, reduce_data,
3755 for (
int n = 0; n < ncomp.n; ++n) {
3756 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3760 ReduceTuple hv = reduce_data.
value(reduce_op);
3765 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
3766 [=] (
int i,
int j,
int k,
int n)
noexcept
3768 return d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3776template <RunOn run_on>
3785template <RunOn run_on>
3789 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3797 using ReduceTuple =
typename decltype(reduce_data)::Type;
3798 reduce_op.
eval(bx, reduce_data,
3802 for (
int n = 0; n < ncomp.n; ++n) {
3803 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3807 ReduceTuple hv = reduce_data.
value(reduce_op);
3812 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
3813 [=] (
int i,
int j,
int k,
int n)
noexcept
3815 return a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3823template <RunOn run_on>
3830 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3831 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3841 using ReduceTuple =
typename decltype(reduce_data)::Type;
3842 reduce_op.
eval(bx, reduce_data,
3846 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
3847 for (
int n = 0; n < ncomp.n; ++n) {
3848 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
3852 ReduceTuple hv = reduce_data.
value(reduce_op);
3857 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
3858 [=] (
int i,
int j,
int k,
int n)
noexcept
3860 int mi =
static_cast<int>(
static_cast<bool>(m(i,j,k)));
3861 return d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
General-purpose algorithm utilities available on both host and device.
Fixed-size array types for use on GPU and CPU.
Assertion macros used across AMReX for runtime consistency checks.
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Iterator over all IntVects in a Box.
A list of Boxes sharing a common IndexType.
Integer-lattice boxes and helpers for defining index-space regions.
Lightweight Arena-backed allocator and deleter helpers.
Compiler- and backend-specific extension macros (e.g., restrict, SIMD, inline).
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:123
#define AMREX_ATTRIBUTE_FLATTEN_FOR
Definition AMReX_Extension.H:155
#define AMREX_DEFAULT_RUNON
Definition AMReX_GpuControl.H:69
#define AMREX_CUDA_SAFE_CALL(call)
Definition AMReX_GpuError.H:73
#define AMREX_HOST_DEVICE_PARALLEL_FOR_1D_FLAG(where_to_run, n, i, block)
Definition AMReX_GpuLaunch.nolint.H:43
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(where_to_run, box, nc, i, j, k, n, block)
Definition AMReX_GpuLaunch.nolint.H:73
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Convenience header for the core AMReX GPU facilities.
#define AMREX_LOOP_3D(bx, i, j, k, block)
void amrex_mempool_free(void *p)
Definition AMReX_MemPool.cpp:80
void * amrex_mempool_alloc(size_t nbytes)
Definition AMReX_MemPool.cpp:74
while parser_exe_t p
Definition AMReX_Parser_Exe_Body.H:33
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Abstract base class for memory arenas.
Definition AMReX_Arena.H:154
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:243
BaseFab< Long > & saxpy(Long a, const BaseFab< Long > &x, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
Array4< T const > const_array() const noexcept
Return a const-qualified Array4 view over all components.
Definition AMReX_BaseFab.H:568
BaseFab< T > & copy(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition AMReX_BaseFab.H:3349
Long sum(int comp, int numcomp=1) const noexcept
gpuStream_t alloc_stream
Definition AMReX_BaseFab.H:1309
Real norminfmask(const Box &subbox, const BaseFab< int > &mask, int scomp=0, int ncomp=1) const noexcept
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition AMReX_BaseFab.H:3581
const int * hiVect() const noexcept
Returns the upper corner of the domain.
Definition AMReX_BaseFab.H:413
BaseFab< T > & minus(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition AMReX_BaseFab.H:3489
BaseFab< Long > & lockAdd(const BaseFab< Long > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp) noexcept
std::size_t copyToMem(const Box &srcbox, int srccomp, int numcomp, void *dst) const noexcept
std::size_t addFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src) noexcept
std::size_t nBytesOwned() const noexcept
Definition AMReX_BaseFab.H:355
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3340
BaseFab< Long > & addproduct(const Box &destbox, int destcomp, int numcomp, const BaseFab< Long > &src1, int comp1, const BaseFab< Long > &src2, int comp2) noexcept
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition AMReX_BaseFab.H:3441
BaseFab< Long > & negate(const Box &b, int comp=0, int numcomp=1) noexcept
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3371
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3527
BaseFab< T > & mult(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition AMReX_BaseFab.H:3559
std::size_t nBytes(const Box &bx, int ncomps) const noexcept
Returns bytes used in the Box for those components.
Definition AMReX_BaseFab.H:360
void setPtr(Long *p, Long sz) noexcept
Definition AMReX_BaseFab.H:478
BaseFab< Long > & linComb(const BaseFab< Long > &f1, const Box &b1, int comp1, const BaseFab< Long > &f2, const Box &b2, int comp2, Real alpha, Real beta, const Box &b, int comp, int numcomp=1) noexcept
BaseFab< T > & operator*=(T const &val) noexcept
Definition AMReX_BaseFab.H:3519
void resize(const Box &b, int N=1, Arena *ar=nullptr)
const IntVect & smallEnd() const noexcept
Returns the lower corner of the domain See class Box for analogue.
Definition AMReX_BaseFab.H:390
BaseFab< Long > & mult(Long const &r, int comp, int numcomp=1) noexcept
BaseFab< Long > & atomicAdd(const BaseFab< Long > &x) noexcept
const int * loVect() const noexcept
Returns the lower corner of the domain.
Definition AMReX_BaseFab.H:403
bool contains(const BaseFab< T > &fab) const noexcept
Returns true if the domain of fab is totally contained within the domain of this BaseFab.
Definition AMReX_BaseFab.H:419
bool isAllocated() const noexcept
Returns true if the data for the FAB has been allocated.
Definition AMReX_BaseFab.H:598
std::unique_ptr< Long, DataDeleter > release() noexcept
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3257
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3449
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition AMReX_BaseFab.H:378
void setValIf(T const &val, Box const &bx, const BaseFab< int > &mask, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3278
Array4< T > array() noexcept
Create a mutable Array4 view over all components.
Definition AMReX_BaseFab.H:531
IntVect indexFromValue(const Box &subbox, int comp, Long const &value) const noexcept
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3543
bool shared_memory
Definition AMReX_BaseFab.H:1307
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3270
BaseFab< T > & plus(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition AMReX_BaseFab.H:3419
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3292
BaseFab< Long > & xpay(Long a, const BaseFab< Long > &x, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
T & operator()(const IntVect &p, int N) noexcept
Returns a reference to the Nth component value defined at position p in the domain....
Definition AMReX_BaseFab.H:1406
std::size_t nBytes() const noexcept
Definition AMReX_BaseFab.H:353
std::size_t copyFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src) noexcept
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition AMReX_BaseFab.H:3651
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3473
BaseFab< Long > & minus(const BaseFab< Long > &src, int srccomp, int destcomp, int numcomp=1) noexcept
T value_type
Definition AMReX_BaseFab.H:248
void SetBoxType(const IndexType &typ) noexcept
Definition AMReX_BaseFab.H:1119
Array4< Long const > array() const noexcept
Definition AMReX_BaseFab.H:496
Long maxabs(int comp=0) const noexcept
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3379
void setComplement(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
setVal on the complement of bx in the fab's domain
Definition AMReX_BaseFab.H:3314
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3457
Long truesize
Definition AMReX_BaseFab.H:1305
void setVal(T const &val) noexcept
Set value on the whole domain and all components.
Definition AMReX_BaseFab.H:3249
const int * nCompPtr() const noexcept
for calls to fortran.
Definition AMReX_BaseFab.H:367
Array4< T const > const_array(int start_comp, int num_comps) const noexcept
Return a const-qualified Array4 view spanning num_comps components.
Definition AMReX_BaseFab.H:592
Box domain
Definition AMReX_BaseFab.H:1303
void fill_snan() noexcept
bool contains(const Box &bx) const noexcept
Returns true if bx is totally contained within the domain of this BaseFab.
Definition AMReX_BaseFab.H:428
Long * dptr
Definition AMReX_BaseFab.H:1302
BaseFab< Long > & shift(const IntVect &v) noexcept
BaseFab< T > & divide(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3597
Long max(int comp=0) const noexcept
BaseFab< Long > & copy(const BaseFab< Long > &src, const Box &srcbox, int srccomp, const Box &destbox, int destcomp, int numcomp) noexcept
Array4< T > array(int start_comp, int num_comps) noexcept
Mutable overload spanning num_comps components.
Definition AMReX_BaseFab.H:556
int nvar
Definition AMReX_BaseFab.H:1304
Long dot(const Box &xbx, int xcomp, const BaseFab< Long > &y, const Box &ybx, int ycomp, int numcomp=1) const noexcept
BaseFab< Long > & divide(Long const &r, int comp, int numcomp=1) noexcept
Array4< T const > array(int start_comp) const noexcept
Create a sliced Array4 view beginning at component start_comp.
Definition AMReX_BaseFab.H:508
BaseFab< T > & operator/=(T const &val) noexcept
Definition AMReX_BaseFab.H:3589
std::pair< Long, Long > minmax(int comp=0) const noexcept
Array4< T const > const_array(int start_comp) const noexcept
Return a const-qualified Array4 view beginning at component start_comp.
Definition AMReX_BaseFab.H:580
void setVal(T const &x, const Box &bx, int dcomp, int ncomp) noexcept
The setVal functions set sub-regions in the BaseFab to a constant value. This most general form speci...
Definition AMReX_BaseFab.H:1537
Long size() const noexcept
Returns the total number of points of all components.
Definition AMReX_BaseFab.H:375
BaseFab< Long > & plus(Long const &r, const Box &b, int comp=0, int numcomp=1) noexcept
BaseFab< T > & operator=(const BaseFab< T > &rhs)=delete
void getVal(T *data, const IntVect &pos, int N, int numcomp) const noexcept
This function puts numcomp component values, starting at component N, from position pos in the domain...
Definition AMReX_BaseFab.H:1453
const IntVect & bigEnd() const noexcept
Returns the upper corner of the domain. See class Box for analogue.
Definition AMReX_BaseFab.H:393
Array4< T > array(int start_comp) noexcept
Mutable overload selecting components starting at start_comp.
Definition AMReX_BaseFab.H:543
Long numPts() const noexcept
Returns the number of points.
Definition AMReX_BaseFab.H:372
const T * dataPtr(int n=0) const noexcept
Const-qualified variant of dataPtr().
Definition AMReX_BaseFab.H:448
void setValIfNot(T const &val, Box const &bx, const BaseFab< int > &mask, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3300
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3511
BaseFab< T > & divide(const BaseFab< T > &src, Box bx, SrcComp scomp, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx does not intersect with src fab.
Definition AMReX_BaseFab.H:3629
void setValIfNot(Long const &val, const Box &bx, const BaseFab< int > &mask, int nstart, int num) noexcept
BaseFab< Long > & shiftHalf(int dir, int n_cell) noexcept
void setVal(T const &x, const Box &bx, int N=0) noexcept
Set a single component N over bx to x.
Definition AMReX_BaseFab.H:1521
void prefetchToDevice() const noexcept
T * dataPtr(int n=0) noexcept
Returns a pointer to an object of type T that is the value of the Nth component associated with the c...
Definition AMReX_BaseFab.H:439
bool ptr_owner
Definition AMReX_BaseFab.H:1306
virtual ~BaseFab() noexcept
The destructor deletes the array memory.
Definition AMReX_BaseFab.H:1726
IntVect length() const noexcept
Returns a pointer to an array of SPACEDIM integers giving the length of the domain in each direction.
Definition AMReX_BaseFab.H:384
IntVect maxIndex(int comp=0) const noexcept
BaseFab< Long > & protected_divide(const BaseFab< Long > &src) noexcept
friend class BaseFab
Definition AMReX_BaseFab.H:246
BaseFab< Long > & invert(Long const &r, const Box &b, int comp=0, int numcomp=1) noexcept
Array4< T const > array(int start_comp, int num_comps) const noexcept
Create a sliced Array4 view spanning num_comps components.
Definition AMReX_BaseFab.H:521
int nComp() const noexcept
Returns the number of components.
Definition AMReX_BaseFab.H:364
Long dotmask(const BaseFab< int > &mask, const Box &xbx, int xcomp, const BaseFab< Long > &y, const Box &ybx, int ycomp, int numcomp) const noexcept
BaseFab< T > & plus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3403
BaseFab() noexcept=default
Construct an empty BaseFab, which must be resized (see BaseFab::resize) before use.
BaseFab< T > & divide(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3613
void prefetchToHost() const noexcept
Advise the runtime to migrate storage to the host.
Definition AMReX_BaseFab.H:1341
Long min(int comp=0) const noexcept
void setComplement(Long const &x, const Box &b, int ns, int num) noexcept
BaseFab< Long > & linInterp(const BaseFab< Long > &f1, const Box &b1, int comp1, const BaseFab< Long > &f2, const Box &b2, int comp2, Real t1, Real t2, Real t, const Box &b, int comp, int numcomp=1) noexcept
IntVect minIndex(int comp=0) const noexcept
T * dataPtr(const IntVect &p, int n=0) noexcept
Return a pointer to the element at spatial index p and component n.
Definition AMReX_BaseFab.H:1316
void getVal(T *data, const IntVect &pos) const noexcept
Copy all components beginning at component 0.
Definition AMReX_BaseFab.H:1471
BaseFab< T > & plus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3387
Real norm(int p, int scomp=0, int numcomp=1) const
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:385
__host__ __device__ bool sameSize(const BoxND &b) const noexcept
Return true is Boxes same size, ie translates of each other,. It is an error if they have different t...
Definition AMReX_Box.H:312
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
__host__ __device__ bool ok() const noexcept
Return true if high bounds are >= low bounds and the index type is valid.
Definition AMReX_Box.H:229
GPU-compatible tuple.
Definition AMReX_Tuple.H:104
static int deviceId() noexcept
Definition AMReX_GpuDevice.cpp:828
static int devicePropMajor() noexcept
Definition AMReX_GpuDevice.H:206
Definition AMReX_GpuElixir.H:13
__host__ static __device__ constexpr IntVectND< dim > TheMinVector() noexcept
Definition AMReX_IntVect.H:848
T * data() noexcept
Definition AMReX_PODVector.H:672
Definition AMReX_Reduce.H:556
Type value()
Definition AMReX_Reduce.H:591
GpuTuple< Ts... > Type
Definition AMReX_Reduce.H:558
Definition AMReX_Reduce.H:715
void eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:855
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1377
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1391
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1352
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1363
std::array< T, N > Array
Definition AMReX_Array.H:31
PODVector< T, ArenaAllocator< T > > DeviceVector
A PODVector that uses the standard memory Arena. Note that the memory might or might not be managed d...
Definition AMReX_GpuContainers.H:24
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:54
__host__ __device__ bool almostEqual(T x, T y, int ulp=2)
Definition AMReX_Algorithm.H:140
__host__ __device__ AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
Definition AMReX_GpuAtomic.H:542
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:454
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:440
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:310
Definition AMReX_Amr.cpp:50
MakeType
Definition AMReX_MakeType.H:7
@ make_deep_copy
Definition AMReX_MakeType.H:7
@ make_alias
Definition AMReX_MakeType.H:7
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
void placementNew(T *const ptr, Long n, RunOn run_on=RunOn::Device)
Start the lifetime of objects in a preallocated buffer.
Definition AMReX_BaseFab.H:152
@ F
Definition AMReX_Order.H:7
__host__ __device__ Array4< T > makeArray4(T *p, Box const &bx, int ncomp) noexcept
Definition AMReX_BaseFab.H:137
void placementDelete(T *const ptr, Long n, RunOn run_on=RunOn::Device)
Destroy objects previously constructed via placementNew.
Definition AMReX_BaseFab.H:173
RunOn
Definition AMReX_GpuControl.H:65
@ Host
Definition AMReX_GpuControl.H:65
@ Device
Definition AMReX_GpuControl.H:65
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Return the iterator begin coordinate of box as Dim3.
Definition AMReX_Box.H:2241
bool InitSNaN() noexcept
Whether new allocations are filled with signaling NaNs when enabled.
Definition AMReX.cpp:183
void fill_snan(T *p, std::size_t nelems)
Definition AMReX_MemPool.H:24
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
Long TotalBytesAllocatedInFabs() noexcept
Total bytes currently held by all BaseFab instances on this rank.
Definition AMReX_BaseFab.cpp:66
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
void BaseFab_Initialize()
Initialize BaseFab subsystem resources (profilers, stats counters, etc.).
Definition AMReX_BaseFab.cpp:30
void BaseFab_Finalize()
Release any BaseFab subsystem resources.
Definition AMReX_BaseFab.cpp:59
void ResetTotalBytesAllocatedInFabsHWM() noexcept
Reset the byte high-water mark reported by TotalBytesAllocatedInFabsHWM().
Definition AMReX_BaseFab.cpp:134
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:3028
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns a BoxList defining the complement of b2 in b1in.
Definition AMReX_BoxList.cpp:621
@ y
Definition AMReX_Orientation.H:14
@ x
Definition AMReX_Orientation.H:14
@ z
Definition AMReX_Orientation.H:14
IndexTypeND< 3 > IndexType
IndexType is an alias for amrex::IndexTypeND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:41
Long TotalBytesAllocatedInFabsHWM() noexcept
High-water mark of BaseFab bytes since the last reset.
Definition AMReX_BaseFab.cpp:83
__host__ __device__ T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition AMReX_GpuComplex.H:361
Long TotalCellsAllocatedInFabsHWM() noexcept
High-water mark of Real BaseFab grid-point count since the last reset.
Definition AMReX_BaseFab.cpp:117
Long TotalCellsAllocatedInFabs() noexcept
Total spatial grid points (numPts) tracked for Real BaseFabs on this rank.
Definition AMReX_BaseFab.cpp:100
void Error(const std::string &msg)
Print a message to stderr and abort the program.
Definition AMReX.cpp:233
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2259
void update_fab_stats(Long n, Long s, size_t szt) noexcept
Definition AMReX_BaseFab.cpp:146
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:2174
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get the Idx-th element of IntVectND<dim>.
Definition AMReX_IntVect.H:1367
__host__ __device__ constexpr std::size_t size() const noexcept
Total number of elements in the ArrayND's index region.
Definition AMReX_Array4.H:659
__host__ __device__ T * ptr(idx... i) const noexcept
Multi-index ptr() for accessing pointer to element.
Definition AMReX_Array4.H:577
DataAllocator() noexcept=default
Default-construct; alloc/free will use The_Arena().
Arena * arena() const noexcept
Return the stored arena, or The_Arena() if none was set.
Definition AMReX_DataAllocator.H:41
void free(void *pt) const noexcept
Return the allocation at pt to the arena.
Definition AMReX_DataAllocator.H:36
Arena * m_arena
Stored arena pointer (may be null).
Definition AMReX_DataAllocator.H:22
void * alloc(std::size_t sz) const
Allocate sz bytes from the arena. Throws OutOfMemoryError on failure.
Definition AMReX_DataAllocator.H:31
Custom deleter that returns memory to an Arena.
Definition AMReX_DataAllocator.H:53
Destination-component descriptor.
Definition AMReX_BaseFab.H:105
int i
Definition AMReX_BaseFab.H:108
__host__ __device__ DestComp(int ai) noexcept
Definition AMReX_BaseFab.H:107
A simple struct holding 3 int values for a 3D index.
Definition AMReX_Dim3.H:24
int x
Definition AMReX_Dim3.H:24
int z
Definition AMReX_Dim3.H:24
int y
Definition AMReX_Dim3.H:24
Definition AMReX_TypeTraits.H:51
Number-of-components descriptor.
Definition AMReX_BaseFab.H:112
__host__ __device__ NumComps(int an) noexcept
Definition AMReX_BaseFab.H:114
int n
Definition AMReX_BaseFab.H:115
Source-component descriptor.
Definition AMReX_BaseFab.H:98
__host__ __device__ SrcComp(int ai) noexcept
Definition AMReX_BaseFab.H:100
int i
Definition AMReX_BaseFab.H:101