[![codecov](https://codecov.io/gh/Helveg/mpilock/branch/main/graph/badge.svg?token=WQ1U6UNPGA)](https://codecov.io/gh/Helveg/mpilock)
# 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 `WindowController`s and can simplify creation of
`WindowController`s.
# Example usage
```python
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()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Helveg/zwembad",
"name": "mpilock",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "mpi pool mpipool zwembad",
"author": "Robin De Schepper",
"author_email": "robingilbert.deschepper@unipv.it",
"download_url": "",
"platform": "",
"description": "[![codecov](https://codecov.io/gh/Helveg/mpilock/branch/main/graph/badge.svg?token=WQ1U6UNPGA)](https://codecov.io/gh/Helveg/mpilock)\n\n# About\n\n`mpilock` offers a `WindowController` class with a high-level API for parallel access to\nresources. The `WindowController` can be used to synchronize MPI processes during `read`,\n`write` or `single_write` operations on shared resources.\n\nRead operations happen in parallel while write operations will lock the resource and\nprevent any new read or write operations and will wait for all existing read operations to\nfinish. After the write operation completes the lock is released and other operations can\nresume.\n\nThe `WindowController` does not contain any logic to control the resources, it only locks\nand synchronizes the MPI processes. Once the operation permission is obtained it's up to\nthe user to perform the reading/writing to the resources.\n\nThe `sync` method is a factory for `WindowController`s and can simplify creation of\n`WindowController`s.\n\n# Example usage\n\n```python\nfrom mpilock import sync\nfrom h5py import File\n\n# Create a default WindowController on `COMM_WORLD` with the master on rank 0\nctrl = sync()\n\n# Fencing is the preferred idiom to fence anyone that isn't writing out of\n# the writer's code block, and afterwards share a resource\nwith ctrl.single_write() as fence:\n # Makes anyone without access long jump to the end of the with statement\n fence.guard()\n resource = h5py.File(\"hello.world\", \"w\")\n # Put a resource to be collected by other processes\n fence.share(resource)\nresource = fence.collect()\n\ntry:\n # Acquire a parallel read lock, guarantees noone writes while you're reading.\n with ctrl.read():\n data = resource[\"/my_data\"][()]\n # Acquire a write lock, will block all reading and writing.\n with ctrl.write():\n resource.create_dataset(lock.rank, data=data)\nfinally:\n with ctrl.single_write() as fence:\n fence.guard()\n resource.close()\n\n# The window controller itself needs to be closed as well (is done atexit)\nctrl.close()\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Synchronize read/write access to resources shared between MPI processes.",
"version": "1.1.0",
"split_keywords": [
"mpi",
"pool",
"mpipool",
"zwembad"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "b78800870662a34f41a4295dace2dd7f",
"sha256": "0902ef859a7b3dfb4312a3c46332302493aa14fa398b610554706b0b9e7cb57c"
},
"downloads": -1,
"filename": "mpilock-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b78800870662a34f41a4295dace2dd7f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6500,
"upload_time": "2021-04-10T18:02:44",
"upload_time_iso_8601": "2021-04-10T18:02:44.557327Z",
"url": "https://files.pythonhosted.org/packages/3b/fc/8126bb4882fbc4946a717cce773819e712cdcd401edf70d6f7754ba4d910/mpilock-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-04-10 18:02:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Helveg",
"github_project": "zwembad",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "mpilock"
}