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 noexcept;
586 [[nodiscard]]
Real norm (const
Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
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(__CUDACC__) && (__CUDACC_VER_MAJOR__ >= 13)
1216 cudaMemLocation location = {};
1217 location.type = cudaMemLocationTypeDevice;
1218 location.id = cudaCpuDeviceId;
1227#elif defined(AMREX_USE_HIP)
1239 if (this->arena()->isManaged()) {
1240#if defined(AMREX_USE_SYCL)
1241 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1242 auto& q = Gpu::Device::streamQueue();
1243 q.submit([&] (sycl::handler& h) { h.prefetch(this->dptr, s); });
1244#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1246 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1247#if defined(__CUDACC__) && (__CUDACC_VER_MAJOR__ >= 13)
1248 cudaMemLocation location = {};
1249 location.type = cudaMemLocationTypeDevice;
1259#elif defined(AMREX_USE_HIP)
1276 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1287 return this->dptr[this->domain.index(p)];
1300 return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
1311 return this->dptr[this->domain.index(p)];
1319 int numcomp)
const noexcept
1321 const int loc = this->domain.index(pos);
1322 const Long sz = this->domain.numPts();
1327 for (
int k = 0; k < numcomp; k++) {
1328 data[k] = this->dptr[loc+(n+k)*sz];
1335 const IntVect& pos)
const noexcept
1337 getVal(data,pos,0,this->nvar);
1373template <
RunOn run_on,
class U,
1374 std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO>
1378 amrex::fill_snan<run_on>(this->dptr, this->truesize);
1382template <RunOn run_on>
1390template <RunOn run_on>
1398template <RunOn run_on>
1406template <RunOn run_on>
1414template <RunOn run_on>
1417 const Box& destbox,
int destcomp,
int numcomp)
noexcept
1423 AMREX_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
1424 AMREX_ASSERT(destcomp >= 0 && destcomp+numcomp <= this->nvar);
1430 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
1441template <RunOn run_on>
1449template <RunOn run_on>
1463 if (this->nvar == 0) {
return; }
1464 AMREX_ASSERT(std::numeric_limits<Long>::max()/this->nvar > this->domain.numPts());
1466 this->truesize = this->nvar*this->domain.numPts();
1467 this->ptr_owner =
true;
1468 this->dptr =
static_cast<T*
>(this->alloc(this->truesize*
sizeof(T)));
1477 if constexpr (std::is_same_v<T,float> || std::is_same_v<T,double>) {
1481 this->
template fill_snan<RunOn::Device>();
1486 this->
template fill_snan<RunOn::Host>();
1506 :
DataAllocator{ar}, domain(bx), nvar(n), shared_memory(shared)
1514 dptr(const_cast<T*>(rhs.dataPtr(scomp))),
1515 domain(rhs.domain), nvar(ncomp),
1516 truesize(ncomp*rhs.domain.numPts())
1521 this->
dptr =
nullptr;
1523 this->copy<RunOn::Device>(rhs, this->
domain, scomp, this->
domain, 0, ncomp);
1533 : dptr(p), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
1539 : dptr(const_cast<T*>(p)), domain(bx), nvar(ncomp), truesize(bx.numPts()*ncomp)
1548 nvar(a.nComp()), truesize(a.size())
1556 nvar(a.nComp()), truesize(a.size())
1561 : dptr(
const_cast<T*
>(a.p)),
1564 nvar(a.nComp()), truesize(a.size())
1569 : dptr(
const_cast<T*
>(a.p)),
1572 nvar(a.nComp()), truesize(a.size())
1584 dptr(rhs.dptr), domain(rhs.domain),
1585 nvar(rhs.nvar), truesize(rhs.truesize),
1586 ptr_owner(rhs.ptr_owner), shared_memory(rhs.shared_memory)
1588 , alloc_stream(rhs.alloc_stream)
1592 rhs.ptr_owner =
false;
1601 DataAllocator::operator=(rhs);
1603 domain = rhs.domain;
1605 truesize = rhs.truesize;
1606 ptr_owner = rhs.ptr_owner;
1607 shared_memory = rhs.shared_memory;
1609 alloc_stream = rhs.alloc_stream;
1613 rhs.ptr_owner =
false;
1619template <RunOn run_on>
1634 if (ar ==
nullptr) {
1643 else if (this->dptr ==
nullptr || !this->ptr_owner)
1645 if (this->shared_memory) {
1646 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1649 this->dptr =
nullptr;
1652 else if (this->nvar*this->domain.numPts() > this->truesize
1654 || (arena()->isStreamOrderedArena() && alloc_stream !=
Gpu::gpuStream())
1658 if (this->shared_memory) {
1659 amrex::Abort(
"BaseFab::resize: BaseFab in shared memory cannot increase size");
1669template <
class U, std::enable_if_t<std::is_trivially_destructible_v<U>,
int>>
1675 o = this->ptr_owner;
1676 this->ptr_owner =
false;
1677 if (o && this->dptr) {
1678 if (this->nvar > 1) {
1687 return Elixir((o ? this->dptr :
nullptr), this->arena());
1699 if (this->ptr_owner)
1701 if (this->shared_memory)
1703 amrex::Abort(
"BaseFab::clear: BaseFab cannot be owner of shared memory");
1709 this->arena()->streamOrderedFree(this->dptr, alloc_stream);
1711 this->free(this->dptr);
1714 if (this->nvar > 1) {
1721 this->dptr =
nullptr;
1727std::unique_ptr<T,DataDeleter>
1730 std::unique_ptr<T,DataDeleter> r(
nullptr,
DataDeleter{this->arena()});
1731 if (this->dptr && this->ptr_owner) {
1732 r.reset(this->dptr);
1733 this->ptr_owner =
false;
1734 if (this->nvar > 1) {
1744template <RunOn run_on>
1749 void* dst)
const noexcept
1760 d(i,j,k,n) = s(i,j,k,n+srccomp);
1762 return sizeof(T)*d.
size();
1771template <RunOn run_on,
typename BUF>
1776 const void* src)
noexcept
1788 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1790 return sizeof(BUF)*s.
size();
1799template <RunOn run_on,
typename BUF>
1804 const void* src)
noexcept
1816 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1818 return sizeof(BUF)*s.
size();
1827template <RunOn run_on>
1835template <RunOn run_on>
1839 this->abs<run_on>(this->domain,0,this->nvar);
1843template <RunOn run_on>
1847 this->abs<run_on>(this->domain,comp,numcomp);
1851template <RunOn run_on>
1858 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
1863template <RunOn run_on>
1866 int scomp,
int ncomp)
const noexcept
1868 BL_ASSERT(this->domain.contains(subbox));
1869 BL_ASSERT(scomp >= 0 && scomp + ncomp <= this->nvar);
1879 reduce_op.
eval(subbox, reduce_data,
1884 for (
int n = 0; n < ncomp; ++n) {
1890 ReduceTuple hv = reduce_data.
value(reduce_op);
1891 r = amrex::get<0>(hv);
1895 amrex::LoopOnCpu(subbox, ncomp, [=,&r] (
int i,
int j,
int k,
int n)
noexcept
1898 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+scomp)));
1907template <RunOn run_on>
1911 return norm<run_on>(this->domain,p,comp,numcomp);
1915template <RunOn run_on>
1919 BL_ASSERT(this->domain.contains(subbox));
1920 BL_ASSERT(comp >= 0 && comp + numcomp <= this->nvar);
1930 reduce_op.
eval(subbox, reduce_data,
1934 for (
int n = 0; n < numcomp; ++n) {
1939 ReduceTuple hv = reduce_data.
value(reduce_op);
1940 nrm = amrex::get<0>(hv);
1941 }
else if (p == 1) {
1945 reduce_op.
eval(subbox, reduce_data,
1949 for (
int n = 0; n < numcomp; ++n) {
1950 t +=
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1954 ReduceTuple hv = reduce_data.
value(reduce_op);
1955 nrm = amrex::get<0>(hv);
1956 }
else if (p == 2) {
1960 reduce_op.
eval(subbox, reduce_data,
1964 for (
int n = 0; n < numcomp; ++n) {
1965 t +=
static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
1969 ReduceTuple hv = reduce_data.
value(reduce_op);
1970 nrm = amrex::get<0>(hv);
1978 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1980 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1983 }
else if (p == 1) {
1984 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1986 nrm += std::abs(a(i,j,k,n+comp));
1988 }
else if (p == 2) {
1989 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1991 nrm += a(i,j,k,n+comp)*a(i,j,k,n+comp);
2002template <RunOn run_on>
2006 return this->min<run_on>(this->domain,comp);
2010template <RunOn run_on>
2019 using ReduceTuple =
typename decltype(reduce_data)::Type;
2020 reduce_op.
eval(subbox, reduce_data,
2023 return { a(i,j,k) };
2025 ReduceTuple hv = reduce_data.
value(reduce_op);
2026 return amrex::get<0>(hv);
2030 T r = std::numeric_limits<T>::max();
2040template <RunOn run_on>
2044 return this->max<run_on>(this->domain,comp);
2048template <RunOn run_on>
2057 using ReduceTuple =
typename decltype(reduce_data)::Type;
2058 reduce_op.
eval(subbox, reduce_data,
2061 return { a(i,j,k) };
2063 ReduceTuple hv = reduce_data.
value(reduce_op);
2064 return amrex::get<0>(hv);
2068 T r = std::numeric_limits<T>::lowest();
2078template <RunOn run_on>
2082 return this->minmax<run_on>(this->domain,comp);
2086template <RunOn run_on>
2095 using ReduceTuple =
typename decltype(reduce_data)::Type;
2096 reduce_op.
eval(subbox, reduce_data,
2099 auto const x = a(i,j,k);
2102 ReduceTuple hv = reduce_data.
value(reduce_op);
2103 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
2107 T rmax = std::numeric_limits<T>::lowest();
2108 T rmin = std::numeric_limits<T>::max();
2111 auto const x = a(i,j,k);
2115 return std::make_pair(rmin,rmax);
2120template <RunOn run_on>
2124 return this->maxabs<run_on>(this->domain,comp);
2128template <RunOn run_on>
2137 using ReduceTuple =
typename decltype(reduce_data)::Type;
2138 reduce_op.
eval(subbox, reduce_data,
2141 return { std::abs(a(i,j,k)) };
2143 ReduceTuple hv = reduce_data.
value(reduce_op);
2144 return amrex::get<0>(hv);
2159template <RunOn run_on>
2167 std::numeric_limits<int>::lowest(),
2168 std::numeric_limits<int>::lowest())};
2175 if ((*flag == 0) && (a(i,j,k) == value)) {
2198template <RunOn run_on>
2202 return this->minIndex<run_on>(this->domain,comp);
2206template <RunOn run_on>
2210 T min_val = this->min<run_on>(subbox, comp);
2211 return this->indexFromValue<run_on>(subbox, comp, min_val);
2215template <RunOn run_on>
2219 min_val = this->min<run_on>(subbox, comp);
2220 min_idx = this->indexFromValue<run_on>(subbox, comp, min_val);
2224template <RunOn run_on>
2228 return this->maxIndex<run_on>(this->domain,comp);
2232template <RunOn run_on>
2236 T max_val = this->max<run_on>(subbox, comp);
2237 return this->indexFromValue<run_on>(subbox, comp, max_val);
2241template <RunOn run_on>
2245 max_val = this->max<run_on>(subbox, comp);
2246 max_idx = this->indexFromValue<run_on>(subbox, comp, max_val);
2250template <RunOn run_on>
2254 mask.resize(this->domain,1);
2262 using ReduceTuple =
typename decltype(reduce_data)::Type;
2263 reduce_op.
eval(this->domain, reduce_data,
2267 if (a(i,j,k) < val) {
2276 ReduceTuple hv = reduce_data.
value(reduce_op);
2277 cnt = amrex::get<0>(hv);
2283 if (a(i,j,k) < val) {
2296template <RunOn run_on>
2300 mask.resize(this->domain,1);
2308 using ReduceTuple =
typename decltype(reduce_data)::Type;
2309 reduce_op.
eval(this->domain, reduce_data,
2313 if (a(i,j,k) <= val) {
2322 ReduceTuple hv = reduce_data.
value(reduce_op);
2323 cnt = amrex::get<0>(hv);
2329 if (a(i,j,k) <= val) {
2342template <RunOn run_on>
2346 mask.resize(this->domain,1);
2354 using ReduceTuple =
typename decltype(reduce_data)::Type;
2355 reduce_op.
eval(this->domain, reduce_data,
2359 if (a(i,j,k) == val) {
2368 ReduceTuple hv = reduce_data.
value(reduce_op);
2369 cnt = amrex::get<0>(hv);
2375 if (a(i,j,k) == val) {
2388template <RunOn run_on>
2392 mask.resize(this->domain,1);
2400 using ReduceTuple =
typename decltype(reduce_data)::Type;
2401 reduce_op.
eval(this->domain, reduce_data,
2405 if (a(i,j,k) > val) {
2414 ReduceTuple hv = reduce_data.
value(reduce_op);
2415 cnt = amrex::get<0>(hv);
2421 if (a(i,j,k) > val) {
2434template <RunOn run_on>
2438 mask.resize(this->domain,1);
2446 using ReduceTuple =
typename decltype(reduce_data)::Type;
2447 reduce_op.
eval(this->domain, reduce_data,
2451 if (a(i,j,k) >= val) {
2460 ReduceTuple hv = reduce_data.
value(reduce_op);
2461 cnt = amrex::get<0>(hv);
2467 if (a(i,j,k) >= val) {
2480template <RunOn run_on>
2484 Box ovlp(this->domain);
2486 return ovlp.
ok() ? this->atomicAdd<run_on>(
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2490template <RunOn run_on>
2493 int srccomp,
int destcomp,
int numcomp)
noexcept
2500 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2507 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2517template <RunOn run_on>
2521 Box ovlp(this->domain);
2523 return ovlp.
ok() ? saxpy<run_on>(a,
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2527template <RunOn run_on>
2530 const Box& srcbox,
const Box& destbox,
2531 int srccomp,
int destcomp,
int numcomp)
noexcept
2538 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2545 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2548 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);
2555template <RunOn run_on>
2563 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2564 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2572 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2579template <RunOn run_on>
2584 int comp,
int numcomp)
noexcept
2594 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2595 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2604 const Dim3 off1{slo1.
x-dlo.x,slo1.y-dlo.y,slo1.z-dlo.z};
2605 const Dim3 off2{slo2.
x-dlo.x,slo2.y-dlo.y,slo2.z-dlo.z};
2609 d(i,j,k,n+comp) = alpha*s1(i+off1.x,j+off1.y,k+off1.z,n+comp1)
2610 + beta*s2(i+off2.x,j+off2.y,k+off2.z,n+comp2);
2616template <RunOn run_on>
2620 int numcomp)
const noexcept
2627 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2633 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2641 using ReduceTuple =
typename decltype(reduce_data)::Type;
2642 reduce_op.
eval(xbx, reduce_data,
2646 for (
int n = 0; n < numcomp; ++n) {
2651 ReduceTuple hv = reduce_data.
value(reduce_op);
2652 r = amrex::get<0>(hv);
2666template <RunOn run_on>
2670 int numcomp)
const noexcept
2677 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2683 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2693 using ReduceTuple =
typename decltype(reduce_data)::Type;
2694 reduce_op.
eval(xbx, reduce_data,
2697 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2699 for (
int n = 0; n < numcomp; ++n) {
2704 ReduceTuple hv = reduce_data.
value(reduce_op);
2705 r = amrex::get<0>(hv);
2711 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2720template <RunOn run_on>
2728template <RunOn run_on>
2736template <RunOn run_on>
2740 return this->negate<run_on>(this->domain,
DestComp{comp},
NumComps{numcomp});
2744template <RunOn run_on>
2752template <RunOn run_on>
2756 return this->invert<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2760template <RunOn run_on>
2768template <RunOn run_on>
2772 return this->plus<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2776template <RunOn run_on>
2784template <RunOn run_on>
2792template <RunOn run_on>
2796 Box ovlp(this->domain);
2798 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2802template <RunOn run_on>
2805 int numcomp)
noexcept
2811template <RunOn run_on>
2814 int numcomp)
noexcept
2816 Box ovlp(this->domain);
2819 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2823template <RunOn run_on>
2826 int srccomp,
int destcomp,
int numcomp)
noexcept
2832 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2839 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2851template <
RunOn run_on,
typename T,
2852 std::enable_if_t<HasAtomicAdd<T>::value,
int> FOO = 0>
2854 const Box& srcbox,
const Box& destbox,
2855 int srccomp,
int destcomp,
int numcomp)
noexcept
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);
2869template <
RunOn run_on,
typename T,
2870 std::enable_if_t<! HasAtomicAdd<T>::value,
int> FOO = 0>
2871void basefab_atomic_add (BaseFab<T>& dfab,
const BaseFab<T>& sfab,
2872 const Box& srcbox,
const Box& destbox,
2873 int srccomp,
int destcomp,
int numcomp)
noexcept
2882template <RunOn run_on>
2885 int srccomp,
int destcomp,
int numcomp)
noexcept
2891 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2894 detail::basefab_atomic_add<run_on>(*
this, src, srcbox, destbox,
2895 srccomp, destcomp, numcomp);
2901template <RunOn run_on>
2904 int srccomp,
int destcomp,
int numcomp)
noexcept
2906#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
2907#if defined(AMREX_USE_GPU)
2914 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2923 Dim3 const offset{slo.
x-dlo.x, slo.y-dlo.y, slo.z-dlo.z};
2939 for (
int ip = 0; ip < nplanes; ++ip) {
2944 int planes_left = nplanes;
2945 while (planes_left > 0) {
2947 auto const m = mm + plo;
2948 auto* lock = OpenMP::get_lock(m);
2949 if (omp_test_lock(lock))
2953 if (planedim == 1) {
2961 for (
int n = 0; n < numcomp; ++n) {
2962 for (
int k = lo.z; k <= hi.z; ++k) {
2963 for (
int j = lo.y; j <= hi.y; ++j) {
2964 auto *
pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
2967 for (
int ii = 0; ii < len.x; ++ii) {
2968 pdst[ii] += psrc[ii];
2976 omp_unset_lock(lock);
2977 if (planes_left == 0) {
break; }
2981 for (
int ip = 0; ip < nplanes; ++ip) {
2982 int new_mm = (mm+ip) % nplanes;
2983 if ( !
mask[new_mm] ) {
2994#if defined(AMREX_USE_GPU)
2996 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3000 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3005template <RunOn run_on>
3013template <RunOn run_on>
3021template <RunOn run_on>
3024 int srccomp,
int destcomp,
int numcomp)
noexcept
3030 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3037 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3047template <RunOn run_on>
3051 return this->mult<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3055template <RunOn run_on>
3063template <RunOn run_on>
3071template <RunOn run_on>
3079template <RunOn run_on>
3082 int srccomp,
int destcomp,
int numcomp)
noexcept
3088 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3095 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3105template <RunOn run_on>
3109 return this->divide<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3113template <RunOn run_on>
3121template <RunOn run_on>
3129template <RunOn run_on>
3137template <RunOn run_on>
3140 int srccomp,
int destcomp,
int numcomp)
noexcept
3146 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3153 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3163template <RunOn run_on>
3167 Box ovlp(this->domain);
3169 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,0,0,this->nvar) : *
this;
3173template <RunOn run_on>
3177 Box ovlp(this->domain);
3179 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3183template <RunOn run_on>
3186 int numcomp)
noexcept
3188 Box ovlp(this->domain);
3191 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3195template <RunOn run_on>
3198 int srccomp,
int destcomp,
int numcomp)
noexcept
3204 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3211 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3215 d(i,j,k,n+destcomp) /= s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
3233template <RunOn run_on>
3238 const Box& b,
int comp,
int numcomp)
noexcept
3241 return copy<run_on>(f1,b1,comp1,b,comp,numcomp);
3243 return copy<run_on>(f2,b2,comp2,b,comp,numcomp);
3245 Real alpha = (t2-t)/(t2-t1);
3246 Real beta = (t-t1)/(t2-t1);
3247 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,b,comp,numcomp);
3252template <RunOn run_on>
3257 const Box& b,
int comp,
int numcomp)
noexcept
3260 return copy<run_on>(f1,b,comp1,b,comp,numcomp);
3262 return copy<run_on>(f2,b,comp2,b,comp,numcomp);
3264 Real alpha = (t2-t)/(t2-t1);
3265 Real beta = (t-t1)/(t2-t1);
3266 return linComb<run_on>(f1,b,comp1,f2,b,comp2,alpha,beta,b,comp,numcomp);
3275template <RunOn run_on>
3279 this->setVal<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3283template <RunOn run_on>
3287 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3291 a(i,j,k,n+dcomp.i) = x;
3296template <RunOn run_on>
3304template <RunOn run_on>
3308 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3313 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3318template <RunOn run_on>
3326template <RunOn run_on>
3330 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3335 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3340template <RunOn run_on>
3345 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3350 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3359 for (
auto const& b : b_lst) {
3360 this->setVal<RunOn::Host>(
x, b, dcomp, ncomp);
3366template <RunOn run_on>
3375template <RunOn run_on>
3381 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3382 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3390 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3397template <RunOn run_on>
3401 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3405template <RunOn run_on>
3409 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3413template <RunOn run_on>
3417 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3422 a(i,j,k,n+dcomp.i) += val;
3429template <RunOn run_on>
3437template <RunOn run_on>
3445template <RunOn run_on>
3451 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3452 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3460 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3467template <RunOn run_on>
3471 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3475template <RunOn run_on>
3479 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3483template <RunOn run_on>
3487 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3492 a(i,j,k,n+dcomp.i) -= val;
3499template <RunOn run_on>
3507template <RunOn run_on>
3515template <RunOn run_on>
3521 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3522 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3530 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3537template <RunOn run_on>
3541 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3545template <RunOn run_on>
3549 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3553template <RunOn run_on>
3557 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3562 a(i,j,k,n+dcomp.i) *= val;
3569template <RunOn run_on>
3577template <RunOn run_on>
3585template <RunOn run_on>
3591 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3592 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3600 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3607template <RunOn run_on>
3611 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3615template <RunOn run_on>
3619 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3623template <RunOn run_on>
3627 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3632 a(i,j,k,n+dcomp.i) /= val;
3639template <RunOn run_on>
3647template <RunOn run_on>
3655template <RunOn run_on>
3661 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3662 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3670 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3677template <RunOn run_on>
3681 return this->negate<run_on>(this->domain,
DestComp{0},
NumComps{this->nvar});
3685template <RunOn run_on>
3689 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3694 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3701template <RunOn run_on>
3705 return this->invert<run_on>(r, this->domain,
DestComp{0},
NumComps{this->nvar});
3709template <RunOn run_on>
3713 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3718 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3725template <RunOn run_on>
3729 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3734 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3737 using ReduceTuple =
typename decltype(reduce_data)::Type;
3738 reduce_op.
eval(bx, reduce_data,
3742 for (
int n = 0; n < ncomp.n; ++n) {
3743 t += a(i,j,k,n+dcomp.i);
3747 ReduceTuple hv = reduce_data.
value(reduce_op);
3748 r = amrex::get<0>(hv);
3754 r += a(i,j,k,n+dcomp.i);
3762template <RunOn run_on>
3767 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3768 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3774 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3777 using ReduceTuple =
typename decltype(reduce_data)::Type;
3778 reduce_op.
eval(bx, reduce_data,
3782 for (
int n = 0; n < ncomp.n; ++n) {
3783 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3787 ReduceTuple hv = reduce_data.
value(reduce_op);
3788 r = amrex::get<0>(hv);
3794 r += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3802template <RunOn run_on>
3811template <RunOn run_on>
3815 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3820 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3823 using ReduceTuple =
typename decltype(reduce_data)::Type;
3824 reduce_op.
eval(bx, reduce_data,
3828 for (
int n = 0; n < ncomp.n; ++n) {
3829 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3833 ReduceTuple hv = reduce_data.
value(reduce_op);
3834 r = amrex::get<0>(hv);
3840 r += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3848template <RunOn run_on>
3855 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3856 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3863 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3866 using ReduceTuple =
typename decltype(reduce_data)::Type;
3867 reduce_op.
eval(bx, reduce_data,
3871 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
3872 for (
int n = 0; n < ncomp.n; ++n) {
3873 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
3877 ReduceTuple hv = reduce_data.
value(reduce_op);
3878 r = amrex::get<0>(hv);
3884 int mi = static_cast<int>(static_cast<bool>(m(i,j,k)));
3885 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: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:127
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:2436
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:2492
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:3377
T sum(int comp, int numcomp=1) const noexcept
Returns sum of given component of FAB state vector.
Definition AMReX_BaseFab.H:2722
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:1865
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition AMReX_BaseFab.H:3609
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:3517
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:2903
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:1746
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:1801
std::size_t nBytesOwned() const noexcept
Definition AMReX_BaseFab.H:271
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3368
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:2557
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition AMReX_BaseFab.H:3469
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:2252
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3399
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3555
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:3587
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:2581
void define()
Allocates memory for the BaseFab<T>.
Definition AMReX_BaseFab.H:1458
BaseFab< T > & operator*=(T const &val) noexcept
Definition AMReX_BaseFab.H:3547
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:1629
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:3049
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition AMReX_BaseFab.H:2482
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:2344
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:1728
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3285
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3477
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:3306
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:2161
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3571
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:2298
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3298
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:3447
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3320
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:2529
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:1269
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:1773
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition AMReX_BaseFab.H:3679
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3501
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:3007
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:2122
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3407
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:3342
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3485
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:3277
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:1342
BaseFab< T > & divide(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3625
T max(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2042
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:1416
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:2618
BaseFab< T > & divide(T const &r, int comp, int numcomp=1) noexcept
As above except specify which components.
Definition AMReX_BaseFab.H:3107
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:1909
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:3617
std::pair< T, T > minmax(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2080
Array4< T const > const_array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:424
void fill_snan() noexcept
Definition AMReX_BaseFab.H:1376
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:1400
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:2778
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:1316
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:1671
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:3328
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3539
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:3657
void setValIfNot(T const &val, const Box &bx, const BaseFab< int > &mask, int nstart, int num) noexcept
Definition AMReX_BaseFab.H:1408
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:1366
void prefetchToDevice() const noexcept
Definition AMReX_BaseFab.H:1236
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:1576
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:2226
BaseFab< T > & protected_divide(const BaseFab< T > &src) noexcept
Divide wherever "src" is "true" or "non-zero".
Definition AMReX_BaseFab.H:3165
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:2762
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:2390
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:2668
void clear() noexcept
The function returns the BaseFab to the invalid state. The memory is freed.
Definition AMReX_BaseFab.H:1692
BaseFab< T > & plus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3431
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:3641
void prefetchToHost() const noexcept
Definition AMReX_BaseFab.H:1203
T min(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2004
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:1829
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:3235
IntVect minIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2200
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:1837
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:1334
BaseFab< T > & plus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3415
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:691
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:727
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:746
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:488
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: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: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:622
Definition AMReX_Amr.cpp:49
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:2851
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:69
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:83
bool InitSNaN() noexcept
Definition AMReX.cpp:183
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:234
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:240
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