Skip to content

s_mpi_allreduce_integer_sum integer overflow #1601#1605

Open
danieljvickers wants to merge 1 commit into
MFlowCode:masterfrom
danieljvickers:1601-s_mpi_allreduce_integer_sum-integer-overflow
Open

s_mpi_allreduce_integer_sum integer overflow #1601#1605
danieljvickers wants to merge 1 commit into
MFlowCode:masterfrom
danieljvickers:1601-s_mpi_allreduce_integer_sum-integer-overflow

Conversation

@danieljvickers

Copy link
Copy Markdown
Member

Description

Fixes integer overflow when counting the number of ghost points at exascale. Simple modification made to the s_mpi_allreduce_integer_sum subroutines to accept 8-byte integers instead of 4-byte.

Closes #1601

Type of change (delete unused ones)

  • Bug fix

Testing

I attempted to recreate the bug locally by using 2 ranks, setting both of their sums to just-below the integer limit, and summing them together, which would normally create an overflow. But instead, the correct value was retrieved.

Checklist

__Check these like this [x] to indicate which of the below applies.

@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 0b38165

Files changed:

  • 2
  • src/common/m_mpi_common.fpp
  • src/simulation/m_ibm.fpp

Findings

[Correctness / Compiler Portability] Breaking API change in a shared common module

s_mpi_allreduce_integer_sum in src/common/m_mpi_common.fpp changes its dummy argument types from integer to integer(kind=8). CLAUDE.md explicitly calls out src/common/ as having "wide blast radius — shared by ALL three executables." This PR only updates callers in m_ibm.fpp. If any other call sites in src/pre_process/, src/post_process/, or other simulation modules pass default-integer arguments to this routine, they will now get a type-mismatch compile error. The two updated call sites correctly use int(..., 8) casts, but the changed signature is a breaking API change that must be verified across all three executables.

-        integer, intent(in)  :: var_loc
-        integer, intent(out) :: var_glb
+        integer(kind=8), intent(in)  :: var_loc
+        integer(kind=8), intent(out) :: var_glb

[Compiler Portability] MPI_INTEGER8 is an optional MPI named type

The MPI_ALLREDUCE call is changed to use MPI_INTEGER8:

-        call MPI_ALLREDUCE(var_loc, var_glb, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr)
+        call MPI_ALLREDUCE(var_loc, var_glb, 1, MPI_INTEGER8, MPI_SUM, MPI_COMM_WORLD, ierr)

Per the MPI-3 standard (§6.9.2), MPI_INTEGER8 is an optional named datatype — conforming implementations are not required to define it. All four CI-gated compilers' MPI libraries (OpenMPI/MPICH for gfortran, NVHPC MPI for nvfortran, Cray MPICH for Cray ftn, Intel MPI for ifx) do provide it in practice, but a portable alternative that is always available is MPI_INT64_T (required since MPI-2.2 when the host C type int64_t is available).

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.52%. Comparing base (b4be438) to head (0b38165).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_ibm.fpp 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1605   +/-   ##
=======================================
  Coverage   60.51%   60.52%           
=======================================
  Files          83       83           
  Lines       19905    19904    -1     
  Branches     2950     2950           
=======================================
  Hits        12046    12046           
+ Misses       5866     5865    -1     
  Partials     1993     1993           

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

None yet

Development

Successfully merging this pull request may close these issues.

s_mpi_allreduce_integer_sum integer overflow

1 participant