Skip to main content

Synchronize read/write access to resources shared between MPI processes.

Project description

codecov

About

mpilock offers a WindowController class with a high-level API for parallel access to resources. The WindowController can be used to synchronize MPI processes during read, write or single_write operations on shared resources.

Read operations happen in parallel while write operations will lock the resource and prevent any new read or write operations and will wait for all existing read operations to finish. After the write operation completes the lock is released and other operations can resume.

The WindowController does not contain any logic to control the resources, it only locks and synchronizes the MPI processes. Once the operation permission is obtained it's up to the user to perform the reading/writing to the resources.

The sync method is a factory for WindowControllers and can simplify creation of WindowControllers.

Example usage

from mpilock import sync
from h5py import File

# Create a default WindowController on `COMM_WORLD` with the master on rank 0
ctrl = sync()

# Fencing is the preferred idiom to fence anyone that isn't writing out of
# the writer's code block, and afterwards share a resource
with ctrl.single_write() as fence:
  # Makes anyone without access long jump to the end of the with statement
  fence.guard()
  resource = h5py.File("hello.world", "w")
  # Put a resource to be collected by other processes
  fence.share(resource)
resource = fence.collect()

try:
  # Acquire a parallel read lock, guarantees noone writes while you're reading.
  with ctrl.read():
    data = resource["/my_data"][()]
  # Acquire a write lock, will block all reading and writing.
  with ctrl.write():
    resource.create_dataset(lock.rank, data=data)
finally:
  with ctrl.single_write() as fence:
    fence.guard()
    resource.close()

# The window controller itself needs to be closed as well (is done atexit)
ctrl.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mpilock-1.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file mpilock-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: mpilock-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for mpilock-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0902ef859a7b3dfb4312a3c46332302493aa14fa398b610554706b0b9e7cb57c
MD5 b78800870662a34f41a4295dace2dd7f
BLAKE2b-256 3bfc8126bb4882fbc4946a717cce773819e712cdcd401edf70d6f7754ba4d910

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page