Skip to content

Avoid invalid in AMReX_MFInterp_3D_C.H#5215

Merged
WeiqunZhang merged 3 commits intoAMReX-Codes:developmentfrom
dpgrote:avoid_invalid_in_AMReX_MFInterp_3D_C
Mar 25, 2026
Merged

Avoid invalid in AMReX_MFInterp_3D_C.H#5215
WeiqunZhang merged 3 commits intoAMReX-Codes:developmentfrom
dpgrote:avoid_invalid_in_AMReX_MFInterp_3D_C

Conversation

@dpgrote
Copy link
Copy Markdown
Contributor

@dpgrote dpgrote commented Mar 20, 2026

Summary

This PR is here to avoid a false positive invalid flag being raised in `AmrCore/AMReX_MFInterp_3D_C.H. The change ensures that dumax is never zero for the divides. This avoids the invalid signal from being triggered when if-conversion optimization is done, where this code is predictively executed even though dumax is zero.

Several checks demonstrate that the change does not break vectorization. Also, the change should have no effect on results since under normal conditions, the divide by dumax would never happen if dumax is zero.

Additional background

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

// This avoids the invalid signal from being triggered when
// if-conversion optimization is done, where this code is
// predictively executed even though dumax is zero.
dumax = dumax == Real(0.) ? Real(1.) : dumax;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add to the comments something like below?

In normal execution, dumax is always positive because at least one of the three terms in its definition is positive, so the following statement is effectively a no-op.

I initially thought the added guard needed to be moved into the if block because dumax is used in the condition and modifying it could change the outcome of the test. I had to go back more than 10 lines to realize that it could never happen.

@WeiqunZhang WeiqunZhang merged commit 2922573 into AMReX-Codes:development Mar 25, 2026
74 checks passed
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.

2 participants