pygsti.tools.mpitools.distribute_indices_base#
- distribute_indices_base(indices, nprocs, rank, allow_split_comm=True)#
Partition an array of “indices” evenly among a given number of “processors”
This function is similar to
distribute_indices(), but allows for more a more generalized notion of what a “processor” is, since the number of processors and rank are given independently and do not have to be associated with an MPI comm. Note also that indices can be an arbitrary list of items, making this function very general.- Parameters:
indices (list) – An array of items (any type) which are to be partitioned.
nprocs (int) – The number of “processors” to distribute the elements of indices among.
rank (int) – The rank of the current “processor” (must be an integer between 0 and nprocs-1). Note that this value is not obtained from any MPI communicator.
allow_split_comm (bool) – If True, when there are more processors than indices, multiple processors will be given the same set of local 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 (i.e. the one specified by rank).
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.