lib.mpi.MPIPool¶
- class lib.mpi.MPIPool(mpicomm=None, check_tasks=False)¶
Bases:
objectA processing pool that distributes tasks using MPI. With this pool class, the master process distributes tasks to worker processes using an MPI communicator.
This implementation is inspired by @juliohm in this module and was adapted from schwimmbad.
initialize
MPIPool.- Parameters
mpicomm (MPI communicator, default=None) – Communicator. Defaults to current communicator.
check_tasks (bool, default=False) – Check that same tasks are input for all processes, if not, raises a
ValueError.
Methods
Tell all the workers to quit.
Is the current process the master process? Master is responsible for distributing the tasks to the other available ranks.
Is the current process a valid worker? Workers wait for instructions from the master.
Evaluate a function or callable on each task in parallel using MPI.
Tell the workers to wait and listen for the master process.
- close()¶
Tell all the workers to quit.
- is_master()¶
Is the current process the master process? Master is responsible for distributing the tasks to the other available ranks.
- is_worker()¶
Is the current process a valid worker? Workers wait for instructions from the master.
- map(function, tasks)¶
Evaluate a function or callable on each task in parallel using MPI. The callable,
worker, is called on each element of thetasksiterable. The results are returned in the expected order.- Parameters
function (callable) – A function or callable object that is executed on each element of the specified
tasksiterable. This should accept a single positional argument and return a single object.tasks (iterable) – A list or iterable of tasks. Each task can be itself an iterable (e.g., tuple) of values or data to pass in to the worker function.
- Returns
results – A list of results from the output of each
functioncall.- Return type
list
- wait()¶
Tell the workers to wait and listen for the master process. This is called automatically when using
MPIPool.map()and doesn’t need to be called by the user.