Skip to content

API: Parallel Module (parallel)

Tools for parallelizing calculations.

pysymmetry.parallel.pmap(f, X, nprocs=cpu_count())

Parallel map over iterable X using up to nprocs worker processes.

INPUT: - f -- callable applied to each element of X (must be picklable) - X -- iterable of inputs - nprocs -- number of processes (default: cpu_count())

OUTPUT: - list with f(x) for x in X, preserving the original order

EXAMPLES::

sage: from pysymmetry.parallel import pmap
sage: pmap(lambda t: t*t, [0,1,2,3], nprocs=2)
[0, 1, 4, 9]

pysymmetry.parallel.pmap_reduce(f, X, fun=add, nprocs=cpu_count())

Parallel map followed by reduction across worker-local partial results.

INPUT: - f -- callable applied to each element of X (must be picklable) - X -- iterable of inputs - fun -- associative binary function used to combine partial results (default: operator.add) - nprocs -- number of processes (default: cpu_count())

OUTPUT: - single value equal to fun(f(x0), fun(f(x1), ...)) in unspecified tree order

EXAMPLES::

sage: from pysymmetry.parallel import pmap_reduce
sage: # Sum of squares of 0..4
sage: pmap_reduce(lambda t: t*t, range(5), fun=lambda a,b: a+b, nprocs=2)
30