pygsti.tools.mpitools.distribute_indices#
- distribute_indices(indices, comm, allow_split_comm=True)#
Partition an array of indices (any type) evenly among comm’s processors.
- Parameters:
indices (list) – An array of items (any type) which are to be partitioned.
comm (mpi4py.MPI.Comm or ResourceAllocation) – The communicator which specifies the number of processors and which may be split into returned sub-communicators. If a
ResourceAllocationobject, node information is also taken into account when available (for shared memory compatibility).allow_split_comm (bool) – If True, when there are more processors than indices, multiple processors will be given the same set of local indices and comm will be split into sub-communicators, one for each group of processors that are given the same indices. If False, then “extra” processors are simply given nothing to do, i.e. empty lists of local indices.
- Returns:
loc_indices (list) – A list containing the elements of indices belonging to the current processor.
owners (dict) – A dictionary mapping the elements of indices to integer ranks, such that owners[el] gives the rank of the processor responsible for communicating that element’s results to the other processors. Note that in the case when allow_split_comm=True and multiple processors have computed the results for a given element, only a single (the first) processor rank “owns” the element, and is thus responsible for sharing the results. This notion of ownership is useful when gathering the results.
loc_comm (mpi4py.MPI.Comm or ResourceAllocation or None) – The local communicator for the group of processors which have been given the same loc_indices to compute, obtained by splitting comm. If loc_indices is unique to the current processor, or if allow_split_comm is False, None is returned.