fipy.tools.sharedtempfile

This module provides a generic, high-level interface for creating shared temporary files. All of the interfaces provided by this module can be used without fear of race conditions.

Functions

SharedTemporaryFile([mode, buffering, ...])

Create a temporary file shared by all MPI ranks.

fipy.tools.sharedtempfile.SharedTemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix='', prefix='tmp', dir=None, delete=True, communicator=DummyComm())

Create a temporary file shared by all MPI ranks.

The file is created as NamedTemporaryFile would do it. The name of the returned file-like object is accessible as its name attribute. The file will be automatically deleted when it is closed unless the delete argument is set to False.

>>> from fipy.tools import SharedTemporaryFile, parallelComm
>>> with SharedTemporaryFile(mode='w+', suffix=".tmp") as tmpFile:
...     # write on processor 0
...     if parallelComm.procID == 0:
...         _ = tmpFile.write("shared text")
...
...     parallelComm.Barrier()
...
...     # read on all processors
...     _ = tmpFile.seek(0)
...     txt = tmpFile.read()
>>> print(txt)
shared text
Parameters:
  • prefix (str) – As for mkstemp

  • suffix (str) – As for mkstemp

  • dir (str) – As for mkstemp

  • mode (str) – The mode argument to io.open (default “w+b”)

  • buffering (int) – The buffer size argument to io.open (default -1)

  • encoding (str or None) – The encoding argument to io.open (default None)

  • newline (str or None) – The newline argument to io.open (default None)

  • delete (bool) – Whether the file is deleted on close (default True)

  • communicator (CommWrapper) – MPI communicator describing ranks to share with. A duck-typed object with procID and Nproc attributes is sufficient.

Return type:

file-like object

Last updated on Jun 26, 2024. Created using Sphinx 7.1.2.