array_partition Subroutine

public subroutine array_partition(n, k, p, start, count)

Compute start and count for the p'th partition of an array of size n where p = 0, 1, ... , k - 1.

For k partitions, an array of n elements can be partitioned into r partitions of length q + 1, and k - r partitions of length q where q and r are the quotient and remainder of n divided by k (i.e. n = q * k + r). Note, we assume that the r partitions of length q + 1 precede the k - r partitions of length q in the array.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n

The total number of elements in the array to be partitioned.

integer, intent(in) :: k

The total number of partitions.

integer, intent(in) :: p

The index of the partition for which to compute the start and count (0-based).

integer, intent(out) :: start

The starting index (1-based) of the p'th partition in the array.

integer, intent(out) :: count

The number of elements in the p'th partition.