Repository navigation
CFL restarts: don't overwrite the restart checkpoint on the first step - #1960
Open
sbryngelson wants to merge 1 commit into
Open
sbryngelson wants to merge 1 commit into
sbryngelson wants to merge 1 commit into
Conversation
CFL mode saved when abs(mod(mytime, t_save)) < dt. A restart starts at exactly n_start*t_save, so after the first step mod(mytime, t_save) is within an ulp of dt and falls below it about half the time. The save then writes index int(mytime/t_save) = n_start and replaces the restart checkpoint with the state one step later. Save instead when int(mytime/t_save), the index s_save_data writes, moves past the last saved index (n_start at start), or at t_stop. Fresh-run saves happen at the same steps as before. The CFL restart test restarts from save indices 1-4 and checks that each restart leaves its own checkpoint byte-identical. Co-Authored-By: Claude <noreply@anthropic.com>
Lines of Code
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1960 +/- ##
==========================================
+ Coverage 61.79% 61.80% +0.01%
==========================================
Files 86 86
Lines 22773 22775 +2
Branches 3353 3354 +1
==========================================
+ Hits 14073 14077 +4
+ Misses 6211 6208 -3
- Partials 2489 2490 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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
In CFL mode (
cfl_adap_dt/cfl_const_dt), a restart can overwrite its own restart checkpoint with the state one step later. @thierrydaoud spotted the symptom in #1926.Mechanism
p_main.fppsaved whenabs(mod(mytime, t_save)) < dt .or. mytime >= t_stop. A restart setsmytime = t_save*n_startexactly. After the first step,mod(n_start*t_save + dt, t_save)should equaldt, but because of round-off it comes out within an ulp ofdtand falls below it about half the time. The save then fires ands_save_datawrites indexint(mytime/t_save) = n_start, so checkpointn_startis replaced by the state after one step.The cause is round-off, not a change in
dt. Thedtused in the check is the step's owndt, becauses_compute_dtruns only at the start ofs_perform_time_step.Fix
Track the last saved index, starting at
n_start. Save whenint(mytime/t_save)moves past it, or att_stop. This is the same expressions_save_datauses for the file index, so each index is written once and the restart checkpoint is never written again.k*t_save.t_stopis unchanged.int(mytime/t_save)rounds down just after a crossing, the save comes one step late with the correct index. The old check would have written the previous index in that case.post_processonly readsint(t_stop/t_save)and does not use themodpattern. No other code usesmod(mytime, ...).Reproduction (Frontier, CCE CPU,
--no-mpi)I modified
examples/1D_sodshocktube/case.pyto usecfl_adap_dt = T,t_save = 0.01,t_stop = 0.06,parallel_io = F,format = 1. I ran it fresh, then restarted it withn_start = 1..4, resettingp_allto the fresh run's output before each restart.At one overwrite, the debug output showed
mod(mytime, t_save) = 5.05147325735151587E-04 < dt = 5.05147325735151695E-04.n_startoverwrittenn_startoverwrittenp_all, master vs this PRI also emulated the old and new save logic in float64 over 50k random
dtsequences andt_save/t_stopcombinations. The new logic never skipped or repeated a non-final index and never rewroten_start. On fresh starts it saved at the same steps as the old logic. On restarts it differed only in the cases where the old logic rewroten_start.Regression test
New case
Restart Roundtrip -> 1D -> cfl_adap_dt=T(25EB3D1F). Forrestart_checkcases in CFL mode,run_restartruns the case straight, then restarts from each interior save index (1-4). After each restart it checks thatp_all/*/<n_start>/is byte-identical to what it was before.The usual comparison of restarted output with the straight run is skipped for CFL cases. A CFL restart starts from a checkpoint stamped
n_start*t_saverather than its true time, so its later states differ from the straight run.t_save = 2^-8, son_start*t_saveis exact. On master this test fails here withRestart from n_start=1 rewrote its own restart checkpoint.With the fix, the test is deterministic: no restart can write its own index. On master, whether the bug triggers depends on round-off, so a given compiler might not catch a regression. Checking four restarts makes a miss unlikely.
The golden file was generated with CCE 19 on Frontier.
Testing (Frontier login node, CCE CPU,
--no-mpi)./mfc.sh format,./mfc.sh build --no-mpi -j 8./mfc.sh test --no-mpi -j 8 -o <24 UUIDs>: everycfl_adap_dt/cfl_const_dtcase and everyrestart_checkcase. 24 passed../mfc.sh test --no-mpi -j 8 -% 20: 142 passed, 0 failed.This PR was written and tested with Claude Code (AI) on OLCF Frontier (CCE CPU, no MPI).
Contribution Policy
We do not accept pull requests generated primarily by AI without genuine understanding or real-world usage context.
All contributions are expected to demonstrate:
If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.
Acknowledgement
PR template credit: junegunn