parallel_map#

caput.util.mpitools.parallel_map(func: collections.abc.Callable, glist: list, root: int | None = None, method: str = 'con', comm: mpi4py.MPI.Comm | None = _comm) list | None[source]#

Apply a parallel map using MPI.

Should be called collectively on the same list. All ranks return the full set of results.

Parameters:
funccallable()

Function to apply.

glistlist

List of map over. Must be globally defined.

rootint | None, optional

Which process should gather the results, all processes will gather the results if None.

method{“con”, “alt”, “rand”}, optional

How to split glist to each process, can be ‘con’: continuously, ‘alt’: alternatively, ‘rand’: randomly. Default is ‘con’.

commMPI.Comm | None, optional

MPI communicator that array is distributed over. Default is the gobal _comm.

Returns:
resultslist | None

Global list of results. Returns None if no partition on this rank.