You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] - swarm.write_timestep fails in parallel (np > 1) #151
collectively on the parallel HDF5 path, but each rank passed its own local-sized array. In parallel HDF5 every rank must specify the same dataset shape on a collective `create_dataset`; passing different shapes leaves HDF5's internal metadata inconsistent and the collective close never synchronises, so the with-block exit hangs silently. Faulthandler stack dump confirmed both ranks stuck in `h5py.File.exit` → `close()`.
Why this only surfaced now
The bug is shape-dependent: it only manifests when ranks have unequal local particle counts. A perfectly balanced run (which is unusual but not impossible — e.g. some structured-mesh + populate-uniformly cases) would coincidentally specify the same shape on every rank and complete normally. Your reproducer triggers it because `UnstructuredSimplexBox` partitions don't balance evenly: at np=2 I see 990 vs 930 particles, which is enough shape mismatch to trip the collective.
Fix
Use the standard parallel-HDF5 collective pattern: `allgather` the per-rank sizes, create the dataset at the global shape, then each rank writes its own slice. Plus two latent bugs in the sequential fallback paths cleaned up along the way (a misplaced `comm.barrier()` and an undefined-variable `NameError`).
Also verified at np=4 (0.12s). New regression test (`tests/parallel/test_0790_swarm_write_timestep_mpi.py`) wraps your reproducer with a 60s pytest timeout so any return of the deadlock fails fast in CI rather than blocking.
Activity
lmoresi commentedon Apr 28, 2026
@bknight1 — root cause found, fix in PR #152.
Root cause
`Swarm.save()` (and `SwarmVariable.save()` for the same reason) called
```python
h5f.create_dataset("coordinates", data=points_data_copy)
```
collectively on the parallel HDF5 path, but each rank passed its own local-sized array. In parallel HDF5 every rank must specify the same dataset shape on a collective `create_dataset`; passing different shapes leaves HDF5's internal metadata inconsistent and the collective close never synchronises, so the with-block exit hangs silently. Faulthandler stack dump confirmed both ranks stuck in `h5py.File.exit` → `close()`.
Why this only surfaced now
The bug is shape-dependent: it only manifests when ranks have unequal local particle counts. A perfectly balanced run (which is unusual but not impossible — e.g. some structured-mesh + populate-uniformly cases) would coincidentally specify the same shape on every rank and complete normally. Your reproducer triggers it because `UnstructuredSimplexBox` partitions don't balance evenly: at np=2 I see 990 vs 930 particles, which is enough shape mismatch to trip the collective.
Fix
Use the standard parallel-HDF5 collective pattern: `allgather` the per-rank sizes, create the dataset at the global shape, then each rank writes its own slice. Plus two latent bugs in the sequential fallback paths cleaned up along the way (a misplaced `comm.barrier()` and an undefined-variable `NameError`).
Verification
Your reproducer at np=2:
Also verified at np=4 (0.12s). New regression test (`tests/parallel/test_0790_swarm_write_timestep_mpi.py`) wraps your reproducer with a 60s pytest timeout so any return of the deadlock fails fast in CI rather than blocking.
PR #152 ready for review.
Underworld development team with AI support from Claude Code
bknight1 commentedon Apr 29, 2026
Thanks @lmoresi, confirmed working.
Merge pull request #152 from underworldcode/bugfix/swarm-write-timest…
Fix swarm.write_timestep parallel deadlock (underworldcode#151)
chore(wave-a): quality-campaign deletions & dead code (D1, D7, D13, D…
fix: swarm empty-rank save deadlock (MPIO dtype) and estimate_dt resh…