Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/AMReX-Codes/amrex in…
Browse files Browse the repository at this point in the history
…to development
  • Loading branch information
JBlaschke committed Jan 22, 2019
2 parents b26c112 + 6510416 commit 8bc605a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 52 deletions.
4 changes: 4 additions & 0 deletions Src/AmrCore/AMReX_TagBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TagBox::coarsen (const IntVect& ratio, bool owner)
const int* lo = b1.loVect();
int longlen = b1.longside();

long numpts = domain.numPts();
Vector<TagType> cfab(numpts);
TagType* cdat = cfab.dataPtr();

Expand Down Expand Up @@ -324,6 +325,7 @@ TagBox::tags_and_untags (const Vector<int>& ar)
void
TagBox::get_itags(Vector<int>& ar, const Box& tilebx) const
{
auto dlen = length();
int Lbx[] = {1,1,1};
for (int idim=0; idim<AMREX_SPACEDIM; idim++) {
Lbx[idim] = dlen[idim];
Expand Down Expand Up @@ -364,6 +366,7 @@ TagBox::get_itags(Vector<int>& ar, const Box& tilebx) const
void
TagBox::tags (const Vector<int>& ar, const Box& tilebx)
{
auto dlen = length();
int Lbx[] = {1,1,1};
for (int idim=0; idim<AMREX_SPACEDIM; idim++) {
Lbx[idim] = dlen[idim];
Expand Down Expand Up @@ -397,6 +400,7 @@ TagBox::tags (const Vector<int>& ar, const Box& tilebx)
void
TagBox::tags_and_untags (const Vector<int>& ar, const Box& tilebx)
{
auto dlen = length();
int Lbx[] = {1,1,1};
for (int idim=0; idim<AMREX_SPACEDIM; idim++) {
Lbx[idim] = dlen[idim];
Expand Down
56 changes: 21 additions & 35 deletions Src/Base/AMReX_BaseFab.H
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,14 @@ struct BaseFabData : public Gpu::Managed
{
AMREX_GPU_HOST_DEVICE
BaseFabData (T* a_dptr, Box const& a_domain, int a_nvar,
IntVect const& a_dlen, long a_numpts, long a_truesize,
bool a_ptr_owner, bool a_shared_memory)
long a_truesize, bool a_ptr_owner, bool a_shared_memory)
: dptr(a_dptr), domain(a_domain), nvar(a_nvar),
dlen(a_dlen), numpts(a_numpts), truesize(a_truesize),
ptr_owner(a_ptr_owner), shared_memory(a_shared_memory)
truesize(a_truesize), ptr_owner(a_ptr_owner), shared_memory(a_shared_memory)
{}
BaseFabData () = default;
T* dptr; // The data pointer.
Box domain; // My index space.
int nvar; // Number components.
IntVect dlen; // Length of domain in each direction.
long numpts; // Cached number of points in FAB.
long truesize; // nvar*numpts that was allocated on heap.
bool ptr_owner;// Owner of T*?
bool shared_memory; // Is the memory allocated in shared memory?
Expand Down Expand Up @@ -257,11 +253,11 @@ public:

//! Returns the number of points
AMREX_GPU_HOST_DEVICE
long nPts () const { return this->numpts; }
long numPts () const { return this->domain.numPts(); }

//! Returns the total number of points of all components
AMREX_GPU_HOST_DEVICE
long size () const { return this->nvar*this->numpts; }
long size () const { return this->nvar*this->domain.numPts(); }

//! Returns the domain (box) where the array is defined
AMREX_GPU_HOST_DEVICE
Expand All @@ -272,7 +268,7 @@ public:
* giving the length of the domain in each direction
*/
AMREX_GPU_HOST_DEVICE
const int* length () const { return this->dlen.getVect(); }
IntVect length () const { return this->domain.length(); }

/**
* \brief Returns the lower corner of the domain
Expand Down Expand Up @@ -334,11 +330,11 @@ public:
* dataPtr returns a pointer to all the Nth components.
*/
AMREX_GPU_HOST_DEVICE
T* dataPtr (int n = 0) { AMREX_ASSERT(!(this->dptr == 0)); return &(this->dptr[n*this->numpts]); }
T* dataPtr (int n = 0) { AMREX_ASSERT(!(this->dptr == 0)); return &(this->dptr[n*this->domain.numPts()]); }

//! Same as above except works on const FABs.
AMREX_GPU_HOST_DEVICE
const T* dataPtr (int n = 0) const { AMREX_ASSERT(!(this->dptr == 0)); return &(this->dptr[n*this->numpts]); }
const T* dataPtr (int n = 0) const { AMREX_ASSERT(!(this->dptr == 0)); return &(this->dptr[n*this->domain.numPts()]); }

AMREX_GPU_HOST_DEVICE
T* dataPtr (const IntVect& iv, int n = 0);
Expand Down Expand Up @@ -1622,7 +1618,7 @@ BaseFab<T>::dataPtr (const IntVect& p, int n)
AMREX_ASSERT(!(this->dptr == 0));
AMREX_ASSERT(this->domain.contains(p));

return this->dptr + (this->domain.index(p)+n*this->numpts);
return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
}

template <class T>
Expand All @@ -1635,7 +1631,7 @@ BaseFab<T>::dataPtr (const IntVect& p, int n) const
AMREX_ASSERT(!(this->dptr == 0));
AMREX_ASSERT(this->domain.contains(p));

return this->dptr + (this->domain.index(p)+n*this->numpts);
return this->dptr + (this->domain.index(p)+n*this->domain.numPts());
}

template <class T>
Expand All @@ -1649,7 +1645,7 @@ BaseFab<T>::operator() (const IntVect& p,
AMREX_ASSERT(!(this->dptr == 0));
AMREX_ASSERT(this->domain.contains(p));

return this->dptr[this->domain.index(p)+n*this->numpts];
return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
}

template <class T>
Expand All @@ -1674,7 +1670,7 @@ BaseFab<T>::operator() (const IntVect& p,
AMREX_ASSERT(!(this->dptr == 0));
AMREX_ASSERT(this->domain.contains(p));

return this->dptr[this->domain.index(p)+n*this->numpts];
return this->dptr[this->domain.index(p)+n*this->domain.numPts()];
}

template <class T>
Expand Down Expand Up @@ -1831,10 +1827,10 @@ BaseFab<T>::define ()
{
AMREX_ASSERT(this->nvar > 0);
AMREX_ASSERT(this->dptr == 0);
AMREX_ASSERT(this->numpts > 0);
AMREX_ASSERT(std::numeric_limits<long>::max()/this->nvar > this->numpts);
AMREX_ASSERT(this->domain.numPts() > 0);
AMREX_ASSERT(std::numeric_limits<long>::max()/this->nvar > this->domain.numPts());

this->truesize = this->nvar*this->numpts;
this->truesize = this->nvar*this->domain.numPts();
this->ptr_owner = true;
this->dptr = static_cast<T*>(amrex::The_Arena()->alloc(this->truesize*sizeof(T)));
//
Expand All @@ -1849,33 +1845,28 @@ BaseFab<T>::define ()
new (ptr) T;
}

amrex::update_fab_stats(this->numpts, this->truesize, sizeof(T));
amrex::update_fab_stats(this->domain.numPts(), this->truesize, sizeof(T));
}

template <class T>
BaseFab<T>::BaseFab ()
: BaseFabData<T>{nullptr, Box(), 0,
IntVect(0), 0L, 0L,
false, false}
: BaseFabData<T>{nullptr, Box(), 0, 0L, false, false}
{}

template <class T>
BaseFab<T>::BaseFab (const Box& bx,
int n,
bool alloc,
bool shared)
: BaseFabData<T>{nullptr, bx, n,
bx.size(), bx.numPts(), 0L,
false, shared}
: BaseFabData<T>{nullptr, bx, n, 0L, false, shared}
{
if (!this->shared_memory && alloc) define();
}

template <class T>
BaseFab<T>::BaseFab (const BaseFab<T>& rhs, MakeType make_type, int scomp, int ncomp)
: BaseFabData<T>{const_cast<T*>(rhs.dataPtr(scomp)), rhs.domain, ncomp,
rhs.dlen, rhs.numpts, ncomp*rhs.numpts,
false, false}
ncomp*rhs.domain.numPts(), false, false}
{
AMREX_ASSERT(scomp+ncomp <= rhs.nComp());
if (make_type == amrex::make_deep_copy)
Expand Down Expand Up @@ -1917,9 +1908,7 @@ BaseFab<T>::BaseFab (const BaseFab<T>& rhs, MakeType make_type)

template<class T>
BaseFab<T>::BaseFab (const Box& bx, int ncomp, T* p)
: BaseFabData<T>{p, bx, ncomp,
bx.size(), bx.numPts(), bx.numPts()*ncomp,
false, false}
: BaseFabData<T>{p, bx, ncomp, bx.numPts()*ncomp, false, false}
{
}

Expand All @@ -1931,8 +1920,7 @@ BaseFab<T>::~BaseFab ()

template <class T>
BaseFab<T>::BaseFab (BaseFab<T>&& rhs) noexcept
: BaseFabData<T>{rhs.dptr, rhs.domain, rhs.nvar,
rhs.dlen, rhs.numpts, rhs.truesize,
: BaseFabData<T>{rhs.dptr, rhs.domain, rhs.nvar,rhs.truesize,
rhs.ptr_owner, rhs.shared_memory}
{
rhs.dptr = nullptr;
Expand All @@ -1954,8 +1942,6 @@ BaseFab<T>::resize (const Box& b,
{
this->nvar = n;
this->domain = b;
this->dlen = b.size();
this->numpts = this->domain.numPts();

if (this->dptr == 0)
{
Expand All @@ -1964,7 +1950,7 @@ BaseFab<T>::resize (const Box& b,

define();
}
else if (this->nvar*this->numpts > this->truesize)
else if (this->nvar*this->domain.numPts() > this->truesize)
{
if (this->shared_memory)
amrex::Abort("BaseFab::resize: BaseFab in shared memory cannot increase size");
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_BaseUmap.H
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace amrex
//! Returns max_mv
int MaxMV () const { return max_mv; }

int nPts () const { return data.size();}
int numPts () const { return data.size();}

int nComp () const {return nvar;}

Expand Down
6 changes: 4 additions & 2 deletions Src/Base/AMReX_FArrayBox.H
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ bool
FArrayBox::contains_nan () const
{
const Real* dp = dptr;
for (int i = 0; i < numpts*nvar; i++) {
const long n = numPts()*nvar;
for (long i = 0; i < n; i++) {
if (amrex::isnan(*dp++)) {
return true;
}
Expand Down Expand Up @@ -492,7 +493,8 @@ bool
FArrayBox::contains_inf () const
{
const Real* dp = dptr;
for (int i = 0; i < numpts*nvar; i++) {
const long n = numPts()*nvar;
for (long i = 0; i < n; i++) {
if (amrex::isinf(*dp++)) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_FabArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ FabArray<FAB>::AllocFabs (const FabFactory<FAB>& factory)
long s = m_fabs_v[i]->size();
if (ownership[i]) {
shmem.n_values += s;
shmem.n_points += m_fabs_v[i]->nPts();
shmem.n_points += m_fabs_v[i]->numPts();
}
if (nextoffset[owner] < 0) {
offset[i] = 0;
Expand Down
20 changes: 10 additions & 10 deletions Src/Base/AMReX_FabArrayCommI.H
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ FabArray<FAB>::FBEP_nowait (int scomp, int ncomp, const IntVect& nghost,
const Box& bx = tag.sbox;
auto const sfab = this->array(tag.srcIndex);
auto pfab = amrex::makeArray4((value_type*)(dptr),bx);
AMREX_HOST_DEVICE_FOR_4D ( bx, ncomp, i, j, k, n,
AMREX_HOST_DEVICE_FOR_4D ( bx, ncomp, ii, jj, kk, n,
{
pfab(i,j,k,n) = sfab(i,j,k,n+scomp);
pfab(ii,jj,kk,n) = sfab(ii,jj,kk,n+scomp);
});
dptr += (bx.numPts() * ncomp * sizeof(value_type));
}
Expand Down Expand Up @@ -370,9 +370,9 @@ FabArray<FAB>::FBEP_nowait (int scomp, int ncomp, const IntVect& nghost,
auto dfab = this->array(tag.dstIndex);
const Dim3 offset = (tag.sbox.smallEnd() - tag.dbox.smallEnd()).dim3();

AMREX_HOST_DEVICE_FOR_4D ( tag.dbox, ncomp, i, j, k, n,
AMREX_HOST_DEVICE_FOR_4D ( tag.dbox, ncomp, ii, jj, kk, n,
{
dfab(i,j,k,n+scomp) = sfab(i+offset.x,j+offset.y,k+offset.z,n+scomp);
dfab(ii,jj,kk,n+scomp) = sfab(ii+offset.x,jj+offset.y,kk+offset.z,n+scomp);
});
});
#ifdef AMREX_USE_GPU
Expand Down Expand Up @@ -986,9 +986,9 @@ FabArray<FAB>::ParallelCopy (const FabArray<FAB>& src,
const Box& bx = tag.sbox;
auto const sfab = src.array(tag.srcIndex);
auto pfab = amrex::makeArray4((value_type*)(dptr),bx);
AMREX_HOST_DEVICE_FOR_4D ( bx, NC, i, j, k, n,
AMREX_HOST_DEVICE_FOR_4D ( bx, NC, ii, jj, kk, n,
{
pfab(i,j,k,n) = sfab(i,j,k,SC+n);
pfab(ii,jj,kk,n) = sfab(ii,jj,kk,SC+n);
});

dptr += (bx.numPts() * NC * sizeof(value_type));
Expand Down Expand Up @@ -1098,14 +1098,14 @@ FabArray<FAB>::ParallelCopy (const FabArray<FAB>& src,
Dim3 offset = (tag.dbox.smallEnd() - tag.sbox.smallEnd()).dim3();

if (op == FabArrayBase::COPY) {
AMREX_HOST_DEVICE_FOR_4D ( tag.sbox, NC, i, j, k, n,
AMREX_HOST_DEVICE_FOR_4D ( tag.sbox, NC, ii, jj, kk, n,
{
dfab(i+offset.x,j+offset.y,k+offset.z,DC+n) = sfab(i,j,k,SC+n);
dfab(ii+offset.x,jj+offset.y,kk+offset.z,DC+n) = sfab(ii,jj,kk,SC+n);
});
} else {
AMREX_HOST_DEVICE_FOR_4D ( tag.sbox, NC, i, j, k, n,
AMREX_HOST_DEVICE_FOR_4D ( tag.sbox, NC, ii, jj, kk, n,
{
dfab(i+offset.x,j+offset.y,k+offset.z,DC+n) += sfab(i,j,k,SC+n);
dfab(ii+offset.x,jj+offset.y,kk+offset.z,DC+n) += sfab(ii,jj,kk,SC+n);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/BaseFabTesting/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ int main(int argc, char* argv[])

amrex::Print() << "BaseFab<Real>::maskLT() test." << std::endl
<< "Results (LT/LE/EQ/GE/GT): " << totalLT << "/" << totalLE << "/" << totalEQ << "/"
<< totalGE << "/" << totalGT << " of " << fab1.nPts() << " points." << std::endl
<< totalGE << "/" << totalGT << " of " << fab1.numPts() << " points." << std::endl
<< "Completed in: " << timer << " seconds." << std::endl
<< " or, completed at a rate of: " << timer/(double(iters)/5) << " seconds/ops." << std::endl
<< " or: " << double(iters)/(5*timer) << " ops/second." << std::endl << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions Tests/C_BaseLib/tUMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ main (int argc, char** argv)
}

// Convert to references.
// umap.nPts() returns a long, fort_umap_norm expects an int
// umap.numPts() returns a long, fort_umap_norm expects an int
// Keytable location may not be quite right
int npts = umap.nPts();
int npts = umap.numPts();
int max_mv = umap.MaxMV();
int ncomp = umap.nComp();
Real norm = amrex_fort_umap_norm(AMREX_ARLIM_3D(umap.box().loVect()), AMREX_ARLIM_3D(umap.box().hiVect()),
Expand Down

0 comments on commit 8bc605a

Please sign in to comment.