1#ifndef AMREX_BASEFAB_H_
2#define AMREX_BASEFAB_H_
3#include <AMReX_Config.H>
49extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs;
50extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs_hwm;
51extern std::atomic<Long> atomic_total_cells_allocated_in_fabs;
52extern std::atomic<Long> atomic_total_cells_allocated_in_fabs_hwm;
53extern Long private_total_bytes_allocated_in_fabs;
54extern Long private_total_bytes_allocated_in_fabs_hwm;
55extern Long private_total_cells_allocated_in_fabs;
56extern Long private_total_cells_allocated_in_fabs_hwm;
58#pragma omp threadprivate(private_total_bytes_allocated_in_fabs)
59#pragma omp threadprivate(private_total_bytes_allocated_in_fabs_hwm)
60#pragma omp threadprivate(private_total_cells_allocated_in_fabs)
61#pragma omp threadprivate(private_total_cells_allocated_in_fabs_hwm)
140 if constexpr (!std::is_trivially_default_constructible_v<T>) {
161 if constexpr (!std::is_trivially_destructible_v<T>) {
240 bool shared = false,
Arena* ar =
nullptr);
319 requires (std::is_trivially_destructible_v<U>)
332 [[nodiscard]] std::
size_t nBytes () const noexcept {
return this->
truesize*
sizeof(T); }
339 [[nodiscard]] std::size_t
nBytes (
const Box& bx,
int ncomps)
const noexcept
340 {
return bx.numPts() *
sizeof(T) * ncomps; }
343 [[nodiscard]]
int nComp () const noexcept {
return this->
nvar; }
346 [[nodiscard]]
const int*
nCompPtr() const noexcept {
347 return &(this->
nvar);
357 [[nodiscard]]
const Box&
box () const noexcept {
return this->
domain; }
382 [[nodiscard]]
const int*
loVect () const noexcept {
return this->
domain.loVect(); }
392 [[nodiscard]]
const int*
hiVect () const noexcept {
return this->
domain.hiVect(); }
418 [[nodiscard]] T*
dataPtr (
int n = 0) noexcept {
420 return &(this->
dptr[n*this->
domain.numPts()]);
427 [[nodiscard]]
const T*
dataPtr (
int n = 0) const noexcept {
429 return &(this->
dptr[n*this->
domain.numPts()]);
601 void getVal (T* data,
const IntVect& pos,
int N,
int numcomp)
const noexcept;
605 template <RunOn run_on AMREX_DEFAULT_RUNON>
606 requires (std::is_same_v<T,float> || std::is_same_v<T,double>)
615 template <RunOn run_on AMREX_DEFAULT_RUNON>
616 void setVal (T
const&
x,
const Box& bx,
int dcomp,
int ncomp)
noexcept;
618 template <RunOn run_on AMREX_DEFAULT_RUNON>
653 const
Box& destbox,
int destcomp,
int numcomp) noexcept;
663 int numcomp = 1) noexcept;
676 int numcomp,
void* dst) const noexcept;
681 int numcomp, const
void* src) noexcept;
686 int numcomp, const
void* src) noexcept;
723 [[nodiscard]]
Real norm (
int p,
int scomp = 0,
int numcomp = 1) const;
727 [[nodiscard]]
Real norm (const
Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const;
733 void abs (
int comp,
int numcomp=1) noexcept;
738 void abs (const
Box& subbox,
int comp = 0,
int numcomp=1) noexcept;
743 [[nodiscard]] T
min (
int comp = 0) const noexcept;
748 [[nodiscard]] T
min (const
Box& subbox,
int comp = 0) const noexcept;
753 [[nodiscard]] T
max (
int comp = 0) const noexcept;
758 [[nodiscard]] T
max (const
Box& subbox,
int comp = 0) const noexcept;
763 [[nodiscard]] std::pair<T,T>
minmax (
int comp = 0) const noexcept;
768 [[nodiscard]] std::pair<T,T>
minmax (const
Box& subbox,
int comp = 0) const noexcept;
773 [[nodiscard]] T
maxabs (
int comp = 0) const noexcept;
778 [[nodiscard]] T
maxabs (const
Box& subbox,
int comp = 0) const noexcept;
846 [[nodiscard]] T
sum (
int comp,
int numcomp = 1) const noexcept;
849 [[nodiscard]] T
sum (const
Box& subbox,
int comp,
int numcomp = 1) const noexcept;
893 int srccomp,
int destcomp,
int numcomp=1) noexcept;
913 int numcomp=1) noexcept;
920 int srccomp,
int destcomp,
int numcomp=1) noexcept;
929 int srccomp,
int destcomp,
int numcomp) noexcept;
934 int srccomp,
int destcomp,
int numcomp=1) noexcept;
942 int srccomp,
int destcomp,
int numcomp=1) noexcept;
947 const
BaseFab<T>& src1,
int comp1,
948 const
BaseFab<T>& src2,
int comp2) noexcept;
964 int numcomp=1) noexcept;
971 int srccomp,
int destcomp,
int numcomp=1) noexcept;
995 int numcomp=1) noexcept;
1003 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1028 int numcomp=1) noexcept;
1035 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1060 int numcomp=1) noexcept;
1069 int srccomp,
int destcomp,
int numcomp=1) noexcept;
1083 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
1085 const
Box& b,
int comp,
int numcomp = 1) noexcept;
1090 const
BaseFab<T>& f2,
int comp2,
1092 const
Box& b,
int comp,
int numcomp = 1) noexcept;
1105 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
1107 int comp,
int numcomp = 1) noexcept;
1112 int numcomp = 1) const noexcept;
1117 int numcomp) const noexcept;
1127 template <RunOn run_on AMREX_DEFAULT_RUNON>
1131 template <RunOn run_on AMREX_DEFAULT_RUNON>
1134 template <RunOn run_on AMREX_DEFAULT_RUNON>
1138 template <RunOn run_on AMREX_DEFAULT_RUNON>
1141 template <RunOn run_on AMREX_DEFAULT_RUNON>
1145 template <RunOn run_on AMREX_DEFAULT_RUNON>
1149 template <RunOn run_on AMREX_DEFAULT_RUNON>
1157 template <RunOn run_on AMREX_DEFAULT_RUNON>
1161 template <RunOn run_on AMREX_DEFAULT_RUNON>
1165 template <RunOn run_on AMREX_DEFAULT_RUNON>
1168 template <RunOn run_on AMREX_DEFAULT_RUNON>
1172 template <RunOn run_on AMREX_DEFAULT_RUNON>
1179 template <RunOn run_on AMREX_DEFAULT_RUNON>
1182 template <RunOn run_on AMREX_DEFAULT_RUNON>
1186 template <RunOn run_on AMREX_DEFAULT_RUNON>
1190 template <RunOn run_on AMREX_DEFAULT_RUNON>
1193 template <RunOn run_on AMREX_DEFAULT_RUNON>
1197 template <RunOn run_on AMREX_DEFAULT_RUNON>
1204 template <RunOn run_on AMREX_DEFAULT_RUNON>
1207 template <RunOn run_on AMREX_DEFAULT_RUNON>
1211 template <RunOn run_on AMREX_DEFAULT_RUNON>
1215 template <RunOn run_on AMREX_DEFAULT_RUNON>
1218 template <RunOn run_on AMREX_DEFAULT_RUNON>
1222 template <RunOn run_on AMREX_DEFAULT_RUNON>
1229 template <RunOn run_on AMREX_DEFAULT_RUNON>
1232 template <RunOn run_on AMREX_DEFAULT_RUNON>
1236 template <RunOn run_on AMREX_DEFAULT_RUNON>
1240 template <RunOn run_on AMREX_DEFAULT_RUNON>
1243 template <RunOn run_on AMREX_DEFAULT_RUNON>
1247 template <RunOn run_on AMREX_DEFAULT_RUNON>
1254 template <RunOn run_on AMREX_DEFAULT_RUNON>
1257 template <RunOn run_on AMREX_DEFAULT_RUNON>
1261 template <RunOn run_on AMREX_DEFAULT_RUNON>
1265 template <RunOn run_on AMREX_DEFAULT_RUNON>
1288 [[nodiscard]] T
dot (const
Box& bx,
int destcomp,
int numcomp) const noexcept;
1345 if (this->
arena()->isManaged()) {
1346#if defined(AMREX_USE_SYCL)
1351#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1353 std::size_t s =
sizeof(T)*this->
nvar*this->
domain.numPts();
1354#if defined(CUDART_VERSION) && (CUDART_VERSION >= 13000)
1355 cudaMemLocation location = {};
1356 location.type = cudaMemLocationTypeHost;
1365#elif defined(AMREX_USE_HIP)
1377 if (this->
arena()->isManaged()) {
1378#if defined(AMREX_USE_SYCL)
1379 std::size_t s =
sizeof(T)*this->
nvar*this->
domain.numPts();
1380 auto& q = Gpu::Device::streamQueue();
1381 q.submit([&] (sycl::handler& h) { h.prefetch(this->
dptr, s); });
1382#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1384 std::size_t s =
sizeof(T)*this->
nvar*this->
domain.numPts();
1385#if defined(CUDART_VERSION) && (CUDART_VERSION >= 13000)
1386 cudaMemLocation location = {};
1387 location.type = cudaMemLocationTypeDevice;
1397#elif defined(AMREX_USE_HIP)
1457 int numcomp)
const noexcept
1465 for (
int k = 0; k < numcomp; k++) {
1466 data[k] = this->
dptr[loc+(n+k)*sz];
1473 const IntVect& pos)
const noexcept
1490 this->
domain.shift(idir,n_cell);
1498 this->
domain.shiftHalf(v);
1506 this->
domain.shiftHalf(idir,n_cell);
1511template <RunOn run_on>
1512requires (std::is_same_v<T,float> || std::is_same_v<T,double>)
1520template <RunOn run_on>
1528template <RunOn run_on>
1536template <RunOn run_on>
1544template <RunOn run_on>
1552template <RunOn run_on>
1555 const Box& destbox,
int destcomp,
int numcomp)
noexcept
1561 AMREX_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
1568 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
1572 d(i,j,k,n+destcomp) = s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
1579template <RunOn run_on>
1587template <RunOn run_on>
1601 if (this->
nvar == 0) {
return; }
1606 this->
dptr =
static_cast<T*
>(this->
alloc(n*
sizeof(T)));
1617 if constexpr (std::is_same_v<T,float> || std::is_same_v<T,double>) {
1661 this->
dptr =
nullptr;
1708 :
dptr(
const_cast<T*
>(a.p)),
1716 :
dptr(
const_cast<T*
>(a.p)),
1731 dptr(rhs.dptr), domain(rhs.domain),
1732 nvar(rhs.nvar), truesize(rhs.truesize),
1733 ptr_owner(rhs.ptr_owner), shared_memory(rhs.shared_memory)
1735 , alloc_stream(rhs.alloc_stream)
1739 rhs.ptr_owner =
false;
1748 DataAllocator::operator=(rhs);
1760 rhs.ptr_owner =
false;
1766template <RunOn run_on>
1781 if (ar ==
nullptr) {
1793 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1796 this->
dptr =
nullptr;
1799 else if (this->
nvar*this->
domain.numPts() > this->truesize
1806 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1817requires (std::is_trivially_destructible_v<U>)
1825 if (o && this->
dptr) {
1826 if (this->
nvar > 0) {
1851 amrex::Abort(
"BaseFab::clear: BaseFab cannot be owner of shared memory");
1862 if (this->
nvar > 0) {
1869 this->
dptr =
nullptr;
1875std::unique_ptr<T,DataDeleter>
1880 r.reset(this->
dptr);
1882 if (this->
nvar > 0) {
1892template <RunOn run_on>
1897 void* dst)
const noexcept
1908 d(i,j,k,n) = s(i,j,k,n+srccomp);
1910 return sizeof(T)*d.
size();
1919template <RunOn run_on,
typename BUF>
1924 const void* src)
noexcept
1936 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1938 return sizeof(BUF)*s.
size();
1947template <RunOn run_on,
typename BUF>
1952 const void* src)
noexcept
1964 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1966 return sizeof(BUF)*s.
size();
1975template <RunOn run_on>
1983template <RunOn run_on>
1991template <RunOn run_on>
1999template <RunOn run_on>
2006 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
2014template <
typename Op,
typename T,
typename F>
2016T basefab_reduce_cpu (
Box const& bx,
int ncomp, T
const& init,
F const& f)
noexcept
2020 Reduce::detail::Lanes<Tup> acc;
2021 Reduce::detail::lanes_set<0>(acc, rem);
2024 for (
int n = 0; n < ncomp; ++n) {
2025 for (
int k = lo.z; k <= hi.z; ++k) {
2026 for (
int j = lo.y; j <= hi.y; ++j) {
2027 Reduce::detail::reduce_row<Op>(lo.x, hi.x, acc, rem,
2028 [&] (
int i) { return Tup{static_cast<T>(f(i,j,k,n))}; });
2030 Reduce::detail::lanes_fold<0,Tup,Op>(acc, rem);
2037template <RunOn run_on>
2040 int scomp,
int ncomp)
const noexcept
2053 reduce_op.
eval(subbox, reduce_data,
2058 for (
int n = 0; n < ncomp; ++n) {
2064 ReduceTuple hv = reduce_data.
value(reduce_op);
2069 r = detail::basefab_reduce_cpu<ReduceOpMax>(subbox, ncomp,
Real(0.0),
2070 [=] (
int i,
int j,
int k,
int n)
noexcept
2072 auto const t = a(i,j,k,n+scomp);
2073 return static_cast<Real>(m(i,j,k) ? std::abs(t) : T(0));
2080template <RunOn run_on>
2088template <RunOn run_on>
2103 reduce_op.
eval(subbox, reduce_data,
2107 for (
int n = 0; n < numcomp; ++n) {
2112 ReduceTuple hv = reduce_data.
value(reduce_op);
2114 }
else if (
p == 1) {
2118 reduce_op.
eval(subbox, reduce_data,
2122 for (
int n = 0; n < numcomp; ++n) {
2123 t +=
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
2127 ReduceTuple hv = reduce_data.
value(reduce_op);
2129 }
else if (
p == 2) {
2133 reduce_op.
eval(subbox, reduce_data,
2137 for (
int n = 0; n < numcomp; ++n) {
2138 t +=
static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
2142 ReduceTuple hv = reduce_data.
value(reduce_op);
2151 nrm = detail::basefab_reduce_cpu<ReduceOpMax>(subbox, numcomp,
Real(0.0),
2152 [=] (
int i,
int j,
int k,
int n)
noexcept
2154 return static_cast<Real>(std::abs(a(i,j,k,n+comp)));
2156 }
else if (
p == 1) {
2157 nrm = detail::basefab_reduce_cpu<ReduceOpSum>(subbox, numcomp,
Real(0.0),
2158 [=] (
int i,
int j,
int k,
int n)
noexcept
2160 return static_cast<Real>(std::abs(a(i,j,k,n+comp)));
2162 }
else if (
p == 2) {
2163 nrm = detail::basefab_reduce_cpu<ReduceOpSum>(subbox, numcomp,
Real(0.0),
2164 [=] (
int i,
int j,
int k,
int n)
noexcept
2166 return static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
2177template <RunOn run_on>
2185template <RunOn run_on>
2194 using ReduceTuple =
typename decltype(reduce_data)::Type;
2195 reduce_op.
eval(subbox, reduce_data,
2198 return { a(i,j,k) };
2200 ReduceTuple hv = reduce_data.
value(reduce_op);
2205 return detail::basefab_reduce_cpu<ReduceOpMin>(subbox, 1, std::numeric_limits<T>::max(),
2206 [=] (
int i,
int j,
int k,
int)
noexcept
2214template <RunOn run_on>
2222template <RunOn run_on>
2231 using ReduceTuple =
typename decltype(reduce_data)::Type;
2232 reduce_op.
eval(subbox, reduce_data,
2235 return { a(i,j,k) };
2237 ReduceTuple hv = reduce_data.
value(reduce_op);
2242 return detail::basefab_reduce_cpu<ReduceOpMax>(subbox, 1, std::numeric_limits<T>::lowest(),
2243 [=] (
int i,
int j,
int k,
int)
noexcept
2251template <RunOn run_on>
2259template <RunOn run_on>
2268 using ReduceTuple =
typename decltype(reduce_data)::Type;
2269 reduce_op.
eval(subbox, reduce_data,
2272 auto const x = a(i,j,k);
2275 ReduceTuple hv = reduce_data.
value(reduce_op);
2281 MM rem{std::numeric_limits<T>::max(), std::numeric_limits<T>::lowest()};
2282 Reduce::detail::Lanes<MM> acc;
2283 Reduce::detail::lanes_set<0>(acc, rem);
2286 for (
int k = lo.z; k <= hi.z; ++k) {
2287 for (
int j = lo.y; j <= hi.y; ++j) {
2288 Reduce::detail::reduce_row<ReduceOpMin,ReduceOpMax>(lo.x, hi.x, acc, rem,
2289 [&] (
int i) { auto const x = a(i,j,k); return MM{x,x}; });
2291 Reduce::detail::lanes_fold<0,MM,ReduceOpMin,ReduceOpMax>(acc, rem);
2297template <RunOn run_on>
2305template <RunOn run_on>
2314 using ReduceTuple =
typename decltype(reduce_data)::Type;
2315 reduce_op.
eval(subbox, reduce_data,
2318 return { std::abs(a(i,j,k)) };
2320 ReduceTuple hv = reduce_data.
value(reduce_op);
2325 return detail::basefab_reduce_cpu<ReduceOpMax>(subbox, 1, T(0),
2326 [=] (
int i,
int j,
int k,
int)
noexcept
2328 return std::abs(a(i,j,k));
2335template <RunOn run_on>
2343 std::numeric_limits<int>::lowest(),
2344 std::numeric_limits<int>::lowest())};
2351 if ((*flag == 0) && (a(i,j,k) == value)) {
2374template <RunOn run_on>
2382template <RunOn run_on>
2391template <RunOn run_on>
2400template <RunOn run_on>
2408template <RunOn run_on>
2417template <RunOn run_on>
2426template <RunOn run_on>
2430 mask.resize(this->
domain,1);
2438 using ReduceTuple =
typename decltype(reduce_data)::Type;
2443 if (a(i,j,k) < val) {
2452 ReduceTuple hv = reduce_data.
value(reduce_op);
2459 if (a(i,j,k) < val) {
2472template <RunOn run_on>
2476 mask.resize(this->
domain,1);
2484 using ReduceTuple =
typename decltype(reduce_data)::Type;
2489 if (a(i,j,k) <= val) {
2498 ReduceTuple hv = reduce_data.
value(reduce_op);
2505 if (a(i,j,k) <= val) {
2518template <RunOn run_on>
2522 mask.resize(this->
domain,1);
2530 using ReduceTuple =
typename decltype(reduce_data)::Type;
2535 if (a(i,j,k) == val) {
2544 ReduceTuple hv = reduce_data.
value(reduce_op);
2551 if (a(i,j,k) == val) {
2564template <RunOn run_on>
2568 mask.resize(this->
domain,1);
2576 using ReduceTuple =
typename decltype(reduce_data)::Type;
2581 if (a(i,j,k) > val) {
2590 ReduceTuple hv = reduce_data.
value(reduce_op);
2597 if (a(i,j,k) > val) {
2610template <RunOn run_on>
2614 mask.resize(this->
domain,1);
2622 using ReduceTuple =
typename decltype(reduce_data)::Type;
2627 if (a(i,j,k) >= val) {
2636 ReduceTuple hv = reduce_data.
value(reduce_op);
2643 if (a(i,j,k) >= val) {
2656template <RunOn run_on>
2666template <RunOn run_on>
2669 int srccomp,
int destcomp,
int numcomp)
noexcept
2676 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2683 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2686 d(i,j,k,n+destcomp) += a * s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
2693template <RunOn run_on>
2703template <RunOn run_on>
2706 const Box& srcbox,
const Box& destbox,
2707 int srccomp,
int destcomp,
int numcomp)
noexcept
2714 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2721 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2724 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);
2731template <RunOn run_on>
2739 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2740 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2748 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2755template <RunOn run_on>
2760 int comp,
int numcomp)
noexcept
2770 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2771 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2780 const Dim3 off1{.x = slo1.x-dlo.x, .y = slo1.y-dlo.y, .z = slo1.z-dlo.z};
2781 const Dim3 off2{.x = slo2.x-dlo.x, .y = slo2.y-dlo.y, .z = slo2.z-dlo.z};
2785 d(i,j,k,n+comp) = alpha*s1(i+off1.
x,j+off1.
y,k+off1.
z,n+comp1)
2786 + beta*s2(i+off2.
x,j+off2.
y,k+off2.
z,n+comp2);
2792template <RunOn run_on>
2796 int numcomp)
const noexcept
2803 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2809 const Dim3 offset{.x = ylo.x-xlo.x, .y = ylo.y-xlo.y, .z = ylo.z-xlo.z};
2817 using ReduceTuple =
typename decltype(reduce_data)::Type;
2818 reduce_op.
eval(xbx, reduce_data,
2822 for (
int n = 0; n < numcomp; ++n) {
2823 t += xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp);
2827 ReduceTuple hv = reduce_data.
value(reduce_op);
2832 r = detail::basefab_reduce_cpu<ReduceOpSum>(xbx, numcomp, T(0),
2833 [=] (
int i,
int j,
int k,
int n)
noexcept
2835 return xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp);
2843template <RunOn run_on>
2847 int numcomp)
const noexcept
2854 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2860 const Dim3 offset{.x = ylo.x-xlo.x, .y = ylo.y-xlo.y, .z = ylo.z-xlo.z};
2870 using ReduceTuple =
typename decltype(reduce_data)::Type;
2871 reduce_op.
eval(xbx, reduce_data,
2874 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2876 for (
int n = 0; n < numcomp; ++n) {
2877 t += xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp) * m;
2881 ReduceTuple hv = reduce_data.
value(reduce_op);
2886 r = detail::basefab_reduce_cpu<ReduceOpSum>(xbx, numcomp, T(0),
2887 [=] (
int i,
int j,
int k,
int n)
noexcept
2889 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2890 return xa(i,j,k,n+xcomp) * ya(i+offset.
x,j+offset.
y,k+offset.
z,n+ycomp) * m;
2898template <RunOn run_on>
2906template <RunOn run_on>
2914template <RunOn run_on>
2922template <RunOn run_on>
2930template <RunOn run_on>
2938template <RunOn run_on>
2946template <RunOn run_on>
2954template <RunOn run_on>
2962template <RunOn run_on>
2970template <RunOn run_on>
2976 return ovlp.
ok() ? this->
atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2980template <RunOn run_on>
2983 int numcomp)
noexcept
2989template <RunOn run_on>
2992 int numcomp)
noexcept
2997 return ovlp.
ok() ? this->
atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3001template <RunOn run_on>
3004 int srccomp,
int destcomp,
int numcomp)
noexcept
3010 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3017 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3020 d(i,j,k,n+destcomp) += s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3029template <RunOn run_on,
typename T>
3032 const Box& srcbox,
const Box& destbox,
3033 int srccomp,
int destcomp,
int numcomp)
noexcept
3039 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3042 T*
p = d.
ptr(i,j,k,n+destcomp);
3043 HostDevice::Atomic::Add(
p, s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp));
3047template <RunOn run_on,
typename T>
3048requires (!HasAtomicAdd<T>::value)
3049void basefab_atomic_add (BaseFab<T>& dfab,
const BaseFab<T>& sfab,
3050 const Box& srcbox,
const Box& destbox,
3051 int srccomp,
int destcomp,
int numcomp)
3060template <RunOn run_on>
3063 int srccomp,
int destcomp,
int numcomp)
noexcept
3069 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3072 detail::basefab_atomic_add<run_on>(*
this, src, srcbox, destbox,
3073 srccomp, destcomp, numcomp);
3079template <RunOn run_on>
3082 int srccomp,
int destcomp,
int numcomp)
noexcept
3084#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
3085#if defined(AMREX_USE_GPU)
3092 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3101 Dim3 const offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3119 for (
int ip = 0; ip < nplanes; ++ip) {
3124 int planes_left = nplanes;
3125 while (planes_left > 0) {
3127 auto const m = mm + plo;
3128 auto* lock = OpenMP::get_lock(m);
3129 if (omp_test_lock(lock))
3133 if (planedim == 1) {
3141 for (
int n = 0; n < numcomp; ++n) {
3142 for (
int k = lo.z; k <= hi.z; ++k) {
3143 for (
int j = lo.y; j <= hi.y; ++j) {
3144 auto * pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
3145 auto const* psrc = s.
ptr(slo.x,j+offset.
y,k+offset.
z,n+ srccomp);
3147 for (
int ii = 0; ii < len.x; ++ii) {
3148 pdst[ii] += psrc[ii];
3156 omp_unset_lock(lock);
3157 if (planes_left == 0) {
break; }
3161 for (
int ip = 0; ip < nplanes; ++ip) {
3162 int new_mm = (mm+ip) % nplanes;
3163 if ( ! mask[new_mm] ) {
3174#if defined(AMREX_USE_GPU)
3176 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3180 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3185template <RunOn run_on>
3193template <RunOn run_on>
3201template <RunOn run_on>
3204 int srccomp,
int destcomp,
int numcomp)
noexcept
3210 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3217 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3220 d(i,j,k,n+destcomp) -= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3227template <RunOn run_on>
3235template <RunOn run_on>
3243template <RunOn run_on>
3251template <RunOn run_on>
3259template <RunOn run_on>
3262 int srccomp,
int destcomp,
int numcomp)
noexcept
3268 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3275 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3278 d(i,j,k,n+destcomp) *= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3285template <RunOn run_on>
3293template <RunOn run_on>
3301template <RunOn run_on>
3309template <RunOn run_on>
3317template <RunOn run_on>
3320 int srccomp,
int destcomp,
int numcomp)
noexcept
3326 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3333 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3336 d(i,j,k,n+destcomp) /= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3343template <RunOn run_on>
3353template <RunOn run_on>
3363template <RunOn run_on>
3366 int numcomp)
noexcept
3375template <RunOn run_on>
3378 int srccomp,
int destcomp,
int numcomp)
noexcept
3384 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3391 const Dim3 offset{.x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3394 if (s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp) != 0) {
3395 d(i,j,k,n+destcomp) /= s(i+offset.
x,j+offset.
y,k+offset.
z,n+srccomp);
3413template <RunOn run_on>
3418 const Box& b,
int comp,
int numcomp)
noexcept
3425 Real alpha = (t2-t)/(t2-t1);
3426 Real beta = (t-t1)/(t2-t1);
3427 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,b,comp,numcomp);
3432template <RunOn run_on>
3437 const Box& b,
int comp,
int numcomp)
noexcept
3444 Real alpha = (t2-t)/(t2-t1);
3445 Real beta = (t-t1)/(t2-t1);
3446 return linComb<run_on>(f1,b,comp1,f2,b,comp2,alpha,beta,b,comp,numcomp);
3455template <RunOn run_on>
3463template <RunOn run_on>
3467 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3471 a(i,j,k,n+dcomp.i) = x;
3476template <RunOn run_on>
3484template <RunOn run_on>
3488 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3493 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3498template <RunOn run_on>
3506template <RunOn run_on>
3510 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3515 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3520template <RunOn run_on>
3530 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3539 for (
auto const& b : b_lst) {
3546template <RunOn run_on>
3555template <RunOn run_on>
3561 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3562 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3570 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3577template <RunOn run_on>
3585template <RunOn run_on>
3593template <RunOn run_on>
3597 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3602 a(i,j,k,n+dcomp.i) += val;
3609template <RunOn run_on>
3617template <RunOn run_on>
3625template <RunOn run_on>
3631 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3632 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3640 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3647template <RunOn run_on>
3655template <RunOn run_on>
3663template <RunOn run_on>
3667 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3672 a(i,j,k,n+dcomp.i) -= val;
3679template <RunOn run_on>
3687template <RunOn run_on>
3695template <RunOn run_on>
3701 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3702 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3710 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3717template <RunOn run_on>
3725template <RunOn run_on>
3733template <RunOn run_on>
3737 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3742 a(i,j,k,n+dcomp.i) *= val;
3749template <RunOn run_on>
3757template <RunOn run_on>
3765template <RunOn run_on>
3771 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3772 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3780 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3787template <RunOn run_on>
3795template <RunOn run_on>
3803template <RunOn run_on>
3807 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3812 a(i,j,k,n+dcomp.i) /= val;
3819template <RunOn run_on>
3827template <RunOn run_on>
3835template <RunOn run_on>
3841 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3842 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3850 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3857template <RunOn run_on>
3865template <RunOn run_on>
3869 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3874 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3881template <RunOn run_on>
3889template <RunOn run_on>
3893 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3898 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3905template <RunOn run_on>
3909 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3917 using ReduceTuple =
typename decltype(reduce_data)::Type;
3918 reduce_op.
eval(bx, reduce_data,
3922 for (
int n = 0; n < ncomp.n; ++n) {
3923 t += a(i,j,k,n+dcomp.i);
3927 ReduceTuple hv = reduce_data.
value(reduce_op);
3932 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
3933 [=] (
int i,
int j,
int k,
int n)
noexcept
3935 return a(i,j,k,n+dcomp.i);
3943template <RunOn run_on>
3948 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3949 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3958 using ReduceTuple =
typename decltype(reduce_data)::Type;
3959 reduce_op.
eval(bx, reduce_data,
3963 for (
int n = 0; n < ncomp.n; ++n) {
3964 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3968 ReduceTuple hv = reduce_data.
value(reduce_op);
3973 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
3974 [=] (
int i,
int j,
int k,
int n)
noexcept
3976 return d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3984template <RunOn run_on>
3993template <RunOn run_on>
3997 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4005 using ReduceTuple =
typename decltype(reduce_data)::Type;
4006 reduce_op.
eval(bx, reduce_data,
4010 for (
int n = 0; n < ncomp.n; ++n) {
4011 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
4015 ReduceTuple hv = reduce_data.
value(reduce_op);
4020 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
4021 [=] (
int i,
int j,
int k,
int n)
noexcept
4023 return a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
4031template <RunOn run_on>
4038 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
4039 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
4049 using ReduceTuple =
typename decltype(reduce_data)::Type;
4050 reduce_op.
eval(bx, reduce_data,
4054 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
4055 for (
int n = 0; n < ncomp.n; ++n) {
4056 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
4060 ReduceTuple hv = reduce_data.
value(reduce_op);
4065 r = detail::basefab_reduce_cpu<ReduceOpSum>(bx, ncomp.n, T(0),
4066 [=] (
int i,
int j,
int k,
int n)
noexcept
4068 int mi =
static_cast<int>(
static_cast<bool>(m(i,j,k)));
4069 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.
Aligned CPU heap-backed implementation of the Arena interface.
Assertion macros used across AMReX for runtime consistency checks.
#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.
Coalescing first-fit dynamic memory arena.
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:124
#define AMREX_ATTRIBUTE_FLATTEN_FOR
Definition AMReX_Extension.H:156
#define AMREX_DEFAULT_RUNON
Definition AMReX_GpuControl.H:69
#define AMREX_CUDA_SAFE_CALL(call)
Definition AMReX_GpuError.H:73
#define AMREX_HOST_DEVICE_FOR_1D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:105
#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:222
int maskGE(BaseFab< int > &mask, Long const &val, int comp=0) const noexcept
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:547
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:3557
Long sum(int comp, int numcomp=1) const noexcept
gpuStream_t alloc_stream
Definition AMReX_BaseFab.H:1310
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:3789
const int * hiVect() const noexcept
Returns the upper corner of the domain.
Definition AMReX_BaseFab.H:392
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:3697
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:334
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3548
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:3649
BaseFab< Long > & negate(const Box &b, int comp=0, int numcomp=1) noexcept
int maskLT(BaseFab< int > &mask, Long const &val, int comp=0) const noexcept
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3579
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3735
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:3767
std::size_t nBytes(const Box &bx, int ncomps) const noexcept
Returns bytes used in the Box for those components.
Definition AMReX_BaseFab.H:339
void setPtr(Long *p, Long sz) noexcept
Definition AMReX_BaseFab.H:457
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:3727
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:369
BaseFab< Long > & mult(Long const &r, int comp, int numcomp=1) noexcept
BaseFab< Long > & atomicAdd(const BaseFab< Long > &x) noexcept
int maskEQ(BaseFab< int > &mask, Long const &val, int comp=0) const noexcept
const int * loVect() const noexcept
Returns the lower corner of the domain.
Definition AMReX_BaseFab.H:382
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:398
bool isAllocated() const noexcept
Returns true if the data for the FAB has been allocated.
Definition AMReX_BaseFab.H:577
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:3465
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3657
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition AMReX_BaseFab.H:357
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:3486
Array4< T > array() noexcept
Create a mutable Array4 view over all components.
Definition AMReX_BaseFab.H:510
IntVect indexFromValue(const Box &subbox, int comp, Long const &value) const noexcept
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3751
bool shared_memory
Definition AMReX_BaseFab.H:1308
int maskLE(BaseFab< int > &mask, Long const &val, int comp=0) const noexcept
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3478
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:3627
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3500
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:1407
std::size_t nBytes() const noexcept
Definition AMReX_BaseFab.H:332
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:3859
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3681
BaseFab< Long > & minus(const BaseFab< Long > &src, int srccomp, int destcomp, int numcomp=1) noexcept
T value_type
Definition AMReX_BaseFab.H:227
void SetBoxType(const IndexType &typ) noexcept
Definition AMReX_BaseFab.H:1120
Array4< Long const > array() const noexcept
Definition AMReX_BaseFab.H:475
Long maxabs(int comp=0) const noexcept
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3587
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:3522
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3665
Long truesize
Definition AMReX_BaseFab.H:1306
void setVal(T const &val) noexcept
Set value on the whole domain and all components.
Definition AMReX_BaseFab.H:3457
const int * nCompPtr() const noexcept
for calls to fortran.
Definition AMReX_BaseFab.H:346
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:571
Box domain
Definition AMReX_BaseFab.H:1304
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:407
Long * dptr
Definition AMReX_BaseFab.H:1303
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:3805
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:535
int nvar
Definition AMReX_BaseFab.H:1305
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:487
BaseFab< T > & operator/=(T const &val) noexcept
Definition AMReX_BaseFab.H:3797
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:559
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:1538
Long size() const noexcept
Returns the total number of points of all components.
Definition AMReX_BaseFab.H:354
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:1454
const IntVect & bigEnd() const noexcept
Returns the upper corner of the domain. See class Box for analogue.
Definition AMReX_BaseFab.H:372
Array4< T > array(int start_comp) noexcept
Mutable overload selecting components starting at start_comp.
Definition AMReX_BaseFab.H:522
Long numPts() const noexcept
Returns the number of points.
Definition AMReX_BaseFab.H:351
const T * dataPtr(int n=0) const noexcept
Const-qualified variant of dataPtr().
Definition AMReX_BaseFab.H:427
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:3508
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3719
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:3837
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:1522
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:418
bool ptr_owner
Definition AMReX_BaseFab.H:1307
virtual ~BaseFab() noexcept
The destructor deletes the array memory.
Definition AMReX_BaseFab.H:1723
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:363
IntVect maxIndex(int comp=0) const noexcept
BaseFab< Long > & protected_divide(const BaseFab< Long > &src) noexcept
friend class BaseFab
Definition AMReX_BaseFab.H:225
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:500
int nComp() const noexcept
Returns the number of components.
Definition AMReX_BaseFab.H:343
int maskGT(BaseFab< int > &mask, Long const &val, int comp=0) const noexcept
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:3611
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:3821
void prefetchToHost() const noexcept
Advise the runtime to migrate storage to the host.
Definition AMReX_BaseFab.H:1342
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:1317
void getVal(T *data, const IntVect &pos) const noexcept
Copy all components beginning at component 0.
Definition AMReX_BaseFab.H:1472
BaseFab< T > & plus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3595
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__ 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:841
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:852
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:1365
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1379
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1340
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1351
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:487
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
@ F
Definition AMReX_Order.H:7
__host__ __device__ Array4< T > makeArray4(T *p, Box const &bx, int ncomp) noexcept
Definition AMReX_BaseFab.H:123
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:188
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:2980
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns a BoxList defining the complement of b2 in b1in.
Definition AMReX_BoxList.cpp:610
void placementNew(T *const ptr, Long n)
Start the lifetime of objects in a preallocated buffer.
Definition AMReX_BaseFab.H:137
@ 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
void placementDelete(T *const ptr, Long n)
Destroy objects previously constructed via placementNew.
Definition AMReX_BaseFab.H:158
__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:238
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:244
__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:2166
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get the Idx-th element of IntVectND<dim>.
Definition AMReX_IntVect.H:1360
__host__ __device__ constexpr std::size_t size() const noexcept
Total number of elements in the ArrayND's index region.
Definition AMReX_Array4.H:643
__host__ __device__ T * ptr(idx... i) const noexcept
Multi-index ptr() for accessing pointer to element.
Definition AMReX_Array4.H:561
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:107
int i
Definition AMReX_BaseFab.H:110
__host__ __device__ DestComp(int ai) noexcept
Definition AMReX_BaseFab.H:109
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:114
__host__ __device__ NumComps(int an) noexcept
Definition AMReX_BaseFab.H:116
int n
Definition AMReX_BaseFab.H:117
Source-component descriptor.
Definition AMReX_BaseFab.H:100
__host__ __device__ SrcComp(int ai) noexcept
Definition AMReX_BaseFab.H:102
int i
Definition AMReX_BaseFab.H:103