Skip to main content

Tools to parallelize operations on large data sets using shared memory with zero copies.

Project description

pasha

pasha (parallelized shared memory) provides tools to process data in parallel with an emphasis on shared memory and zero copy. It uses the map pattern similar to Python's builtin map() function, where a callable is applied to many elements in a collection. To avoid the high cost of IPC or other communication schemes, the results are meant to be written directly to memory shared between all workers as well as the calling site. The current implementations cover distribution across threads and processes on a single node.

Quick guide

To use it, simply import it, define your kernel function of choice and map away!

import numpy as np
import pasha as psh

# Get some random input data
inp = np.random.rand(100)

# Allocate output array via pasha. The returned array is
# guaranteed to be accessible from any worker, and may
# reside in shared memory.
outp = psh.alloc(like=inp)

# Define a kernel function multiplying each value with 3.
def triple_it(worker_id, index, value):
    outp[index] = 3 * value

# Map the kernel function.
psh.map(triple_it, inp)

# Check the result
np.testing.assert_allclose(outp, inp*3)

The runtime environment is controlled by a map context. The default context object is ProcessContext, which uses multiprocessing.Pool to distribute the work across several processes. This context only works on *nix systems supporting the fork() system call, as it expects any input data to be shared. When the process context is selected, psh.alloc() creates arrays in shared memory, so workers can write output data there and the caller can retrieve it with no memory copies.

You may either create an explicit context object and use it directly or change the default context, e.g.

psh.set_default_context('threads', num_workers=4)

There are three different context types builtin: serial, threads and processes.

The input array passed to map() is called a functor and is automatically wrapped in a suitable Functor object, here SequenceFunctor. This works for a number of common array and sequence types, but you may also implement your own Functor object to wrap anything else that can be iterated over.

For example, this is used to provide tight integration with EXtra-data, a toolkit used to access scientific data recorded at European XFEL. With this, you can map over DataCollection and KeyData objects to parallelize your data analysis.

def analysis_kernel(worker_id, index, train_id, data):
    # Do something with the data and save it to shared memory.

run = extra_data.open_run(proposal=700000, run=1)
psh.map(analysis_kernel, run[source, key])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pasha-0.1.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pasha-0.1.2-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pasha-0.1.2.tar.gz.

File metadata

  • Download URL: pasha-0.1.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.16

File hashes

Hashes for pasha-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7133ae62639e3c88d18f9b16e61efda9200d1963dc49cf7019565cc5d61c6fe9
MD5 e0941d8626c6a77bb4838422f6f3fe49
BLAKE2b-256 84aa3d7524e1dc5dd0251a215ae9469ab1d988517f1fbef2b0497fa3eba1da30

See more details on using hashes here.

File details

Details for the file pasha-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pasha-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.16

File hashes

Hashes for pasha-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87950b9ee0f4e9a5c47ba886e196dc6566ada66f1e2353439e0bc89823c91902
MD5 45a31f97448ef7376457b5739cb2e786
BLAKE2b-256 534962bcd4792b202d1b720e6675cda8fd50dab6f9d8a083c51a31a674a62eda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page