omp4py


Nameomp4py JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/citiususc/omp4py
SummaryAn OpenMP Implementation for Python
upload_time2024-11-21 13:39:50
maintainerNone
docs_urlNone
authorCésar Pomar
requires_python<4.0,>=3.10
licenseLGPL-3.0-only
keywords hpc openmp programming models
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OMP4Py: a pure Python implementation of OpenMP

**OMP4Py** is a Python library that provides an implementation of OpenMP, which is widely recognized as the standard 
programming model for exploiting multithreading parallelism in HPC. OMP4Py brings OpenMP’s familiar directive-based 
parallelization paradigm to Python, allowing developers to write parallel code with the same level of control and 
flexibility as in C, C++, or Fortran.

OMP4Py, as a pure Python implementation, provides greater flexibility compared to the Numba-based [PyOMP](https://github.com/Python-for-HPC/PyOMP) 
solution. Unlike PyOMP, it does not impose restrictions on using functions from non-Numba-optimized libraries or 
certain Python objects and data structures. Additionally, OMP4Py code can be combined with [mpi4py](https://github.com/mpi4py/mpi4py) to develop 
parallel applications that exploit both intra-node and inter-node parallelism.

## Features

- Native Python library
- Simplified parallelization of loops and code sections
- Efficient thread management and synchronization
- API compliant with [OpenMP 3.0 standard](https://www.openmp.org/wp-content/uploads/spec30.pdf)

## Installation

You can install omp4py via pip:

```bash
pip install omp4py
```
**Note**: OMP4Py is compatible with Python versions 3.10 and later, which include the Global Interpreter Lock (GIL). 
However, to fully exploit multithreading for scaling applications, it is necessary to use Python 3.13 (free threading) 
or later, which offers a no-GIL option.

## Usage

OMP4Py defines a function `omp` that operates similarly to OpenMP directives in C/C++, maintaining the same syntax and 
functionality. The function itself has no effect when executed; it serves solely as a container for the OpenMP 
directives. Note that when a OpenMP directive must be used within structured blocks, the `omp` function is used together 
as part of a `with` block; otherwise, it is used as a standalone function call. Note that functions or classes 
containing the OpenMP directives must be decorated with the `@omp` decorator.

Here's a basic example of how to use OMP4Py to calculate $\pi$:

```python
from omp4py import *
import random 
    
@omp
def pi(num_points):
    count = 0
    with omp("parallel for reduction(+:count)"):
        for i in range(num_points):
            x = random.random()
            y = random.random()
            if x * x + y * y <= 1.0:
                count += 1
    pi = count / num_points
    return pi

print(pi(10000000))  
```

## Tests

To run the unit tests and check the coverage, you can use the following commands with Poetry*:

1. **Run the unit tests:**

    ```bash
     poetry run coverage run
    ```

2. **Generate a coverage report:**

    ```bash
     poetry run coverage html
    ```
\* Test dependencies are required, and pip only installs project dependencies. Use ``poetry install`` to install them.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/citiususc/omp4py",
    "name": "omp4py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "HPC, OpenMP, Programming models",
    "author": "C\u00e9sar Pomar",
    "author_email": "cesaralfredo.pineiro@usc.es",
    "download_url": "https://files.pythonhosted.org/packages/9f/72/80afce992fc685613e65f5d06baf3d064ffa8968a7e6da4d2f032b454f83/omp4py-0.1.tar.gz",
    "platform": null,
    "description": "# OMP4Py: a pure Python implementation of OpenMP\n\n**OMP4Py** is a Python library that provides an implementation of OpenMP, which is widely recognized as the standard \nprogramming model for exploiting multithreading parallelism in HPC. OMP4Py brings OpenMP\u2019s familiar directive-based \nparallelization paradigm to Python, allowing developers to write parallel code with the same level of control and \nflexibility as in C, C++, or Fortran.\n\nOMP4Py, as a pure Python implementation, provides greater flexibility compared to the Numba-based [PyOMP](https://github.com/Python-for-HPC/PyOMP) \nsolution. Unlike PyOMP, it does not impose restrictions on using functions from non-Numba-optimized libraries or \ncertain Python objects and data structures. Additionally, OMP4Py code can be combined with [mpi4py](https://github.com/mpi4py/mpi4py) to develop \nparallel applications that exploit both intra-node and inter-node parallelism.\n\n## Features\n\n- Native Python library\n- Simplified parallelization of loops and code sections\n- Efficient thread management and synchronization\n- API compliant with [OpenMP 3.0 standard](https://www.openmp.org/wp-content/uploads/spec30.pdf)\n\n## Installation\n\nYou can install omp4py via pip:\n\n```bash\npip install omp4py\n```\n**Note**: OMP4Py is compatible with Python versions 3.10 and later, which include the Global Interpreter Lock (GIL). \nHowever, to fully exploit multithreading for scaling applications, it is necessary to use Python 3.13 (free threading) \nor later, which offers a no-GIL option.\n\n## Usage\n\nOMP4Py defines a function `omp` that operates similarly to OpenMP directives in C/C++, maintaining the same syntax and \nfunctionality. The function itself has no effect when executed; it serves solely as a container for the OpenMP \ndirectives. Note that when a OpenMP directive must be used within structured blocks, the `omp` function is used together \nas part of a `with` block; otherwise, it is used as a standalone function call. Note that functions or classes \ncontaining the OpenMP directives must be decorated with the `@omp` decorator.\n\nHere's a basic example of how to use OMP4Py to calculate $\\pi$:\n\n```python\nfrom omp4py import *\nimport random \n    \n@omp\ndef pi(num_points):\n    count = 0\n    with omp(\"parallel for reduction(+:count)\"):\n        for i in range(num_points):\n            x = random.random()\n            y = random.random()\n            if x * x + y * y <= 1.0:\n                count += 1\n    pi = count / num_points\n    return pi\n\nprint(pi(10000000))  \n```\n\n## Tests\n\nTo run the unit tests and check the coverage, you can use the following commands with Poetry*:\n\n1. **Run the unit tests:**\n\n    ```bash\n     poetry run coverage run\n    ```\n\n2. **Generate a coverage report:**\n\n    ```bash\n     poetry run coverage html\n    ```\n\\* Test dependencies are required, and pip only installs project dependencies. Use ``poetry install`` to install them.",
    "bugtrack_url": null,
    "license": "LGPL-3.0-only",
    "summary": "An OpenMP Implementation for Python",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/citiususc/omp4py",
        "Repository": "https://github.com/citiususc/omp4py"
    },
    "split_keywords": [
        "hpc",
        " openmp",
        " programming models"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00e8f6b79d4c3eb4859701ab3f5d6a32d3960c138b756f586c2807a3025401a9",
                "md5": "9574464f7a6b5016ebde3e106318880d",
                "sha256": "b9b6894468d660ae72c0f4333a350f6721dba30648c15ce3c147aa7f0c0cf14a"
            },
            "downloads": -1,
            "filename": "omp4py-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9574464f7a6b5016ebde3e106318880d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 52890,
            "upload_time": "2024-11-21T13:39:48",
            "upload_time_iso_8601": "2024-11-21T13:39:48.697600Z",
            "url": "https://files.pythonhosted.org/packages/00/e8/f6b79d4c3eb4859701ab3f5d6a32d3960c138b756f586c2807a3025401a9/omp4py-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f7280afce992fc685613e65f5d06baf3d064ffa8968a7e6da4d2f032b454f83",
                "md5": "8f905a321802d5247b9f00db27a57115",
                "sha256": "b4af1988b9adb7fa95e83a9166750abdd3841d4aefc10650e040fb98043dfc5e"
            },
            "downloads": -1,
            "filename": "omp4py-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8f905a321802d5247b9f00db27a57115",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 38922,
            "upload_time": "2024-11-21T13:39:50",
            "upload_time_iso_8601": "2024-11-21T13:39:50.746790Z",
            "url": "https://files.pythonhosted.org/packages/9f/72/80afce992fc685613e65f5d06baf3d064ffa8968a7e6da4d2f032b454f83/omp4py-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-21 13:39:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "citiususc",
    "github_project": "omp4py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "omp4py"
}
        
Elapsed time: 0.36919s