Skip to main content

unipram: write a PRAM algorithm once, check it, run it anywhere

unipram is made to teach parallel algorithms. A PRAM algorithm is written once, in plain Python. The same code then runs on three machines:

Machine What it does
SimulatedPRAM(model, writes) an ideal machine, with as many processors as you need: it checks every memory access against EREW, CREW or CRCW, and counts steps and work
ThreadedPRAM(nb_threads) runs each step on a few threads (Brent's theorem); use free-threaded Python for a real speed-up
GpuPRAM(device) runs each step as a GPU kernel, with unigpu

Documentation (in French, like the error messages and the docstrings).

Install

python -m pip install unipram            # simulator and threads (needs only NumPy)
python -m pip install "unipram[metal]"   # with a GPU: metal, cuda, cuda13 or opencl

Example

from unipram import Model, SimulatedPRAM


def max_step(pe, jump, t):                # one processor, during one step
    if pe + jump < t.size:
        t[pe] = max(t[pe], t[pe + jump])


def maximum(machine, values):             # the program
    t = machine.array(values, name="T")
    jump = 1
    while jump < t.size:
        machine.parallel_for(t.size, max_step, jump, t)
        jump *= 2
    return int(machine.read(t)[0])


machine = SimulatedPRAM(Model.CREW)
print(maximum(machine, [3, 9, 4, 1]), machine.costs())
# 9 2 pas, travail 8, 4 PE au plus

During a step, every read sees the memory as it was at the start of the step, and writes take effect at its end. This algorithm is not EREW, and the simulator says so:

maximum(SimulatedPRAM(Model.EREW), [3, 9, 4, 1])
# AccessViolation: EREW violé au pas 1 : la case T[1] est lue par 2 PE (0, 1)

Only the simulator checks the accesses: debug there first. An instruction must be a plain function, defined with def in a file or a notebook. It takes the number of its processor, then numbers and shared arrays, and writes only to these arrays and its local variables. Every machine refuses anything else.

See every step

from unipram import TraceRecorder, TraceView, wait_for_enter

trace = TraceRecorder()
maximum(SimulatedPRAM(Model.CREW, observers=[trace]), [3, 9, 4, 1])
TraceView(print, pause=wait_for_enter).show(trace.records)

This shows what each processor reads and writes, then the arrays before and after the step. Changed cells are in brackets, and large data are shortened.

Extend it without changing it

  • Another model: Model("ERCW", concurrent_reads=False, concurrent_writes=True).
  • Another rule for concurrent writes: a subclass of WritePolicy, like ArbitraryWrite, ConsistentWrite and MergeWrite(operator).
  • Another measure: a subclass of StepObserver, given to the simulator.
  • Another machine: a subclass of PRAM.

To raise an error when the written values are incompatible, a WritePolicy raises WriteConflict.

Develop

python -m pip install -e ".[test]"
python -m ruff check .
python -m mypy
python -m pytest --cov

python -m pip install -e ".[docs]"
python -m mkdocs serve

License

MIT

Metadata

Release files for unipram 0.1.0

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

Source distribution (sdist)

Source distribution for unipram 0.1.0
File Size Uploaded Provenance Actions
unipram-0.1.0.tar.gz 38.6 kB With provenance Details for unipram-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 66.7 kB

Release files / unipram-0.1.0.tar.gz

Download URL unipram-0.1.0.tar.gz
Size 38.6 kB
Tags Source
SHA-256 checksum
How to use checksums
60d17fe18fa5a1335ff121ac6f93693539df48724f54f3d7a53f33c988cda7ed
BLAKE2b-256 checksum
How to use checksums
af9e18d1148bf7143567fc5a19765978eb402eec5eb8bb275a503d999e61c537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Release files / unipram-0.1.0-py3-none-any.whl

Download URL unipram-0.1.0-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f380076e66f312c81f01100f641442fff36d1703743987f94a95ba57d769a2c
BLAKE2b-256 checksum
How to use checksums
70348af0b4ec7f90934b6845261162e857516f6ac47aa661fa1cc0ce1833ddb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 29, 2026.

Transparency log

Security for unipram 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for unipram-0.1.0.tar.gz

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 Nov 29, 2026.

Transparency log

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.0 This release

2 release files Full 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