Skip to content

Commit 5f20c44

Browse files
committed
Reverting to non-collective IO if needed
1 parent 334a264 commit 5f20c44

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pySDC/helpers/fieldsIO.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from typing import Type, TypeVar
5555
import logging
5656
import itertools
57+
import warnings
5758

5859
T = TypeVar("T")
5960

@@ -494,6 +495,7 @@ def toVTR(self, baseName, varNames, idxFormat="{:06d}"):
494495
# MPI-parallel implementation
495496
# -------------------------------------------------------------------------
496497
comm: MPI.Intracomm = None
498+
balanced_distribution = None
497499

498500
@classmethod
499501
def setupMPI(cls, comm: MPI.Intracomm, iLoc, nLoc):
@@ -514,6 +516,11 @@ def setupMPI(cls, comm: MPI.Intracomm, iLoc, nLoc):
514516
cls.iLoc = iLoc
515517
cls.nLoc = nLoc
516518
cls.mpiFile = None
519+
cls.balanced_distribution = all(cls.nLoc == me for me in comm.allgather(nLoc))
520+
if not cls.balanced_distribution:
521+
warnings.warn(
522+
f'You requested an unbalanced block decomposition, in {cls.__name__!r} which will result in far slower IO! Please consider changing the resolution or number of tasks.'
523+
)
517524

518525
@property
519526
def MPI_ON(self):
@@ -553,7 +560,10 @@ def MPI_WRITE_AT(self, offset, data: np.ndarray):
553560
data : np.ndarray
554561
Data to be written in the binary file.
555562
"""
556-
self.mpiFile.Write_at_all(offset, data)
563+
if self.balanced_distribution:
564+
self.mpiFile.Write_at_all(offset, data)
565+
else:
566+
self.mpiFile.Write_at(offset, data)
557567

558568
def MPI_READ_AT(self, offset, data):
559569
"""
@@ -567,7 +577,10 @@ def MPI_READ_AT(self, offset, data):
567577
data : np.ndarray
568578
Array on which to read the data from the binary file.
569579
"""
570-
self.mpiFile.Read_at_all(offset, data)
580+
if self.balanced_distribution:
581+
self.mpiFile.Read_at_all(offset, data)
582+
else:
583+
self.mpiFile.Read_at(offset, data)
571584

572585
def MPI_FILE_CLOSE(self):
573586
"""Close the binary file in MPI mode"""

0 commit comments

Comments
 (0)