Skip to main content

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 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 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

Installation

You can install omp4py via pip:

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$:

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:

     poetry run coverage run
    
  2. Generate a coverage report:

     poetry run coverage html
    

* Test dependencies are required, and pip only installs project dependencies. Use poetry install to install them.

Metadata

Release files for omp4py 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for omp4py 0.1
File Size Uploaded Provenance
omp4py-0.1.tar.gz 38.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for omp4py 0.1
File Interpreter ABI Platform
omp4py-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 91.8 kB

Release files / omp4py-0.1.tar.gz

Download URL omp4py-0.1.tar.gz
Size 38.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b4af1988b9adb7fa95e83a9166750abdd3841d4aefc10650e040fb98043dfc5e
BLAKE2b-256 checksum
How to use checksums
9f7280afce992fc685613e65f5d06baf3d064ffa8968a7e6da4d2f032b454f83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Windows/11

Release files / omp4py-0.1-py3-none-any.whl

Download URL omp4py-0.1-py3-none-any.whl
Size 52.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9b6894468d660ae72c0f4333a350f6721dba30648c15ce3c147aa7f0c0cf14a
BLAKE2b-256 checksum
How to use checksums
00e8f6b79d4c3eb4859701ab3f5d6a32d3960c138b756f586c2807a3025401a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Windows/11

Security for omp4py 0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page