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.0.0.tar.gz (15.0 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.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mpilock-2.0.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for mpilock-2.0.0.tar.gz
Algorithm Hash digest
SHA256 093051fd4795f86ee682d2228cd9a87821f65851b0306b34a06c6de8936b42f1
MD5 6feead092cbd8b504fd9612da1391d44
BLAKE2b-256 90c747840ec1e1257362f0fa192618a8c2ad573fed4e75177ea8238f5fe61797

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mpilock-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for mpilock-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bef425318c0251069b08b86a52c9dafec1e9483b3ca3e1da2b5b5ac2c5028c6
MD5 f83fd97fdbe0bb8e82cc2b39d956f749
BLAKE2b-256 caaf7403c609b1d72212f48b1c7308127ee2b0f20f82c50580bb75b387330ade

See more details on using hashes here.

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