1#ifndef AMREX_BASEFAB_H_
2#define AMREX_BASEFAB_H_
3#include <AMReX_Config.H>
43extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs;
44extern std::atomic<Long> atomic_total_bytes_allocated_in_fabs_hwm;
45extern std::atomic<Long> atomic_total_cells_allocated_in_fabs;
46extern std::atomic<Long> atomic_total_cells_allocated_in_fabs_hwm;
47extern Long private_total_bytes_allocated_in_fabs;
48extern Long private_total_bytes_allocated_in_fabs_hwm;
49extern Long private_total_cells_allocated_in_fabs;
50extern Long private_total_cells_allocated_in_fabs_hwm;
52#pragma omp threadprivate(private_total_bytes_allocated_in_fabs)
53#pragma omp threadprivate(private_total_bytes_allocated_in_fabs_hwm)
54#pragma omp threadprivate(private_total_cells_allocated_in_fabs)
55#pragma omp threadprivate(private_total_cells_allocated_in_fabs_hwm)
72 explicit SrcComp (
int ai) noexcept : i(ai) {}
97std::enable_if_t<std::is_arithmetic_v<T>>
102std::enable_if_t<std::is_trivially_default_constructible_v<T>
103 && !std::is_arithmetic_v<T>>
106 for (
Long i = 0; i < n; ++i) {
112std::enable_if_t<!std::is_trivially_default_constructible_v<T>>
122std::enable_if_t<std::is_trivially_destructible_v<T>>
127std::enable_if_t<!std::is_trivially_destructible_v<T>>
205 bool shared = false,
Arena* ar =
nullptr);
255 template <class U=T, std::enable_if_t<std::is_trivially_destructible_v<U>,
int> = 0>
268 [[nodiscard]] std::
size_t nBytes () const noexcept {
return this->
truesize*
sizeof(T); }
275 [[nodiscard]] std::size_t
nBytes (
const Box& bx,
int ncomps)
const noexcept
276 {
return bx.numPts() *
sizeof(T) * ncomps; }
279 [[nodiscard]]
int nComp () const noexcept {
return this->
nvar; }
282 [[nodiscard]]
const int*
nCompPtr() const noexcept {
283 return &(this->
nvar);
293 [[nodiscard]]
const Box&
box () const noexcept {
return this->
domain; }
354 [[nodiscard]] T*
dataPtr (
int n = 0) noexcept {
363 [[nodiscard]]
const T*
dataPtr (
int n = 0) const noexcept {
459 void getVal (T* data,
const IntVect& pos,
int N,
int numcomp)
const noexcept;
464 class U=T, std::enable_if_t<std::is_same_v<U,float> || std::is_same_v<U,double>,
int> FOO = 0>
474 void setVal (T const&
x, const
Box& bx,
int dcomp,
int ncomp) noexcept;
511 const
Box& destbox,
int destcomp,
int numcomp) noexcept;
521 int numcomp = 1) noexcept;
534 int numcomp,
void* dst) const noexcept;
539 int numcomp, const
void* src) noexcept;
544 int numcomp, const
void* src) noexcept;
581 [[nodiscard]]
Real norm (
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
585 [[nodiscard]]
Real norm (const
Box& subbox,
int p,
int scomp = 0,
int numcomp = 1) const noexcept;
591 void abs (
int comp,
int numcomp=1) noexcept;
596 void abs (const
Box& subbox,
int comp = 0,
int numcomp=1) noexcept;
601 [[nodiscard]] T
min (
int comp = 0) const noexcept;
606 [[nodiscard]] T
min (const
Box& subbox,
int comp = 0) const noexcept;
611 [[nodiscard]] T
max (
int comp = 0) const noexcept;
616 [[nodiscard]] T
max (const
Box& subbox,
int comp = 0) const noexcept;
621 [[nodiscard]] std::pair<T,T>
minmax (
int comp = 0) const noexcept;
626 [[nodiscard]] std::pair<T,T>
minmax (const
Box& subbox,
int comp = 0) const noexcept;
631 [[nodiscard]] T
maxabs (
int comp = 0) const noexcept;
636 [[nodiscard]] T
maxabs (const
Box& subbox,
int comp = 0) const noexcept;
704 [[nodiscard]] T
sum (
int comp,
int numcomp = 1) const noexcept;
707 [[nodiscard]] T
sum (const
Box& subbox,
int comp,
int numcomp = 1) const noexcept;
751 int srccomp,
int destcomp,
int numcomp=1) noexcept;
771 int numcomp=1) noexcept;
778 int srccomp,
int destcomp,
int numcomp=1) noexcept;
787 int srccomp,
int destcomp,
int numcomp) noexcept;
792 int srccomp,
int destcomp,
int numcomp=1) noexcept;
800 int srccomp,
int destcomp,
int numcomp=1) noexcept;
805 const
BaseFab<T>& src1,
int comp1,
806 const
BaseFab<T>& src2,
int comp2) noexcept;
822 int numcomp=1) noexcept;
829 int srccomp,
int destcomp,
int numcomp=1) noexcept;
855 int numcomp=1) noexcept;
863 int srccomp,
int destcomp,
int numcomp=1) noexcept;
888 int numcomp=1) noexcept;
895 int srccomp,
int destcomp,
int numcomp=1) noexcept;
920 int numcomp=1) noexcept;
929 int srccomp,
int destcomp,
int numcomp=1) noexcept;
943 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
945 const
Box& b,
int comp,
int numcomp = 1) noexcept;
950 const
BaseFab<T>& f2,
int comp2,
952 const
Box& b,
int comp,
int numcomp = 1) noexcept;
965 const
BaseFab<T>& f2, const
Box& b2,
int comp2,
967 int comp,
int numcomp = 1) noexcept;
972 int numcomp = 1) const noexcept;
977 int numcomp) const noexcept;
987 template <RunOn run_on AMREX_DEFAULT_RUNON>
991 template <RunOn run_on AMREX_DEFAULT_RUNON>
994 template <RunOn run_on AMREX_DEFAULT_RUNON>
998 template <RunOn run_on AMREX_DEFAULT_RUNON>
1001 template <RunOn run_on AMREX_DEFAULT_RUNON>
1005 template <RunOn run_on AMREX_DEFAULT_RUNON>
1009 template <RunOn run_on AMREX_DEFAULT_RUNON>
1017 template <RunOn run_on AMREX_DEFAULT_RUNON>
1021 template <RunOn run_on AMREX_DEFAULT_RUNON>
1025 template <RunOn run_on AMREX_DEFAULT_RUNON>
1028 template <RunOn run_on AMREX_DEFAULT_RUNON>
1032 template <RunOn run_on AMREX_DEFAULT_RUNON>
1039 template <RunOn run_on AMREX_DEFAULT_RUNON>
1042 template <RunOn run_on AMREX_DEFAULT_RUNON>
1046 template <RunOn run_on AMREX_DEFAULT_RUNON>
1050 template <RunOn run_on AMREX_DEFAULT_RUNON>
1053 template <RunOn run_on AMREX_DEFAULT_RUNON>
1057 template <RunOn run_on AMREX_DEFAULT_RUNON>
1064 template <RunOn run_on AMREX_DEFAULT_RUNON>
1067 template <RunOn run_on AMREX_DEFAULT_RUNON>
1071 template <RunOn run_on AMREX_DEFAULT_RUNON>
1075 template <RunOn run_on AMREX_DEFAULT_RUNON>
1078 template <RunOn run_on AMREX_DEFAULT_RUNON>
1082 template <RunOn run_on AMREX_DEFAULT_RUNON>
1089 template <RunOn run_on AMREX_DEFAULT_RUNON>
1092 template <RunOn run_on AMREX_DEFAULT_RUNON>
1096 template <RunOn run_on AMREX_DEFAULT_RUNON>
1100 template <RunOn run_on AMREX_DEFAULT_RUNON>
1103 template <RunOn run_on AMREX_DEFAULT_RUNON>
1107 template <RunOn run_on AMREX_DEFAULT_RUNON>
1114 template <RunOn run_on AMREX_DEFAULT_RUNON>
1117 template <RunOn run_on AMREX_DEFAULT_RUNON>
1121 template <RunOn run_on AMREX_DEFAULT_RUNON>
1125 template <RunOn run_on AMREX_DEFAULT_RUNON>
1148 [[nodiscard]] T
dot (const
Box& bx,
int destcomp,
int numcomp) const noexcept;
1184 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1197 return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
1205 if (this->arena()->isManaged()) {
1206#if defined(AMREX_USE_SYCL)
1211#elif defined(AMREX_USE_CUDA) && !defined(_WIN32)
1213 std::size_t s =
sizeof(T)*this->nvar*this->domain.numPts();
1214#if defined(__CUDACC__) && (__CUDACC_VER_MAJOR__ >= 13)
1215 cudaMemLocation location = {};
1216 location.type = cudaMemLocationTypeDevice;
1217 location.id = cudaCpuDeviceId;
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(__CUDACC__) && (__CUDACC_VER_MAJOR__ >= 13)
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{slo.
x-dlo.x,slo.y-dlo.y,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");
1711 this->free(this->dptr);
1716 if (this->nvar > 1) {
1723 this->dptr =
nullptr;
1729std::unique_ptr<T,DataDeleter>
1732 std::unique_ptr<T,DataDeleter> r(
nullptr,
DataDeleter{this->arena()});
1733 if (this->dptr && this->ptr_owner) {
1734 r.reset(this->dptr);
1735 this->ptr_owner =
false;
1736 if (this->nvar > 1) {
1746template <RunOn run_on>
1751 void* dst)
const noexcept
1762 d(i,j,k,n) = s(i,j,k,n+srccomp);
1764 return sizeof(T)*d.
size();
1773template <RunOn run_on,
typename BUF>
1778 const void* src)
noexcept
1790 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1792 return sizeof(BUF)*s.
size();
1801template <RunOn run_on,
typename BUF>
1806 const void* src)
noexcept
1818 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1820 return sizeof(BUF)*s.
size();
1829template <RunOn run_on>
1837template <RunOn run_on>
1841 this->abs<run_on>(this->domain,0,this->nvar);
1845template <RunOn run_on>
1849 this->abs<run_on>(this->domain,comp,numcomp);
1853template <RunOn run_on>
1860 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
1865template <RunOn run_on>
1868 int scomp,
int ncomp)
const noexcept
1870 BL_ASSERT(this->domain.contains(subbox));
1871 BL_ASSERT(scomp >= 0 && scomp + ncomp <= this->nvar);
1881 reduce_op.
eval(subbox, reduce_data,
1886 for (
int n = 0; n < ncomp; ++n) {
1892 ReduceTuple hv = reduce_data.
value(reduce_op);
1893 r = amrex::get<0>(hv);
1897 amrex::LoopOnCpu(subbox, ncomp, [=,&r] (
int i,
int j,
int k,
int n)
noexcept
1900 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+scomp)));
1909template <RunOn run_on>
1913 return norm<run_on>(this->domain,p,comp,numcomp);
1917template <RunOn run_on>
1921 BL_ASSERT(this->domain.contains(subbox));
1922 BL_ASSERT(comp >= 0 && comp + numcomp <= this->nvar);
1932 reduce_op.
eval(subbox, reduce_data,
1936 for (
int n = 0; n < numcomp; ++n) {
1941 ReduceTuple hv = reduce_data.
value(reduce_op);
1942 nrm = amrex::get<0>(hv);
1943 }
else if (p == 1) {
1947 reduce_op.
eval(subbox, reduce_data,
1951 for (
int n = 0; n < numcomp; ++n) {
1952 t +=
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1956 ReduceTuple hv = reduce_data.
value(reduce_op);
1957 nrm = amrex::get<0>(hv);
1958 }
else if (p == 2) {
1962 reduce_op.
eval(subbox, reduce_data,
1966 for (
int n = 0; n < numcomp; ++n) {
1967 t +=
static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
1971 ReduceTuple hv = reduce_data.
value(reduce_op);
1972 nrm = amrex::get<0>(hv);
1980 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1982 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1985 }
else if (p == 1) {
1986 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1988 nrm += std::abs(a(i,j,k,n+comp));
1990 }
else if (p == 2) {
1991 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1993 nrm += a(i,j,k,n+comp)*a(i,j,k,n+comp);
2004template <RunOn run_on>
2008 return this->min<run_on>(this->domain,comp);
2012template <RunOn run_on>
2021 using ReduceTuple =
typename decltype(reduce_data)::Type;
2022 reduce_op.
eval(subbox, reduce_data,
2025 return { a(i,j,k) };
2027 ReduceTuple hv = reduce_data.
value(reduce_op);
2028 return amrex::get<0>(hv);
2032 T r = std::numeric_limits<T>::max();
2042template <RunOn run_on>
2046 return this->max<run_on>(this->domain,comp);
2050template <RunOn run_on>
2059 using ReduceTuple =
typename decltype(reduce_data)::Type;
2060 reduce_op.
eval(subbox, reduce_data,
2063 return { a(i,j,k) };
2065 ReduceTuple hv = reduce_data.
value(reduce_op);
2066 return amrex::get<0>(hv);
2070 T r = std::numeric_limits<T>::lowest();
2080template <RunOn run_on>
2084 return this->minmax<run_on>(this->domain,comp);
2088template <RunOn run_on>
2097 using ReduceTuple =
typename decltype(reduce_data)::Type;
2098 reduce_op.
eval(subbox, reduce_data,
2101 auto const x = a(i,j,k);
2104 ReduceTuple hv = reduce_data.
value(reduce_op);
2105 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
2109 T rmax = std::numeric_limits<T>::lowest();
2110 T rmin = std::numeric_limits<T>::max();
2113 auto const x = a(i,j,k);
2117 return std::make_pair(rmin,rmax);
2122template <RunOn run_on>
2126 return this->maxabs<run_on>(this->domain,comp);
2130template <RunOn run_on>
2139 using ReduceTuple =
typename decltype(reduce_data)::Type;
2140 reduce_op.
eval(subbox, reduce_data,
2143 return { std::abs(a(i,j,k)) };
2145 ReduceTuple hv = reduce_data.
value(reduce_op);
2146 return amrex::get<0>(hv);
2161template <RunOn run_on>
2169 std::numeric_limits<int>::lowest(),
2170 std::numeric_limits<int>::lowest())};
2177 if ((*flag == 0) && (a(i,j,k) == value)) {
2200template <RunOn run_on>
2204 return this->minIndex<run_on>(this->domain,comp);
2208template <RunOn run_on>
2212 T min_val = this->min<run_on>(subbox, comp);
2213 return this->indexFromValue<run_on>(subbox, comp, min_val);
2217template <RunOn run_on>
2221 min_val = this->min<run_on>(subbox, comp);
2222 min_idx = this->indexFromValue<run_on>(subbox, comp, min_val);
2226template <RunOn run_on>
2230 return this->maxIndex<run_on>(this->domain,comp);
2234template <RunOn run_on>
2238 T max_val = this->max<run_on>(subbox, comp);
2239 return this->indexFromValue<run_on>(subbox, comp, max_val);
2243template <RunOn run_on>
2247 max_val = this->max<run_on>(subbox, comp);
2248 max_idx = this->indexFromValue<run_on>(subbox, comp, max_val);
2252template <RunOn run_on>
2256 mask.resize(this->domain,1);
2264 using ReduceTuple =
typename decltype(reduce_data)::Type;
2265 reduce_op.
eval(this->domain, reduce_data,
2269 if (a(i,j,k) < val) {
2278 ReduceTuple hv = reduce_data.
value(reduce_op);
2279 cnt = amrex::get<0>(hv);
2285 if (a(i,j,k) < val) {
2298template <RunOn run_on>
2302 mask.resize(this->domain,1);
2310 using ReduceTuple =
typename decltype(reduce_data)::Type;
2311 reduce_op.
eval(this->domain, reduce_data,
2315 if (a(i,j,k) <= val) {
2324 ReduceTuple hv = reduce_data.
value(reduce_op);
2325 cnt = amrex::get<0>(hv);
2331 if (a(i,j,k) <= val) {
2344template <RunOn run_on>
2348 mask.resize(this->domain,1);
2356 using ReduceTuple =
typename decltype(reduce_data)::Type;
2357 reduce_op.
eval(this->domain, reduce_data,
2361 if (a(i,j,k) == val) {
2370 ReduceTuple hv = reduce_data.
value(reduce_op);
2371 cnt = amrex::get<0>(hv);
2377 if (a(i,j,k) == val) {
2390template <RunOn run_on>
2394 mask.resize(this->domain,1);
2402 using ReduceTuple =
typename decltype(reduce_data)::Type;
2403 reduce_op.
eval(this->domain, reduce_data,
2407 if (a(i,j,k) > val) {
2416 ReduceTuple hv = reduce_data.
value(reduce_op);
2417 cnt = amrex::get<0>(hv);
2423 if (a(i,j,k) > val) {
2436template <RunOn run_on>
2440 mask.resize(this->domain,1);
2448 using ReduceTuple =
typename decltype(reduce_data)::Type;
2449 reduce_op.
eval(this->domain, reduce_data,
2453 if (a(i,j,k) >= val) {
2462 ReduceTuple hv = reduce_data.
value(reduce_op);
2463 cnt = amrex::get<0>(hv);
2469 if (a(i,j,k) >= val) {
2482template <RunOn run_on>
2486 Box ovlp(this->domain);
2488 return ovlp.
ok() ? this->atomicAdd<run_on>(
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2492template <RunOn run_on>
2495 int srccomp,
int destcomp,
int numcomp)
noexcept
2502 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2509 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2519template <RunOn run_on>
2523 Box ovlp(this->domain);
2525 return ovlp.
ok() ? saxpy<run_on>(a,
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2529template <RunOn run_on>
2532 const Box& srcbox,
const Box& destbox,
2533 int srccomp,
int destcomp,
int numcomp)
noexcept
2540 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2547 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2550 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);
2557template <RunOn run_on>
2565 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2566 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2574 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2581template <RunOn run_on>
2586 int comp,
int numcomp)
noexcept
2596 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2597 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2606 const Dim3 off1{slo1.
x-dlo.x,slo1.y-dlo.y,slo1.z-dlo.z};
2607 const Dim3 off2{slo2.
x-dlo.x,slo2.y-dlo.y,slo2.z-dlo.z};
2611 d(i,j,k,n+comp) = alpha*s1(i+off1.x,j+off1.y,k+off1.z,n+comp1)
2612 + beta*s2(i+off2.x,j+off2.y,k+off2.z,n+comp2);
2618template <RunOn run_on>
2622 int numcomp)
const noexcept
2629 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2635 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2643 using ReduceTuple =
typename decltype(reduce_data)::Type;
2644 reduce_op.
eval(xbx, reduce_data,
2648 for (
int n = 0; n < numcomp; ++n) {
2653 ReduceTuple hv = reduce_data.
value(reduce_op);
2654 r = amrex::get<0>(hv);
2668template <RunOn run_on>
2672 int numcomp)
const noexcept
2679 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2685 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2695 using ReduceTuple =
typename decltype(reduce_data)::Type;
2696 reduce_op.
eval(xbx, reduce_data,
2699 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2701 for (
int n = 0; n < numcomp; ++n) {
2706 ReduceTuple hv = reduce_data.
value(reduce_op);
2707 r = amrex::get<0>(hv);
2713 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2722template <RunOn run_on>
2730template <RunOn run_on>
2738template <RunOn run_on>
2742 return this->negate<run_on>(this->domain,
DestComp{comp},
NumComps{numcomp});
2746template <RunOn run_on>
2754template <RunOn run_on>
2758 return this->invert<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2762template <RunOn run_on>
2770template <RunOn run_on>
2774 return this->plus<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2778template <RunOn run_on>
2786template <RunOn run_on>
2794template <RunOn run_on>
2798 Box ovlp(this->domain);
2800 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2804template <RunOn run_on>
2807 int numcomp)
noexcept
2813template <RunOn run_on>
2816 int numcomp)
noexcept
2818 Box ovlp(this->domain);
2821 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2825template <RunOn run_on>
2828 int srccomp,
int destcomp,
int numcomp)
noexcept
2834 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2841 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2851template <RunOn run_on>
2854 int srccomp,
int destcomp,
int numcomp)
noexcept
2860 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2867 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2870 T* p = d.
ptr(i,j,k,n+destcomp);
2878template <RunOn run_on>
2881 int srccomp,
int destcomp,
int numcomp)
noexcept
2883#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
2884#if defined(AMREX_USE_GPU)
2891 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2900 Dim3 const offset{slo.
x-dlo.x, slo.y-dlo.y, slo.z-dlo.z};
2916 for (
int ip = 0; ip < nplanes; ++ip) {
2921 int planes_left = nplanes;
2922 while (planes_left > 0) {
2924 auto const m = mm + plo;
2925 auto* lock = OpenMP::get_lock(m);
2926 if (omp_test_lock(lock))
2930 if (planedim == 1) {
2938 for (
int n = 0; n < numcomp; ++n) {
2939 for (
int k = lo.z; k <= hi.z; ++k) {
2940 for (
int j = lo.y; j <= hi.y; ++j) {
2941 auto *
pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
2944 for (
int ii = 0; ii < len.x; ++ii) {
2945 pdst[ii] += psrc[ii];
2953 omp_unset_lock(lock);
2954 if (planes_left == 0) {
break; }
2958 for (
int ip = 0; ip < nplanes; ++ip) {
2959 int new_mm = (mm+ip) % nplanes;
2960 if ( !
mask[new_mm] ) {
2971#if defined(AMREX_USE_GPU)
2973 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2977 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
2982template <RunOn run_on>
2990template <RunOn run_on>
2998template <RunOn run_on>
3001 int srccomp,
int destcomp,
int numcomp)
noexcept
3007 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3014 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3024template <RunOn run_on>
3028 return this->mult<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3032template <RunOn run_on>
3040template <RunOn run_on>
3048template <RunOn run_on>
3056template <RunOn run_on>
3059 int srccomp,
int destcomp,
int numcomp)
noexcept
3065 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3072 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3082template <RunOn run_on>
3086 return this->divide<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3090template <RunOn run_on>
3098template <RunOn run_on>
3106template <RunOn run_on>
3114template <RunOn run_on>
3117 int srccomp,
int destcomp,
int numcomp)
noexcept
3123 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3130 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3140template <RunOn run_on>
3144 Box ovlp(this->domain);
3146 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,0,0,this->nvar) : *
this;
3150template <RunOn run_on>
3154 Box ovlp(this->domain);
3156 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3160template <RunOn run_on>
3163 int numcomp)
noexcept
3165 Box ovlp(this->domain);
3168 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3172template <RunOn run_on>
3175 int srccomp,
int destcomp,
int numcomp)
noexcept
3181 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3188 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3192 d(i,j,k,n+destcomp) /= s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
3210template <RunOn run_on>
3215 const Box& b,
int comp,
int numcomp)
noexcept
3218 return copy<run_on>(f1,b1,comp1,b,comp,numcomp);
3220 return copy<run_on>(f2,b2,comp2,b,comp,numcomp);
3222 Real alpha = (t2-t)/(t2-t1);
3223 Real beta = (t-t1)/(t2-t1);
3224 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,b,comp,numcomp);
3229template <RunOn run_on>
3234 const Box& b,
int comp,
int numcomp)
noexcept
3237 return copy<run_on>(f1,b,comp1,b,comp,numcomp);
3239 return copy<run_on>(f2,b,comp2,b,comp,numcomp);
3241 Real alpha = (t2-t)/(t2-t1);
3242 Real beta = (t-t1)/(t2-t1);
3243 return linComb<run_on>(f1,b,comp1,f2,b,comp2,alpha,beta,b,comp,numcomp);
3252template <RunOn run_on>
3256 this->setVal<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3260template <RunOn run_on>
3264 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3268 a(i,j,k,n+dcomp.i) = x;
3273template <RunOn run_on>
3281template <RunOn run_on>
3285 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3290 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
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>
3322 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3327 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3336 for (
auto const& b : b_lst) {
3337 this->setVal<RunOn::Host>(
x, b, dcomp, ncomp);
3343template <RunOn run_on>
3352template <RunOn run_on>
3358 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3359 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3367 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3374template <RunOn run_on>
3378 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3382template <RunOn run_on>
3386 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3390template <RunOn run_on>
3394 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3399 a(i,j,k,n+dcomp.i) += val;
3406template <RunOn run_on>
3414template <RunOn run_on>
3422template <RunOn run_on>
3428 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3429 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3437 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3444template <RunOn run_on>
3448 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3452template <RunOn run_on>
3456 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3460template <RunOn run_on>
3464 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3469 a(i,j,k,n+dcomp.i) -= val;
3476template <RunOn run_on>
3484template <RunOn run_on>
3492template <RunOn run_on>
3498 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3499 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3507 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3514template <RunOn run_on>
3518 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3522template <RunOn run_on>
3526 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3530template <RunOn run_on>
3534 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3539 a(i,j,k,n+dcomp.i) *= val;
3546template <RunOn run_on>
3554template <RunOn run_on>
3562template <RunOn run_on>
3568 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3569 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3577 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3584template <RunOn run_on>
3588 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3592template <RunOn run_on>
3596 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3600template <RunOn run_on>
3604 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3609 a(i,j,k,n+dcomp.i) /= val;
3616template <RunOn run_on>
3624template <RunOn run_on>
3632template <RunOn run_on>
3638 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3639 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3647 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3654template <RunOn run_on>
3658 return this->negate<run_on>(this->domain,
DestComp{0},
NumComps{this->nvar});
3662template <RunOn run_on>
3666 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3671 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3678template <RunOn run_on>
3682 return this->invert<run_on>(r, this->domain,
DestComp{0},
NumComps{this->nvar});
3686template <RunOn run_on>
3690 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3695 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3702template <RunOn run_on>
3706 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3711 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3714 using ReduceTuple =
typename decltype(reduce_data)::Type;
3715 reduce_op.
eval(bx, reduce_data,
3719 for (
int n = 0; n < ncomp.n; ++n) {
3720 t += a(i,j,k,n+dcomp.i);
3724 ReduceTuple hv = reduce_data.
value(reduce_op);
3725 r = amrex::get<0>(hv);
3731 r += a(i,j,k,n+dcomp.i);
3739template <RunOn run_on>
3744 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3745 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3751 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3754 using ReduceTuple =
typename decltype(reduce_data)::Type;
3755 reduce_op.
eval(bx, reduce_data,
3759 for (
int n = 0; n < ncomp.n; ++n) {
3760 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3764 ReduceTuple hv = reduce_data.
value(reduce_op);
3765 r = amrex::get<0>(hv);
3771 r += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3779template <RunOn run_on>
3788template <RunOn run_on>
3792 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3797 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3800 using ReduceTuple =
typename decltype(reduce_data)::Type;
3801 reduce_op.
eval(bx, reduce_data,
3805 for (
int n = 0; n < ncomp.n; ++n) {
3806 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3810 ReduceTuple hv = reduce_data.
value(reduce_op);
3811 r = amrex::get<0>(hv);
3817 r += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3825template <RunOn run_on>
3832 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3833 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3840 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3843 using ReduceTuple =
typename decltype(reduce_data)::Type;
3844 reduce_op.
eval(bx, reduce_data,
3848 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
3849 for (
int n = 0; n < ncomp.n; ++n) {
3850 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
3854 ReduceTuple hv = reduce_data.
value(reduce_op);
3855 r = amrex::get<0>(hv);
3861 int mi = static_cast<int>(static_cast<bool>(m(i,j,k)));
3862 r += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_DEFAULT_RUNON
Definition AMReX_GpuControl.H:73
#define AMREX_CUDA_SAFE_CALL(call)
Definition AMReX_GpuError.H:73
#define AMREX_HOST_DEVICE_FOR_1D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:105
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(where_to_run, box, nc, i, j, k, n, block)
Definition AMReX_GpuLaunch.nolint.H:73
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
int idir
Definition AMReX_HypreMLABecLap.cpp:1093
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1089
Real * pdst
Definition AMReX_HypreMLABecLap.cpp:1090
Array4< int const > mask
Definition AMReX_InterpFaceRegister.cpp:93
#define AMREX_LOOP_3D(bx, i, j, k, block)
Definition AMReX_Loop.nolint.H:4
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
Definition AMReX_Loop.nolint.H:16
void amrex_mempool_free(void *p)
Definition AMReX_MemPool.cpp:80
void * amrex_mempool_alloc(size_t nbytes)
Definition AMReX_MemPool.cpp:74
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
A virtual base class for objects that manage their own dynamic memory allocation.
Definition AMReX_Arena.H:124
A FortranArrayBox(FAB)-like object.
Definition AMReX_BaseFab.H:189
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:2438
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:2494
Array4< T const > const_array() const noexcept
Definition AMReX_BaseFab.H:417
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:3354
T sum(int comp, int numcomp=1) const noexcept
Returns sum of given component of FAB state vector.
Definition AMReX_BaseFab.H:2724
gpuStream_t alloc_stream
Definition AMReX_BaseFab.H:1170
Real norminfmask(const Box &subbox, const BaseFab< int > &mask, int scomp=0, int ncomp=1) const noexcept
Definition AMReX_BaseFab.H:1867
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition AMReX_BaseFab.H:3586
const int * hiVect() const noexcept
Returns the upper corner of the domain.
Definition AMReX_BaseFab.H:328
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:3494
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:2880
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:1748
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:1803
std::size_t nBytesOwned() const noexcept
Definition AMReX_BaseFab.H:270
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3345
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:2559
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition AMReX_BaseFab.H:3446
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:2254
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3376
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3532
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:3564
std::size_t nBytes(const Box &bx, int ncomps) const noexcept
Returns bytes used in the Box for those components.
Definition AMReX_BaseFab.H:275
void setPtr(T *p, Long sz) noexcept
Definition AMReX_BaseFab.H:375
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:2583
void define()
Allocates memory for the BaseFab<T>.
Definition AMReX_BaseFab.H:1457
BaseFab< T > & operator*=(T const &val) noexcept
Definition AMReX_BaseFab.H:3524
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
const IntVect & smallEnd() const noexcept
Returns the lower corner of the domain See class Box for analogue.
Definition AMReX_BaseFab.H:305
BaseFab< T > & mult(T const &r, int comp, int numcomp=1) noexcept
Scalar multiplication, except control which components are multiplied.
Definition AMReX_BaseFab.H:3026
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition AMReX_BaseFab.H:2484
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:2346
const int * loVect() const noexcept
Returns the lower corner of the domain.
Definition AMReX_BaseFab.H:318
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:334
bool isAllocated() const noexcept
Returns true if the data for the FAB has been allocated.
Definition AMReX_BaseFab.H:435
std::unique_ptr< T, DataDeleter > release() noexcept
Release ownership of memory.
Definition AMReX_BaseFab.H:1730
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3262
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3454
const Box & box() const noexcept
Returns the domain (box) where the array is defined.
Definition AMReX_BaseFab.H:293
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:3283
Array4< T > array() noexcept
Definition AMReX_BaseFab.H:399
IntVect indexFromValue(const Box &subbox, int comp, T const &value) const noexcept
Definition AMReX_BaseFab.H:2163
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3548
bool shared_memory
Is the memory allocated in shared memory?
Definition AMReX_BaseFab.H:1168
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:2300
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3275
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:3424
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3297
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:2531
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:268
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:1775
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition AMReX_BaseFab.H:3656
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3478
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:2984
T value_type
Definition AMReX_BaseFab.H:194
void SetBoxType(const IndexType &typ) noexcept
Change the Box type without change the length.
Definition AMReX_BaseFab.H:980
Array4< T const > array() const noexcept
Definition AMReX_BaseFab.H:381
T maxabs(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2124
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3384
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:3319
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3462
Long truesize
nvar*numpts that was allocated on heap.
Definition AMReX_BaseFab.H:1166
void setVal(T const &val) noexcept
Set value on the whole domain and all components.
Definition AMReX_BaseFab.H:3254
const int * nCompPtr() const noexcept
for calls to fortran.
Definition AMReX_BaseFab.H:282
Array4< T const > const_array(int start_comp, int num_comps) const noexcept
Definition AMReX_BaseFab.H:429
Box domain
My index space.
Definition AMReX_BaseFab.H:1164
bool contains(const Box &bx) const noexcept
Returns true if bx is totally contained within the domain of this BaseFab.
Definition AMReX_BaseFab.H:343
T * dptr
The data pointer.
Definition AMReX_BaseFab.H:1163
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:3602
T max(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2044
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:411
int nvar
Number components.
Definition AMReX_BaseFab.H:1165
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:2620
BaseFab< T > & divide(T const &r, int comp, int numcomp=1) noexcept
As above except specify which components.
Definition AMReX_BaseFab.H:3084
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:1911
Array4< T const > array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:387
BaseFab< T > & operator/=(T const &val) noexcept
Definition AMReX_BaseFab.H:3594
std::pair< T, T > minmax(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2082
Array4< T const > const_array(int start_comp) const noexcept
Definition AMReX_BaseFab.H:423
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:290
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:2780
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:308
Array4< T > array(int start_comp) noexcept
Definition AMReX_BaseFab.H:405
Elixir elixir() noexcept
Definition AMReX_BaseFab.H:1670
Long numPts() const noexcept
Returns the number of points.
Definition AMReX_BaseFab.H:287
const T * dataPtr(int n=0) const noexcept
Same as above except works on const FABs.
Definition AMReX_BaseFab.H:363
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:3305
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3516
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:3634
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:354
bool ptr_owner
Owner of T*?
Definition AMReX_BaseFab.H:1167
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:299
IntVect maxIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2228
BaseFab< T > & protected_divide(const BaseFab< T > &src) noexcept
Divide wherever "src" is "true" or "non-zero".
Definition AMReX_BaseFab.H:3142
friend class BaseFab
Definition AMReX_BaseFab.H:192
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:2764
Array4< T const > array(int start_comp, int num_comps) const noexcept
Definition AMReX_BaseFab.H:393
int nComp() const noexcept
Returns the number of components.
Definition AMReX_BaseFab.H:279
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:2392
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:2670
void clear() noexcept
The function returns the BaseFab to the invalid state. The memory is freed.
Definition AMReX_BaseFab.H:1691
BaseFab< T > & plus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3408
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:3618
void prefetchToHost() const noexcept
Definition AMReX_BaseFab.H:1202
T min(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2006
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:1831
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:3212
IntVect minIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2202
T * dataPtr(const IntVect &p, int n=0) noexcept
Definition AMReX_BaseFab.H:1177
void abs() noexcept
Compute absolute value for all components of this FAB.
Definition AMReX_BaseFab.H:1839
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:3392
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 gpuStream_t setStream(gpuStream_t s) noexcept
Definition AMReX_GpuDevice.cpp:731
static gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:78
static int deviceId() noexcept
Definition AMReX_GpuDevice.cpp:679
static int devicePropMajor() noexcept
Definition AMReX_GpuDevice.H:166
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:257
Type value()
Definition AMReX_Reduce.H:289
Definition AMReX_Reduce.H:389
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:458
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
amrex_long Long
Definition AMReX_INT.H:30
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:263
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:315
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:301
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:244
__host__ __device__ AMREX_FORCE_INLINE void Add(T *const sum, T const value) noexcept
Definition AMReX_GpuAtomic.H:621
Definition AMReX_Amr.cpp:49
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:1005
MakeType
Definition AMReX_MakeType.H:7
@ make_deep_copy
Definition AMReX_MakeType.H:7
@ make_alias
Definition AMReX_MakeType.H:7
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2854
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:91
__host__ __device__ Dim3 length(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:1012
RunOn
Definition AMReX_GpuControl.H:69
std::enable_if_t< std::is_arithmetic_v< T > > placementNew(T *const, Long)
Definition AMReX_BaseFab.H:98
cudaStream_t gpuStream_t
Definition AMReX_GpuControl.H:83
bool InitSNaN() noexcept
Definition AMReX.cpp:173
Long TotalBytesAllocatedInFabs() noexcept
Definition AMReX_BaseFab.cpp:66
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:116
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:224
std::enable_if_t< std::is_trivially_destructible_v< T > > placementDelete(T *const, Long)
Definition AMReX_BaseFab.H:123
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
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
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Definition AMReX_Array4.H:998
A multidimensional array accessor.
Definition AMReX_Array4.H:224
__host__ __device__ constexpr std::size_t size() const noexcept
Definition AMReX_Array4.H:544
__host__ __device__ T * ptr(idx... i) const noexcept
Multi-index ptr() for accessing pointer to element.
Definition AMReX_Array4.H:472
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:76
int i
Definition AMReX_BaseFab.H:79
__host__ __device__ DestComp(int ai) noexcept
Definition AMReX_BaseFab.H:78
Definition AMReX_Dim3.H:12
int x
Definition AMReX_Dim3.H:12
Definition AMReX_BaseFab.H:82
__host__ __device__ NumComps(int an) noexcept
Definition AMReX_BaseFab.H:84
int n
Definition AMReX_BaseFab.H:85
Definition AMReX_BaseFab.H:70
__host__ __device__ SrcComp(int ai) noexcept
Definition AMReX_BaseFab.H:72
int i
Definition AMReX_BaseFab.H:73