Skip to content

Fix host and device memory leaks in module setup and teardown - #2155

Open
sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:wave2/memory-leaks
Open

sbryngelson wants to merge 1 commit into
MFlowCode:masterfrom
sbryngelson:wave2/memory-leaks

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

What

  • m_surface_tension: c_divs has num_dims + 1 fields but finalize freed
    only num_dims of them, leaking the gradient-magnitude field.
  • m_cbc: pi_coef_y/z are allocated when weno_order > 1 or
    muscl_order > 1 but were freed only for weno_order > 1, leaking them
    in MUSCL runs with characteristic BCs. Use the x-direction condition.
  • m_global_parameters (pre/sim/post): MPI_IO_DATA%var(i)%sf and
    MPI_IO_IB_DATA%var%sf were allocated and then immediately nullified,
    leaking every buffer. The pointers are default-initialized to null and
    are associated later by s_initialize_mpi_data, so drop the allocate
    loops. Free MPI_IO_DATA%var/view unconditionally in finalize to match
    the unconditional allocation (they leaked when parallel_io was off).
  • m_global_parameters (sim): neighbor_ranks was freed after the n == 0
    and p == 0 early returns, so 1D/2D runs leaked it. Free it first.
  • m_data_output (sim): the file_per_process path called
    s_initialize_mpi_data a second time (identical pointers, leaked MPI
    derived types) and created the restart directory twice. Down-sampled
    output writes q_cons_temp_ds directly, and down_sample requires IGR,
    which excludes Euler bubbles, so the second call had no effect.

No change to results: the debug CPU test suite passes unchanged, and
2-rank NVHPC MPI runs with parallel_io (2D IBM with a shared file and
with file_per_process; 3D IGR file_per_process with and without
down_sample) give byte-identical restart data and identical silo output
(h5diff) against master.

Verification

Testing. Built with GPU offload (OpenMP, AMD) and ran the full test suite with this fix and the species-bounds change (#2154) on one test branch: 731 tests in 4 shards, 0 failures (MI300A and MI250X). ./mfc.sh precheck passes.

Prepared with Claude Code (AI-assisted); I reviewed the change and ran the tests.

- m_surface_tension: c_divs has num_dims + 1 fields but finalize freed
  only num_dims of them, leaking the gradient-magnitude field.
- m_cbc: pi_coef_y/z are allocated when weno_order > 1 or
  muscl_order > 1 but were freed only for weno_order > 1, leaking them
  in MUSCL runs with characteristic BCs. Use the x-direction condition.
- m_global_parameters (pre/sim/post): MPI_IO_DATA%var(i)%sf and
  MPI_IO_IB_DATA%var%sf were allocated and then immediately nullified,
  leaking every buffer. The pointers are default-initialized to null and
  are associated later by s_initialize_mpi_data, so drop the allocate
  loops. Free MPI_IO_DATA%var/view unconditionally in finalize to match
  the unconditional allocation (they leaked when parallel_io was off).
- m_global_parameters (sim): neighbor_ranks was freed after the n == 0
  and p == 0 early returns, so 1D/2D runs leaked it. Free it first.
- m_data_output (sim): the file_per_process path called
  s_initialize_mpi_data a second time (identical pointers, leaked MPI
  derived types) and created the restart directory twice. Down-sampled
  output writes q_cons_temp_ds directly, and down_sample requires IGR,
  which excludes Euler bubbles, so the second call had no effect.

No change to results: the debug CPU test suite passes unchanged, and
2-rank NVHPC MPI runs with parallel_io (2D IBM with a shared file and
with file_per_process; 3D IGR file_per_process with and without
down_sample) give byte-identical restart data and identical silo output
(h5diff) against master.
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Claude Code Review

Head SHA: b66ed8c

Files changed:

  • 6
  • src/post_process/m_global_parameters.fpp
  • src/pre_process/m_global_parameters.fpp
  • src/simulation/m_cbc.fpp
  • src/simulation/m_data_output.fpp
  • src/simulation/m_global_parameters.fpp
  • src/simulation/m_surface_tension.fpp

Findings:
No issues found. Checked in step 4: all six changed files (MPI_IO_DATA allocation/deallocation, CBC pi_coef guards, c_divs loop bound, neighbor_ranks ordering, s_initialize_mpi_data removal).

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_global_parameters.fpp 766 -13
src/post_process/m_global_parameters.fpp 392 -7
src/pre_process/m_global_parameters.fpp 468 -7
src/simulation/m_data_output.fpp 1577 -2
Directory Lines Diff
pre_process 5015 -7
simulation 28565 -15
post_process 3477 -7
total 47601 -29

@sbryngelson
sbryngelson marked this pull request as ready for review November 4, 2026 18:00
@sbryngelson
sbryngelson requested a review from a team as a code owner November 4, 2026 18:00
@sbryngelson
sbryngelson requested review from wilfonba and removed request for a team November 4, 2026 18:00
@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.89%. Comparing base (a03848a) to head (b66ed8c).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_cbc.fpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2155      +/-   ##
==========================================
- Coverage   61.90%   61.89%   -0.01%     
==========================================
  Files          86       86              
  Lines       22948    22934      -14     
  Branches     3386     3380       -6     
==========================================
- Hits        14205    14196       -9     
  Misses       6229     6229              
+ Partials     2514     2509       -5     

☔ 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.

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