1#ifndef AMREX_BASEFAB_H_
2#define AMREX_BASEFAB_H_
3#include <AMReX_Config.H>
44extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs;
45extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs_hwm;
46extern std::atomic<Long> atomic_total_cells_allocated_in_fabs;
47extern std::atomic<Long> atomic_total_cells_allocated_in_fabs_hwm;
48extern Long private_total_bytes_allocated_in_fabs;
49extern Long private_total_bytes_allocated_in_fabs_hwm;
50extern Long private_total_cells_allocated_in_fabs;
51extern Long private_total_cells_allocated_in_fabs_hwm;
53#pragma omp threadprivate(private_total_bytes_allocated_in_fabs)
54#pragma omp threadprivate(private_total_bytes_allocated_in_fabs_hwm)
55#pragma omp threadprivate(private_total_cells_allocated_in_fabs)
56#pragma omp threadprivate(private_total_cells_allocated_in_fabs_hwm)
73 explicit SrcComp (
int ai) noexcept : i(ai) {}
98std::enable_if_t<std::is_arithmetic_v<T>>
103std::enable_if_t<std::is_trivially_default_constructible_v<T>
104 && !std::is_arithmetic_v<T>>
107 for (
Long i = 0; i < n; ++i) {
113std::enable_if_t<!std::is_trivially_default_constructible_v<T>>
123std::enable_if_t<std::is_trivially_destructible_v<T>>
128std::enable_if_t<!std::is_trivially_destructible_v<T>>
206 bool shared = false,
Arena* ar =
nullptr);
256 template <class U=T, std::enable_if_t<std::is_trivially_destructible_v<U>,
int> = 0>
269 [[nodiscard]] std::
size_t nBytes () const noexcept {
return this->
truesize*
sizeof(T); }
276 [[nodiscard]] std::size_t
nBytes (
const Box& bx,
int ncomps)
const noexcept
277 {
return bx.numPts() *
sizeof(T) * ncomps; }
280 [[nodiscard]]
int nComp () const noexcept {
return this->
nvar; }
283 [[nodiscard]]
const int*
nCompPtr() const noexcept {
284 return &(this->
nvar);
294 [[nodiscard]]
const Box&
box () const noexcept {
return this->
domain; }
355 [[nodiscard]] T*
dataPtr (
int n = 0) noexcept {
364 [[nodiscard]]
const T*
dataPtr (
int n = 0) const noexcept {
460 void getVal (T* data,
const IntVect& pos,
int N,
int numcomp)
const noexcept;
465 class U=T, std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO = 0>
475 void setVal (T const&
x, const
Box& bx,
int dcomp,
int ncomp) noexcept;
512 const
Box& destbox,
int destcomp,
int numcomp) noexcept;
522 int numcomp = 1) noexcept;
535 int numcomp,
void* dst) const noexcept;
540 int numcomp, const
void* src) noexcept;
545 int numcomp, const
void* src) noexcept;
582 [[nodiscard]]
Real norm (
int p,
int scomp = 0,
int numcomp = 1) const;
586 [[nodiscard]]
Real norm (const
Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const;
592 void abs (
int comp,
int numcomp=1) noexcept;
597 void abs (const
Box& subbox,
int comp = 0,
int numcomp=1) noexcept;
602 [[nodiscard]] T
min (
int comp = 0) const noexcept;
607 [[nodiscard]] T
min (const
Box& subbox,
int comp = 0) const noexcept;
612 [[nodiscard]] T
max (
int comp = 0) const noexcept;
617 [[nodiscard]] T
max (const
Box& subbox,
int comp = 0) const noexcept;
622 [[nodiscard]] std::pair<T,T>
minmax (
int comp = 0) const noexcept;
627 [[nodiscard]] std::pair<T,T>
minmax (const
Box& subbox,
int comp = 0) const noexcept;
632 [[nodiscard]] T
maxabs (
int comp = 0) const noexcept;
637 [[nodiscard]] T
maxabs (const
Box& subbox,
int comp = 0) const noexcept;
705 [[nodiscard]] T
sum (
int comp,
int numcomp = 1) const noexcept;
708 [[nodiscard]] T
sum (const
Box& subbox,
int comp,
int numcomp = 1) const noexcept;
752 int srccomp,
int destcomp,
int numcomp=1) noexcept;
772 int numcomp=1) noexcept;
779 int srccomp,
int destcomp,
int numcomp=1) noexcept;
788 int srccomp,
int destcomp,
int numcomp) noexcept;
793 int srccomp,
int destcomp,
int numcomp=1) noexcept;
801 int srccomp,
int destcomp,
int numcomp=1) noexcept;
806 const
BaseFab<T>& src1,
int comp1,
807 const
BaseFab<T>& src2,
int comp2) noexcept;
823 int numcomp=1) noexcept;
830 int srccomp,
int destcomp,
int numcomp=1) noexcept;
856 int numcomp=1) noexcept;
864 int srccomp,
int destcomp,
int numcomp=1) noexcept;
889 int numcomp=1) noexcept;
896 int srccomp,
int destcomp,
int numcomp=1) noexcept;
921 int numcomp=1) noexcept;
930 int srccomp,
int destcomp,
int numcomp=1) noexcept;
944 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
946 const
Box& b,
int comp,
int numcomp = 1) noexcept;
951 const
BaseFab<T>& f2,
int comp2,
953 const
Box& b,
int comp,
int numcomp = 1) noexcept;
966 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
968 int comp,
int numcomp = 1) noexcept;
973 int numcomp = 1) const noexcept;
978 int numcomp) const noexcept;
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>
1002 template <RunOn run_on AMREX_DEFAULT_RUNON>
1006 template <RunOn run_on AMREX_DEFAULT_RUNON>
1010 template <RunOn run_on AMREX_DEFAULT_RUNON>
1018 template <RunOn run_on AMREX_DEFAULT_RUNON>
1022 template <RunOn run_on AMREX_DEFAULT_RUNON>
1026 template <RunOn run_on AMREX_DEFAULT_RUNON>
1029 template <RunOn run_on AMREX_DEFAULT_RUNON>
1033 template <RunOn run_on AMREX_DEFAULT_RUNON>
1040 template <RunOn run_on AMREX_DEFAULT_RUNON>
1043 template <RunOn run_on AMREX_DEFAULT_RUNON>
1047 template <RunOn run_on AMREX_DEFAULT_RUNON>
1051 template <RunOn run_on AMREX_DEFAULT_RUNON>
1054 template <RunOn run_on AMREX_DEFAULT_RUNON>
1058 template <RunOn run_on AMREX_DEFAULT_RUNON>
1065 template <RunOn run_on AMREX_DEFAULT_RUNON>
1068 template <RunOn run_on AMREX_DEFAULT_RUNON>
1072 template <RunOn run_on AMREX_DEFAULT_RUNON>
1076 template <RunOn run_on AMREX_DEFAULT_RUNON>
1079 template <RunOn run_on AMREX_DEFAULT_RUNON>
1083 template <RunOn run_on AMREX_DEFAULT_RUNON>
1090 template <RunOn run_on AMREX_DEFAULT_RUNON>
1093 template <RunOn run_on AMREX_DEFAULT_RUNON>
1097 template <RunOn run_on AMREX_DEFAULT_RUNON>
1101 template <RunOn run_on AMREX_DEFAULT_RUNON>
1104 template <RunOn run_on AMREX_DEFAULT_RUNON>
1108 template <RunOn run_on AMREX_DEFAULT_RUNON>
1115 template <RunOn run_on AMREX_DEFAULT_RUNON>
1118 template <RunOn run_on AMREX_DEFAULT_RUNON>
1122 template <RunOn run_on AMREX_DEFAULT_RUNON>
1126 template <RunOn run_on AMREX_DEFAULT_RUNON>
1149 [[nodiscard]] T
dot (const
Box& bx,
int destcomp,
int numcomp) const noexcept;
1185 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1198 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1206 if (this->arena()->isManaged()) {
1207#if defined(AMREX_USE_SYCL)
1212#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1214 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1215#if defined(CUDART_VERSION) && (CUDART_VERSION >= 13000)
1216 cudaMemLocation location = {};
1217 location.type = cudaMemLocationTypeHost;
1226#elif defined(AMREX_USE_HIP)
1238 if (this->arena()->isManaged()) {
1239#if defined(AMREX_USE_SYCL)
1240 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1241 auto& q = Gpu::Device::streamQueue();
1242 q.submit([&] (sycl::handler& h) { h.prefetch(this->dptr, s); });
1243#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1245 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1246#if defined(CUDART_VERSION) && (CUDART_VERSION >= 13000)
1247 cudaMemLocation location = {};
1248 location.type = cudaMemLocationTypeDevice;
1258#elif defined(AMREX_USE_HIP)
1275 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1286 return this->dptr[this->domain.index(p)];
1299 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1310 return this->dptr[this->domain.index(p)];
1318 int numcomp)
const noexcept
1320 const int loc = this->domain.index(pos);
1321 const Long sz = this->domain.numPts();
1326 for (
int k = 0; k < numcomp; k++) {
1327 data[k] = this->dptr[loc+(n+k)*sz];
1334 const IntVect& pos)
const noexcept
1336 getVal(data,pos,0,this->nvar);
1372template <
RunOn run_on,
class U,
1373 std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO>
1377 amrex::fill_snan<run_on>(this->dptr, this->truesize);
1381template <RunOn run_on>
1389template <RunOn run_on>
1397template <RunOn run_on>
1405template <RunOn run_on>
1413template <RunOn run_on>
1416 const Box& destbox,
int destcomp,
int numcomp)
noexcept
1422 AMREX_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
1423 AMREX_ASSERT(destcomp >= 0 && destcomp+numcomp <= this->nvar);
1429 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
1440template <RunOn run_on>
1448template <RunOn run_on>
1462 if (this->nvar == 0) {
return; }
1463 AMREX_ASSERT(std::numeric_limits<Long>::max()/this->nvar > this->domain.numPts());
1465 this->truesize = this->nvar*this->domain.numPts();
1466 this->ptr_owner =
true;
1467 this->dptr =
static_cast<T*
>(this->alloc(this->truesize*
sizeof(T)));
1476 if constexpr (std::is_same_v<T,float> || std::is_same_v<T,double>) {
1480 this->
template fill_snan<RunOn::Device>();
1485 this->
template fill_snan<RunOn::Host>();
1505 :
DataAllocator{ar}, domain(bx), nvar(n), shared_memory(shared)
1513 dptr(const_cast<T*>(rhs.dataPtr(scomp))),
1514 domain(rhs.domain), nvar(ncomp),
1515 truesize(ncomp*rhs.domain.numPts())
1520 this->
dptr =
nullptr;
1522 this->copy<RunOn::Device>(rhs, this->
domain, scomp, this->
domain, 0, ncomp);
1532 : dptr(p), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
1538 : dptr(const_cast<T*>(p)), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
1547 nvar(a.nComp()), truesize(a.size())
1555 nvar(a.nComp()), truesize(a.size())
1560 : dptr(
const_cast<T*
>(a.p)),
1563 nvar(a.nComp()), truesize(a.size())
1568 : dptr(
const_cast<T*
>(a.p)),
1571 nvar(a.nComp()), truesize(a.size())
1583 dptr(rhs.dptr), domain(rhs.domain),
1584 nvar(rhs.nvar), truesize(rhs.truesize),
1585 ptr_owner(rhs.ptr_owner), shared_memory(rhs.shared_memory)
1587 , alloc_stream(rhs.alloc_stream)
1591 rhs.ptr_owner =
false;
1600 DataAllocator::operator=(rhs);
1602 domain = rhs.domain;
1604 truesize = rhs.truesize;
1605 ptr_owner = rhs.ptr_owner;
1606 shared_memory = rhs.shared_memory;
1608 alloc_stream = rhs.alloc_stream;
1612 rhs.ptr_owner =
false;
1618template <RunOn run_on>
1633 if (ar ==
nullptr) {
1642 else if (this->dptr ==
nullptr || !this->ptr_owner)
1644 if (this->shared_memory) {
1645 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1648 this->dptr =
nullptr;
1651 else if (this->nvar*this->domain.numPts() > this->truesize
1653 || (arena()->isStreamOrderedArena() && alloc_stream !=
Gpu::gpuStream())
1657 if (this->shared_memory) {
1658 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1668template <
class U, std::enable_if_t<std::is_trivially_destructible_v<U>,
int>>
1674 o = this->ptr_owner;
1675 this->ptr_owner =
false;
1676 if (o && this->dptr) {
1677 if (this->nvar > 1) {
1686 return Elixir((o ? this->dptr :
nullptr), this->arena());
1698 if (this->ptr_owner)
1700 if (this->shared_memory)
1702 amrex::Abort(
"BaseFab::clear: BaseFab cannot be owner of shared memory");
1708 this->arena()->streamOrderedFree(this->dptr, alloc_stream);
1710 this->free(this->dptr);
1713 if (this->nvar > 1) {
1720 this->dptr =
nullptr;
1726std::unique_ptr<T,DataDeleter>
1729 std::unique_ptr<T,DataDeleter> r(
nullptr,
DataDeleter{this->arena()});
1730 if (this->dptr && this->ptr_owner) {
1731 r.reset(this->dptr);
1732 this->ptr_owner =
false;
1733 if (this->nvar > 1) {
1743template <RunOn run_on>
1748 void* dst)
const noexcept
1759 d(i,j,k,n) = s(i,j,k,n+srccomp);
1761 return sizeof(T)*d.
size();
1770template <RunOn run_on,
typename BUF>
1775 const void* src)
noexcept
1787 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1789 return sizeof(BUF)*s.
size();
1798template <RunOn run_on,
typename BUF>
1803 const void* src)
noexcept
1815 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1817 return sizeof(BUF)*s.
size();
1826template <RunOn run_on>
1834template <RunOn run_on>
1838 this->abs<run_on>(this->domain,0,this->nvar);
1842template <RunOn run_on>
1846 this->abs<run_on>(this->domain,comp,numcomp);
1850template <RunOn run_on>
1857 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
1862template <RunOn run_on>
1865 int scomp,
int ncomp)
const noexcept
1867 BL_ASSERT(this->domain.contains(subbox));
1868 BL_ASSERT(scomp >= 0 && scomp + ncomp <= this->nvar);
1878 reduce_op.
eval(subbox, reduce_data,
1883 for (
int n = 0; n < ncomp; ++n) {
1889 ReduceTuple hv = reduce_data.
value(reduce_op);
1890 r = amrex::get<0>(hv);
1894 amrex::LoopOnCpu(subbox, ncomp, [=,&r] (
int i,
int j,
int k,
int n)
noexcept
1897 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+scomp)));
1906template <RunOn run_on>
1910 return norm<run_on>(this->domain,p,comp,numcomp);
1914template <RunOn run_on>
1918 BL_ASSERT(this->domain.contains(subbox));
1919 BL_ASSERT(comp >= 0 && comp + numcomp <= this->nvar);
1929 reduce_op.
eval(subbox, reduce_data,
1933 for (
int n = 0; n < numcomp; ++n) {
1938 ReduceTuple hv = reduce_data.
value(reduce_op);
1939 nrm = amrex::get<0>(hv);
1940 }
else if (p == 1) {
1944 reduce_op.
eval(subbox, reduce_data,
1948 for (
int n = 0; n < numcomp; ++n) {
1949 t +=
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1953 ReduceTuple hv = reduce_data.
value(reduce_op);
1954 nrm = amrex::get<0>(hv);
1955 }
else if (p == 2) {
1959 reduce_op.
eval(subbox, reduce_data,
1963 for (
int n = 0; n < numcomp; ++n) {
1964 t +=
static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
1968 ReduceTuple hv = reduce_data.
value(reduce_op);
1969 nrm = amrex::get<0>(hv);
1977 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1979 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1982 }
else if (p == 1) {
1983 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1985 nrm += std::abs(a(i,j,k,n+comp));
1987 }
else if (p == 2) {
1988 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1990 nrm += a(i,j,k,n+comp)*a(i,j,k,n+comp);
2001template <RunOn run_on>
2005 return this->min<run_on>(this->domain,comp);
2009template <RunOn run_on>
2018 using ReduceTuple =
typename decltype(reduce_data)::Type;
2019 reduce_op.
eval(subbox, reduce_data,
2022 return { a(i,j,k) };
2024 ReduceTuple hv = reduce_data.
value(reduce_op);
2025 return amrex::get<0>(hv);
2029 T r = std::numeric_limits<T>::max();
2039template <RunOn run_on>
2043 return this->max<run_on>(this->domain,comp);
2047template <RunOn run_on>
2056 using ReduceTuple =
typename decltype(reduce_data)::Type;
2057 reduce_op.
eval(subbox, reduce_data,
2060 return { a(i,j,k) };
2062 ReduceTuple hv = reduce_data.
value(reduce_op);
2063 return amrex::get<0>(hv);
2067 T r = std::numeric_limits<T>::lowest();
2077template <RunOn run_on>
2081 return this->minmax<run_on>(this->domain,comp);
2085template <RunOn run_on>
2094 using ReduceTuple =
typename decltype(reduce_data)::Type;
2095 reduce_op.
eval(subbox, reduce_data,
2098 auto const x = a(i,j,k);
2101 ReduceTuple hv = reduce_data.
value(reduce_op);
2102 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
2106 T rmax = std::numeric_limits<T>::lowest();
2107 T rmin = std::numeric_limits<T>::max();
2110 auto const x = a(i,j,k);
2114 return std::make_pair(rmin,rmax);
2119template <RunOn run_on>
2123 return this->maxabs<run_on>(this->domain,comp);
2127template <RunOn run_on>
2136 using ReduceTuple =
typename decltype(reduce_data)::Type;
2137 reduce_op.
eval(subbox, reduce_data,
2140 return { std::abs(a(i,j,k)) };
2142 ReduceTuple hv = reduce_data.
value(reduce_op);
2143 return amrex::get<0>(hv);
2158template <RunOn run_on>
2166 std::numeric_limits<int>::lowest(),
2167 std::numeric_limits<int>::lowest())};
2174 if ((*flag == 0) && (a(i,j,k) == value)) {
2197template <RunOn run_on>
2201 return this->minIndex<run_on>(this->domain,comp);
2205template <RunOn run_on>
2209 T min_val = this->min<run_on>(subbox, comp);
2210 return this->indexFromValue<run_on>(subbox, comp, min_val);
2214template <RunOn run_on>
2218 min_val = this->min<run_on>(subbox, comp);
2219 min_idx = this->indexFromValue<run_on>(subbox, comp, min_val);
2223template <RunOn run_on>
2227 return this->maxIndex<run_on>(this->domain,comp);
2231template <RunOn run_on>
2235 T max_val = this->max<run_on>(subbox, comp);
2236 return this->indexFromValue<run_on>(subbox, comp, max_val);
2240template <RunOn run_on>
2244 max_val = this->max<run_on>(subbox, comp);
2245 max_idx = this->indexFromValue<run_on>(subbox, comp, max_val);
2249template <RunOn run_on>
2253 mask.resize(this->domain,1);
2261 using ReduceTuple =
typename decltype(reduce_data)::Type;
2262 reduce_op.
eval(this->domain, reduce_data,
2266 if (a(i,j,k) < val) {
2275 ReduceTuple hv = reduce_data.
value(reduce_op);
2276 cnt = amrex::get<0>(hv);
2282 if (a(i,j,k) < val) {
2295template <RunOn run_on>
2299 mask.resize(this->domain,1);
2307 using ReduceTuple =
typename decltype(reduce_data)::Type;
2308 reduce_op.
eval(this->domain, reduce_data,
2312 if (a(i,j,k) <= val) {
2321 ReduceTuple hv = reduce_data.
value(reduce_op);
2322 cnt = amrex::get<0>(hv);
2328 if (a(i,j,k) <= val) {
2341template <RunOn run_on>
2345 mask.resize(this->domain,1);
2353 using ReduceTuple =
typename decltype(reduce_data)::Type;
2354 reduce_op.
eval(this->domain, reduce_data,
2358 if (a(i,j,k) == val) {
2367 ReduceTuple hv = reduce_data.
value(reduce_op);
2368 cnt = amrex::get<0>(hv);
2374 if (a(i,j,k) == val) {
2387template <RunOn run_on>
2391 mask.resize(this->domain,1);
2399 using ReduceTuple =
typename decltype(reduce_data)::Type;
2400 reduce_op.
eval(this->domain, reduce_data,
2404 if (a(i,j,k) > val) {
2413 ReduceTuple hv = reduce_data.
value(reduce_op);
2414 cnt = amrex::get<0>(hv);
2420 if (a(i,j,k) > val) {
2433template <RunOn run_on>
2437 mask.resize(this->domain,1);
2445 using ReduceTuple =
typename decltype(reduce_data)::Type;
2446 reduce_op.
eval(this->domain, reduce_data,
2450 if (a(i,j,k) >= val) {
2459 ReduceTuple hv = reduce_data.
value(reduce_op);
2460 cnt = amrex::get<0>(hv);
2466 if (a(i,j,k) >= val) {
2479template <RunOn run_on>
2483 Box ovlp(this->domain);
2485 return ovlp.
ok() ? this->atomicAdd<run_on>(
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2489template <RunOn run_on>
2492 int srccomp,
int destcomp,
int numcomp)
noexcept
2499 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2506 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2516template <RunOn run_on>
2520 Box ovlp(this->domain);
2522 return ovlp.
ok() ? saxpy<run_on>(a,
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2526template <RunOn run_on>
2529 const Box& srcbox,
const Box& destbox,
2530 int srccomp,
int destcomp,
int numcomp)
noexcept
2537 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2544 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2547 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);
2554template <RunOn run_on>
2562 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2563 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2571 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2578template <RunOn run_on>
2583 int comp,
int numcomp)
noexcept
2593 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2594 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2603 const Dim3 off1{.
x = slo1.x-dlo.x, .y = slo1.y-dlo.y, .z = slo1.z-dlo.z};
2604 const Dim3 off2{.
x = slo2.x-dlo.x, .y = slo2.y-dlo.y, .z = slo2.z-dlo.z};
2608 d(i,j,k,n+comp) = alpha*s1(i+off1.x,j+off1.y,k+off1.z,n+comp1)
2609 + beta*s2(i+off2.x,j+off2.y,k+off2.z,n+comp2);
2615template <RunOn run_on>
2619 int numcomp)
const noexcept
2626 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2632 const Dim3 offset{.
x = ylo.x-xlo.x, .y = ylo.y-xlo.y, .z = ylo.z-xlo.z};
2640 using ReduceTuple =
typename decltype(reduce_data)::Type;
2641 reduce_op.
eval(xbx, reduce_data,
2645 for (
int n = 0; n < numcomp; ++n) {
2650 ReduceTuple hv = reduce_data.
value(reduce_op);
2651 r = amrex::get<0>(hv);
2665template <RunOn run_on>
2669 int numcomp)
const noexcept
2676 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2682 const Dim3 offset{.
x = ylo.x-xlo.x, .y = ylo.y-xlo.y, .z = ylo.z-xlo.z};
2692 using ReduceTuple =
typename decltype(reduce_data)::Type;
2693 reduce_op.
eval(xbx, reduce_data,
2696 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2698 for (
int n = 0; n < numcomp; ++n) {
2703 ReduceTuple hv = reduce_data.
value(reduce_op);
2704 r = amrex::get<0>(hv);
2710 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2719template <RunOn run_on>
2727template <RunOn run_on>
2735template <RunOn run_on>
2739 return this->negate<run_on>(this->domain,
DestComp{comp},
NumComps{numcomp});
2743template <RunOn run_on>
2751template <RunOn run_on>
2755 return this->invert<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2759template <RunOn run_on>
2767template <RunOn run_on>
2771 return this->plus<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2775template <RunOn run_on>
2783template <RunOn run_on>
2791template <RunOn run_on>
2795 Box ovlp(this->domain);
2797 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2801template <RunOn run_on>
2804 int numcomp)
noexcept
2810template <RunOn run_on>
2813 int numcomp)
noexcept
2815 Box ovlp(this->domain);
2818 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2822template <RunOn run_on>
2825 int srccomp,
int destcomp,
int numcomp)
noexcept
2831 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2838 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2850template <
RunOn run_on,
typename T,
2851 std::enable_if_t<HasAtomicAdd<T>::value,
int> FOO = 0>
2853 const Box& srcbox,
const Box& destbox,
2854 int srccomp,
int destcomp,
int numcomp)
noexcept
2860 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2863 T* p = d.
ptr(i,j,k,n+destcomp);
2868template <
RunOn run_on,
typename T,
2869 std::enable_if_t<! HasAtomicAdd<T>::value,
int> FOO = 0>
2870void basefab_atomic_add (BaseFab<T>& dfab,
const BaseFab<T>& sfab,
2871 const Box& srcbox,
const Box& destbox,
2872 int srccomp,
int destcomp,
int numcomp)
2881template <RunOn run_on>
2884 int srccomp,
int destcomp,
int numcomp)
noexcept
2890 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2893 detail::basefab_atomic_add<run_on>(*
this, src, srcbox, destbox,
2894 srccomp, destcomp, numcomp);
2900template <RunOn run_on>
2903 int srccomp,
int destcomp,
int numcomp)
noexcept
2905#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
2906#if defined(AMREX_USE_GPU)
2913 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2922 Dim3 const offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
2938 for (
int ip = 0; ip < nplanes; ++ip) {
2943 int planes_left = nplanes;
2944 while (planes_left > 0) {
2946 auto const m = mm + plo;
2947 auto* lock = OpenMP::get_lock(m);
2948 if (omp_test_lock(lock))
2952 if (planedim == 1) {
2960 for (
int n = 0; n < numcomp; ++n) {
2961 for (
int k = lo.z; k <= hi.z; ++k) {
2962 for (
int j = lo.y; j <= hi.y; ++j) {
2963 auto *
pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
2966 for (
int ii = 0; ii < len.x; ++ii) {
2967 pdst[ii] += psrc[ii];
2975 omp_unset_lock(lock);
2976 if (planes_left == 0) {
break; }
2980 for (
int ip = 0; ip < nplanes; ++ip) {
2981 int new_mm = (mm+ip) % nplanes;
2982 if ( !
mask[new_mm] ) {
2993#if defined(AMREX_USE_GPU)
2995 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2999 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3004template <RunOn run_on>
3012template <RunOn run_on>
3020template <RunOn run_on>
3023 int srccomp,
int destcomp,
int numcomp)
noexcept
3029 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3036 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3046template <RunOn run_on>
3050 return this->mult<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3054template <RunOn run_on>
3062template <RunOn run_on>
3070template <RunOn run_on>
3078template <RunOn run_on>
3081 int srccomp,
int destcomp,
int numcomp)
noexcept
3087 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3094 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3104template <RunOn run_on>
3108 return this->divide<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3112template <RunOn run_on>
3120template <RunOn run_on>
3128template <RunOn run_on>
3136template <RunOn run_on>
3139 int srccomp,
int destcomp,
int numcomp)
noexcept
3145 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3152 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3162template <RunOn run_on>
3166 Box ovlp(this->domain);
3168 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,0,0,this->nvar) : *
this;
3172template <RunOn run_on>
3176 Box ovlp(this->domain);
3178 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3182template <RunOn run_on>
3185 int numcomp)
noexcept
3187 Box ovlp(this->domain);
3190 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3194template <RunOn run_on>
3197 int srccomp,
int destcomp,
int numcomp)
noexcept
3203 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3210 const Dim3 offset{.
x = slo.x-dlo.x, .y = slo.y-dlo.y, .z = slo.z-dlo.z};
3214 d(i,j,k,n+destcomp) /= s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
3232template <RunOn run_on>
3237 const Box& b,
int comp,
int numcomp)
noexcept
3240 return copy<run_on>(f1,b1,comp1,b,comp,numcomp);
3242 return copy<run_on>(f2,b2,comp2,b,comp,numcomp);
3244 Real alpha = (t2-t)/(t2-t1);
3245 Real beta = (t-t1)/(t2-t1);
3246 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,b,comp,numcomp);
3251template <RunOn run_on>
3256 const Box& b,
int comp,
int numcomp)
noexcept
3259 return copy<run_on>(f1,b,comp1,b,comp,numcomp);
3261 return copy<run_on>(f2,b,comp2,b,comp,numcomp);
3263 Real alpha = (t2-t)/(t2-t1);
3264 Real beta = (t-t1)/(t2-t1);
3265 return linComb<run_on>(f1,b,comp1,f2,b,comp2,alpha,beta,b,comp,numcomp);
3274template <RunOn run_on>
3278 this->setVal<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3282template <RunOn run_on>
3286 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3290 a(i,j,k,n+dcomp.i) = x;
3295template <RunOn run_on>
3303template <RunOn run_on>
3307 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3312 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3317template <RunOn run_on>
3325template <RunOn run_on>
3329 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3334 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3339template <RunOn run_on>
3344 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3349 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3358 for (
auto const& b : b_lst) {
3359 this->setVal<RunOn::Host>(
x, b, dcomp, ncomp);
3365template <RunOn run_on>
3374template <RunOn run_on>
3380 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3381 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3389 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3396template <RunOn run_on>
3400 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3404template <RunOn run_on>
3408 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3412template <RunOn run_on>
3416 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3421 a(i,j,k,n+dcomp.i) += val;
3428template <RunOn run_on>
3436template <RunOn run_on>
3444template <RunOn run_on>
3450 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3451 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3459 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3466template <RunOn run_on>
3470 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3474template <RunOn run_on>
3478 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3482template <RunOn run_on>
3486 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3491 a(i,j,k,n+dcomp.i) -= val;
3498template <RunOn run_on>
3506template <RunOn run_on>
3514template <RunOn run_on>
3520 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3521 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3529 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3536template <RunOn run_on>
3540 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3544template <RunOn run_on>
3548 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3552template <RunOn run_on>
3556 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3561 a(i,j,k,n+dcomp.i) *= val;
3568template <RunOn run_on>
3576template <RunOn run_on>
3584template <RunOn run_on>
3590 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3591 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3599 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3606template <RunOn run_on>
3610 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3614template <RunOn run_on>
3618 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3622template <RunOn run_on>
3626 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3631 a(i,j,k,n+dcomp.i) /= val;
3638template <RunOn run_on>
3646template <RunOn run_on>
3654template <RunOn run_on>
3660 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3661 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3669 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3676template <RunOn run_on>
3680 return this->negate<run_on>(this->domain,
DestComp{0},
NumComps{this->nvar});
3684template <RunOn run_on>
3688 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3693 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3700template <RunOn run_on>
3704 return this->invert<run_on>(r, this->domain,
DestComp{0},
NumComps{this->nvar});
3708template <RunOn run_on>
3712 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3717 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3724template <RunOn run_on>
3728 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3733 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3736 using ReduceTuple =
typename decltype(reduce_data)::Type;
3737 reduce_op.
eval(bx, reduce_data,
3741 for (
int n = 0; n < ncomp.n; ++n) {
3742 t += a(i,j,k,n+dcomp.i);
3746 ReduceTuple hv = reduce_data.
value(reduce_op);
3747 r = amrex::get<0>(hv);
3753 r += a(i,j,k,n+dcomp.i);
3761template <RunOn run_on>
3766 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3767 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3773 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3776 using ReduceTuple =
typename decltype(reduce_data)::Type;
3777 reduce_op.
eval(bx, reduce_data,
3781 for (
int n = 0; n < ncomp.n; ++n) {
3782 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3786 ReduceTuple hv = reduce_data.
value(reduce_op);
3787 r = amrex::get<0>(hv);
3793 r += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3801template <RunOn run_on>
3810template <RunOn run_on>
3814 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3819 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3822 using ReduceTuple =
typename decltype(reduce_data)::Type;
3823 reduce_op.
eval(bx, reduce_data,
3827 for (
int n = 0; n < ncomp.n; ++n) {
3828 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3832 ReduceTuple hv = reduce_data.
value(reduce_op);
3833 r = amrex::get<0>(hv);
3839 r += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3847template <RunOn run_on>
3854 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3855 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3862 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3865 using ReduceTuple =
typename decltype(reduce_data)::Type;
3866 reduce_op.
eval(bx, reduce_data,
3870 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
3871 for (
int n = 0; n < ncomp.n; ++n) {
3872 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
3876 ReduceTuple hv = reduce_data.
value(reduce_op);
3877 r = amrex::get<0>(hv);
3883 int mi = static_cast<int>(static_cast<bool>(m(i,j,k)));
3884 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: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:75
#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:1143
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
Real * pdst
Definition AMReX_HypreMLABecLap.cpp:1140
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:132
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:190
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:2435
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:2491
Array4< T const > const_array() const noexcept
Definition AMReX_BaseFab.H:418
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:3376
T sum(int comp, int numcomp=1) const noexcept
Returns sum of given component of FAB state vector.
Definition AMReX_BaseFab.H:2721
gpuStream_t alloc_stream
Definition AMReX_BaseFab.H:1171
Real norminfmask(const Box &subbox, const BaseFab< int > &mask, int scomp=0, int ncomp=1) const noexcept
Definition AMReX_BaseFab.H:1864
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition AMReX_BaseFab.H:3608
const int * hiVect() const noexcept
Returns the upper corner of the domain.
Definition AMReX_BaseFab.H:329
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:3516
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:2902
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:1745
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:1800
std::size_t nBytesOwned() const noexcept
Definition AMReX_BaseFab.H:271
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3367
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:2556
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition AMReX_BaseFab.H:3468
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:2251
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3398
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3554
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:3586
std::size_t nBytes(const Box &bx, int ncomps) const noexcept
Returns bytes used in the Box for those components.
Definition AMReX_BaseFab.H:276
void setPtr(T *p, Long sz) noexcept
Definition AMReX_BaseFab.H:376
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:2580
void define()
Allocates memory for the BaseFab<T>.
Definition AMReX_BaseFab.H:1457
BaseFab< T > & operator*=(T const &val) noexcept
Definition AMReX_BaseFab.H:3546
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:1628
void clear()
The function returns the BaseFab to the invalid state. The memory is freed.
Definition AMReX_BaseFab.H:1691
const IntVect & smallEnd() const noexcept
Returns the lower corner of the domain See class Box for analogue.
Definition AMReX_BaseFab.H:306
BaseFab< T > & mult(T const &r, int comp, int numcomp=1) noexcept
Scalar multiplication, except control which components are multiplied.
Definition AMReX_BaseFab.H:3048
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition AMReX_BaseFab.H:2481
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:2343
const int * loVect() const noexcept
Returns the lower corner of the domain.
Definition AMReX_BaseFab.H:319
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:335
bool isAllocated() const noexcept
Returns true if the data for the FAB has been allocated.
Definition AMReX_BaseFab.H:436
std::unique_ptr< T, DataDeleter > release() noexcept
Release ownership of memory.
Definition AMReX_BaseFab.H:1727
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3284
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3476
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition AMReX_BaseFab.H:294
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:3305
Array4< T > array() noexcept
Definition AMReX_BaseFab.H:400
IntVect indexFromValue(const Box &subbox, int comp, T const &value) const noexcept
Definition AMReX_BaseFab.H:2160
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3570
bool shared_memory
Is the memory allocated in shared memory?
Definition AMReX_BaseFab.H:1169
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:2297
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3297
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:3446
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3319
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:2528
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:1268
std::size_t nBytes() const noexcept
Returns how many bytes used.
Definition AMReX_BaseFab.H:269
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:1772
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition AMReX_BaseFab.H:3678
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3500
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:3006
T value_type
Definition AMReX_BaseFab.H:195
void SetBoxType(const IndexType &typ) noexcept
Change the Box type without change the length.
Definition AMReX_BaseFab.H:981
Array4< T const > array() const noexcept
Definition AMReX_BaseFab.H:382
T maxabs(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2121
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3406
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:3341
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3484
Long truesize
nvar*numpts that was allocated on heap.
Definition AMReX_BaseFab.H:1167
void setVal(T const &val) noexcept
Set value on the whole domain and all components.
Definition AMReX_BaseFab.H:3276
const int * nCompPtr() const noexcept
for calls to fortran.
Definition AMReX_BaseFab.H:283
Array4< T const > const_array(int start_comp, int num_comps) const noexcept
Definition AMReX_BaseFab.H:430
Box domain
My index space.
Definition AMReX_BaseFab.H:1165
bool contains(const Box &bx) const noexcept
Returns true if bx is totally contained within the domain of this BaseFab.
Definition AMReX_BaseFab.H:344
T * dptr
The data pointer.
Definition AMReX_BaseFab.H:1164
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:1341
BaseFab< T > & divide(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3624
T max(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2041
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:1415
Array4< T > array(int start_comp, int num_comps) noexcept
Definition AMReX_BaseFab.H:412
int nvar
Number components.
Definition AMReX_BaseFab.H:1166
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:2617
BaseFab< T > & divide(T const &r, int comp, int numcomp=1) noexcept
As above except specify which components.
Definition AMReX_BaseFab.H:3106
Array4< T const > array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:388
BaseFab< T > & operator/=(T const &val) noexcept
Definition AMReX_BaseFab.H:3616
std::pair< T, T > minmax(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2079
Array4< T const > const_array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:424
void fill_snan() noexcept
Definition AMReX_BaseFab.H:1375
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:1399
Long size() const noexcept
Returns the total number of points of all components.
Definition AMReX_BaseFab.H:291
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:2777
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:1315
const IntVect & bigEnd() const noexcept
Returns the upper corner of the domain. See class Box for analogue.
Definition AMReX_BaseFab.H:309
Array4< T > array(int start_comp) noexcept
Definition AMReX_BaseFab.H:406
Elixir elixir() noexcept
Definition AMReX_BaseFab.H:1670
Long numPts() const noexcept
Returns the number of points.
Definition AMReX_BaseFab.H:288
const T * dataPtr(int n=0) const noexcept
Same as above except works on const FABs.
Definition AMReX_BaseFab.H:364
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:3327
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3538
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:3656
void setValIfNot(T const &val, const Box &bx, const BaseFab< int > &mask, int nstart, int num) noexcept
Definition AMReX_BaseFab.H:1407
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:1365
void prefetchToDevice() const noexcept
Definition AMReX_BaseFab.H:1235
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:355
bool ptr_owner
Owner of T*?
Definition AMReX_BaseFab.H:1168
virtual ~BaseFab() noexcept
The destructor deletes the array memory.
Definition AMReX_BaseFab.H:1575
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:300
IntVect maxIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2225
BaseFab< T > & protected_divide(const BaseFab< T > &src) noexcept
Divide wherever "src" is "true" or "non-zero".
Definition AMReX_BaseFab.H:3164
friend class BaseFab
Definition AMReX_BaseFab.H:193
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:2761
Array4< T const > array(int start_comp, int num_comps) const noexcept
Definition AMReX_BaseFab.H:394
int nComp() const noexcept
Returns the number of components.
Definition AMReX_BaseFab.H:280
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:2389
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:2667
BaseFab< T > & plus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3430
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:3640
void prefetchToHost() const noexcept
Definition AMReX_BaseFab.H:1203
T min(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2003
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:1828
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:3234
IntVect minIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2199
T * dataPtr(const IntVect &p, int n=0) noexcept
Definition AMReX_BaseFab.H:1178
void abs() noexcept
Compute absolute value for all components of this FAB.
Definition AMReX_BaseFab.H:1836
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:1333
BaseFab< T > & plus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3414
Real norm(int p, int scomp=0, int numcomp=1) const
Compute the Lp-norm of this FAB using components (scomp : scomp+ncomp-1). p < 0 -> ERROR p = 0 -> inf...
Definition AMReX_BaseFab.H:1908
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
Return the inclusive upper bound of the box.
Definition AMReX_Box.H:123
__host__ __device__ const int * hiVect() const &noexcept
Return a constant pointer the array of high end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:191
__host__ __device__ Long numPts() const noexcept
Return the number of points contained in the BoxND.
Definition AMReX_Box.H:356
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:154
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:212
__host__ __device__ const int * loVect() const &noexcept
Return a constant pointer the array of low end coordinates. Useful for calls to FORTRAN.
Definition AMReX_Box.H:186
__host__ __device__ BoxND & setType(const IndexTypeND< dim > &t) noexcept
Set indexing type.
Definition AMReX_Box.H:505
__host__ __device__ bool ok() const noexcept
Checks if it is a proper BoxND (including a valid type).
Definition AMReX_Box.H:208
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:111
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
static int deviceId() noexcept
Definition AMReX_GpuDevice.cpp:692
static int devicePropMajor() noexcept
Definition AMReX_GpuDevice.H:203
Definition AMReX_GpuElixir.H:13
__host__ static __device__ constexpr IntVectND< dim > TheMinVector() noexcept
Definition AMReX_IntVect.H:819
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
T * data() noexcept
Definition AMReX_PODVector.H:666
Definition AMReX_Reduce.H:453
Type value()
Definition AMReX_Reduce.H:488
Definition AMReX_Reduce.H:612
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:748
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
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:1331
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Return the spatial extents of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1345
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1317
std::array< T, N > Array
Definition AMReX_Array.H:26
__host__ __device__ AMREX_FORCE_INLINE T Exch(T *address, T val) noexcept
Definition AMReX_GpuAtomic.H:487
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:435
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:421
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:291
__host__ __device__ AMREX_FORCE_INLINE void Add(T *const sum, T const value) noexcept
Definition AMReX_GpuAtomic.H:636
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 &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2852
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:193
__host__ __device__ Array4< T > makeArray4(T *p, Box const &bx, int ncomp) noexcept
Definition AMReX_BaseFab.H:92
RunOn
Definition AMReX_GpuControl.H:65
std::enable_if_t< std::is_arithmetic_v< T > > placementNew(T *const, Long)
Definition AMReX_BaseFab.H:99
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:79
bool InitSNaN() noexcept
Definition AMReX.cpp:185
Long TotalBytesAllocatedInFabs() noexcept
Definition AMReX_BaseFab.cpp:66
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:30
void BaseFab_Initialize()
Definition AMReX_BaseFab.cpp:30
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:24
void BaseFab_Finalize()
Definition AMReX_BaseFab.cpp:59
__host__ __device__ Dim3 begin(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2006
void ResetTotalBytesAllocatedInFabsHWM() noexcept
Definition AMReX_BaseFab.cpp:134
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:122
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
Long TotalBytesAllocatedInFabsHWM() noexcept
Definition AMReX_BaseFab.cpp:83
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:44
Long TotalCellsAllocatedInFabsHWM() noexcept
Definition AMReX_BaseFab.cpp:117
Long TotalCellsAllocatedInFabs() noexcept
Definition AMReX_BaseFab.cpp:100
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:235
std::enable_if_t< std::is_trivially_destructible_v< T > > placementDelete(T *const, Long)
Definition AMReX_BaseFab.H:124
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:241
void LoopOnCpu(Dim3 lo, Dim3 hi, F const &f) noexcept
Definition AMReX_Loop.H:365
void update_fab_stats(Long n, Long s, size_t szt) noexcept
Definition AMReX_BaseFab.cpp:146
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Definition AMReX_Box.H:2015
A multidimensional array accessor.
Definition AMReX_Array4.H:283
__host__ __device__ constexpr std::size_t size() const noexcept
Total number of elements in the ArrayND's index region.
Definition AMReX_Array4.H:638
__host__ __device__ T * ptr(idx... i) const noexcept
Multi-index ptr() for accessing pointer to element.
Definition AMReX_Array4.H:556
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:77
int i
Definition AMReX_BaseFab.H:80
__host__ __device__ DestComp(int ai) noexcept
Definition AMReX_BaseFab.H:79
Definition AMReX_Dim3.H:12
int x
Definition AMReX_Dim3.H:12
Definition AMReX_BaseFab.H:83
__host__ __device__ NumComps(int an) noexcept
Definition AMReX_BaseFab.H:85
int n
Definition AMReX_BaseFab.H:86
Definition AMReX_BaseFab.H:71
__host__ __device__ SrcComp(int ai) noexcept
Definition AMReX_BaseFab.H:73
int i
Definition AMReX_BaseFab.H:74