Skip to content

Comments

Fix loc_violations used uninitialized in MPI_Allreduce#1186

Open
sbryngelson wants to merge 2 commits intoMFlowCode:masterfrom
sbryngelson:fix/loc-violations-init
Open

Fix loc_violations used uninitialized in MPI_Allreduce#1186
sbryngelson wants to merge 2 commits intoMFlowCode:masterfrom
sbryngelson:fix/loc-violations-init

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 21, 2026

Summary

Severity: HIGH — non-violating MPI ranks sum garbage in the reduction.

File: src/pre_process/m_data_output.fpp, line 479

loc_violations is declared but never initialized to 0. It is only assigned inside a conditional (if (mod(...) > 0)), so ranks that don't enter the conditional contribute uninitialized values to the subsequent MPI_Allreduce sum.

Before

real(wp) :: loc_violations, glb_violations
...
if (down_sample) then
    if ((mod(m + 1, 3) > 0) .or. ...) then
        loc_violations = 1._wp     ! only set inside this branch
    end if
    ! MPI_Allreduce sums loc_violations across ranks — garbage if branch not taken

After

real(wp) :: loc_violations = 0._wp, glb_violations

Why this went undetected

Ranks that happen to have zero-initialized stack memory would produce correct results. The bug is non-deterministic and depends on memory state.

Test plan

  • Run multi-rank pre-process with downsampling enabled
  • Verify violation count is deterministically correct

🤖 Generated with Claude Code

Fixes #1206

Copilot AI review requested due to automatic review settings February 21, 2026 03:23
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

Warning

Rate limit exceeded

@sbryngelson has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@codeant-ai codeant-ai bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Feb 21, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 2026

CodeAnt AI finished reviewing your PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where the loc_violations variable is used in an MPI_Allreduce operation without being initialized, causing non-violating ranks to contribute undefined values to the global sum.

Changes:

  • Initialize loc_violations to 0 at declaration to prevent uninitialized memory from being used in MPI reduction operations

cubic-dev-ai[bot]

This comment was marked as off-topic.

loc_violations is never set to 0 before the conditional that may or
may not assign it. Non-violating ranks sum garbage in the reduction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Initializing a local variable in its declaration gives it the SAVE
attribute in Fortran, meaning it would not reset to zero on subsequent
calls. Move the initialization to an executable assignment so the
variable is properly zeroed each time the subroutine is entered.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.05%. Comparing base (84c46e0) to head (1f03190).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1186   +/-   ##
=======================================
  Coverage   44.05%   44.05%           
=======================================
  Files          70       70           
  Lines       20498    20499    +1     
  Branches     1990     1990           
=======================================
+ Hits         9030     9031    +1     
  Misses      10329    10329           
  Partials     1139     1139           

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

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

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Development

Successfully merging this pull request may close these issues.

Duplicate R3bar accumulation line doubles bubble perturbation

1 participant