Skip to content

Comments

Fix fluid_rho broadcast using MPI_LOGICAL instead of mpi_p#1176

Open
sbryngelson wants to merge 1 commit intoMFlowCode:masterfrom
sbryngelson:fix/fluid-rho-broadcast-type
Open

Fix fluid_rho broadcast using MPI_LOGICAL instead of mpi_p#1176
sbryngelson wants to merge 1 commit intoMFlowCode:masterfrom
sbryngelson:fix/fluid-rho-broadcast-type

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 21, 2026

Summary

Severity: CRITICAL — silently corrupts reference densities on non-root ranks.

File: src/pre_process/m_mpi_proxy.fpp, line 61

fluid_rho is a real(wp) array but is broadcast using MPI_LOGICAL instead of mpi_p. MPI doesn't type-check its arguments, so the bytes are reinterpreted as logicals on the receiving ranks, silently producing wrong density values.

Before

call MPI_BCAST(fluid_rho(1), num_fluids_max, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
!                                             ^^^^^^^^^^^ should be mpi_p

After

call MPI_BCAST(fluid_rho(1), num_fluids_max, mpi_p, 0, MPI_COMM_WORLD, ierr)

Why this went undetected

On most systems, MPI_LOGICAL and a real happen to be the same size (4 or 8 bytes), so the call doesn't segfault. It just reinterprets the bits, producing subtly wrong values that are hard to trace back to a broadcast type mismatch.

Test plan

  • Run multi-rank simulation and verify fluid_rho is identical across all ranks

🤖 Generated with Claude Code

Fixes #1197

Copilot AI review requested due to automatic review settings February 21, 2026 03:22
@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 28 minutes and 31 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

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • MPI datatype mapping
    The new broadcast uses mpi_p for fluid_rho. Confirm mpi_p exactly matches the Fortran kind of fluid_rho (real(wp)). If mpi_p is not the MPI datatype corresponding to real(wp) (e.g. MPI_REAL8 for double precision), values will still be corrupted across ranks. Validate the mapping across platforms and build configurations.

  • Potential uninitialized data
    The call broadcasts num_fluids_max elements. If only num_fluids entries are valid on root, the extra entries may be uninitialized and lead to unpredictable values on other ranks. Consider broadcasting only the active count or ensuring the tail is initialized before broadcast.

@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

Fixes critical MPI broadcast type mismatch where fluid_rho, a real-valued array, was incorrectly broadcast using MPI_LOGICAL instead of mpi_p, causing data corruption on non-root MPI ranks through bit reinterpretation.

Changes:

  • Corrected MPI datatype for fluid_rho broadcast from MPI_LOGICAL to mpi_p

cubic-dev-ai[bot]

This comment was marked as off-topic.

fluid_rho is a real(wp) array but is broadcast with MPI_LOGICAL type,
silently corrupting reference densities via bit reinterpretation on
non-root ranks.

Co-Authored-By: Claude Opus 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 (27cad3b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1176   +/-   ##
=======================================
  Coverage   44.05%   44.05%           
=======================================
  Files          70       70           
  Lines       20498    20498           
  Branches     1990     1990           
=======================================
  Hits         9030     9030           
  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.

moncon_cutoff declared as integer, truncating 1e-8 to 0

1 participant