Skip to content

Commit

Permalink
Assert no nested MFIters (#1530)
Browse files Browse the repository at this point in the history
## Summary
Add assertion to catch nested MFIters (e.g., MultiFab functions are called inside MFIter).

## Checklist

The proposed changes:
- [ ] fix a bug or incorrect behavior in AMReX
- [x] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX users
- [ ] are described in the proposed changes to the AMReX documentation, if appropriate
  • Loading branch information
WeiqunZhang authored Nov 9, 2020
1 parent ad7c4ea commit b94e1d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions Src/Base/AMReX_MFIter.H
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ protected:
#endif

static int nextDynamicIndex;
static int depth;

void Initialize ();
};
Expand Down
16 changes: 16 additions & 0 deletions Src/Base/AMReX_MFIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace amrex {

int MFIter::nextDynamicIndex = std::numeric_limits<int>::min();
int MFIter::depth = 0;

MFIter::MFIter (const FabArrayBase& fabarray_,
unsigned char flags_)
Expand Down Expand Up @@ -200,6 +201,13 @@ MFIter::MFIter (const FabArrayBase& fabarray_, const MFItInfo& info)

MFIter::~MFIter ()
{
#ifdef _OPENMP
#pragma omp master
#endif
{
depth = 0;
}

#ifdef BL_USE_TEAM
if ( ! (flags & NoTeamBarrier) )
ParallelDescriptor::MyTeam().MemoryBarrier();
Expand Down Expand Up @@ -242,6 +250,14 @@ MFIter::~MFIter ()
void
MFIter::Initialize ()
{
#ifdef _OPENMP
#pragma omp master
#endif
{
++depth;
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(depth == 1, "Nested MFIter is not supported");
}

if (flags & SkipInit) {
return;
}
Expand Down

0 comments on commit b94e1d2

Please sign in to comment.