pathos

0.3.5 · active · verified Sun Mar 29

pathos is a framework for heterogeneous computing that provides tools for parallel graph management and execution. It offers a consistent high-level interface for configuring and launching parallel computations across diverse resources, aiming to extend user code to parallel and distributed computing with minimal refactoring. The library is currently at version 0.3.5 and has a consistent release cadence with minor versions released every few months, typically adding incremental features and dependency updates.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `pathos.multiprocessing.ProcessingPool` to parallelize a function with multiple arguments using its enhanced `map` method. The `nodes` parameter configures the number of worker processes. Ensure the `if __name__ == '__main__':` block is used for multiprocessing compatibility.

from pathos.multiprocessing import ProcessingPool as Pool

def calculate_power(base, exponent):
    return base ** exponent

if __name__ == '__main__':
    bases = [1, 2, 3, 4, 5]
    exponents = [2, 3, 2, 4, 3]

    # Initialize a pool with a number of worker processes (e.g., 4)
    pool = Pool(nodes=4)

    # Use the map method to apply calculate_power in parallel
    # pathos's map directly accepts multiple iterables for multiple arguments
    results = pool.map(calculate_power, bases, exponents)

    print(f"Bases: {bases}")
    print(f"Exponents: {exponents}")
    print(f"Parallel Results: {results}")

    # Don't forget to close and join the pool when done
    pool.close()
    pool.join()

view raw JSON →