Repository navigation
Rotated free slip: a workspace rebuild frees what the old workspace dropped (#1007) - #1013
Conversation
…ropped (#1007) A reassigned expression re-JITs the solver and rebuilds its DM, and dm.handle is in the rotated workspace's geometry signature, so the workspace rebuilds: rotation, operator and custom-FMG prolongation. The old prolongation list and the builders' intermediate matrices were dropped, not destroyed, and in parallel petsc4py defers each destroy to a collective garbage cleanup, which only a new mesh ran: about 7 MB per rank per solve at np 2 (#1007's table). The rebuild now runs mpi._free_petsc_garbage on the solver's communicator; the verdict that triggers it is allgathered, so every rank takes it together. Both builders destroy the velocity submatrix they only need for the product. tests/parallel/test_1144: a body force reassigned each solve at np 2, the workspace rebuilt every time (asserted), resident-set growth under 2 MB per solve and rank (Linux only, as test_0078). Underworld development team with AI support from Claude Code
…ew workspace The cleanup at the cache verdict was never reached on the case it was for: a reassigned expression rebuilds the solver, whose own _reset_rotated_solver_cache empties the rotated cache before solve_rotated_freeslip runs, so the verdict sees no cache (hyperion, np 2: no change against development, 6.6 MB per solve). It now runs at the end of any solve that built a new workspace (not rotation_reused, the same on every rank: the reset is collective and the verdict allgathered), once the new workspace has replaced what the old one shared. Hyperion's control, the same cleanup called by hand after each solve, flattens the growth after three solves. Underworld development team with AI support from Claude Code
A test that runs earlier in the same process can free enough heap to absorb the leak before the resident set moves: on development test_1144 passed after test_1139 or test_1097 (about 33 MB absorbed, hyperion 2026-11-08), so whether it caught the leak depended on where CI's batches of six files fell. The test now reads petsc4py's deferred-destroy list through PETSc.garbage_view (file descriptor 1 captured around the call), which belongs to this process and does not depend on what ran before: fixed, every rebuild's drops are freed at the end of its solve and the summary does not grow; unfixed, it grows at every rebuild. No longer Linux-only. Underworld development team with AI support from Claude Code
#1007) Hyperion: names and object ids that print wider could grow the summary by a byte or two with no growth in the list, a false failure. The test sums the "Total entries: N" lines garbage_view prints (rank 0 prints every rank's). At np 2 the byte-length form failed on development in all four orders tried (alone, in its CI batch, after test_1139 and after test_1097: rank 0 grew 5412 bytes a rebuild) and passed on the fix in all four. Underworld development team with AI support from Claude Code
Review record for this PR: #1007 at np 2 and 4, hyperionVerdict: ready, no open merge condition. The leak is gone at np 2. test_1144 fails on development and passes on this branch whatever runs before it in the same process, and no rotated parallel file regresses. Head 5d431d3; the fix is unchanged since ee3f4d4 and the later commits only touch the test. Base development 06c574e. Linux, PETSc 3.25.3, MPICH, through The first fix did not work, and whyOn 8b39ba6 the cleanup ran at the geometry verdict. At np 2 peak RSS still went 785, 798, 813, 826, 840, 854 MB over six rebuild solves, against 786 to 856 on development. The RSS-based test_1144 failed on both, at 6.61 MB per solve per rank. Controls in test_1144's loop, current RSS on the worst rank, change per solve:
A collective cleanup after the solve was enough on development too, so the cleanup at the verdict was never reached on this path. W1 traced it: the solver's own reset empties the cache first. This PR moves it to the end of the solve. This PR, np 2
test_1144's loop, current RSS on the worst rank, change per solve: 3.4, 3.2, 1.9, then 0 for five solves. That matches development with the hand cleanup, so the first three solves are heap warm-up, not leak. The test can failThe RSS version of test_1144 depended on run order. On development it failed alone (6.61) and after test_1142 (6.56), but passed after test_1139 or test_1097 in the same mpirun: the heap those tests free absorbed the leak. CI's batches are six files in glob order, so the outcome depended on where the boundaries fell. The test now counts petsc4py's deferred-destroy entries from
Development keeps 66 more entries at every rebuild. The list is the same whatever ran before. With nothing deferred, Regression: the 23 tests/parallel files that use rotated free slip, at ee3f4d4
Found on the way#1012: Stokes with Issues#1007: fixed by this PR at np 2. #1012: separate, still live. Could not testnp above 4; long time loops beyond 9 solves; the spherical-shell rotated files, which skip on this host's gmsh; the adjoint path's reuse of the forward prolongation, which was checked only by reading. Underworld development team with AI support from Claude Code |
…rence-policy Underworld development team with AI support from Claude Code
A rotated free-slip solve whose expression is reassigned each step no longer grows memory in parallel (#1007).
The bug
A reassigned expression re-JITs the solver and rebuilds its DM. The solver's own
_reset_rotated_solver_cachethen drops the rotated workspace beforesolve_rotated_freeslipruns. The next rotated solve finds no cache, so it builds a new rotation, operator and custom-FMG prolongation.The dropped prolongation list and the builders' intermediate matrices were never destroyed. In parallel petsc4py defers each destroy to a collective
PETSc.garbage_cleanup, and only a new mesh ran one (test_0078). So every rebuild kept them. On development at np 2, #1007's table has peak RSS rising about 7 MB per rank per solve.The change
not rotation_reused) ends withmpi._free_petsc_garbage(solver.dm.comm), the cleanup a new mesh runs.gc.collect()plus the cleanup on each solve that rebuilds. That includes every solve that keeps no workspace, such as the direct-LU diagnostic and datum solves.Evidence
From hyperion, Linux, np 2, against development 06c574e. The record is posted below as the review.
leak.py, rebuild every solve (peak RSS over both ranks):leak.py, reuse path: flat on both.tests/parallel/test_1144, tier B, at np 2:PETSc.garbage_view) after each solve.Issues
Underworld development team with AI support from Claude Code