Add range-based for and ND to BoxIterator#4668
Merged
WeiqunZhang merged 3 commits intoAMReX-Codes:developmentfrom Sep 22, 2025
Merged
Conversation
WeiqunZhang
approved these changes
Sep 22, 2025
WeiqunZhang
requested changes
Sep 22, 2025
Src/Base/AMReX_BoxIterator.H
Outdated
| * a_bx (not modified) the Box to iterate over. | ||
| */ | ||
| void define (const BoxND<dim>& a_bx) noexcept { | ||
| if (a_bx.ok() && a_bx.smallEnd().allLE(a_bx.bigEnd())) { |
Member
There was a problem hiding this comment.
The second part of the test seems redundant.
Member
Author
There was a problem hiding this comment.
It is. It was a leftover from the previous version. I removed it now.
WeiqunZhang
approved these changes
Sep 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends BoxIterator to be n-dimensional. Additionally, it now supports a range-based for loops. The hope is that this can be useful to reduce the reliance on ifdefs/macros to write loops over boxes that run on CPUs, though so far I haven't found that many places where this can be used.
Note that while regular iteration of the range-based version is reasonably performant,
it is not compatible with
omp parallel foror simd autovectorization.Additional background
The range-based version produces good assembly when compiling with -O3, having minimal instructions in the innermost loop.
https://godbolt.org/z/MTcM8Ysaq
Checklist
The proposed changes: