Skip to main content

A common interface for parallel processing pools.

Project description

http://img.shields.io/travis/adrn/schwimmbad/master.svg?style=flat http://img.shields.io/pypi/v/schwimmbad.svg?style=flat http://img.shields.io/badge/license-MIT-blue.svg?style=flat

A common interface to parallel processing pools.

Enables easy switching between serial execution, multiprocessing, and MPI by providing a common interface.

Example

If you can write your code following the MapReduce programming model, you can trivially parallelize it using The Schwimmbad. For example, if you can structure your code so that a ‘worker’ function operates on elements from a list of tasks, like this:

def worker(task):
    # do something with the task!
    return task**2

def main():
    tasks = range(100)
    results = map(worker, tasks)

if __name__ == "__main__":
    main()

with a few added lines of code, you can make it runnable with multiprocessing and MPI at the switch of a command-line flag:

import schwimmbad

def worker(task):
    # do something with the task!
    return task**2

def main(pool):
    tasks = range(100)
    results = pool.map(worker, tasks)
    pool.close()

if __name__ == "__main__":
    from argparse import ArgumentParser
    parser = ArgumentParser(description="")

    group = parser.add_mutually_exclusive_group()
    group.add_argument("--ncores", dest="n_cores", default=1,
                       type=int, help="Number of processes (uses multiprocessing).")
    group.add_argument("--mpi", dest="mpi", default=False,
                       action="store_true", help="Run with MPI.")
    args = parser.parse_args()

    pool = schwimmbad.choose_pool(mpi=args.mpi, processes=args.n_cores)
    main(pool)

Installation

The easiest way to install is via pip:

pip install schwimmbad

The project is also installable by cloning or downloading the source and using the standard:

python setup.py install

Dependencies

  • six

  • mpi4py (optional - needed for MPI pool support)

License

Copyright 2016 Adrian Price-Whelan.

schwimmbad is free software made available under the MIT License. For details see the LICENSE file.

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

schwimmbad-0.2.0.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file schwimmbad-0.2.0.tar.gz.

File metadata

  • Download URL: schwimmbad-0.2.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for schwimmbad-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2f03f674be696f769c4a7817ec7d175b216a0a5926664024fb03597bd710def7
MD5 8d4758f27907ad91f4ee7fa11889ca81
BLAKE2b-256 adf2a2cc9d37ed52c80507750d6b3e01d9a9c6fdd2669fafc14cf11547b576d7

See more details on using hashes here.

Supported by

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