Skip to content

AllGatherBoxes broadcasts Long count_tot with MPI_INT #5063

@WeiqunZhang

Description

@WeiqunZhang
  • Type: Correctness / MPI data-type mismatch
  • Severity: High
  • Component: Box communication helper
  • Location:
    • Src/Base/AMReX_Box.cpp:166
    • Src/Base/AMReX_Box.cpp:176

Problem

AllGatherBoxes computes the total number of boxes in Long count_tot, then broadcasts it via

MPI_Bcast(&count_tot, 1, MPI_INT, root, comm);

On LP64 platforms (Long = 64-bit), this is a type-size mismatch (MPI_INT = 32-bit).

Impact

  • Non-root ranks receive only the low 32 bits of count_tot.
  • High bits are lost/undefined, which can lead to incorrect buffer sizing and undefined behavior for large totals.
  • The subsequent overflow guard runs on corrupted data on non-root ranks.

Suggested patch

Use the AMReX MPI typemap for Long (or MPI_LONG if guaranteed compatible).

--- a/Src/Base/AMReX_Box.cpp
+++ b/Src/Base/AMReX_Box.cpp
@@
-    MPI_Bcast(&count_tot, 1, MPI_INT, root, comm);
+    MPI_Bcast(&count_tot, 1,
+              ParallelDescriptor::Mpi_typemap<Long>::type(),
+              root, comm);

Prepared by Codex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions