Skip to content

Fix mpi io data leak - #2114

Open
thierrydaoud wants to merge 3 commits into
MFlowCode:masterfrom
thierrydaoud:fix-mpi-io-data-leak
Open

thierrydaoud wants to merge 3 commits into
MFlowCode:masterfrom
thierrydaoud:fix-mpi-io-data-leak

Conversation

@thierrydaoud

Copy link
Copy Markdown

Description

s_initialize_global_parameters_module in all three targets allocates an interior-sized array for each MPI_IO_DATA%var(i)%sf and then immediately does sf => null(). The arrays become unreachable and are never freed. The arrays are also never needed: s_initialize_mpi_data / s_initialize_mpi_data_ds (src/common/m_mpi_common.fpp) point every sf at the existing q_cons_vf, beta, pb/mv slices before each MPI-IO read or write (in post_process through s_setup_mpi_io_params), and sf already defaults to null() in scalar_field.

This PR deletes those allocate-then-nullify loops. The MPI_IO_DATA%var/%view arrays themselves are still allocated as before.

Memory lost per rank before this change, with (m+1)(n+1)(p+1) × 8 bytes per array:

Target Lost arrays
simulation (every MPI build, regardless of parallel_io) sys_size; with bubbles_lagrange, sys_size + sys_size + 1
simulation, pre_process, post_process with non-polytropic QBMM + 2*nb*nnode
pre_process sys_size (if not down_sample)
post_process sys_size (larger with down_sample)

Example: 3D, single fluid (sys_size = 6), 200³ cells per rank: 384 MB of host memory lost per rank, and 832 MB with Lagrangian bubbles. On APUs (MI300A) host and device share the same HBM.

Testing

  • Heap allocated by simulation mid-run (macOS heap), 3D single-fluid shock tube, 100³ cells, 1 rank:
    • master e95a827a: 1,108,359,392 B
    • this PR: 1,060,286,992 B
    • difference: 48.07 MB, i.e. 6 arrays × 8.00 MB as expected
  • Full test suite (./mfc.sh test -j 8, CPU, macOS): 726 passed, 0 failed, 39 skipped

thierrydaoud and others added 2 commits October 27, 2026 13:01
Each target allocated an interior-sized array for every
MPI_IO_DATA%var(i)%sf and then set sf => null(), leaving the array
unreachable. The arrays were never used: s_initialize_mpi_data points
each sf at the q_cons_vf, beta or pb/mv slices before every MPI-IO read
or write, and sf defaults to null().

simulation lost sys_size arrays per rank in every MPI build, plus
sys_size + 1 more with Lagrangian bubbles (384 MB and 832 MB per rank
for a single-fluid 3D case at 200^3). Measured on 100^3, 1 rank: heap
1,108,359,392 B -> 1,060,286,992 B (6 x 8 MB).
@thierrydaoud
thierrydaoud requested a review from a team as a code owner October 27, 2026 17:02
@thierrydaoud
thierrydaoud requested review from sbryngelson and removed request for a team October 27, 2026 17:02
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: ecc5f16

The review produced no output (Claude step: failure). Run and transcript: https://github.com/MFlowCode/MFC/actions/runs/40546783749

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.02%. Comparing base (4e96e0d) to head (74ca04a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2114      +/-   ##
==========================================
- Coverage   62.02%   62.02%   -0.01%     
==========================================
  Files          86       86              
  Lines       22936    22910      -26     
  Branches     3370     3364       -6     
==========================================
- Hits        14226    14209      -17     
+ Misses       6210     6205       -5     
+ Partials     2500     2496       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_global_parameters.fpp 780 -17
src/post_process/m_global_parameters.fpp 400 -14
src/pre_process/m_global_parameters.fpp 475 -12
Directory Lines Diff
pre_process 5022 -12
simulation 28581 -17
post_process 3485 -14
total 47632 -43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant