def evenly_distrib_idxs(num_divisions, arr_size):
    """Given a number of divisions and the size of an array, chop the array up
    into pieces according to number of divisions, keeping the distribution
    of entries as even as possible. Returns a tuple of
    (sizes, offsets), where sizes and offsets contain values for all
    divisions.
    """
    base = arr_size / num_divisions
    leftover = arr_size % num_divisions
    sizes = numpy.ones(num_divisions, dtype="int") * base

    # evenly distribute the remainder across size-leftover procs,
    # instead of giving the whole remainder to one proc
    sizes[:leftover] += 1

    offsets = numpy.zeros(num_divisions, dtype="int")
    offsets[1:] = numpy.cumsum(sizes)[:-1]

    return sizes, offsets
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/mpiwrap.py/evenly_distrib_idxs/original