Skip to content

Commit 9dc9f34

Browse files
committed
TL: better implementation
1 parent 9bcb6f0 commit 9dc9f34

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pySDC/helpers/fieldsIO.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def readHeader(self, f):
439439
coords = [np.fromfile(f, dtype=np.float64, count=n) for n in gridSizes]
440440
self.setHeader(nVar, coords)
441441
if self.MPI_ON:
442-
self.MPI_SETUP()
442+
self.MPI_SETUP_FILETYPE()
443443

444444
def reshape(self, fields: np.ndarray):
445445
"""Reshape the fields to a N-d array (inplace operation)"""
@@ -537,7 +537,7 @@ def MPI_ROOT(self):
537537
return True
538538
return self.comm.Get_rank() == 0
539539

540-
def MPI_SETUP(self):
540+
def MPI_SETUP_FILETYPE(self):
541541
"""Setup subarray masks for each processes"""
542542
self.mpiType = MPI_DTYPE(self.dtype)
543543
self.mpiFileType = self.mpiType.Create_subarray(
@@ -554,6 +554,8 @@ def MPI_FILE_OPEN(self, mode):
554554
"a": MPI.MODE_WRONLY | MPI.MODE_APPEND,
555555
}[mode]
556556
self.mpiFile = MPI.File.Open(self.comm, self.fileName, amode)
557+
if self.mpiType is None:
558+
self.MPI_SETUP_FILETYPE()
557559

558560
def MPI_WRITE(self, data):
559561
"""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):
571573
data : np.ndarray
572574
Data to be written in the binary file.
573575
"""
574-
if self.mpiType is None:
575-
self.MPI_SETUP()
576576
self.mpiFile.Set_view(disp=offset, etype=self.mpiType, filetype=self.mpiFileType)
577577
self.mpiFile.Write_all(data)
578578

@@ -588,8 +588,6 @@ def MPI_READ_AT_ALL(self, offset, data: np.ndarray):
588588
data : np.ndarray
589589
Array on which to read the data from the binary file.
590590
"""
591-
if self.mpiType is None:
592-
self.MPI_SETUP()
593591
self.mpiFile.Set_view(disp=offset, etype=self.mpiType, filetype=self.mpiFileType)
594592
self.mpiFile.Read_all(data)
595593

0 commit comments

Comments
 (0)