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.2.0.tar.gz (9.1 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.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mpilock-2.2.0.tar.gz
Algorithm Hash digest
SHA256 520ac23d57e7a2f3196fec2da60050865d5082c94350e3619a0c9e041b035102
MD5 47fc7ebec64602c249fec0fb4503bcbe
BLAKE2b-256 9fa1d8d098ffc5c809bfccb2656c062d42f1147431d40a76762a2e5490085402

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpilock-2.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: mpilock-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e1c1bdfd9b609424f604f38c0503b013842ce15a558e1d34da2b79726024766
MD5 3d3a7eabf2139272babc7e40850f2b44
BLAKE2b-256 969456056688ecc1b4f3bf96ba6b8e9379ffb36aaca2a927b203ad0b52902370

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpilock-2.2.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