Skip to content

Comments

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

Open
sbryngelson wants to merge 4 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 4 commits intoMFlowCode:masterfrom
sbryngelson:fix/wp-mok-precision

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 21, 2026

User description

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.

CodeAnt-AI Description

Correct MPI I/O offsets in single-precision builds

What Changed

  • MPI file read/write offsets no longer assume 8-byte reals; offsets are computed from the actual floating-point storage size so file seeks match build precision
  • Fixed offset calculation in post_process, pre_process, and simulation code paths (affects regular IO, IB data, and restart/parallel IO)
  • Observable result: single-precision builds now read and write the intended data blocks (double-precision behavior unchanged)

Impact

✅ Correct file reads in single-precision builds
✅ Correct file writes in single-precision builds
✅ Fewer corrupted/shifted MPI I/O reads during parallel restart

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

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 29 minutes and 55 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.

📝 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.
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.
Description check ✅ Passed PR description comprehensively addresses the bug, provides clear before/after code examples, explains impact, and includes test plan. Follows template structure with summary, type of change (implicit as bug fix), and testing approach.

✏️ 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 (df28255) to head (f4ac2d6).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1187   +/-   ##
=======================================
  Coverage   44.05%   44.05%           
=======================================
  Files          70       70           
  Lines       20496    20496           
  Branches     1989     1989           
=======================================
  Hits         9030     9030           
  Misses      10328    10328           
  Partials     1138     1138           

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

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI is running Incremental review


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

@codeant-ai codeant-ai bot added size:S This PR changes 10-29 lines, ignoring generated files and removed size:XS This PR changes 0-9 lines, ignoring generated files labels Feb 22, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI Incremental review completed.

@github-actions
Copy link

Claude Code Review

No issues found. Checked for bugs and CLAUDE.md compliance.

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

Labels

size:S This PR changes 10-29 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