Skip to content

Commit

Permalink
FabArray::isDefined (AMReX-Codes#2997)
Browse files Browse the repository at this point in the history
## Summary

Add a new query to `define_function_called`.

## Additional background

This is a cheaper check than `ok()` for finding out if a MultiFab has
been allocated or not yet, assuming that the calling code follows the
convention that `define()` is called collectively.

Update: It turns out you can also call `empty` inherited from
`FabArrayBase`. The new API is quite explicit, which is ok, too.

Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
  • Loading branch information
ax3l and WeiqunZhang committed Oct 26, 2022
1 parent 7f3c908 commit 3ec0768
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Src/Base/AMReX_FabArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ public:
*/
bool ok () const;

/** Has define() been called on this rank?
*
* \return true if `define` has been called on this `FabArray`. Note that all constructors except `FabArray ()`
* and `FabArray(Arena*a)` call `define`, even if the `MFInfo` argument has `alloc=false`. One could
* also use `FabArrayBase::empty()` to find whether `define` is called or not, although they are not exactly
* the same.
*/
bool isDefined () const;

//! Return a constant reference to the FAB associated with mfi.
const FAB& operator[] (const MFIter& mfi) const noexcept { return *(this->fabPtr(mfi)); }

Expand Down Expand Up @@ -1128,6 +1137,7 @@ protected:
std::unique_ptr<FabFactory<FAB> > m_factory;
DataAllocator m_dallocator;

//! has define() been called?
bool define_function_called = false;

//
Expand Down Expand Up @@ -1768,6 +1778,13 @@ FabArray<FAB>::ok () const
return isok == 1;
}

template <class FAB>
bool
FabArray<FAB>::isDefined () const
{
return define_function_called;
}

template <class FAB>
void
FabArray<FAB>::define (const BoxArray& bxs,
Expand Down

0 comments on commit 3ec0768

Please sign in to comment.