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

Add a for loop that is unrolled at compile time #3674

Merged
merged 2 commits into from
Dec 19, 2023

Conversation

maxpkatz
Copy link
Member

Summary

The constexpr_for function is fully unrolled at compile time. This is useful for relatively short loops where some of the functions inside the loop are known to possible to evaluate at compile time and may be relatively expensive, so evaluating them at compile time rather than at runtime may be beneficial for performance reasons.

Additional background

This has been used in AMReX-Astro/Microphysics successfully in the context of evaluating some nuclear reaction network quantities at compile time.

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
  • include documentation in the code and/or rst files, if appropriate

@maxpkatz maxpkatz marked this pull request as ready for review December 17, 2023 20:27
// i and then call the for loop at i+1. f() is a lambda function
// that provides the body of the loop and takes only an integer
// i as its argument. It is assumed that at the loop call site
// the lambda is declared [&] so that it can operate on the data
Copy link
Member

@WeiqunZhang WeiqunZhang Dec 18, 2023

Choose a reason for hiding this comment

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

I am not sure how what this comment about [&] means. If the loop body uses a pointer (a raw pointer or Array4), I don't think you need [&] and [=] would also work. (I am not saying = is better.) (Edited to add not in my last sentence. I unfortunately have the tendency of having "not" in my mind and not typing it.)

Copy link
Member Author

Choose a reason for hiding this comment

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

That was there because of its specific usage in Microphysics. You are right that it is not helpful when copied to AMReX for general usage. I've removed that comment just to avoid confusion.

@WeiqunZhang WeiqunZhang enabled auto-merge (squash) December 19, 2023 04:17
@WeiqunZhang WeiqunZhang merged commit ef38229 into AMReX-Codes:development Dec 19, 2023
69 checks passed
@maxpkatz maxpkatz deleted the add_constexpr_for branch December 19, 2023 04:22
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.

None yet

2 participants