Skip to content

Commit 8da67cf

Browse files
authored
Merge pull request #165 from underworldcode/docs/print-table-csv-recommendation-134
Document CSV timing output as the high-rank workaround (#134)
2 parents ed3de29 + 79dc253 commit 8da67cf

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

docs/advanced/parallel-computing.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,26 @@ These operations require **ALL ranks** to participate:
508508
- [ ] Test with `mpirun -np 2` and `mpirun -np 4`
509509
- [ ] Check for deadlocks (script hangs = collective operation issue)
510510

511+
## Timing Output at Extreme Scale
512+
513+
`uw.timing.print_table()` ultimately calls PETSc's `PetscLogView`. At very
514+
high CPU counts (≳1000 ranks), the **ASCII output path** can hang —
515+
typically appearing as a job that completes its computation cleanly but
516+
never exits. The CSV write path uses a different, less collective-heavy
517+
strategy and avoids the issue:
518+
519+
```python
520+
# Default — fine at small scale, can hang at ≳1000 ranks
521+
uw.timing.print_table()
522+
uw.timing.print_table("results.txt")
523+
524+
# Safe at any scale — recommended for HPC runs
525+
uw.timing.print_table("results.csv")
526+
```
527+
528+
The behaviour is in PETSc, not Underworld; choosing CSV at scale is the
529+
recommended workaround. (Issue #134.)
530+
511531
## Summary
512532

513533
**Key Takeaways:**
@@ -517,5 +537,6 @@ These operations require **ALL ranks** to participate:
517537
3. **Use `with uw.selective_ranks(ranks):`** for serial operations
518538
4. **Collective operations must run on ALL ranks** - never inside rank conditionals
519539
5. **Test with `mpirun -np N`** to catch issues early
540+
6. **At ≳1000 ranks, write timing output as `.csv`** to avoid `PetscLogView` hangs
520541

521542
The parallel safety system makes parallel programming in Underworld3 safer and more intuitive - collective operations are evaluated on all ranks automatically, preventing common deadlock scenarios!

src/underworld3/timing.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,36 @@ def print_table(filename=None, format="auto"):
150150
----------
151151
filename : str, optional
152152
If provided, write results to file. Extension determines format:
153-
- `.csv` : Spreadsheet-compatible CSV format
154-
- `.txt` or other : Human-readable ASCII table
153+
- ``.csv`` : Spreadsheet-compatible CSV format
154+
- ``.txt`` or other : Human-readable ASCII table
155155
format : str, optional
156156
Override automatic format detection:
157-
- "auto" : Detect from filename (default)
158-
- "ascii" : Human-readable table
159-
- "csv" : Comma-separated values
157+
- ``"auto"`` : Detect from filename (default)
158+
- ``"ascii"`` : Human-readable table
159+
- ``"csv"`` : Comma-separated values
160160
161161
Example
162162
-------
163163
>>> uw.timing.start()
164164
>>> # ... do work ...
165165
>>> uw.timing.print_table() # Print to console
166166
>>> uw.timing.print_table("results.csv") # Save as CSV
167+
168+
Notes
169+
-----
170+
**High-CPU-count usage (≳1000 ranks): prefer CSV output.**
171+
172+
Issue #134 (gthyagi, 2026-04-23): the underlying PETSc ``PetscLogView``
173+
ASCII output path can hang at extreme rank counts on some clusters
174+
(BD-integral routines + ASCII table emit appear to be the trigger),
175+
while the CSV write path uses a different, less collective-heavy
176+
strategy and avoids the issue. If your job is large enough that
177+
timing-output cost matters, write to a ``.csv`` filename:
178+
179+
>>> uw.timing.print_table("results.csv") # safe at any scale
180+
181+
The behaviour is in PETSc, not Underworld; choosing CSV at scale is
182+
the recommended workaround.
167183
"""
168184
print_petsc_log(filename=filename, format=format)
169185

0 commit comments

Comments
 (0)