Skip to content

Fix debug build warnings: intent(out) init, unused vars, dead code, float comparisons, precision tolerance#1341

Open
sbryngelson wants to merge 12 commits intomasterfrom
fix-debug-warnings
Open

Fix debug build warnings: intent(out) init, unused vars, dead code, float comparisons, precision tolerance#1341
sbryngelson wants to merge 12 commits intomasterfrom
fix-debug-warnings

Conversation

@sbryngelson
Copy link
Copy Markdown
Member

@sbryngelson sbryngelson commented Mar 31, 2026

Summary

Fixes compiler warnings from --debug / --reldebug gfortran builds. All changes verified across all build targets (pre_process, simulation, post_process) and all #ifdef paths.

Intent(out) initialization

  • Initialize intent(out) arguments unconditionally before #ifdef MFC_SIMULATION blocks in m_mpi_common.fpp and m_variables_conversion.fpp
  • Change intent(out) to intent(inout) in s_mpi_allreduce_vectors_sum for aliased calls

Unused variables and dead code

  • Remove ~50 unused local variables across 15 files, verified by grep within function scope
  • Remove 4 dead module-level variables from m_rhs.fpp (gm_alpha_qp, gm_alphaL_n, gm_alphaR_n, nbub)
  • Remove 4 dead CCFL variables from m_data_output.fpp
  • Remove 13 dead module-level variables from m_ib_patches.fpp
  • Remove dead bubrs_qbmm from m_qbmm.fpp
  • Remove dead stores (pres_mag, loc, M11, flg, str_MOK, NVARS_MOK)

Dead subroutines

  • s_convert_cylindrical_to_spherical_coord (m_ib_patches.fpp, m_icpp_patches.fpp)
  • s_compute_fd_divergence (m_finite_differences.fpp)
  • s_solve_linear_system (post_process/m_derived_variables.fpp)

Floating-point equality fixes

  • m_ibm.fpp: Re(1) /= 0._wpRe(1) > 0._wp (matches codebase convention)
  • m_ibm.fpp: sqrt(sum(axis**2)) == 0< sgm_eps
  • ExtrusionHardcodedIC.fpp: dummy_x == x0f_approx_equal

Precision-aware tolerance

  • f_approx_equal / f_approx_in_array: default tolerance 1e-6 for single precision, 1e-10 for double (single precision epsilon is ~1.2e-7, so 1e-10 was below machine precision)

Test plan

  • ./mfc.sh precheck -j 8 passes
  • ./mfc.sh build -j 8 passes (all targets, gfortran)
  • ./mfc.sh test --reldebug -j 8 -% 5 — 27/27 pass
  • CI: all checks passing

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Claude Code Review

Incremental review from: a8e1ea8
Head SHA: d2f483b

New findings since last Claude review:

  • FC/CC/CXX set to empty strings for non-NVHPC builds (.github/workflows/test.yml): The new job-level env: block sets FC: ${{ matrix.nvhpc && 'nvfortran' || '' }} (and similarly for CC, CXX). For every non-NVHPC matrix entry (matrix.nvhpc == ''), these evaluate to empty strings and are exported into the step environment. Setting FC="" is distinct from leaving FC unset: CMake reads the FC env var on startup and, if set to an empty string, may attempt to invoke an empty string as a Fortran compiler rather than falling back to auto-detection. This would silently break the existing Ubuntu/macOS gfortran matrix runs. The Intel setup step does append FC=ifx to GITHUB_ENV (which overrides the empty value for subsequent steps), but non-Intel Ubuntu builds have no such override and will run mfc.sh build with FC=''.

  • HDF5_ENABLE_PARALLEL=OFF globally disables parallel HDF5 in bundled builds (toolchain/dependencies/CMakeLists.txt): The previous configuration omitted this flag, allowing CMake to auto-detect MPI and enable parallel HDF5 when building the bundled copy. The change now explicitly forces serial-only HDF5 for all systems where no system HDF5 is found. If any HPC cluster build relies on the bundled HDF5 and uses parallel I/O (e.g., collective writes in post-processing), this will silently fall back to serial I/O or fail at link-time with undefined H5Pset_fapl_mpio references. The change appears motivated by NVHPC Docker container compatibility, but it applies to the bundled build for all platforms.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

This change introduces a new RelDebug build-type configuration alongside existing Debug and Release modes, with compiler-specific flags providing lightweight debugging with optimizations. A new Bash script automates compiler-warning collection in CI workflows. The test workflow is refactored to replace full test execution with compiler-warning collection, using the new build type. Toolchain Python modules are updated to support the reldebug configuration option with CLI flag normalization. Multiple source files remove unused local variable declarations.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title is partially related to the changeset, referring to real changes like intent(out) initialization, unused variables, and float comparisons, but omits major changes like the new RelDebug build type and dead code removal.
Description check ✅ Passed The PR description comprehensively covers the main changes: intent(out) initialization, unused variable removal, dead subroutines, float-point fixes, precision tolerance adjustments, and RelDebug build type introduction with test results.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6b24091-bf9c-42f2-bdb6-2337efce7132

📥 Commits

Reviewing files that changed from the base of the PR and between 336487c and 9574365.

📒 Files selected for processing (16)
  • .github/workflows/common/build-warnings.sh
  • .github/workflows/test.yml
  • CMakeLists.txt
  • src/common/m_helper.fpp
  • src/common/m_mpi_common.fpp
  • src/common/m_variables_conversion.fpp
  • src/post_process/m_data_output.fpp
  • src/pre_process/m_icpp_patches.fpp
  • src/simulation/m_bubbles_EL.fpp
  • src/simulation/m_compute_cbc.fpp
  • src/simulation/m_compute_levelset.fpp
  • src/simulation/m_start_up.fpp
  • toolchain/mfc/build.py
  • toolchain/mfc/cli/argparse_gen.py
  • toolchain/mfc/cli/docs_gen.py
  • toolchain/mfc/state.py
💤 Files with no reviewable changes (1)
  • src/simulation/m_compute_cbc.fpp

Comment on lines +41 to +45
# RelDebug: a lighter debug mode for CI. Compiler-specific blocks below add the
# actual flags; these defaults just tell CMake it is a recognised build type.
set(CMAKE_C_FLAGS_RELDEBUG "-g" CACHE STRING "")
set(CMAKE_CXX_FLAGS_RELDEBUG "-g" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_RELDEBUG "-g" CACHE STRING "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C2 'CMAKE_CONFIGURATION_TYPES|CONFIG:RelDebug|CMAKE_BUILD_TYPE STREQUAL "RelDebug"|--config[^[:alnum:]]*RelDebug|RelDebug' \
  CMakeLists.txt toolchain/mfc

Repository: MFlowCode/MFC

Length of output: 3855


RelDebug build type is implemented only for single-config generators.

The CMAKE_*_FLAGS_RELDEBUG flags are defined here, but throughout CMakeLists.txt, RelDebug configuration is selected via if (CMAKE_BUILD_TYPE STREQUAL "RelDebug") checks. This works only for single-config generators (Make, Ninja); multi-config generators (Visual Studio, Xcode, Ninja Multi-Config) do not set CMAKE_BUILD_TYPE and instead require:

  • Registration in CMAKE_CONFIGURATION_TYPES
  • Config-scoped settings via $<CONFIG:RelDebug> generator expressions

Currently, RelDebug will not be available or will be partially non-functional for multi-config generators.

Comment on lines +386 to 389
# Set build type (Debug, RelDebug, or Release).
# See: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
f"-DCMAKE_BUILD_TYPE={'Debug' if ARG('debug') else 'Release'}",
f"-DCMAKE_BUILD_TYPE={'Debug' if ARG('debug') else 'RelDebug' if ARG('reldebug') else 'Release'}",
# Used by FIND_PACKAGE (/FindXXX) to search for packages, with the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Make conflicting build modes an error.

--debug and --reldebug can both be true today, and these ternaries quietly collapse that state to Debug. Reject the combination once so configure/build/reporting stay unambiguous.

💡 Suggested fix
+        if ARG("debug") and ARG("reldebug"):
+            raise MFCException("`--debug` and `--reldebug` are mutually exclusive.")
+        build_type = "Debug" if ARG("debug") else "RelDebug" if ARG("reldebug") else "Release"
+
         flags: list = self.flags.copy() + [
@@
-            f"-DCMAKE_BUILD_TYPE={'Debug' if ARG('debug') else 'RelDebug' if ARG('reldebug') else 'Release'}",
+            f"-DCMAKE_BUILD_TYPE={build_type}",
@@
-            "Debug" if ARG("debug") else "RelDebug" if ARG("reldebug") else "Release",
+            build_type,

Also applies to: 458-468

@sbryngelson sbryngelson force-pushed the fix-debug-warnings branch 3 times, most recently from f0672e9 to b1351c8 Compare April 1, 2026 00:17
Initialize intent(out) arguments unconditionally before #ifdef blocks:
- m_mpi_common.fpp: icfl_max_glb, vcfl_max_glb, Rc_min_glb
- m_variables_conversion.fpp: rho_K, gamma_K, pi_inf_K, qv_K, Re_K, G_K
- m_mpi_common.fpp: change intent(out) to intent(inout) for aliased allreduce

Remove unused local variables verified across all build targets.
Remove dead CCFL variables from m_data_output.fpp (ccfl_sf, ccfl_max_loc,
ccfl_max_glb, ccfl_max).

Remove dead gradient magnitude variables from m_rhs.fpp (gm_alpha_qp,
gm_alphaL_n, gm_alphaR_n, nbub) including their GPU_DECLARE and ALLOCATE.

Remove 13 unused module-level variables from m_ib_patches.fpp and 7 unused
local variables from its subroutines.

Remove unused idist/odist from m_fftw.fpp and dest from m_time_steppers.fpp.
Remove unused locals in m_boundary_common.fpp (status, i, offset),
m_model.fpp (theta, ndot, norm_mag, c, total_vertices, eta, max_iv1/2),
m_data_input.f90 (delx, dely, delz), and m_time_steppers.fpp (gm_alpha_qp).

Remove dead module-level bubrs_qbmm from m_qbmm.fpp (allocated and
GPU-updated but never read by any code).
Dead subroutines (zero call sites, verified case-insensitive across entire repo
including Fypp includes, hardcoded IC dispatch tables, and case.fpp):
- s_convert_cylindrical_to_spherical_coord in m_ib_patches.fpp and m_icpp_patches.fpp
- s_compute_fd_divergence in m_finite_differences.fpp
- s_solve_linear_system in post_process/m_derived_variables.fpp

Dead stores (assigned but never read):
- pres_mag, loc in m_assign_variables.fpp
- M11 in simulation/m_data_output.fpp
- flg in post_process/m_derived_variables.fpp
- str_MOK, NVARS_MOK in pre_process and simulation m_start_up.fpp

Unused variables:
- my_divu in m_bubbles_EE.fpp (declared and in GPU private clause but never used)
- theta1, theta2, En_tot, dirname, dir_exists in post_process/m_start_up.fpp
- i in m_perturbation.fpp s_prng
- t_step_ib_dir in post_process/m_data_input.f90
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.85%. Comparing base (2d15ba9) to head (ce52fe7).

Files with missing lines Patch % Lines
src/common/m_mpi_common.fpp 0.00% 5 Missing ⚠️
src/common/m_model.fpp 0.00% 3 Missing ⚠️
src/common/m_variables_conversion.fpp 83.33% 0 Missing and 1 partial ⚠️
src/pre_process/m_icpp_patches.fpp 0.00% 1 Missing ⚠️
src/simulation/m_compute_levelset.fpp 0.00% 1 Missing ⚠️
src/simulation/m_ibm.fpp 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1341      +/-   ##
==========================================
+ Coverage   64.67%   64.85%   +0.17%     
==========================================
  Files          70       70              
  Lines       18251    18228      -23     
  Branches     1504     1506       +2     
==========================================
+ Hits        11804    11821      +17     
+ Misses       5492     5446      -46     
- Partials      955      961       +6     

☔ View full report in Codecov by Sentry.
📢 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.

- m_ibm.fpp: Re(1) /= 0._wp -> Re(1) > 0._wp (matches convention in
  m_global_parameters.fpp where Re is checked with > 0)
- m_ibm.fpp: sqrt(sum(axis**2)) == 0 -> < sgm_eps (floating-point
  magnitude should not be compared with exact equality)
- ExtrusionHardcodedIC.fpp: dummy_x == x0 -> f_approx_equal (coordinates
  read from files should not be compared with exact equality)
@sbryngelson
Copy link
Copy Markdown
Member Author

If @wilfonba @DimAdam-01 @danieljvickers could double check this I would appreciate it

Single precision (wp=real(4)) has ~7 decimal digits of precision, so
a default tolerance of 1e-10 is below machine epsilon (~1.2e-7) and
f_approx_equal would almost never return true. Use 1e-6 for single
precision builds and keep 1e-10 for double precision.

The wp == single_precision comparison uses integer parameter constants
that the compiler resolves at compile time, so there is no runtime cost.
@sbryngelson sbryngelson changed the title Fix debug build warnings: uninitialized intent(out) args, unused variables Fix debug build warnings: intent(out) init, unused vars, dead code, float comparisons, precision tolerance Apr 1, 2026
…ve dead store

- Remove sph_phi from m_ib_patches.fpp and m_icpp_patches.fpp (only user
  was s_convert_cylindrical_to_spherical_coord, removed in prior commit)
- Fix #ifdef DEBUG to #ifdef MFC_DEBUG in m_data_output.fpp and
  m_variables_conversion.fpp (bare DEBUG is never defined, MFC_DEBUG is)
- Remove dead igr assignment in toolchain/mfc/case.py (overwritten on
  line 360 without being read)
@wilfonba
Copy link
Copy Markdown
Contributor

wilfonba commented Apr 1, 2026

@sbryngelson Looks good to me

@qodo-code-review
Copy link
Copy Markdown
Contributor

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: Georgia Tech | Phoenix (NVHPC) (gpu-acc)

Failed stage: Bench (Master v. PR) [❌]

Failed test name: ""

Failure summary:

The action failed because the PR SLURM monitoring process was terminated with exit code 137
(SIGKILL), causing the workflow step to error out.
- pr/.github/scripts/run_monitored_slurm_job.sh
was killed while running monitor_slurm_job.sh (see run_monitored_slurm_job.sh: line 22).
- The
parent script pr/.github/scripts/run_parallel_benchmarks.sh was also killed (see
run_parallel_benchmarks.sh: line 61), and it reported PR job exited with code: 137, followed by
Process completed with exit code 137.
- The later benchmark summary shows 0 failed, 10 passed,
indicating the failure was not due to a failing benchmark/test case, but due to the
monitoring/runner process being forcibly killed (commonly from OOM or external cancellation on the
runner/login node).

Relevant error logs:
1:  Runner name: 'phoenix-2'
2:  Runner group name: 'phoenix'
...

290:  Stale job 6110466 (state=CANCELLEDby3048356) — submitting fresh
291:  sbatch attempt 1 of 3...
292:  Submitted batch job 6236562
293:  Job ID written to bench-gpu-acc.slurm_job_id
294:  SUBMIT_ONLY mode: skipping monitor (job_id=6236562 output=bench-gpu-acc.out)
295:  Master job submitted: 6236562
296:  Both SLURM jobs submitted — running concurrently on compute nodes.
297:  Monitoring sequentially to conserve login node memory.
298:  === Monitoring PR job 6236560 ===
299:  Submitted batch job 6236560
300:  Monitoring output file: pr/bench-gpu-acc.out
301:  Waiting for job to start...
302:  /storage/project/r-sbryngelson3-0/sbryngelson3/mfc-runners-2/actions-runner-2/_work/MFC/MFC/pr/.github/scripts/run_monitored_slurm_job.sh: line 22: 3249454 Killed                  bash "$SCRIPT_DIR/monitor_slurm_job.sh" "$job_id" "$output_file"
303:  pr/.github/scripts/run_parallel_benchmarks.sh: line 61: 3249070 Killed                  bash "${SCRIPT_DIR}/run_monitored_slurm_job.sh" "$pr_job_id" "pr/${job_slug}.out"
304:  PR job exited with code: 137
305:  ##[error]Process completed with exit code 137.
306:  ##[group]Run (cd pr && . ./mfc.sh load -c p -m g)
...

929:  - acc
930:  - -g
931:  - '0'
932:  - '1'
933:  - -n
934:  - '2'
935:  lock:
936:  debug: false
937:  fastmath: false
938:  gcov: false
939:  gpu: acc
940:  mixed: false
941:  mpi: true
942:  single: false
943:  unified: false
944:  ##[group]Run passed=() failed=()
945:  �[36;1mpassed=() failed=()�[0m
946:  �[36;1mfor out in pr/build/benchmarks/*/*.out master/build/benchmarks/*/*.out; do�[0m
947:  �[36;1m  [ -f "$out" ] || continue�[0m
948:  �[36;1m  [ -f "${out%.out}.yaml" ] && passed+=("$out") || failed+=("$out")�[0m
949:  �[36;1mdone�[0m
950:  �[36;1m�[0m
951:  �[36;1mecho "=== Per-Case Summary: ${#failed[@]} failed, ${#passed[@]} passed ==="�[0m
952:  �[36;1mfor out in "${failed[@]}"; do echo "  [FAILED] $out"; done�[0m
953:  �[36;1mfor out in "${passed[@]}"; do echo "  [PASSED] $out"; done�[0m
954:  �[36;1m�[0m
955:  �[36;1mif [ ${#failed[@]} -gt 0 ]; then�[0m
956:  �[36;1m  echo ""�[0m
957:  �[36;1m  echo "=== Failed Case Logs ==="�[0m
958:  �[36;1m  for out in "${failed[@]}"; do�[0m
959:  �[36;1m    echo "--- $out ---"�[0m
960:  �[36;1m    cat "$out"�[0m
961:  �[36;1m    echo ""�[0m
962:  �[36;1m  done�[0m
963:  �[36;1mfi�[0m
964:  shell: /usr/bin/bash -e {0}
965:  ##[endgroup]
966:  === Per-Case Summary: 0 failed, 10 passed ===
967:  [PASSED] pr/build/benchmarks/b53b/5eq_rk3_weno3_hllc.out

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.

2 participants