Skip to content

Fix Tapenade 3.16 reverse mode crash in SA routines#404

Open
yixin-cfd wants to merge 1 commit into
mdolab:mainfrom
yixin-cfd:fix_tapenade3.16
Open

Fix Tapenade 3.16 reverse mode crash in SA routines#404
yixin-cfd wants to merge 1 commit into
mdolab:mainfrom
yixin-cfd:fix_tapenade3.16

Conversation

@yixin-cfd

@yixin-cfd yixin-cfd commented Jun 12, 2026

Copy link
Copy Markdown

Purpose

This PR fixes reverse-mode AD regeneration with recent Tapenade 3.16 develop builds.

It addresses the issue discussed in #403, where make -f Makefile_tapenade ad_reverse crashes while processing the SA turbulence routines in sa.F90.

Recent Tapenade 3.16 develop builds, including:

  • 3.16 develop, 25 Feb 2026, rev 3.16-v2-1304
  • 3.16 develop, 2 Jun 2026, rev 3.16-v2-1337

crash during reverse TBR dependency analysis with errors like:

Uncaught exception - Index 71 out of bounds for length 70
java.lang.ArrayIndexOutOfBoundsException
    at fr.inria.tapenade.utils.BoolVector.set
    at fr.inria.tapenade.analysis.ADTBRAnalyzer.fixpointDependents

The crash is triggered by the SA routines:

sa%saSource(...)
sa%saViscous(...)

Forward mode works, and reverse mode works for the other routines in the same file, such as saResScale and turbAdvection.

The issue appears to be related to how recent Tapenade develop builds handle module-level global variables used by these routines. In particular, the SA model constants:

real(kind=realType) :: cv13, kar2Inv, cw36, cb3Inv

were module-level variables that were assigned inside saSource, saViscous, and saSolve. These values are only needed locally inside those routines, so this PR makes their definition and assignment local to the routines that use them.

This avoids the Tapenade reverse-mode crash while preserving the original numerical behavior.

Expected time until merged

This is a small bugfix intended to restore compatibility with recent Tapenade 3.16 develop builds. I expect it should be reviewable within about a week.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

I tested reverse-mode AD regeneration using a recent Tapenade 3.16 develop build.

Before this change, Tapenade crashed when processing the SA routines:

make -f Makefile_tapenade ad_reverse

with:

java.lang.ArrayIndexOutOfBoundsException: Index 71 out of bounds for length 70

After this change, the SA routines no longer trigger the Tapenade reverse TBR dependency-analysis crash.

I also tested the reduced trigger cases identified in #403:

sa%saSource(...)
sa%saViscous(...)

Both previously reproduced the crash when run alone with the full input file list present. With this change, Tapenade proceeds past these routines.

The change is intended to be numerically neutral: the constants cv13, kar2Inv, cw36, and cb3Inv are assigned the same values as before, but are now local to the routines that use them instead of being module-level global state.

Checklist

  • I have run ruff check and ruff format to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@yixin-cfd yixin-cfd requested a review from a team as a code owner June 12, 2026 07:31
@yixin-cfd yixin-cfd requested review from ArshSaja and anilyil June 12, 2026 07:31
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.

1 participant