From 9bcb6f08cceea0fdf5bfa4515dfdc9fb1ccd6497 Mon Sep 17 00:00:00 2001 From: Thibaut Lunet Date: Fri, 16 May 2025 10:31:49 +0200 Subject: [PATCH 1/3] TL: mini fix for edge cases --- pySDC/helpers/fieldsIO.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pySDC/helpers/fieldsIO.py b/pySDC/helpers/fieldsIO.py index 58e00d3cb4..a72601a021 100644 --- a/pySDC/helpers/fieldsIO.py +++ b/pySDC/helpers/fieldsIO.py @@ -417,8 +417,6 @@ def setHeader(self, nVar, coords): coords = self.setupCoords(*coords) self.header = {"nVar": int(nVar), "coords": coords} self.nItems = nVar * self.nDoF - if self.MPI_ON: - self.MPI_SETUP() @property def hInfos(self): @@ -573,6 +571,8 @@ def MPI_WRITE_AT_ALL(self, offset, data: np.ndarray): data : np.ndarray Data to be written in the binary file. """ + if self.mpiType is None: + self.MPI_SETUP() self.mpiFile.Set_view(disp=offset, etype=self.mpiType, filetype=self.mpiFileType) self.mpiFile.Write_all(data) @@ -588,6 +588,8 @@ def MPI_READ_AT_ALL(self, offset, data: np.ndarray): data : np.ndarray Array on which to read the data from the binary file. """ + if self.mpiType is None: + self.MPI_SETUP() self.mpiFile.Set_view(disp=offset, etype=self.mpiType, filetype=self.mpiFileType) self.mpiFile.Read_all(data) From 9dc9f34489f70be57e3834a2c73deb2df1b3d4ac Mon Sep 17 00:00:00 2001 From: Thibaut Lunet Date: Fri, 16 May 2025 10:45:14 +0200 Subject: [PATCH 2/3] TL: better implementation --- pySDC/helpers/fieldsIO.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pySDC/helpers/fieldsIO.py b/pySDC/helpers/fieldsIO.py index a72601a021..21ffe8c4d6 100644 --- a/pySDC/helpers/fieldsIO.py +++ b/pySDC/helpers/fieldsIO.py @@ -439,7 +439,7 @@ def readHeader(self, f): coords = [np.fromfile(f, dtype=np.float64, count=n) for n in gridSizes] self.setHeader(nVar, coords) if self.MPI_ON: - self.MPI_SETUP() + self.MPI_SETUP_FILETYPE() def reshape(self, fields: np.ndarray): """Reshape the fields to a N-d array (inplace operation)""" @@ -537,7 +537,7 @@ def MPI_ROOT(self): return True return self.comm.Get_rank() == 0 - def MPI_SETUP(self): + def MPI_SETUP_FILETYPE(self): """Setup subarray masks for each processes""" self.mpiType = MPI_DTYPE(self.dtype) self.mpiFileType = self.mpiType.Create_subarray( @@ -554,6 +554,8 @@ def MPI_FILE_OPEN(self, mode): "a": MPI.MODE_WRONLY | MPI.MODE_APPEND, }[mode] self.mpiFile = MPI.File.Open(self.comm, self.fileName, amode) + if self.mpiType is None: + self.MPI_SETUP_FILETYPE() def MPI_WRITE(self, data): """Write data (np.ndarray) in the binary file in MPI mode, at the current file cursor position.""" @@ -571,8 +573,6 @@ def MPI_WRITE_AT_ALL(self, offset, data: np.ndarray): data : np.ndarray Data to be written in the binary file. """ - if self.mpiType is None: - self.MPI_SETUP() self.mpiFile.Set_view(disp=offset, etype=self.mpiType, filetype=self.mpiFileType) self.mpiFile.Write_all(data) @@ -588,8 +588,6 @@ def MPI_READ_AT_ALL(self, offset, data: np.ndarray): data : np.ndarray Array on which to read the data from the binary file. """ - if self.mpiType is None: - self.MPI_SETUP() self.mpiFile.Set_view(disp=offset, etype=self.mpiType, filetype=self.mpiFileType) self.mpiFile.Read_all(data) From 8433042e8e40763a70e071c8033167dfddecf524 Mon Sep 17 00:00:00 2001 From: Thibaut Lunet Date: Fri, 16 May 2025 10:46:03 +0200 Subject: [PATCH 3/3] TL: forgot that --- pySDC/helpers/fieldsIO.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pySDC/helpers/fieldsIO.py b/pySDC/helpers/fieldsIO.py index 21ffe8c4d6..43e4fdb562 100644 --- a/pySDC/helpers/fieldsIO.py +++ b/pySDC/helpers/fieldsIO.py @@ -438,8 +438,6 @@ def readHeader(self, f): gridSizes = np.fromfile(f, dtype=np.int32, count=dim) coords = [np.fromfile(f, dtype=np.float64, count=n) for n in gridSizes] self.setHeader(nVar, coords) - if self.MPI_ON: - self.MPI_SETUP_FILETYPE() def reshape(self, fields: np.ndarray): """Reshape the fields to a N-d array (inplace operation)"""