Skip to content

Comments

Fix WP_MOK hardcoded to 8 bytes, use storage_size for portability#1187

Open
sbryngelson wants to merge 2 commits intoMFlowCode:masterfrom
sbryngelson:fix/wp-mok-precision
Open

Fix WP_MOK hardcoded to 8 bytes, use storage_size for portability#1187
sbryngelson wants to merge 2 commits intoMFlowCode:masterfrom
sbryngelson:fix/wp-mok-precision

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 21, 2026

Summary

Severity: HIGH — MPI file I/O reads from wrong offsets in single-precision builds.

File: src/post_process/m_data_input.f90, line 136 (and 2 other sites in the same file)

WP_MOK (the MPI offset for the working-precision real size) is hardcoded to int(8._wp, MPI_OFFSET_KIND), assuming 8-byte (double-precision) reals. In single-precision builds where wp corresponds to 4 bytes, this causes all MPI file read offsets to be wrong by a factor of 2.

Before

WP_MOK = int(8._wp, MPI_OFFSET_KIND)    ! assumes double precision

After

WP_MOK = int(storage_size(0._wp)/8, MPI_OFFSET_KIND)    ! actual byte size

All 3 occurrences in the file are fixed.

Why this went undetected

The codebase is predominantly used in double precision where wp = 8 bytes, so the hardcoded value happens to be correct.

Test plan

  • Build in both single and double precision
  • Verify MPI parallel I/O reads correct data in both modes

🤖 Generated with Claude Code

Fixes #1207

Summary by CodeRabbit

Bug Fixes

  • Fixed MPI I/O offset calculations to dynamically determine floating-point word size instead of hard-coded values, improving data alignment and correctness in parallel file operations across data input, output, and simulation modules.

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

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This PR fixes a critical bug where MPI I/O offset calculations hardcoded 8-byte assumptions for working precision real size, breaking single-precision builds. The fix replaces hardcoded values with dynamic calculations using storage_size(0._wp)/8 to derive the actual working precision byte width.

Changes

Cohort / File(s) Summary
Post-Process MPI I/O
src/post_process/m_data_input.f90
Replaced three hardcoded int(8._wp, MPI_OFFSET_KIND) calls with int(storage_size(0._wp)/8, MPI_OFFSET_KIND) in conservative variable and IB data MPI read paths.
Pre-Process MPI I/O
src/pre_process/m_data_output.fpp, src/pre_process/m_start_up.fpp
Replaced two WP_MOK initializations in data output setup and one in MPI file read path from fixed 8-byte to dynamic storage-size calculation.
Simulation MPI I/O
src/simulation/m_data_output.fpp, src/simulation/m_start_up.fpp
Replaced three hardcoded WP_MOK values in data output offset computation and one in MPI read metadata setup with storage-aware calculations.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested Labels

Review effort 3/5, size:M

Poem

🐰 Eight bytes assumed, but times have changed,
Single precision left deranged,
Dynamic sizing saves the day,
MPI offsets now find their way,
Real storage size, at last revealed! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing hardcoded WP_MOK value from 8 bytes to dynamic storage_size-based computation for portability.
Description check ✅ Passed The description covers the bug, severity, affected code, solution approach, and reasoning. It includes issue reference (#1207) and test plan checklist items.
Linked Issues check ✅ Passed The PR addresses all 10 occurrences of hardcoded WP_MOK across five files identified in issue #1207, replacing each with storage_size(0._wp)/8 for precision-portable MPI offset computation.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to replacing hardcoded WP_MOK calculations with storage_size-based equivalents, directly addressing the single-precision MPI I/O bug without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ 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

  • storage_size semantics
    The code now uses storage_size(0._wp)/8 to compute bytes per working precision real. Verify that storage_size returns bits on all supported compilers and that dividing by 8 yields the expected bytes (e.g. 4 or 8). Confirm this produces an integer and that no unintended real-to-integer truncation/rounding can occur in target builds.

  • Inconsistent integer kinds
    In s_read_ib_data_files WP_MOK (and related MPI-offset variables) are declared as default INTEGER, but the assignment uses INT(..., MPI_OFFSET_KIND). This can cause implicit kind conversions and subtle bugs when offsets are used with MPI calls. Ensure local declarations use KIND=MPI_OFFSET_KIND where appropriate.

@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 MPI file offset calculations that were hardcoded for 8-byte wp reals, making parallel I/O portable across single- and double-precision builds.

Changes:

  • Replaced WP_MOK = int(8._wp, MPI_OFFSET_KIND) with a storage_size-based byte-size computation.
  • Applied the fix across multiple MPI I/O read/setup paths to keep offsets consistent.

cubic-dev-ai[bot]

This comment was marked as off-topic.

…bility

MPI file offsets assume 8-byte reals. Single-precision builds would
read from wrong offsets. Use storage_size(0._wp)/8 instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The same int(8._wp, MPI_OFFSET_KIND) pattern that was fixed in
post_process/m_data_input.f90 was present in 7 additional locations
across simulation/m_data_output.fpp, simulation/m_start_up.fpp,
pre_process/m_data_output.fpp, and pre_process/m_start_up.fpp.
All hardcoded 8-byte strides are replaced with storage_size(0._wp)/8
so MPI file offsets are correct in single-precision builds.

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 (adf2515).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1187   +/-   ##
=======================================
  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.

WP_MOK hardcoded to 8 bytes, breaks single-precision builds

1 participant