mpi4py.util.pool
Added in version 4.0.0.
See also
This module intends to be a drop-in replacement for the
multiprocessing.pool
interface from the Python standard library.
The Pool
class exposed here is implemented as a
thin wrapper around MPIPoolExecutor
.
Note
The mpi4py.futures
package offers a higher level interface
for asynchronously pushing tasks to MPI worker process, allowing
for a clear separation between submitting tasks and waiting for the
results.
- class mpi4py.util.pool.Pool
Pool using MPI processes as workers.
- __init__(processes=None, initializer=None, initargs=(), **kwargs)
Initialize a new Pool instance.
- Parameters:
- Return type:
Note
Additional keyword arguments are passed down to the
MPIPoolExecutor
constructor.Warning
The maxtasksperchild and context arguments of
multiprocessing.pool.Pool
are not supported. Specifying maxtasksperchild or context with a value other thanNone
will issue a warning of categoryUserWarning
.
- apply(func, args=(), kwds={})
Call func with arguments args and keyword arguments kwds.
Equivalent to
func(*args, **kwds)
.
- apply_async(func, args=(), kwds={}, callback=None, error_callback=None)
Asynchronous version of
apply()
returningApplyResult
.- Parameters:
- Return type:
- map(func, iterable, chunksize=None)
Apply func to each element in iterable.
Equivalent to
list(map(func, iterable))
.Block until all results are ready and return them in a
list
.The iterable is choped into a number of chunks which are submitted as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.
Consider using
imap()
orimap_unordered()
with explicit chunksize for better efficiency.
- map_async(func, iterable, chunksize=None, callback=None, error_callback=None)
- imap(func, iterable, chunksize=1)
Like
map()
but return aniterator
.Equivalent to
map(func, iterable)
.
- starmap(func, iterable, chunksize=None)
Apply func to each argument tuple in iterable.
Equivalent to
list(itertools.starmap(func, iterable))
.Block until all results are ready and return them in a
list
.The iterable is choped into a number of chunks which are submitted as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.
Consider using
istarmap()
oristarmap_unordered()
with explicit chunksize for better efficiency.
- starmap_async(func, iterable, chunksize=None, callback=None, error_callback=None)
- istarmap(func, iterable, chunksize=1)
Like
starmap()
but return aniterator
.Equivalent to
itertools.starmap(func, iterable)
.
- istarmap_unordered(func, iterable, chunksize=1)
Like
istarmap()
but ordering of results is arbitrary.
- class mpi4py.util.pool.AsyncResult
Asynchronous result.
- get(timeout=None)
Return the result when it arrives.
If timeout is not
None
and the result does not arrive within timeout seconds then raiseTimeoutError
.If the remote call raised an exception then that exception will be reraised.
- wait(timeout=None)
Wait until the result is available or timeout seconds pass.
- successful()
Return whether the call completed without raising an exception.
If the result is not ready then raise
ValueError
.- Return type:
- class mpi4py.util.pool.ApplyResult
Bases:
AsyncResult
Result type of
apply_async()
.
- class mpi4py.util.pool.MapResult
Bases:
AsyncResult
Result type of
map_async()
andstarmap_async()
.