1#ifndef AMREX_BASEFAB_H_
2#define AMREX_BASEFAB_H_
3#include <AMReX_Config.H>
50#pragma omp threadprivate(private_total_bytes_allocated_in_fabs)
51#pragma omp threadprivate(private_total_bytes_allocated_in_fabs_hwm)
52#pragma omp threadprivate(private_total_cells_allocated_in_fabs)
53#pragma omp threadprivate(private_total_cells_allocated_in_fabs_hwm)
68 explicit SrcComp (
int ai) noexcept : i(ai) {}
93std::enable_if_t<std::is_arithmetic_v<T>>
98std::enable_if_t<std::is_trivially_default_constructible_v<T>
99 && !std::is_arithmetic_v<T>>
102 for (Long i = 0; i < n; ++i) {
108std::enable_if_t<!std::is_trivially_default_constructible_v<T>>
118std::enable_if_t<std::is_trivially_destructible_v<T>>
123std::enable_if_t<!std::is_trivially_destructible_v<T>>
199 bool shared = false,
Arena* ar =
nullptr);
249 template <class U=T, std::enable_if_t<std::is_trivially_destructible_v<U>,
int> = 0>
262 [[nodiscard]] std::
size_t nBytes () const noexcept {
return this->
truesize*
sizeof(T); }
269 [[nodiscard]] std::size_t
nBytes (
const Box& bx,
int ncomps)
const noexcept
270 {
return bx.numPts() *
sizeof(T) * ncomps; }
273 [[nodiscard]]
int nComp () const noexcept {
return this->
nvar; }
276 [[nodiscard]]
const int*
nCompPtr() const noexcept {
277 return &(this->
nvar);
287 [[nodiscard]]
const Box&
box () const noexcept {
return this->
domain; }
348 [[nodiscard]] T*
dataPtr (
int n = 0) noexcept {
357 [[nodiscard]]
const T*
dataPtr (
int n = 0) const noexcept {
453 void getVal (T* data,
const IntVect& pos,
int N,
int numcomp)
const noexcept;
458 class U=T, std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO = 0>
468 void setVal (T const&
x, const
Box& bx,
int dcomp,
int ncomp) noexcept;
505 const
Box& destbox,
int destcomp,
int numcomp) noexcept;
515 int numcomp = 1) noexcept;
528 int numcomp,
void* dst) const noexcept;
533 int numcomp, const
void* src) noexcept;
538 int numcomp, const
void* src) noexcept;
575 [[nodiscard]] Real
norm (
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
579 [[nodiscard]] Real
norm (const
Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
585 void abs (
int comp,
int numcomp=1) noexcept;
590 void abs (const
Box& subbox,
int comp = 0,
int numcomp=1) noexcept;
595 [[nodiscard]] T
min (
int comp = 0) const noexcept;
600 [[nodiscard]] T
min (const
Box& subbox,
int comp = 0) const noexcept;
605 [[nodiscard]] T
max (
int comp = 0) const noexcept;
610 [[nodiscard]] T
max (const
Box& subbox,
int comp = 0) const noexcept;
615 [[nodiscard]] std::pair<T,T>
minmax (
int comp = 0) const noexcept;
620 [[nodiscard]] std::pair<T,T>
minmax (const
Box& subbox,
int comp = 0) const noexcept;
625 [[nodiscard]] T
maxabs (
int comp = 0) const noexcept;
630 [[nodiscard]] T
maxabs (const
Box& subbox,
int comp = 0) const noexcept;
698 [[nodiscard]] T
sum (
int comp,
int numcomp = 1) const noexcept;
701 [[nodiscard]] T
sum (const
Box& subbox,
int comp,
int numcomp = 1) const noexcept;
745 int srccomp,
int destcomp,
int numcomp=1) noexcept;
765 int numcomp=1) noexcept;
772 int srccomp,
int destcomp,
int numcomp=1) noexcept;
781 int srccomp,
int destcomp,
int numcomp) noexcept;
786 int srccomp,
int destcomp,
int numcomp=1) noexcept;
794 int srccomp,
int destcomp,
int numcomp=1) noexcept;
799 const
BaseFab<T>& src1,
int comp1,
800 const
BaseFab<T>& src2,
int comp2) noexcept;
816 int numcomp=1) noexcept;
823 int srccomp,
int destcomp,
int numcomp=1) noexcept;
849 int numcomp=1) noexcept;
857 int srccomp,
int destcomp,
int numcomp=1) noexcept;
882 int numcomp=1) noexcept;
889 int srccomp,
int destcomp,
int numcomp=1) noexcept;
914 int numcomp=1) noexcept;
923 int srccomp,
int destcomp,
int numcomp=1) noexcept;
937 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
938 Real t1, Real t2, Real t,
939 const
Box&
b,
int comp,
int numcomp = 1) noexcept;
944 const
BaseFab<T>& f2,
int comp2,
945 Real t1, Real t2, Real t,
946 const
Box&
b,
int comp,
int numcomp = 1) noexcept;
959 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
960 Real alpha, Real beta, const
Box&
b,
961 int comp,
int numcomp = 1) noexcept;
966 int numcomp = 1) const noexcept;
971 int numcomp) const noexcept;
981 template <RunOn run_on AMREX_DEFAULT_RUNON>
985 template <RunOn run_on AMREX_DEFAULT_RUNON>
988 template <RunOn run_on AMREX_DEFAULT_RUNON>
992 template <RunOn run_on AMREX_DEFAULT_RUNON>
995 template <RunOn run_on AMREX_DEFAULT_RUNON>
999 template <RunOn run_on AMREX_DEFAULT_RUNON>
1003 template <RunOn run_on AMREX_DEFAULT_RUNON>
1011 template <RunOn run_on AMREX_DEFAULT_RUNON>
1015 template <RunOn run_on AMREX_DEFAULT_RUNON>
1019 template <RunOn run_on AMREX_DEFAULT_RUNON>
1022 template <RunOn run_on AMREX_DEFAULT_RUNON>
1026 template <RunOn run_on AMREX_DEFAULT_RUNON>
1033 template <RunOn run_on AMREX_DEFAULT_RUNON>
1036 template <RunOn run_on AMREX_DEFAULT_RUNON>
1040 template <RunOn run_on AMREX_DEFAULT_RUNON>
1044 template <RunOn run_on AMREX_DEFAULT_RUNON>
1047 template <RunOn run_on AMREX_DEFAULT_RUNON>
1051 template <RunOn run_on AMREX_DEFAULT_RUNON>
1058 template <RunOn run_on AMREX_DEFAULT_RUNON>
1061 template <RunOn run_on AMREX_DEFAULT_RUNON>
1065 template <RunOn run_on AMREX_DEFAULT_RUNON>
1069 template <RunOn run_on AMREX_DEFAULT_RUNON>
1072 template <RunOn run_on AMREX_DEFAULT_RUNON>
1076 template <RunOn run_on AMREX_DEFAULT_RUNON>
1083 template <RunOn run_on AMREX_DEFAULT_RUNON>
1086 template <RunOn run_on AMREX_DEFAULT_RUNON>
1090 template <RunOn run_on AMREX_DEFAULT_RUNON>
1094 template <RunOn run_on AMREX_DEFAULT_RUNON>
1097 template <RunOn run_on AMREX_DEFAULT_RUNON>
1101 template <RunOn run_on AMREX_DEFAULT_RUNON>
1108 template <RunOn run_on AMREX_DEFAULT_RUNON>
1111 template <RunOn run_on AMREX_DEFAULT_RUNON>
1115 template <RunOn run_on AMREX_DEFAULT_RUNON>
1119 template <RunOn run_on AMREX_DEFAULT_RUNON>
1142 [[nodiscard]] T
dot (const
Box& bx,
int destcomp,
int numcomp) const noexcept;
1178 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1191 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1199 if (this->arena()->isManaged()) {
1200#if defined(AMREX_USE_SYCL)
1205#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1207 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1208#if defined(__CUDACC__) && (__CUDACC_VER_MAJOR__ >= 13)
1209 cudaMemLocation location = {};
1210 location.type = cudaMemLocationTypeDevice;
1211 location.id = cudaCpuDeviceId;
1220#elif defined(AMREX_USE_HIP)
1232 if (this->arena()->isManaged()) {
1233#if defined(AMREX_USE_SYCL)
1234 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1235 auto& q = Gpu::Device::streamQueue();
1236 q.submit([&] (sycl::handler& h) { h.prefetch(this->dptr, s); });
1237#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1239 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1240#if defined(__CUDACC__) && (__CUDACC_VER_MAJOR__ >= 13)
1241 cudaMemLocation location = {};
1242 location.type = cudaMemLocationTypeDevice;
1252#elif defined(AMREX_USE_HIP)
1269 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1280 return this->dptr[this->domain.index(p)];
1293 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1304 return this->dptr[this->domain.index(p)];
1312 int numcomp)
const noexcept
1314 const int loc = this->domain.index(pos);
1315 const Long sz = this->domain.numPts();
1320 for (
int k = 0; k < numcomp; k++) {
1321 data[k] = this->dptr[loc+(n+k)*sz];
1328 const IntVect& pos)
const noexcept
1330 getVal(data,pos,0,this->nvar);
1366template <
RunOn run_on,
class U,
1367 std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO>
1371 amrex::fill_snan<run_on>(this->dptr, this->truesize);
1375template <RunOn run_on>
1383template <RunOn run_on>
1391template <RunOn run_on>
1399template <RunOn run_on>
1407template <RunOn run_on>
1410 const Box& destbox,
int destcomp,
int numcomp)
noexcept
1416 AMREX_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
1417 AMREX_ASSERT(destcomp >= 0 && destcomp+numcomp <= this->nvar);
1423 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
1434template <RunOn run_on>
1442template <RunOn run_on>
1456 if (this->nvar == 0) {
return; }
1457 AMREX_ASSERT(std::numeric_limits<Long>::max()/this->nvar > this->domain.numPts());
1459 this->truesize = this->nvar*this->domain.numPts();
1460 this->ptr_owner =
true;
1461 this->dptr =
static_cast<T*
>(this->alloc(this->truesize*
sizeof(T)));
1470 if constexpr (std::is_same_v<T,float> || std::is_same_v<T,double>) {
1474 this->
template fill_snan<RunOn::Device>();
1479 this->
template fill_snan<RunOn::Host>();
1499 :
DataAllocator{ar}, domain(bx), nvar(n), shared_memory(shared)
1507 dptr(const_cast<T*>(rhs.dataPtr(scomp))),
1508 domain(rhs.domain), nvar(ncomp),
1509 truesize(ncomp*rhs.domain.numPts())
1514 this->
dptr =
nullptr;
1516 this->copy<RunOn::Device>(rhs, this->
domain, scomp, this->
domain, 0, ncomp);
1526 : dptr(p), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
1532 : dptr(const_cast<T*>(p)), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
1541 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
1549 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
1554 : dptr(
const_cast<T*
>(a.p)),
1557 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
1562 : dptr(
const_cast<T*
>(a.p)),
1565 nvar(a.ncomp), truesize(a.ncomp*a.nstride)
1577 dptr(rhs.dptr), domain(rhs.domain),
1578 nvar(rhs.nvar), truesize(rhs.truesize),
1579 ptr_owner(rhs.ptr_owner), shared_memory(rhs.shared_memory)
1581 , alloc_stream(rhs.alloc_stream)
1585 rhs.ptr_owner =
false;
1594 DataAllocator::operator=(rhs);
1596 domain = rhs.domain;
1598 truesize = rhs.truesize;
1599 ptr_owner = rhs.ptr_owner;
1600 shared_memory = rhs.shared_memory;
1602 alloc_stream = rhs.alloc_stream;
1606 rhs.ptr_owner =
false;
1612template <RunOn run_on>
1627 if (ar ==
nullptr) {
1636 else if (this->dptr ==
nullptr || !this->ptr_owner)
1638 if (this->shared_memory) {
1639 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1642 this->dptr =
nullptr;
1645 else if (this->nvar*this->domain.numPts() > this->truesize
1647 || (arena()->isStreamOrderedArena() && alloc_stream !=
Gpu::gpuStream())
1651 if (this->shared_memory) {
1652 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1662template <
class U, std::enable_if_t<std::is_trivially_destructible_v<U>,
int>>
1668 o = this->ptr_owner;
1669 this->ptr_owner =
false;
1670 if (o && this->dptr) {
1671 if (this->nvar > 1) {
1680 return Elixir((o ? this->dptr :
nullptr), this->arena());
1692 if (this->ptr_owner)
1694 if (this->shared_memory)
1696 amrex::Abort(
"BaseFab::clear: BaseFab cannot be owner of shared memory");
1705 this->free(this->dptr);
1710 if (this->nvar > 1) {
1717 this->dptr =
nullptr;
1723std::unique_ptr<T,DataDeleter>
1726 std::unique_ptr<T,DataDeleter>
r(
nullptr,
DataDeleter{this->arena()});
1727 if (this->dptr && this->ptr_owner) {
1728 r.reset(this->dptr);
1729 this->ptr_owner =
false;
1730 if (this->nvar > 1) {
1740template <RunOn run_on>
1745 void* dst)
const noexcept
1756 d(i,j,k,n) = s(i,j,k,n+srccomp);
1758 return sizeof(T)*d.
size();
1767template <RunOn run_on,
typename BUF>
1772 const void* src)
noexcept
1784 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1786 return sizeof(BUF)*s.
size();
1795template <RunOn run_on,
typename BUF>
1800 const void* src)
noexcept
1812 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1814 return sizeof(BUF)*s.
size();
1823template <RunOn run_on>
1831template <RunOn run_on>
1835 this->abs<run_on>(this->domain,0,this->nvar);
1839template <RunOn run_on>
1843 this->abs<run_on>(this->domain,comp,numcomp);
1847template <RunOn run_on>
1854 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
1859template <RunOn run_on>
1862 int scomp,
int ncomp)
const noexcept
1864 BL_ASSERT(this->domain.contains(subbox));
1865 BL_ASSERT(scomp >= 0 && scomp + ncomp <= this->nvar);
1875 reduce_op.
eval(subbox, reduce_data,
1880 for (
int n = 0; n < ncomp; ++n) {
1881 t =
amrex::max(t,
static_cast<Real
>(std::abs(a(i,j,k,n+scomp))));
1886 ReduceTuple hv = reduce_data.
value(reduce_op);
1887 r = amrex::get<0>(hv);
1894 Real t =
static_cast<Real
>(std::abs(a(i,j,k,n+scomp)));
1903template <RunOn run_on>
1907 return norm<run_on>(this->domain,p,comp,numcomp);
1911template <RunOn run_on>
1915 BL_ASSERT(this->domain.contains(subbox));
1916 BL_ASSERT(comp >= 0 && comp + numcomp <= this->nvar);
1926 reduce_op.
eval(subbox, reduce_data,
1930 for (
int n = 0; n < numcomp; ++n) {
1931 t =
amrex::max(t,
static_cast<Real
>(std::abs(a(i,j,k,n+comp))));
1935 ReduceTuple hv = reduce_data.
value(reduce_op);
1936 nrm = amrex::get<0>(hv);
1937 }
else if (p == 1) {
1941 reduce_op.
eval(subbox, reduce_data,
1945 for (
int n = 0; n < numcomp; ++n) {
1946 t +=
static_cast<Real
>(std::abs(a(i,j,k,n+comp)));
1950 ReduceTuple hv = reduce_data.
value(reduce_op);
1951 nrm = amrex::get<0>(hv);
1952 }
else if (p == 2) {
1956 reduce_op.
eval(subbox, reduce_data,
1960 for (
int n = 0; n < numcomp; ++n) {
1961 t +=
static_cast<Real
>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
1965 ReduceTuple hv = reduce_data.
value(reduce_op);
1966 nrm = amrex::get<0>(hv);
1974 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1976 Real t =
static_cast<Real
>(std::abs(a(i,j,k,n+comp)));
1979 }
else if (p == 1) {
1980 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1982 nrm += std::abs(a(i,j,k,n+comp));
1984 }
else if (p == 2) {
1985 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1987 nrm += a(i,j,k,n+comp)*a(i,j,k,n+comp);
1998template <RunOn run_on>
2002 return this->min<run_on>(this->domain,comp);
2006template <RunOn run_on>
2015 using ReduceTuple =
typename decltype(reduce_data)::Type;
2016 reduce_op.
eval(subbox, reduce_data,
2019 return { a(i,j,k) };
2021 ReduceTuple hv = reduce_data.
value(reduce_op);
2022 return amrex::get<0>(hv);
2026 T
r = std::numeric_limits<T>::max();
2036template <RunOn run_on>
2040 return this->max<run_on>(this->domain,comp);
2044template <RunOn run_on>
2053 using ReduceTuple =
typename decltype(reduce_data)::Type;
2054 reduce_op.
eval(subbox, reduce_data,
2057 return { a(i,j,k) };
2059 ReduceTuple hv = reduce_data.
value(reduce_op);
2060 return amrex::get<0>(hv);
2064 T
r = std::numeric_limits<T>::lowest();
2074template <RunOn run_on>
2078 return this->minmax<run_on>(this->domain,comp);
2082template <RunOn run_on>
2091 using ReduceTuple =
typename decltype(reduce_data)::Type;
2092 reduce_op.
eval(subbox, reduce_data,
2095 auto const x = a(i,j,k);
2098 ReduceTuple hv = reduce_data.
value(reduce_op);
2099 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
2103 T rmax = std::numeric_limits<T>::lowest();
2104 T rmin = std::numeric_limits<T>::max();
2107 auto const x = a(i,j,k);
2111 return std::make_pair(rmin,rmax);
2116template <RunOn run_on>
2120 return this->maxabs<run_on>(this->domain,comp);
2124template <RunOn run_on>
2133 using ReduceTuple =
typename decltype(reduce_data)::Type;
2134 reduce_op.
eval(subbox, reduce_data,
2137 return { std::abs(a(i,j,k)) };
2139 ReduceTuple hv = reduce_data.
value(reduce_op);
2140 return amrex::get<0>(hv);
2155template <RunOn run_on>
2163 std::numeric_limits<int>::lowest(),
2164 std::numeric_limits<int>::lowest())};
2171 if ((*flag == 0) && (a(i,j,k) == value)) {
2194template <RunOn run_on>
2198 return this->minIndex<run_on>(this->domain,comp);
2202template <RunOn run_on>
2206 T min_val = this->min<run_on>(subbox, comp);
2207 return this->indexFromValue<run_on>(subbox, comp, min_val);
2211template <RunOn run_on>
2215 min_val = this->min<run_on>(subbox, comp);
2216 min_idx = this->indexFromValue<run_on>(subbox, comp, min_val);
2220template <RunOn run_on>
2224 return this->maxIndex<run_on>(this->domain,comp);
2228template <RunOn run_on>
2232 T max_val = this->max<run_on>(subbox, comp);
2233 return this->indexFromValue<run_on>(subbox, comp, max_val);
2237template <RunOn run_on>
2241 max_val = this->max<run_on>(subbox, comp);
2242 max_idx = this->indexFromValue<run_on>(subbox, comp, max_val);
2246template <RunOn run_on>
2250 mask.resize(this->domain,1);
2258 using ReduceTuple =
typename decltype(reduce_data)::Type;
2259 reduce_op.
eval(this->domain, reduce_data,
2263 if (a(i,j,k) < val) {
2272 ReduceTuple hv = reduce_data.
value(reduce_op);
2273 cnt = amrex::get<0>(hv);
2279 if (a(i,j,k) < val) {
2292template <RunOn run_on>
2296 mask.resize(this->domain,1);
2304 using ReduceTuple =
typename decltype(reduce_data)::Type;
2305 reduce_op.
eval(this->domain, reduce_data,
2309 if (a(i,j,k) <= val) {
2318 ReduceTuple hv = reduce_data.
value(reduce_op);
2319 cnt = amrex::get<0>(hv);
2325 if (a(i,j,k) <= val) {
2338template <RunOn run_on>
2342 mask.resize(this->domain,1);
2350 using ReduceTuple =
typename decltype(reduce_data)::Type;
2351 reduce_op.
eval(this->domain, reduce_data,
2355 if (a(i,j,k) == val) {
2364 ReduceTuple hv = reduce_data.
value(reduce_op);
2365 cnt = amrex::get<0>(hv);
2371 if (a(i,j,k) == val) {
2384template <RunOn run_on>
2388 mask.resize(this->domain,1);
2396 using ReduceTuple =
typename decltype(reduce_data)::Type;
2397 reduce_op.
eval(this->domain, reduce_data,
2401 if (a(i,j,k) > val) {
2410 ReduceTuple hv = reduce_data.
value(reduce_op);
2411 cnt = amrex::get<0>(hv);
2417 if (a(i,j,k) > val) {
2430template <RunOn run_on>
2434 mask.resize(this->domain,1);
2442 using ReduceTuple =
typename decltype(reduce_data)::Type;
2443 reduce_op.
eval(this->domain, reduce_data,
2447 if (a(i,j,k) >= val) {
2456 ReduceTuple hv = reduce_data.
value(reduce_op);
2457 cnt = amrex::get<0>(hv);
2463 if (a(i,j,k) >= val) {
2476template <RunOn run_on>
2480 Box ovlp(this->domain);
2482 return ovlp.
ok() ? this->atomicAdd<run_on>(
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2486template <RunOn run_on>
2489 int srccomp,
int destcomp,
int numcomp)
noexcept
2496 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2503 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2513template <RunOn run_on>
2517 Box ovlp(this->domain);
2519 return ovlp.
ok() ? saxpy<run_on>(a,
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2523template <RunOn run_on>
2526 const Box& srcbox,
const Box& destbox,
2527 int srccomp,
int destcomp,
int numcomp)
noexcept
2534 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2541 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2544 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);
2551template <RunOn run_on>
2559 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2560 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2568 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2575template <RunOn run_on>
2579 Real alpha, Real beta,
const Box&
b,
2580 int comp,
int numcomp)
noexcept
2590 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2591 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2600 const Dim3 off1{slo1.
x-dlo.x,slo1.y-dlo.y,slo1.z-dlo.z};
2601 const Dim3 off2{slo2.
x-dlo.x,slo2.y-dlo.y,slo2.z-dlo.z};
2605 d(i,j,k,n+comp) = alpha*s1(i+off1.x,j+off1.y,k+off1.z,n+comp1)
2606 + beta*s2(i+off2.x,j+off2.y,k+off2.z,n+comp2);
2612template <RunOn run_on>
2616 int numcomp)
const noexcept
2623 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2629 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2637 using ReduceTuple =
typename decltype(reduce_data)::Type;
2638 reduce_op.
eval(xbx, reduce_data,
2642 for (
int n = 0; n < numcomp; ++n) {
2647 ReduceTuple hv = reduce_data.
value(reduce_op);
2648 r = amrex::get<0>(hv);
2662template <RunOn run_on>
2666 int numcomp)
const noexcept
2673 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2679 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2689 using ReduceTuple =
typename decltype(reduce_data)::Type;
2690 reduce_op.
eval(xbx, reduce_data,
2693 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2695 for (
int n = 0; n < numcomp; ++n) {
2700 ReduceTuple hv = reduce_data.
value(reduce_op);
2701 r = amrex::get<0>(hv);
2707 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2716template <RunOn run_on>
2724template <RunOn run_on>
2732template <RunOn run_on>
2736 return this->negate<run_on>(this->domain,
DestComp{comp},
NumComps{numcomp});
2740template <RunOn run_on>
2748template <RunOn run_on>
2752 return this->invert<run_on>(
r, this->domain,
DestComp{comp},
NumComps{numcomp});
2756template <RunOn run_on>
2764template <RunOn run_on>
2772template <RunOn run_on>
2780template <RunOn run_on>
2788template <RunOn run_on>
2792 Box ovlp(this->domain);
2794 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2798template <RunOn run_on>
2801 int numcomp)
noexcept
2807template <RunOn run_on>
2810 int numcomp)
noexcept
2812 Box ovlp(this->domain);
2815 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2819template <RunOn run_on>
2822 int srccomp,
int destcomp,
int numcomp)
noexcept
2828 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2835 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2845template <RunOn run_on>
2848 int srccomp,
int destcomp,
int numcomp)
noexcept
2854 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2861 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2864 T* p = d.
ptr(i,j,k,n+destcomp);
2872template <RunOn run_on>
2875 int srccomp,
int destcomp,
int numcomp)
noexcept
2877#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
2878#if defined(AMREX_USE_GPU)
2885 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2894 Dim3 const offset{slo.
x-dlo.x, slo.y-dlo.y, slo.z-dlo.z};
2910 for (
int ip = 0; ip < nplanes; ++ip) {
2915 int planes_left = nplanes;
2916 while (planes_left > 0) {
2918 auto const m = mm + plo;
2919 auto* lock = OpenMP::get_lock(m);
2920 if (omp_test_lock(lock))
2924 if (planedim == 1) {
2932 for (
int n = 0; n < numcomp; ++n) {
2933 for (
int k = lo.z; k <= hi.z; ++k) {
2934 for (
int j = lo.y; j <= hi.y; ++j) {
2935 auto *
pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
2938 for (
int ii = 0; ii < len.x; ++ii) {
2939 pdst[ii] += psrc[ii];
2947 omp_unset_lock(lock);
2948 if (planes_left == 0) {
break; }
2952 for (
int ip = 0; ip < nplanes; ++ip) {
2953 int new_mm = (mm+ip) % nplanes;
2954 if ( !
mask[new_mm] ) {
2965#if defined(AMREX_USE_GPU)
2967 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2971 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2976template <RunOn run_on>
2984template <RunOn run_on>
2992template <RunOn run_on>
2995 int srccomp,
int destcomp,
int numcomp)
noexcept
3001 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3008 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3018template <RunOn run_on>
3026template <RunOn run_on>
3034template <RunOn run_on>
3042template <RunOn run_on>
3050template <RunOn run_on>
3053 int srccomp,
int destcomp,
int numcomp)
noexcept
3059 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3066 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3076template <RunOn run_on>
3080 return this->divide<run_on>(
r, this->domain,
DestComp{comp},
NumComps{numcomp});
3084template <RunOn run_on>
3092template <RunOn run_on>
3100template <RunOn run_on>
3108template <RunOn run_on>
3111 int srccomp,
int destcomp,
int numcomp)
noexcept
3117 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3124 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3134template <RunOn run_on>
3138 Box ovlp(this->domain);
3140 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,0,0,this->nvar) : *
this;
3144template <RunOn run_on>
3148 Box ovlp(this->domain);
3150 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3154template <RunOn run_on>
3157 int numcomp)
noexcept
3159 Box ovlp(this->domain);
3162 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3166template <RunOn run_on>
3169 int srccomp,
int destcomp,
int numcomp)
noexcept
3175 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3182 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3186 d(i,j,k,n+destcomp) /= s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
3204template <RunOn run_on>
3208 Real t1, Real t2, Real t,
3209 const Box&
b,
int comp,
int numcomp)
noexcept
3212 return copy<run_on>(f1,b1,comp1,
b,comp,numcomp);
3214 return copy<run_on>(f2,b2,comp2,
b,comp,numcomp);
3216 Real alpha = (t2-t)/(t2-t1);
3217 Real beta = (t-t1)/(t2-t1);
3218 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,
b,comp,numcomp);
3223template <RunOn run_on>
3227 Real t1, Real t2, Real t,
3228 const Box&
b,
int comp,
int numcomp)
noexcept
3231 return copy<run_on>(f1,
b,comp1,
b,comp,numcomp);
3233 return copy<run_on>(f2,
b,comp2,
b,comp,numcomp);
3235 Real alpha = (t2-t)/(t2-t1);
3236 Real beta = (t-t1)/(t2-t1);
3237 return linComb<run_on>(f1,
b,comp1,f2,
b,comp2,alpha,beta,
b,comp,numcomp);
3246template <RunOn run_on>
3250 this->setVal<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3254template <RunOn run_on>
3258 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3262 a(i,j,k,n+dcomp.i) = x;
3267template <RunOn run_on>
3275template <RunOn run_on>
3279 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3284 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3289template <RunOn run_on>
3297template <RunOn run_on>
3301 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3306 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3311template <RunOn run_on>
3316 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3321 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3330 for (
auto const&
b : b_lst) {
3331 this->setVal<RunOn::Host>(
x,
b, dcomp, ncomp);
3337template <RunOn run_on>
3346template <RunOn run_on>
3352 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3353 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3361 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3368template <RunOn run_on>
3372 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3376template <RunOn run_on>
3380 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3384template <RunOn run_on>
3388 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3393 a(i,j,k,n+dcomp.i) += val;
3400template <RunOn run_on>
3408template <RunOn run_on>
3416template <RunOn run_on>
3422 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3423 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3431 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3438template <RunOn run_on>
3442 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3446template <RunOn run_on>
3450 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3454template <RunOn run_on>
3458 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3463 a(i,j,k,n+dcomp.i) -= val;
3470template <RunOn run_on>
3478template <RunOn run_on>
3486template <RunOn run_on>
3492 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3493 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3501 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3508template <RunOn run_on>
3512 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3516template <RunOn run_on>
3520 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3524template <RunOn run_on>
3528 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3533 a(i,j,k,n+dcomp.i) *= val;
3540template <RunOn run_on>
3548template <RunOn run_on>
3556template <RunOn run_on>
3562 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3563 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3571 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3578template <RunOn run_on>
3582 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3586template <RunOn run_on>
3590 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3594template <RunOn run_on>
3598 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3603 a(i,j,k,n+dcomp.i) /= val;
3610template <RunOn run_on>
3618template <RunOn run_on>
3626template <RunOn run_on>
3632 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3633 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3641 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3648template <RunOn run_on>
3652 return this->negate<run_on>(this->domain,
DestComp{0},
NumComps{this->nvar});
3656template <RunOn run_on>
3660 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3665 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3672template <RunOn run_on>
3676 return this->invert<run_on>(
r, this->domain,
DestComp{0},
NumComps{this->nvar});
3680template <RunOn run_on>
3684 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3689 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3696template <RunOn run_on>
3700 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3705 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3708 using ReduceTuple =
typename decltype(reduce_data)::Type;
3709 reduce_op.
eval(bx, reduce_data,
3713 for (
int n = 0; n < ncomp.n; ++n) {
3714 t += a(i,j,k,n+dcomp.i);
3718 ReduceTuple hv = reduce_data.
value(reduce_op);
3719 r = amrex::get<0>(hv);
3725 r += a(i,j,k,n+dcomp.i);
3733template <RunOn run_on>
3738 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3739 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3745 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3748 using ReduceTuple =
typename decltype(reduce_data)::Type;
3749 reduce_op.
eval(bx, reduce_data,
3753 for (
int n = 0; n < ncomp.n; ++n) {
3754 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3758 ReduceTuple hv = reduce_data.
value(reduce_op);
3759 r = amrex::get<0>(hv);
3765 r += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3773template <RunOn run_on>
3782template <RunOn run_on>
3786 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3791 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3794 using ReduceTuple =
typename decltype(reduce_data)::Type;
3795 reduce_op.
eval(bx, reduce_data,
3799 for (
int n = 0; n < ncomp.n; ++n) {
3800 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3804 ReduceTuple hv = reduce_data.
value(reduce_op);
3805 r = amrex::get<0>(hv);
3811 r += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3819template <RunOn run_on>
3826 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3827 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3834 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3837 using ReduceTuple =
typename decltype(reduce_data)::Type;
3838 reduce_op.
eval(bx, reduce_data,
3842 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
3843 for (
int n = 0; n < ncomp.n; ++n) {
3844 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
3848 ReduceTuple hv = reduce_data.
value(reduce_op);
3849 r = amrex::get<0>(hv);
3855 int mi = static_cast<int>(static_cast<bool>(m(i,j,k)));
3856 r += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_DEFAULT_RUNON
Definition AMReX_GpuControl.H:73
#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
int idir
Definition AMReX_HypreMLABecLap.cpp:1093
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
Real * pdst
Definition AMReX_HypreMLABecLap.cpp:1090
Array4< int const > mask
Definition AMReX_InterpFaceRegister.cpp:93
#define AMREX_LOOP_3D(bx, i, j, k, block)
Definition AMReX_Loop.nolint.H:4
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
Definition AMReX_Loop.nolint.H:16
void amrex_mempool_free(void *p)
Definition AMReX_MemPool.cpp:80
void * amrex_mempool_alloc(size_t nbytes)
Definition AMReX_MemPool.cpp:74
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
A virtual base class for objects that manage their own dynamic memory allocation.
Definition AMReX_Arena.H:105
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:183
int maskGE(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value greater than or equal to val.
Definition AMReX_BaseFab.H:2432
BaseFab< T > & saxpy(T a, const BaseFab< T > &x, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
FAB SAXPY (y[i] <- y[i] + a * x[i]), in place.
Definition AMReX_BaseFab.H:2488
Array4< T const > const_array() const noexcept
Definition AMReX_BaseFab.H:411
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:3348
T sum(int comp, int numcomp=1) const noexcept
Returns sum of given component of FAB state vector.
Definition AMReX_BaseFab.H:2718
gpuStream_t alloc_stream
Definition AMReX_BaseFab.H:1164
Real norminfmask(const Box &subbox, const BaseFab< int > &mask, int scomp=0, int ncomp=1) const noexcept
Definition AMReX_BaseFab.H:1861
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition AMReX_BaseFab.H:3580
const int * hiVect() const noexcept
Returns the upper corner of the domain.
Definition AMReX_BaseFab.H:322
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:3488
BaseFab< T > & lockAdd(const BaseFab< T > &src, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp) noexcept
Atomically add srcbox region of src FAB to destbox region of this FAB. The srcbox and destbox must be...
Definition AMReX_BaseFab.H:2874
std::size_t copyToMem(const Box &srcbox, int srccomp, int numcomp, void *dst) const noexcept
Copy from the srcbox of this Fab to raw memory and return the number of bytes copied.
Definition AMReX_BaseFab.H:1742
std::size_t addFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src) noexcept
Add from raw memory to the dstbox of this Fab and return the number of bytes copied.
Definition AMReX_BaseFab.H:1797
std::size_t nBytesOwned() const noexcept
Definition AMReX_BaseFab.H:264
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3339
BaseFab< T > & addproduct(const Box &destbox, int destcomp, int numcomp, const BaseFab< T > &src1, int comp1, const BaseFab< T > &src2, int comp2) noexcept
y[i] <- y[i] + x1[i] * x2[i])
Definition AMReX_BaseFab.H:2553
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition AMReX_BaseFab.H:3440
int maskLT(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Compute mask array with value of 1 in cells where BaseFab has value less than val,...
Definition AMReX_BaseFab.H:2248
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3370
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3526
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:3558
std::size_t nBytes(const Box &bx, int ncomps) const noexcept
Returns bytes used in the Box for those components.
Definition AMReX_BaseFab.H:269
void setPtr(T *p, Long sz) noexcept
Definition AMReX_BaseFab.H:369
BaseFab< T > & linComb(const BaseFab< T > &f1, const Box &b1, int comp1, const BaseFab< T > &f2, const Box &b2, int comp2, Real alpha, Real beta, const Box &b, int comp, int numcomp=1) noexcept
Linear combination. Result is alpha*f1 + beta*f2. Data is taken from b1 region of f1,...
Definition AMReX_BaseFab.H:2577
void define()
Allocates memory for the BaseFab<T>.
Definition AMReX_BaseFab.H:1451
BaseFab< T > & operator*=(T const &val) noexcept
Definition AMReX_BaseFab.H:3518
void resize(const Box &b, int N=1, Arena *ar=nullptr)
This function resizes a BaseFab so it covers the Box b with N components.
Definition AMReX_BaseFab.H:1622
const IntVect & smallEnd() const noexcept
Returns the lower corner of the domain See class Box for analogue.
Definition AMReX_BaseFab.H:299
BaseFab< T > & mult(T const &r, int comp, int numcomp=1) noexcept
Scalar multiplication, except control which components are multiplied.
Definition AMReX_BaseFab.H:3020
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition AMReX_BaseFab.H:2478
int maskEQ(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value equal to val.
Definition AMReX_BaseFab.H:2340
const int * loVect() const noexcept
Returns the lower corner of the domain.
Definition AMReX_BaseFab.H:312
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:328
bool isAllocated() const noexcept
Returns true if the data for the FAB has been allocated.
Definition AMReX_BaseFab.H:429
std::unique_ptr< T, DataDeleter > release() noexcept
Release ownership of memory.
Definition AMReX_BaseFab.H:1724
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3256
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3448
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition AMReX_BaseFab.H:287
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:3277
Array4< T > array() noexcept
Definition AMReX_BaseFab.H:393
IntVect indexFromValue(const Box &subbox, int comp, T const &value) const noexcept
Definition AMReX_BaseFab.H:2157
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3542
bool shared_memory
Is the memory allocated in shared memory?
Definition AMReX_BaseFab.H:1162
int maskLE(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value less than or equal to val.
Definition AMReX_BaseFab.H:2294
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3269
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:3418
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3291
BaseFab< T > & xpay(T a, const BaseFab< T > &x, const Box &srcbox, const Box &destbox, int srccomp, int destcomp, int numcomp=1) noexcept
FAB XPAY (y[i] <- x[i] + a * y[i])
Definition AMReX_BaseFab.H:2525
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:1262
std::size_t nBytes() const noexcept
Returns how many bytes used.
Definition AMReX_BaseFab.H:262
std::size_t copyFromMem(const Box &dstbox, int dstcomp, int numcomp, const void *src) noexcept
Copy from raw memory to the dstbox of this Fab and return the number of bytes copied.
Definition AMReX_BaseFab.H:1769
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition AMReX_BaseFab.H:3650
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3472
BaseFab< T > & minus(const BaseFab< T > &src, int srccomp, int destcomp, int numcomp=1) noexcept
Subtract src components (srccomp:srccomp+numcomp-1) to this FABs components (destcomp:destcomp+numcom...
Definition AMReX_BaseFab.H:2978
T value_type
Definition AMReX_BaseFab.H:188
void SetBoxType(const IndexType &typ) noexcept
Change the Box type without change the length.
Definition AMReX_BaseFab.H:974
Array4< T const > array() const noexcept
Definition AMReX_BaseFab.H:375
T maxabs(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2118
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3378
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:3313
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3456
Long truesize
nvar*numpts that was allocated on heap.
Definition AMReX_BaseFab.H:1160
void setVal(T const &val) noexcept
Set value on the whole domain and all components.
Definition AMReX_BaseFab.H:3248
const int * nCompPtr() const noexcept
for calls to fortran.
Definition AMReX_BaseFab.H:276
Array4< T const > const_array(int start_comp, int num_comps) const noexcept
Definition AMReX_BaseFab.H:423
Box domain
My index space.
Definition AMReX_BaseFab.H:1158
bool contains(const Box &bx) const noexcept
Returns true if bx is totally contained within the domain of this BaseFab.
Definition AMReX_BaseFab.H:337
T * dptr
The data pointer.
Definition AMReX_BaseFab.H:1157
BaseFab< T > & shift(const IntVect &v) noexcept
Perform shifts upon the domain of the BaseFab. They are completely analogous to the corresponding Box...
Definition AMReX_BaseFab.H:1335
BaseFab< T > & divide(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3596
T max(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2038
BaseFab< T > & copy(const BaseFab< T > &src, const Box &srcbox, int srccomp, const Box &destbox, int destcomp, int numcomp) noexcept
The copy functions copy the contents of one BaseFab into another. The destination BaseFab is always t...
Definition AMReX_BaseFab.H:1409
Array4< T > array(int start_comp, int num_comps) noexcept
Definition AMReX_BaseFab.H:405
int nvar
Number components.
Definition AMReX_BaseFab.H:1159
T dot(const Box &xbx, int xcomp, const BaseFab< T > &y, const Box &ybx, int ycomp, int numcomp=1) const noexcept
Dot product of x (i.e.,this) and y.
Definition AMReX_BaseFab.H:2614
BaseFab< T > & divide(T const &r, int comp, int numcomp=1) noexcept
As above except specify which components.
Definition AMReX_BaseFab.H:3078
Real norm(int p, int scomp=0, int numcomp=1) const noexcept
Compute the Lp-norm of this FAB using components (scomp : scomp+ncomp-1). p < 0 -> ERROR p = 0 -> inf...
Definition AMReX_BaseFab.H:1905
Array4< T const > array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:381
BaseFab< T > & operator/=(T const &val) noexcept
Definition AMReX_BaseFab.H:3588
std::pair< T, T > minmax(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2076
Array4< T const > const_array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:417
void fill_snan() noexcept
Definition AMReX_BaseFab.H:1369
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:1393
Long size() const noexcept
Returns the total number of points of all components.
Definition AMReX_BaseFab.H:284
BaseFab< T > & plus(T const &r, const Box &b, int comp=0, int numcomp=1) noexcept
Scalar addition (a[i] <- a[i] + r), most general.
Definition AMReX_BaseFab.H:2774
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:1309
const IntVect & bigEnd() const noexcept
Returns the upper corner of the domain. See class Box for analogue.
Definition AMReX_BaseFab.H:302
Array4< T > array(int start_comp) noexcept
Definition AMReX_BaseFab.H:399
Elixir elixir() noexcept
Definition AMReX_BaseFab.H:1664
Long numPts() const noexcept
Returns the number of points.
Definition AMReX_BaseFab.H:281
const T * dataPtr(int n=0) const noexcept
Same as above except works on const FABs.
Definition AMReX_BaseFab.H:357
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:3299
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3510
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:3628
void setValIfNot(T const &val, const Box &bx, const BaseFab< int > &mask, int nstart, int num) noexcept
Definition AMReX_BaseFab.H:1401
BaseFab< T > & shiftHalf(int dir, int n_cell) noexcept
Perform shifts upon the domain of the BaseFab. They are completely analogous to the corresponding Box...
Definition AMReX_BaseFab.H:1359
void prefetchToDevice() const noexcept
Definition AMReX_BaseFab.H:1229
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:348
bool ptr_owner
Owner of T*?
Definition AMReX_BaseFab.H:1161
virtual ~BaseFab() noexcept
The destructor deletes the array memory.
Definition AMReX_BaseFab.H:1569
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:293
IntVect maxIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2222
BaseFab< T > & protected_divide(const BaseFab< T > &src) noexcept
Divide wherever "src" is "true" or "non-zero".
Definition AMReX_BaseFab.H:3136
friend class BaseFab
Definition AMReX_BaseFab.H:186
BaseFab< T > & invert(T const &r, const Box &b, int comp=0, int numcomp=1) noexcept
Most general version, specify subbox and which components.
Definition AMReX_BaseFab.H:2758
Array4< T const > array(int start_comp, int num_comps) const noexcept
Definition AMReX_BaseFab.H:387
int nComp() const noexcept
Returns the number of components.
Definition AMReX_BaseFab.H:273
int maskGT(BaseFab< int > &mask, T const &val, int comp=0) const noexcept
Same as above except mark cells with value greater than val.
Definition AMReX_BaseFab.H:2386
T dotmask(const BaseFab< int > &mask, const Box &xbx, int xcomp, const BaseFab< T > &y, const Box &ybx, int ycomp, int numcomp) const noexcept
Definition AMReX_BaseFab.H:2664
void clear() noexcept
The function returns the BaseFab to the invalid state. The memory is freed.
Definition AMReX_BaseFab.H:1685
BaseFab< T > & plus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3402
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:3612
void prefetchToHost() const noexcept
Definition AMReX_BaseFab.H:1196
T min(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2000
void setComplement(T const &x, const Box &b, int ns, int num) noexcept
This function is analogous to the fourth form of setVal above, except that instead of setting values ...
Definition AMReX_BaseFab.H:1825
BaseFab< T > & linInterp(const BaseFab< T > &f1, const Box &b1, int comp1, const BaseFab< T > &f2, const Box &b2, int comp2, Real t1, Real t2, Real t, const Box &b, int comp, int numcomp=1) noexcept
Linear interpolation / extrapolation. Result is (t2-t)/(t2-t1)*f1 + (t-t1)/(t2-t1)*f2 Data is taken f...
Definition AMReX_BaseFab.H:3206
IntVect minIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2196
T * dataPtr(const IntVect &p, int n=0) noexcept
Definition AMReX_BaseFab.H:1171
void abs() noexcept
Compute absolute value for all components of this FAB.
Definition AMReX_BaseFab.H:1833
void getVal(T *data, const IntVect &pos) const noexcept
Same as above, except that starts at component 0 and copies all comps.
Definition AMReX_BaseFab.H:1327
BaseFab< T > & plus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3386
A class for managing a List of Boxes that share a common IndexType. This class implements operations ...
Definition AMReX_BoxList.H:52
__host__ __device__ const IntVectND< dim > & bigEnd() const &noexcept
Get the bigend.
Definition AMReX_Box.H:119
__host__ __device__ const int * hiVect() const &noexcept
Returns a constant pointer the array of high end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:186
__host__ __device__ Long numPts() const noexcept
Returns the number of points contained in the BoxND.
Definition AMReX_Box.H:349
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:149
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Returns true if argument is contained within BoxND.
Definition AMReX_Box.H:207
__host__ __device__ const int * loVect() const &noexcept
Returns a constant pointer the array of low end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:181
__host__ __device__ BoxND & setType(const IndexTypeND< dim > &t) noexcept
Set indexing type.
Definition AMReX_Box.H:495
__host__ __device__ bool ok() const noexcept
Checks if it is a proper BoxND (including a valid type).
Definition AMReX_Box.H:203
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Get the smallend of the BoxND.
Definition AMReX_Box.H:108
Definition AMReX_Tuple.H:93
static gpuStream_t setStream(gpuStream_t s) noexcept
Definition AMReX_GpuDevice.cpp:724
static gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:77
static int deviceId() noexcept
Definition AMReX_GpuDevice.cpp:672
static int devicePropMajor() noexcept
Definition AMReX_GpuDevice.H:163
Definition AMReX_GpuElixir.H:13
__host__ static __device__ constexpr IntVectND< dim > TheMinVector() noexcept
Definition AMReX_IntVect.H:725
Definition AMReX_PODVector.H:297
T * data() noexcept
Definition AMReX_PODVector.H:655
Definition AMReX_Reduce.H:249
Type value()
Definition AMReX_Reduce.H:281
Definition AMReX_Reduce.H:364
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:433
__host__ __device__ AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
Definition AMReX_GpuAtomic.H:485
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:260
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:303
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:92
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:93
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:289
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:241
__host__ __device__ AMREX_FORCE_INLINE void Add(T *const sum, T const value) noexcept
Definition AMReX_GpuAtomic.H:619
Definition AMReX_Amr.cpp:49
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:319
std::atomic< Long > atomic_total_bytes_allocated_in_fabs_hwm
Definition AMReX_BaseFab.cpp:14
MakeType
Definition AMReX_MakeType.H:7
@ make_deep_copy
Definition AMReX_MakeType.H:7
@ make_alias
Definition AMReX_MakeType.H:7
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2852
Long private_total_cells_allocated_in_fabs_hwm
high-water-mark over a given interval
Definition AMReX_BaseFab.cpp:20
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:191
__host__ __device__ Array4< T > makeArray4(T *p, Box const &bx, int ncomp) noexcept
Definition AMReX_BaseFab.H:87
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:326
RunOn
Definition AMReX_GpuControl.H:69
std::enable_if_t< std::is_arithmetic_v< T > > placementNew(T *const, Long)
Definition AMReX_BaseFab.H:94
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:83
Long private_total_cells_allocated_in_fabs
total cells at any given time
Definition AMReX_BaseFab.cpp:19
bool InitSNaN() noexcept
Definition AMReX.cpp:173
Long TotalBytesAllocatedInFabs() noexcept
Definition AMReX_BaseFab.cpp:64
Long private_total_bytes_allocated_in_fabs_hwm
high-water-mark over a given interval
Definition AMReX_BaseFab.cpp:18
void BaseFab_Initialize()
Definition AMReX_BaseFab.cpp:28
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:21
void BaseFab_Finalize()
Definition AMReX_BaseFab.cpp:57
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1899
void ResetTotalBytesAllocatedInFabsHWM() noexcept
Definition AMReX_BaseFab.cpp:132
BoxList boxDiff(const Box &b1in, const Box &b2)
Returns BoxList defining the compliment of b2 in b1in.
Definition AMReX_BoxList.cpp:599
__host__ __device__ std::enable_if_t< std::is_floating_point_v< T >, bool > almostEqual(T x, T y, int ulp=2)
Definition AMReX_Algorithm.H:93
IntVectND< 3 > IntVect
Definition AMReX_BaseFwd.H:30
Long TotalBytesAllocatedInFabsHWM() noexcept
Definition AMReX_BaseFab.cpp:81
std::atomic< Long > atomic_total_bytes_allocated_in_fabs
Definition AMReX_BaseFab.cpp:13
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:35
Long TotalCellsAllocatedInFabsHWM() noexcept
Definition AMReX_BaseFab.cpp:115
Long TotalCellsAllocatedInFabs() noexcept
Definition AMReX_BaseFab.cpp:98
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:224
std::atomic< Long > atomic_total_cells_allocated_in_fabs
Definition AMReX_BaseFab.cpp:15
std::enable_if_t< std::is_trivially_destructible_v< T > > placementDelete(T *const, Long)
Definition AMReX_BaseFab.H:119
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
Long private_total_bytes_allocated_in_fabs
total bytes at any given time
Definition AMReX_BaseFab.cpp:17
std::atomic< Long > atomic_total_cells_allocated_in_fabs_hwm
Definition AMReX_BaseFab.cpp:16
void LoopOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:355
void update_fab_stats(Long n, Long s, size_t szt) noexcept
Definition AMReX_BaseFab.cpp:144
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:1908
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:312
std::array< T, N > Array
Definition AMReX_Array.H:24
Definition AMReX_Array4.H:61
__host__ __device__ std::size_t size() const noexcept
Definition AMReX_Array4.H:243
__host__ __device__ T * ptr(int i, int j, int k) const noexcept
Definition AMReX_Array4.H:149
Definition AMReX_DataAllocator.H:9
void * alloc(std::size_t sz) const noexcept
Definition AMReX_DataAllocator.H:16
Arena * arena() const noexcept
Definition AMReX_DataAllocator.H:24
Definition AMReX_DataAllocator.H:29
Definition AMReX_BaseFab.H:72
int i
Definition AMReX_BaseFab.H:75
__host__ __device__ DestComp(int ai) noexcept
Definition AMReX_BaseFab.H:74
Definition AMReX_Dim3.H:12
int x
Definition AMReX_Dim3.H:12
Definition AMReX_BaseFab.H:78
__host__ __device__ NumComps(int an) noexcept
Definition AMReX_BaseFab.H:80
int n
Definition AMReX_BaseFab.H:81
Definition AMReX_BaseFab.H:66
__host__ __device__ SrcComp(int ai) noexcept
Definition AMReX_BaseFab.H:68
int i
Definition AMReX_BaseFab.H:69