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
uw.selective_ranks(r) runs its body on every rank; the docstring and parallel-computing.md show the bare form as correct #837
selective_ranks is a generator context manager: it yields True on the selected ranks and False on the others, and the with body runs on every rank. Only the with uw.selective_ranks(0) as run_here: if run_here: form restricts execution.
The documentation shows the bare form as the correct one:
the selective_ranks docstring example in src/underworld3/mpi.py (with uw.mpi.selective_ranks(0): ... plt.savefig(...));
docs/advanced/parallel-computing.md, which also shows the right form elsewhere (lines ~150-168):
the "RIGHT - only rank 0" example (~line 363);
the migration table row "Serial code (viz, I/O) | with uw.selective_ranks(ranks):" (~424);
the RankGroups example (~452);
the migration checklist "Replace if uw.mpi.rank == 0: for visualization with with uw.selective_ranks(0):" (~506);
the summary "Use with uw.selective_ranks(ranks): for serial operations" (~537).
Observed. A campaign driver followed the docstring and wrote its JSON results with the bare form at np 16. Every rank wrote the same file, and 2 of 139 result files were corrupted (trailing duplicate characters).
Fix options.
Docs only: make every example with uw.selective_ranks(r) as run_here: / if run_here:, and say in the docstring that the body runs on all ranks.
API: make the bare form safe as well, either by a callable that returns a bool or by skipping the body, as some libraries do with a sentinel exception.
No library source uses the bare form (git grep on src/); the problem is in the documentation and in user code that copies it.
Underworld development team with AI support from Claude Code
Labelled fixed-in-development, left open: Closes fires only on a merge to main, and this merged to development. It closes when development is released (#805).
Underworld development team with AI support from Claude Code
Activity
lmoresi commentedon Oct 13, 2026
Fixed in #838, merged to
developmentas 5fecebf.Labelled
fixed-in-development, left open:Closesfires only on a merge tomain, and this merged todevelopment. It closes whendevelopmentis released (#805).Underworld development team with AI support from Claude Code
selective_ranks: document the collective block; one rank selection fo…