Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert no nested MFIters #1530

Merged

Conversation

WeiqunZhang
Copy link
Member

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
  • 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

Add assertion to catch nested MFIters.
@WeiqunZhang WeiqunZhang merged commit b94e1d2 into AMReX-Codes:development Nov 9, 2020
@WeiqunZhang WeiqunZhang deleted the assert_nested_mfiters branch November 9, 2020 18:30
Copy link
Member

@drummerdoc drummerdoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea!

@maximumcats
Copy link
Member

maximumcats commented Nov 9, 2020

This is indeed a good idea but we need to fix the implementation. This breaks AmrLevel (at least) because FillPatchIterator is derived from MFIter

FillPatchIterator::FillPatchIterator (AmrLevel& amrlevel,
                                      MultiFab& leveldata,
                                      int       boxGrow,
                                      Real      time,
                                      int       idx,
                                      int       scomp,
                                      int       ncomp)
    :
    MFIter(leveldata),
    m_amrlevel(amrlevel),
    m_leveldata(leveldata),
    m_ncomp(ncomp)
{
    BL_ASSERT(scomp >= 0);
    BL_ASSERT(ncomp >= 1);
    BL_ASSERT(AmrLevel::desc_lst[idx].inRange(scomp,ncomp));
    BL_ASSERT(0 <= idx && idx < AmrLevel::desc_lst.size());

    Initialize(boxGrow,time,idx,scomp,ncomp);

#ifdef BL_USE_TEAM
    ParallelDescriptor::MyTeam().MemoryBarrier();
#endif
}

and so the constructor will increment depth here -- if Initialize has any MFIter loops this will cause a false positive. And it does, the call to setDomainBndry (at least).

@WeiqunZhang
Copy link
Member Author

Thanks for catching this. This is tricky. There is another case that can cause problems. I think some codes do

for (FillPatchIterator A(...), B(...); ....)

I think we can fix it by setting MFIter::depth = 0 in FillPatchIterator ctor.

WeiqunZhang added a commit to WeiqunZhang/amrex that referenced this pull request Nov 9, 2020
`FillPatchIterator` is derived from `MFIter`.  We need to reset
`MFIter::depth` so that the ctor of `FillPatchIterator` can start `MFIter`.
atmyers pushed a commit that referenced this pull request Nov 9, 2020
`FillPatchIterator` is derived from `MFIter`.  We need to reset
`MFIter::depth` so that the ctor of `FillPatchIterator` can start `MFIter`.
WeiqunZhang added a commit that referenced this pull request Nov 12, 2020
## Summary
`MultiFab::setVal` should not be called inside `MFIter`.

## Additional background
This was caught by #1530.

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants