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");
1712 this->free(this->dptr);
1717 if (this->nvar > 1) {
1724 this->dptr =
nullptr;
1730std::unique_ptr<T,DataDeleter>
1733 std::unique_ptr<T,DataDeleter> r(
nullptr,
DataDeleter{this->arena()});
1734 if (this->dptr && this->ptr_owner) {
1735 r.reset(this->dptr);
1736 this->ptr_owner =
false;
1737 if (this->nvar > 1) {
1747template <RunOn run_on>
1752 void* dst)
const noexcept
1763 d(i,j,k,n) = s(i,j,k,n+srccomp);
1765 return sizeof(T)*d.
size();
1774template <RunOn run_on,
typename BUF>
1779 const void* src)
noexcept
1791 d(i,j,k,n+dstcomp) =
static_cast<T
>(s(i,j,k,n));
1793 return sizeof(BUF)*s.
size();
1802template <RunOn run_on,
typename BUF>
1807 const void* src)
noexcept
1819 d(i,j,k,n+dstcomp) +=
static_cast<T
>(s(i,j,k,n));
1821 return sizeof(BUF)*s.
size();
1830template <RunOn run_on>
1838template <RunOn run_on>
1842 this->abs<run_on>(this->domain,0,this->nvar);
1846template <RunOn run_on>
1850 this->abs<run_on>(this->domain,comp,numcomp);
1854template <RunOn run_on>
1861 a(i,j,k,n+comp) = std::abs(a(i,j,k,n+comp));
1866template <RunOn run_on>
1869 int scomp,
int ncomp)
const noexcept
1871 BL_ASSERT(this->domain.contains(subbox));
1872 BL_ASSERT(scomp >= 0 && scomp + ncomp <= this->nvar);
1882 reduce_op.
eval(subbox, reduce_data,
1887 for (
int n = 0; n < ncomp; ++n) {
1893 ReduceTuple hv = reduce_data.
value(reduce_op);
1894 r = amrex::get<0>(hv);
1898 amrex::LoopOnCpu(subbox, ncomp, [=,&r] (
int i,
int j,
int k,
int n)
noexcept
1901 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+scomp)));
1910template <RunOn run_on>
1914 return norm<run_on>(this->domain,p,comp,numcomp);
1918template <RunOn run_on>
1922 BL_ASSERT(this->domain.contains(subbox));
1923 BL_ASSERT(comp >= 0 && comp + numcomp <= this->nvar);
1933 reduce_op.
eval(subbox, reduce_data,
1937 for (
int n = 0; n < numcomp; ++n) {
1942 ReduceTuple hv = reduce_data.
value(reduce_op);
1943 nrm = amrex::get<0>(hv);
1944 }
else if (p == 1) {
1948 reduce_op.
eval(subbox, reduce_data,
1952 for (
int n = 0; n < numcomp; ++n) {
1953 t +=
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1957 ReduceTuple hv = reduce_data.
value(reduce_op);
1958 nrm = amrex::get<0>(hv);
1959 }
else if (p == 2) {
1963 reduce_op.
eval(subbox, reduce_data,
1967 for (
int n = 0; n < numcomp; ++n) {
1968 t +=
static_cast<Real>(a(i,j,k,n+comp)*a(i,j,k,n+comp));
1972 ReduceTuple hv = reduce_data.
value(reduce_op);
1973 nrm = amrex::get<0>(hv);
1981 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1983 Real t =
static_cast<Real>(std::abs(a(i,j,k,n+comp)));
1986 }
else if (p == 1) {
1987 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1989 nrm += std::abs(a(i,j,k,n+comp));
1991 }
else if (p == 2) {
1992 amrex::LoopOnCpu(subbox, numcomp, [=,&nrm] (
int i,
int j,
int k,
int n)
noexcept
1994 nrm += a(i,j,k,n+comp)*a(i,j,k,n+comp);
2005template <RunOn run_on>
2009 return this->min<run_on>(this->domain,comp);
2013template <RunOn run_on>
2022 using ReduceTuple =
typename decltype(reduce_data)::Type;
2023 reduce_op.
eval(subbox, reduce_data,
2026 return { a(i,j,k) };
2028 ReduceTuple hv = reduce_data.
value(reduce_op);
2029 return amrex::get<0>(hv);
2033 T r = std::numeric_limits<T>::max();
2043template <RunOn run_on>
2047 return this->max<run_on>(this->domain,comp);
2051template <RunOn run_on>
2060 using ReduceTuple =
typename decltype(reduce_data)::Type;
2061 reduce_op.
eval(subbox, reduce_data,
2064 return { a(i,j,k) };
2066 ReduceTuple hv = reduce_data.
value(reduce_op);
2067 return amrex::get<0>(hv);
2071 T r = std::numeric_limits<T>::lowest();
2081template <RunOn run_on>
2085 return this->minmax<run_on>(this->domain,comp);
2089template <RunOn run_on>
2098 using ReduceTuple =
typename decltype(reduce_data)::Type;
2099 reduce_op.
eval(subbox, reduce_data,
2102 auto const x = a(i,j,k);
2105 ReduceTuple hv = reduce_data.
value(reduce_op);
2106 return std::make_pair(amrex::get<0>(hv), amrex::get<1>(hv));
2110 T rmax = std::numeric_limits<T>::lowest();
2111 T rmin = std::numeric_limits<T>::max();
2114 auto const x = a(i,j,k);
2118 return std::make_pair(rmin,rmax);
2123template <RunOn run_on>
2127 return this->maxabs<run_on>(this->domain,comp);
2131template <RunOn run_on>
2140 using ReduceTuple =
typename decltype(reduce_data)::Type;
2141 reduce_op.
eval(subbox, reduce_data,
2144 return { std::abs(a(i,j,k)) };
2146 ReduceTuple hv = reduce_data.
value(reduce_op);
2147 return amrex::get<0>(hv);
2162template <RunOn run_on>
2170 std::numeric_limits<int>::lowest(),
2171 std::numeric_limits<int>::lowest())};
2178 if ((*flag == 0) && (a(i,j,k) == value)) {
2201template <RunOn run_on>
2205 return this->minIndex<run_on>(this->domain,comp);
2209template <RunOn run_on>
2213 T min_val = this->min<run_on>(subbox, comp);
2214 return this->indexFromValue<run_on>(subbox, comp, min_val);
2218template <RunOn run_on>
2222 min_val = this->min<run_on>(subbox, comp);
2223 min_idx = this->indexFromValue<run_on>(subbox, comp, min_val);
2227template <RunOn run_on>
2231 return this->maxIndex<run_on>(this->domain,comp);
2235template <RunOn run_on>
2239 T max_val = this->max<run_on>(subbox, comp);
2240 return this->indexFromValue<run_on>(subbox, comp, max_val);
2244template <RunOn run_on>
2248 max_val = this->max<run_on>(subbox, comp);
2249 max_idx = this->indexFromValue<run_on>(subbox, comp, max_val);
2253template <RunOn run_on>
2257 mask.resize(this->domain,1);
2265 using ReduceTuple =
typename decltype(reduce_data)::Type;
2266 reduce_op.
eval(this->domain, reduce_data,
2270 if (a(i,j,k) < val) {
2279 ReduceTuple hv = reduce_data.
value(reduce_op);
2280 cnt = amrex::get<0>(hv);
2286 if (a(i,j,k) < val) {
2299template <RunOn run_on>
2303 mask.resize(this->domain,1);
2311 using ReduceTuple =
typename decltype(reduce_data)::Type;
2312 reduce_op.
eval(this->domain, reduce_data,
2316 if (a(i,j,k) <= val) {
2325 ReduceTuple hv = reduce_data.
value(reduce_op);
2326 cnt = amrex::get<0>(hv);
2332 if (a(i,j,k) <= val) {
2345template <RunOn run_on>
2349 mask.resize(this->domain,1);
2357 using ReduceTuple =
typename decltype(reduce_data)::Type;
2358 reduce_op.
eval(this->domain, reduce_data,
2362 if (a(i,j,k) == val) {
2371 ReduceTuple hv = reduce_data.
value(reduce_op);
2372 cnt = amrex::get<0>(hv);
2378 if (a(i,j,k) == val) {
2391template <RunOn run_on>
2395 mask.resize(this->domain,1);
2403 using ReduceTuple =
typename decltype(reduce_data)::Type;
2404 reduce_op.
eval(this->domain, reduce_data,
2408 if (a(i,j,k) > val) {
2417 ReduceTuple hv = reduce_data.
value(reduce_op);
2418 cnt = amrex::get<0>(hv);
2424 if (a(i,j,k) > val) {
2437template <RunOn run_on>
2441 mask.resize(this->domain,1);
2449 using ReduceTuple =
typename decltype(reduce_data)::Type;
2450 reduce_op.
eval(this->domain, reduce_data,
2454 if (a(i,j,k) >= val) {
2463 ReduceTuple hv = reduce_data.
value(reduce_op);
2464 cnt = amrex::get<0>(hv);
2470 if (a(i,j,k) >= val) {
2483template <RunOn run_on>
2487 Box ovlp(this->domain);
2489 return ovlp.
ok() ? this->atomicAdd<run_on>(
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2493template <RunOn run_on>
2496 int srccomp,
int destcomp,
int numcomp)
noexcept
2503 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2510 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2520template <RunOn run_on>
2524 Box ovlp(this->domain);
2526 return ovlp.
ok() ? saxpy<run_on>(a,
x,ovlp,ovlp,0,0,this->nvar) : *
this;
2530template <RunOn run_on>
2533 const Box& srcbox,
const Box& destbox,
2534 int srccomp,
int destcomp,
int numcomp)
noexcept
2541 BL_ASSERT( srccomp >= 0 && srccomp+numcomp <=
x.nComp());
2548 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2551 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);
2558template <RunOn run_on>
2566 BL_ASSERT( comp1 >= 0 && comp1+numcomp <= src1.nComp());
2567 BL_ASSERT( comp2 >= 0 && comp2+numcomp <= src2.nComp());
2575 d(i,j,k,n+destcomp) += s1(i,j,k,n+comp1) * s2(i,j,k,n+comp2);
2582template <RunOn run_on>
2587 int comp,
int numcomp)
noexcept
2597 BL_ASSERT(comp1 >= 0 && comp1+numcomp <= f1.nComp());
2598 BL_ASSERT(comp2 >= 0 && comp2+numcomp <= f2.nComp());
2607 const Dim3 off1{slo1.
x-dlo.x,slo1.y-dlo.y,slo1.z-dlo.z};
2608 const Dim3 off2{slo2.
x-dlo.x,slo2.y-dlo.y,slo2.z-dlo.z};
2612 d(i,j,k,n+comp) = alpha*s1(i+off1.x,j+off1.y,k+off1.z,n+comp1)
2613 + beta*s2(i+off2.x,j+off2.y,k+off2.z,n+comp2);
2619template <RunOn run_on>
2623 int numcomp)
const noexcept
2630 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2636 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2644 using ReduceTuple =
typename decltype(reduce_data)::Type;
2645 reduce_op.
eval(xbx, reduce_data,
2649 for (
int n = 0; n < numcomp; ++n) {
2654 ReduceTuple hv = reduce_data.
value(reduce_op);
2655 r = amrex::get<0>(hv);
2669template <RunOn run_on>
2673 int numcomp)
const noexcept
2680 BL_ASSERT(ycomp >= 0 && ycomp+numcomp <=
y.nComp());
2686 const Dim3 offset{ylo.
x-xlo.x,ylo.y-xlo.y,ylo.z-xlo.z};
2696 using ReduceTuple =
typename decltype(reduce_data)::Type;
2697 reduce_op.
eval(xbx, reduce_data,
2700 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2702 for (
int n = 0; n < numcomp; ++n) {
2707 ReduceTuple hv = reduce_data.
value(reduce_op);
2708 r = amrex::get<0>(hv);
2714 int m =
static_cast<int>(
static_cast<bool>(ma(i,j,k)));
2723template <RunOn run_on>
2731template <RunOn run_on>
2739template <RunOn run_on>
2743 return this->negate<run_on>(this->domain,
DestComp{comp},
NumComps{numcomp});
2747template <RunOn run_on>
2755template <RunOn run_on>
2759 return this->invert<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2763template <RunOn run_on>
2771template <RunOn run_on>
2775 return this->plus<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
2779template <RunOn run_on>
2787template <RunOn run_on>
2795template <RunOn run_on>
2799 Box ovlp(this->domain);
2801 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2805template <RunOn run_on>
2808 int numcomp)
noexcept
2814template <RunOn run_on>
2817 int numcomp)
noexcept
2819 Box ovlp(this->domain);
2822 return ovlp.
ok() ? this->atomicAdd<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
2826template <RunOn run_on>
2829 int srccomp,
int destcomp,
int numcomp)
noexcept
2835 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2842 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2854template <
RunOn run_on,
typename T,
2855 std::enable_if_t<HasAtomicAdd<T>::value,
int> FOO = 0>
2857 const Box& srcbox,
const Box& destbox,
2858 int srccomp,
int destcomp,
int numcomp)
noexcept
2864 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
2867 T* p = d.
ptr(i,j,k,n+destcomp);
2872template <
RunOn run_on,
typename T,
2873 std::enable_if_t<! HasAtomicAdd<T>::value,
int> FOO = 0>
2874void basefab_atomic_add (BaseFab<T>& dfab,
const BaseFab<T>& sfab,
2875 const Box& srcbox,
const Box& destbox,
2876 int srccomp,
int destcomp,
int numcomp)
noexcept
2885template <RunOn run_on>
2888 int srccomp,
int destcomp,
int numcomp)
noexcept
2894 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2897 detail::basefab_atomic_add<run_on>(*
this, src, srcbox, destbox,
2898 srccomp, destcomp, numcomp);
2904template <RunOn run_on>
2907 int srccomp,
int destcomp,
int numcomp)
noexcept
2909#if defined(AMREX_USE_OMP) && (AMREX_SPACEDIM > 1)
2910#if defined(AMREX_USE_GPU)
2917 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
2926 Dim3 const offset{slo.
x-dlo.x, slo.y-dlo.y, slo.z-dlo.z};
2942 for (
int ip = 0; ip < nplanes; ++ip) {
2947 int planes_left = nplanes;
2948 while (planes_left > 0) {
2950 auto const m = mm + plo;
2951 auto* lock = OpenMP::get_lock(m);
2952 if (omp_test_lock(lock))
2956 if (planedim == 1) {
2964 for (
int n = 0; n < numcomp; ++n) {
2965 for (
int k = lo.z; k <= hi.z; ++k) {
2966 for (
int j = lo.y; j <= hi.y; ++j) {
2967 auto *
pdst = d.
ptr(dlo.x,j ,k ,n+destcomp);
2970 for (
int ii = 0; ii < len.x; ++ii) {
2971 pdst[ii] += psrc[ii];
2979 omp_unset_lock(lock);
2980 if (planes_left == 0) {
break; }
2984 for (
int ip = 0; ip < nplanes; ++ip) {
2985 int new_mm = (mm+ip) % nplanes;
2986 if ( !
mask[new_mm] ) {
2997#if defined(AMREX_USE_GPU)
2999 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3003 return this->
template atomicAdd<run_on>(src, srcbox, destbox, srccomp, destcomp, numcomp);
3008template <RunOn run_on>
3016template <RunOn run_on>
3024template <RunOn run_on>
3027 int srccomp,
int destcomp,
int numcomp)
noexcept
3033 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3040 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3050template <RunOn run_on>
3054 return this->mult<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3058template <RunOn run_on>
3066template <RunOn run_on>
3074template <RunOn run_on>
3082template <RunOn run_on>
3085 int srccomp,
int destcomp,
int numcomp)
noexcept
3091 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3098 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3108template <RunOn run_on>
3112 return this->divide<run_on>(r, this->domain,
DestComp{comp},
NumComps{numcomp});
3116template <RunOn run_on>
3124template <RunOn run_on>
3132template <RunOn run_on>
3140template <RunOn run_on>
3143 int srccomp,
int destcomp,
int numcomp)
noexcept
3149 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3156 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3166template <RunOn run_on>
3170 Box ovlp(this->domain);
3172 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,0,0,this->nvar) : *
this;
3176template <RunOn run_on>
3180 Box ovlp(this->domain);
3182 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3186template <RunOn run_on>
3189 int numcomp)
noexcept
3191 Box ovlp(this->domain);
3194 return ovlp.
ok() ? this->protected_divide<run_on>(src,ovlp,ovlp,srccomp,destcomp,numcomp) : *
this;
3198template <RunOn run_on>
3201 int srccomp,
int destcomp,
int numcomp)
noexcept
3207 BL_ASSERT(srccomp >= 0 && srccomp+numcomp <= src.nComp());
3214 const Dim3 offset{slo.
x-dlo.x,slo.y-dlo.y,slo.z-dlo.z};
3218 d(i,j,k,n+destcomp) /= s(i+offset.x,j+offset.y,k+offset.z,n+srccomp);
3236template <RunOn run_on>
3241 const Box& b,
int comp,
int numcomp)
noexcept
3244 return copy<run_on>(f1,b1,comp1,b,comp,numcomp);
3246 return copy<run_on>(f2,b2,comp2,b,comp,numcomp);
3248 Real alpha = (t2-t)/(t2-t1);
3249 Real beta = (t-t1)/(t2-t1);
3250 return linComb<run_on>(f1,b1,comp1,f2,b2,comp2,alpha,beta,b,comp,numcomp);
3255template <RunOn run_on>
3260 const Box& b,
int comp,
int numcomp)
noexcept
3263 return copy<run_on>(f1,b,comp1,b,comp,numcomp);
3265 return copy<run_on>(f2,b,comp2,b,comp,numcomp);
3267 Real alpha = (t2-t)/(t2-t1);
3268 Real beta = (t-t1)/(t2-t1);
3269 return linComb<run_on>(f1,b,comp1,f2,b,comp2,alpha,beta,b,comp,numcomp);
3278template <RunOn run_on>
3282 this->setVal<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3286template <RunOn run_on>
3290 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3294 a(i,j,k,n+dcomp.i) = x;
3299template <RunOn run_on>
3307template <RunOn run_on>
3311 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3316 if (m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3321template <RunOn run_on>
3329template <RunOn run_on>
3333 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3338 if (!m(i,j,k)) { a(i,j,k,n+dcomp.i) = val; }
3343template <RunOn run_on>
3348 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3353 for (
int n = dcomp.i; n < ncomp.n+dcomp.i; ++n) {
3362 for (
auto const& b : b_lst) {
3363 this->setVal<RunOn::Host>(
x, b, dcomp, ncomp);
3369template <RunOn run_on>
3378template <RunOn run_on>
3384 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3385 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3393 d(i,j,k,n+dcomp.i) = s(i,j,k,n+scomp.i);
3400template <RunOn run_on>
3404 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3408template <RunOn run_on>
3412 return this->plus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3416template <RunOn run_on>
3420 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3425 a(i,j,k,n+dcomp.i) += val;
3432template <RunOn run_on>
3440template <RunOn run_on>
3448template <RunOn run_on>
3454 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3455 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3463 d(i,j,k,n+dcomp.i) += s(i,j,k,n+scomp.i);
3470template <RunOn run_on>
3474 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3478template <RunOn run_on>
3482 return this->minus<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3486template <RunOn run_on>
3490 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3495 a(i,j,k,n+dcomp.i) -= val;
3502template <RunOn run_on>
3510template <RunOn run_on>
3518template <RunOn run_on>
3524 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3525 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3533 d(i,j,k,n+dcomp.i) -= s(i,j,k,n+scomp.i);
3540template <RunOn run_on>
3544 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3548template <RunOn run_on>
3552 return this->mult<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3556template <RunOn run_on>
3560 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3565 a(i,j,k,n+dcomp.i) *= val;
3572template <RunOn run_on>
3580template <RunOn run_on>
3588template <RunOn run_on>
3594 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3595 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3603 d(i,j,k,n+dcomp.i) *= s(i,j,k,n+scomp.i);
3610template <RunOn run_on>
3614 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3618template <RunOn run_on>
3622 return this->divide<run_on>(val, this->domain,
DestComp{0},
NumComps{this->nvar});
3626template <RunOn run_on>
3630 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3635 a(i,j,k,n+dcomp.i) /= val;
3642template <RunOn run_on>
3650template <RunOn run_on>
3658template <RunOn run_on>
3664 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3665 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3673 d(i,j,k,n+dcomp.i) /= s(i,j,k,n+scomp.i);
3680template <RunOn run_on>
3684 return this->negate<run_on>(this->domain,
DestComp{0},
NumComps{this->nvar});
3688template <RunOn run_on>
3692 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3697 a(i,j,k,n+dcomp.i) = -a(i,j,k,n+dcomp.i);
3704template <RunOn run_on>
3708 return this->invert<run_on>(r, this->domain,
DestComp{0},
NumComps{this->nvar});
3712template <RunOn run_on>
3716 BL_ASSERT(dcomp.i >= 0 && dcomp.i + ncomp.n <= this->nvar);
3721 a(i,j,k,n+dcomp.i) = r / a(i,j,k,n+dcomp.i);
3728template <RunOn run_on>
3732 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3737 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3740 using ReduceTuple =
typename decltype(reduce_data)::Type;
3741 reduce_op.
eval(bx, reduce_data,
3745 for (
int n = 0; n < ncomp.n; ++n) {
3746 t += a(i,j,k,n+dcomp.i);
3750 ReduceTuple hv = reduce_data.
value(reduce_op);
3751 r = amrex::get<0>(hv);
3757 r += a(i,j,k,n+dcomp.i);
3765template <RunOn run_on>
3770 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3771 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3777 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3780 using ReduceTuple =
typename decltype(reduce_data)::Type;
3781 reduce_op.
eval(bx, reduce_data,
3785 for (
int n = 0; n < ncomp.n; ++n) {
3786 t += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3790 ReduceTuple hv = reduce_data.
value(reduce_op);
3791 r = amrex::get<0>(hv);
3797 r += d(i,j,k,n+dcomp.i) * s(i,j,k,n+scomp.i);
3805template <RunOn run_on>
3814template <RunOn run_on>
3818 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3823 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3826 using ReduceTuple =
typename decltype(reduce_data)::Type;
3827 reduce_op.
eval(bx, reduce_data,
3831 for (
int n = 0; n < ncomp.n; ++n) {
3832 t += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3836 ReduceTuple hv = reduce_data.
value(reduce_op);
3837 r = amrex::get<0>(hv);
3843 r += a(i,j,k,n+dcomp.i)*a(i,j,k,n+dcomp.i);
3851template <RunOn run_on>
3858 AMREX_ASSERT(scomp.i >= 0 && scomp.i+ncomp.n <= src.nvar);
3859 AMREX_ASSERT(dcomp.i >= 0 && dcomp.i+ncomp.n <= this->nvar);
3866 if (run_on == RunOn::Device && Gpu::inLaunchRegion()) {
3869 using ReduceTuple =
typename decltype(reduce_data)::Type;
3870 reduce_op.
eval(bx, reduce_data,
3874 T mi =
static_cast<T
>(
static_cast<int>(
static_cast<bool>(m(i,j,k))));
3875 for (
int n = 0; n < ncomp.n; ++n) {
3876 t += d(i,j,k,n+dcomp.i)*s(i,j,k,n+scomp.i)*mi;
3880 ReduceTuple hv = reduce_data.
value(reduce_op);
3881 r = amrex::get<0>(hv);
3887 int mi = static_cast<int>(static_cast<bool>(m(i,j,k)));
3888 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: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:2439
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:2495
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:3380
T sum(int comp, int numcomp=1) const noexcept
Returns sum of given component of FAB state vector.
Definition AMReX_BaseFab.H:2725
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:1868
BaseFab< T > & divide(T const &val) noexcept
Scalar division on the whole domain and all components.
Definition AMReX_BaseFab.H:3612
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:3520
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:2906
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:1749
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:1804
std::size_t nBytesOwned() const noexcept
Definition AMReX_BaseFab.H:271
BaseFab< T > & copy(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3371
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:2560
BaseFab< T > & minus(T const &val) noexcept
Scalar subtraction on the whole domain and all components.
Definition AMReX_BaseFab.H:3472
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:2255
BaseFab< T > & plus(T const &val) noexcept
Scalar addition on the whole domain and all components.
Definition AMReX_BaseFab.H:3402
BaseFab< T > & mult(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3558
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:3590
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:2584
void define()
Allocates memory for the BaseFab<T>.
Definition AMReX_BaseFab.H:1458
BaseFab< T > & operator*=(T const &val) noexcept
Definition AMReX_BaseFab.H:3550
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:3052
BaseFab< T > & atomicAdd(const BaseFab< T > &x) noexcept
Atomic FAB addition (a[i] <- a[i] + b[i]).
Definition AMReX_BaseFab.H:2485
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:2347
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:1731
void setVal(T const &x, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3288
BaseFab< T > & operator-=(T const &val) noexcept
Definition AMReX_BaseFab.H:3480
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:3309
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:2164
BaseFab< T > & mult(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3574
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:2301
void setValIf(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3301
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:3450
void setValIfNot(T const &val, const BaseFab< int > &mask) noexcept
Definition AMReX_BaseFab.H:3323
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:2532
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:1776
BaseFab< T > & negate() noexcept
on the whole domain and all components
Definition AMReX_BaseFab.H:3682
BaseFab< T > & minus(const BaseFab< T > &src) noexcept
Definition AMReX_BaseFab.H:3504
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:3010
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:2125
BaseFab< T > & operator+=(T const &val) noexcept
Definition AMReX_BaseFab.H:3410
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:3345
BaseFab< T > & minus(T const &val, Box const &bx, DestComp dcomp, NumComps ncomp) noexcept
Do nothing if bx is empty.
Definition AMReX_BaseFab.H:3488
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:3280
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:3628
T max(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2045
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:2621
BaseFab< T > & divide(T const &r, int comp, int numcomp=1) noexcept
As above except specify which components.
Definition AMReX_BaseFab.H:3110
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:1912
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:3620
std::pair< T, T > minmax(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2083
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:2781
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:3331
BaseFab< T > & mult(T const &val) noexcept
Scalar multiplication on the whole domain and all components.
Definition AMReX_BaseFab.H:3542
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:3660
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:2229
BaseFab< T > & protected_divide(const BaseFab< T > &src) noexcept
Divide wherever "src" is "true" or "non-zero".
Definition AMReX_BaseFab.H:3168
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:2765
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:2393
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:2671
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:3434
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:3644
void prefetchToHost() const noexcept
Definition AMReX_BaseFab.H:1203
T min(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2007
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:1832
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:3238
IntVect minIndex(int comp=0) const noexcept
Definition AMReX_BaseFab.H:2203
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:1840
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:3418
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:735
static gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:78
static int deviceId() noexcept
Definition AMReX_GpuDevice.cpp:683
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:453
Type value()
Definition AMReX_Reduce.H:485
Definition AMReX_Reduce.H:582
std::enable_if_t< IsFabArray< MF >::value > eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:716
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: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: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:173
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:224
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: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
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