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()
Release files for mpilock 2.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mpilock-2.2.1.tar.gz | 9.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mpilock-2.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.4 kB
Release files / mpilock-2.2.1.tar.gz
| Download URL | mpilock-2.2.1.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e88000da7de88468a58650102a2637f7ea588c88e316e0b88934c0955e62fdcd
|
|
BLAKE2b-256 checksum How to use checksums |
2f1d30aee7d5992b478546701244ce049aad813b406f0f905e98133821c4520c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logRelease files / mpilock-2.2.1-py3-none-any.whl
| Download URL | mpilock-2.2.1-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64f41a0d64a50ae7a31ed49b4d394ccaf851a47210c60efa2906a522678c8cbf
|
|
BLAKE2b-256 checksum How to use checksums |
3dbe973ef89b1c379f35261de1f8ba49a77acd35f1f8c9c6212d976dcf91bd3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency log