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, 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.

[!IMPORTANT]

One of the MPI ranks involved will need to act as the root. Under some conditions, for some MPI implementations, whenever the root rank acquires a read lock, others may not be able to acquire a read or write lock in parallel. This applies to you if:

  • The root rank acquires read locks
  • You use an affected MPI implementation
  • Your root rank does not perform MPI operations while it holds the read lock.

A solution to this is to frequently call an MPI noop like Iprobe() from the root rank while it holds the read lock.

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 Distribution

mpilock-2.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpilock-2.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file mpilock-2.1.0.tar.gz.

File metadata

  • Download URL: mpilock-2.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mpilock-2.1.0.tar.gz
Algorithm Hash digest
SHA256 e0ab45284765c94775b5f9bd6cfaee7a9e1f48c087c87581fd9334f55bc41bd0
MD5 9e72352892fdfde047cc68ef44968d67
BLAKE2b-256 84ec74bb5198660478bbf615af5e8d47a74d09155a5b8930c9e9cdd339ecca06

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpilock-2.1.0.tar.gz:

Publisher: release.yml on Helveg/mpilock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: mpilock-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mpilock-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fa90e2e982c6284b044a4c1a2bdba712cc77900c134319b70e8d7b6aaf9285b
MD5 41adb6c383f81fa52b05460382d836a7
BLAKE2b-256 cea10d26051756248fa3c23d7ce8921e5d1854e108003579029dc181ade823e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpilock-2.1.0-py3-none-any.whl:

Publisher: release.yml on Helveg/mpilock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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