Skip to content

Fix MPI broadcast 2 GB message-size limit (#36)#124

Merged
mesonepigreco merged 1 commit into
masterfrom
fix-issue-36-broadcast
Jul 20, 2026
Merged

Fix MPI broadcast 2 GB message-size limit (#36)#124
mesonepigreco merged 1 commit into
masterfrom
fix-issue-36-broadcast

Conversation

@mesonepigreco

@mesonepigreco mesonepigreco commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Closes #36

Problem

Settings.broadcast() uses comm.bcast() (pickle-based MPI broadcast) for all data types, including numpy arrays. This has a 2 GB MPI message-size limit, causing cryptic failures in production when broadcasting large tensor arrays. The original raw Bcast code path was dead (enforce_double always overridden to False at line 80).

Fix

  • Numpy arrays are now detected automatically and broadcast via chunked raw comm.Bcast:
    1. Metadata (shape, dtype) synchronized via pickle (negligible size)
    2. Raw data sent in 2M-element chunks (~16 MB for float64), well within MPI limits
  • Non-array types (ints, lists, scalars) still use the pickle path (unchanged)
  • The enforce_double override is removed; parameter kept for backward compatibility

Benchmark: pickle vs chunked Bcast

Measured with mpirun -np 2 across varying array sizes (5 repeats each):

Size Pickle Chunked Speedup
1K 0.0ms 0.0ms --
50K 0.3ms 0.2ms 1.5x
500K 3.4ms 3.0ms 1.1x
2.5M 20.3ms 16.6ms 1.2x
5M 35.0ms 21.0ms 1.7x
10M 69.8ms 41.7ms 1.7x
25M 174.4ms 104.7ms 1.7x
50M 351.0ms 213.8ms 1.6x

Chunked Bcast is consistently faster (~1.6x at scale) and has no 2 GB limit.

New test

tests/TestForceTensor/test_tensor_broadcast.py — production-mimic regression test that exercises the exact code path from the issue traceback (Tensor2.SetupFromPhonons then Center), both of which broadcast tensor data across MPI ranks. Verified with mpirun -np 2.

Regression verification

  • GoParallel / GoParallelTuple: pass (use list-type broadcast, unchanged path)
  • All broadcast() call sites in ForceTensor.py (50+): pass
  • Serial mode: pass

Replace pickle-based comm.bcast() for numpy arrays with chunked raw
MPI Bcast, avoiding the 2 GB MPI message-size limit that causes
production failures at large tensor sizes.

The broadcast function now:
- Detects numpy arrays automatically and uses _broadcast_ndarray()
  with metadata sync (shape/dtype via pickle) + chunked raw Bcast
  (2M elements per chunk = 16 MB for float64, well under 2 GB limit)
- Falls through to pickle-based comm.bcast() for non-array types
- Removes the enforce_double = False override that made the original
  raw-Bcast path dead code

New production-mimic regression test exercises the exact broadcast
code path from the issue traceback: Tensor2.SetupFromPhonons and
Center, both of which broadcast tensor/x_r_vector2/r_vector2 arrays
across MPI ranks.  Verified with mpirun -np 2.
@mesonepigreco
mesonepigreco merged commit 78262ff into master Jul 20, 2026
3 checks passed
@mesonepigreco mesonepigreco added this to the 1.7 milestone Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MPI broadcast memory limit

1 participant