Next:
Array Sorting Functions Up: Library Procedures Previous: Array Combining Scatter

Array Prefix and Suffix Functions

In a scan of a vector, each element of the result is a function of the elements of the vector that precede it (for a prefix scan) or that follow it (for a suffix scan). These functions provide scan operations on arrays and subarrays. The functions all have the form XXX_PREFIX(ARRAY, DIM, MASK, SEGMENT, EXCLUSIVE) XXX_SUFFIX(ARRAY, DIM, MASK, SEGMENT, EXCLUSIVE) The allowed values of XXX are ALL, ANY, COPY, COUNT, IALL, IANY, IPARITY, MAXVAL, MINVAL, PARITY, PRODUCT, and SUM.

When comments below apply to both prefix and suffix forms of the routines, we will refer to them as YYYFIX functions.

The arguments DIM, MASK, SEGMENT, and EXCLUSIVE are optional. The COPY_YYYFIX functions do not have MASK or EXCLUSIVE arguments. The ALL_YYYFIX, ANY_YYYFIX, COUNT_YYYFIX, and PARITY_YYYFIX functions do not have MASK arguments. Their ARRAY argument must be of type logical; it is denoted MASK in their specifications in Section .

The arguments MASK and SEGMENT must be of type logical. SEGMENT must have the same shape as ARRAY. MASK must be conformable with ARRAY. EXCLUSIVE is a logical scalar. DIM is a scalar integer between one and the rank of ARRAY.

Result Value. The result has the same shape as ARRAY, and, with the exception of COUNT_YYYFIX, the same type and kind type parameter as ARRAY. (The result of COUNT_YYYFIX is default integer.)

In every case, every element of the result is determined by the values of certain selected elements of ARRAY in a way that is specific to the particular function and is described in its specification. The optional arguments affect the selection of elements of ARRAY for each element of the result; the selected elements of ARRAY are said to contribute to the result element. This section describes fully which elements of ARRAY contribute to a given element of the result.

If no elements of ARRAY are selected for a given element of the result, that result element is set to a default value that is specific to the particular function and is described in its specification.

For any given element of the result, let be the corresponding element of ARRAY. Every element of ARRAY contributes to unless disqualified by one of the following rules.

  1. If the function is XXX_PREFIX, no element that follows in the array element ordering of ARRAY contributes to . If the function is XXX_SUFFIX, no element that precedes in the array element ordering of ARRAY contributes to .

  2. If the DIM argument is provided, an element of ARRAY does not contribute to unless all its indices, excepting only the index for dimension DIM, are the same as the corresponding indices of . (It follows that if the DIM argument is omitted, then ARRAY, MASK, and SEGMENT are processed in array element order, as if temporarily regarded as rank-one arrays. If the DIM argument is present, then a family of completely independent scan operations are carried out along the selected dimension of ARRAY.)

  3. If the MASK argument is provided, an element of ARRAY contributes to only if the element of MASK corresponding to is true. (It follows that array elements corresponding to positions where the MASK is false do not contribute anywhere to the result. However, the result is nevertheless defined at all positions, even positions where the MASK is false.)

  4. If the SEGMENT argument is provided, an element of ARRAY does not contribute if there is some intermediate element of ARRAY, possibly itself, with all of the following properties:

    1. If the function is XXX_PREFIX, does not precede but does precede in the array element ordering; if the function is XXX_SUFFIX, does not follow but does follow in the array element ordering;

    2. If the DIM argument is present, all the indices of , excepting only the index for dimension DIM, are the same as the corresponding indices of ; and

    3. The element of SEGMENT corresponding to does not have the same value as the element of SEGMENT corresponding to . (In other words, can contribute only if there is an unbroken string of SEGMENT values, all alike, extending from through .)

  5. If the EXCLUSIVE argument is provided and is true, then itself does not contribute to .

These general rules lead to the following important cases:
*

(i): If ARRAY has rank one, element of the result of XXX_PREFIX(ARRAY) is determined by the first elements of ARRAY; element of the result of XXX_SUFFIX(ARRAY) is determined by the last elements of ARRAY.

(ii): If ARRAY has rank greater than one, then each element of the result of XXX_PREFIX(ARRAY) has a value determined by the corresponding element of the ARRAY and all elements of ARRAY that precede in array element order. For XXX_SUFFIX, is determined by the elements of ARRAY that correspond to or follow in array element order.

(iii): Each element of the result of XXX_PREFIX(ARRAY,MASK=MASK) is determined by selected elements of ARRAY, namely the corresponding element of the ARRAY and all elements of ARRAY that precede in array element order, but an element of ARRAY may contribute to the result only if the corresponding element of MASK is true. If this restriction results in selecting no array elements to contribute to some element of the result, then that element of the result is set to the default value for the given function.

(iv): Each element of the result of XXX_PREFIX(ARRAY,DIM=DIM) is determined by selected elements of ARRAY, namely the corresponding element of the ARRAY and all elements of ARRAY that precede along dimension DIM; for example, in SUM_PREFIX(A(1:N,1:N), DIM=2), result element could be computed as SUM(A(,)). More generally, in SUM_PREFIX(ARRAY, DIM), result element could be computed as SUM(ARRAY( )) . (Note the colon before i_DIM in that last expression.)

(v): If ARRAY has rank one, then element of the result of XXX_PREFIX(ARRAY, EXCLUSIVE=.TRUE.) is determined by the first elements of ARRAY.

(vi): The options may be used in any combination.

Examples. The examples below illustrate all possible combinations of optional arguments for SUM_PREFIX. The default value for SUM_YYYFIX is zero.
*

(i): SUM_PREFIX((/1,3,5,7/)) is ,1,4,9,16,, plus 1filll -1;1,4,9,16,; plus 1filll -1:1,4,9,16,: plus 1filll -1.1,4,9,16,. plus 1filll -11,4,9,16, plus 1filll-1.

(ii): If B is the array , 1, 2, 3 4, 5, 6 7, 8, 9 ,, plus 1filll -1; 1, 2, 3 4, 5, 6 7, 8, 9 ,; plus 1filll -1: 1, 2, 3 4, 5, 6 7, 8, 9 ,: plus 1filll -1.plus 1filll 1, 2, 3 4, 5, 6 7, 8, 9 ,.-50 1, 2, 3 4, 5, 6 7, 8, 9 , plus 1filll-1, SUM_PREFIX(B) is the array , 1, 14, 30 5, 19, 36 12, 27, 45 ,, plus 1filll -1; 1, 14, 30 5, 19, 36 12, 27, 45 ,; plus 1filll -1: 1, 14, 30 5, 19, 36 12, 27, 45 ,: plus 1filll -1.plus 1filll 1, 14, 30 5, 19, 36 12, 27, 45 ,.-50 1, 14, 30 5, 19, 36 12, 27, 45 , plus 1filll-1.

(iii): If A is the array ,3, 5, -2, -1, 7, 4, 8,, plus 1filll -1;3, 5, -2, -1, 7, 4, 8,; plus 1filll -1:3, 5, -2, -1, 7, 4, 8,: plus 1filll -1.3, 5, -2, -1, 7, 4, 8,. plus 1filll -13, 5, -2, -1, 7, 4, 8, plus 1filll-1, then SUM_PREFIX(A, MASK = A .LT. 6) is ,3, 8, 6, 5, 5, 9, 9,, plus 1filll -1;3, 8, 6, 5, 5, 9, 9,; plus 1filll -1:3, 8, 6, 5, 5, 9, 9,: plus 1filll -1.3, 8, 6, 5, 5, 9, 9,. plus 1filll -13, 8, 6, 5, 5, 9, 9, plus 1filll-1.

(iv): If B is the array , 1, 2, 3 4, 5, 6 7, 8, 9 ,, plus 1filll -1; 1, 2, 3 4, 5, 6 7, 8, 9 ,; plus 1filll -1: 1, 2, 3 4, 5, 6 7, 8, 9 ,: plus 1filll -1.plus 1filll 1, 2, 3 4, 5, 6 7, 8, 9 ,.-50 1, 2, 3 4, 5, 6 7, 8, 9 , plus 1filll-1, then SUM_PREFIX(B, DIM=1) is the array , 1, 2, 3 5, 7, 9 12, 15, 18 ,, plus 1filll -1; 1, 2, 3 5, 7, 9 12, 15, 18 ,; plus 1filll -1: 1, 2, 3 5, 7, 9 12, 15, 18 ,: plus 1filll -1.plus 1filll 1, 2, 3 5, 7, 9 12, 15, 18 ,.-50 1, 2, 3 5, 7, 9 12, 15, 18 , plus 1filll-1 and SUM_PREFIX(B, DIM=2) is the array , 1, 3, 6 4, 9, 15 7, 15, 24 ,, plus 1filll -1; 1, 3, 6 4, 9, 15 7, 15, 24 ,; plus 1filll -1: 1, 3, 6 4, 9, 15 7, 15, 24 ,: plus 1filll -1.plus 1filll 1, 3, 6 4, 9, 15 7, 15, 24 ,.-50 1, 3, 6 4, 9, 15 7, 15, 24 , plus 1filll-1.

(v): SUM_PREFIX((/1,3,5,7/), EXCLUSIVE=.TRUE.) is ,0,1,4,9,, plus 1filll -1;0,1,4,9,; plus 1filll -1:0,1,4,9,: plus 1filll -1.0,1,4,9,. plus 1filll -10,1,4,9, plus 1filll-1.

(vi): If B is the array , 1, 2, 3, 4, 5 6, 7, 8, 9, 10 11, 12, 13, 14, 15 ,, plus 1filll -1; 1, 2, 3, 4, 5 6, 7, 8, 9, 10 11, 12, 13, 14, 15 ,; plus 1filll -1: 1, 2, 3, 4, 5 6, 7, 8, 9, 10 11, 12, 13, 14, 15 ,: plus 1filll -1.plus 1filll 1, 2, 3, 4, 5 6, 7, 8, 9, 10 11, 12, 13, 14, 15 ,.-50 1, 2, 3, 4, 5 6, 7, 8, 9, 10 11, 12, 13, 14, 15 , plus 1filll-1, M is the array , T, T, T, T, T F, F, T, T, T T, F, T, F, F ,, plus 1filll -1; T, T, T, T, T F, F, T, T, T T, F, T, F, F ,; plus 1filll -1: T, T, T, T, T F, F, T, T, T T, F, T, F, F ,: plus 1filll -1.plus 1filll T, T, T, T, T F, F, T, T, T T, F, T, F, F ,.-50 T, T, T, T, T F, F, T, T, T T, F, T, F, F , plus 1filll-1, and S is the array , T, T, F, F, F F, T, T, F, F T, T, T, T, T ,, plus 1filll -1; T, T, F, F, F F, T, T, F, F T, T, T, T, T ,; plus 1filll -1: T, T, F, F, F F, T, T, F, F T, T, T, T, T ,: plus 1filll -1.plus 1filll T, T, F, F, F F, T, T, F, F T, T, T, T, T ,.-50 T, T, F, F, F F, T, T, F, F T, T, T, T, T , plus 1filll-1, then:
SUM_PREFIX(B, DIM=2, MASK=M, SEGMENT=S, EXCLUSIVE=.TRUE.) is , 0, 1, 0, 3, 7 0, 0, 0, 0, 9 0, 11, 11, 24, 24 ,, plus 1filll -1; 0, 1, 0, 3, 7 0, 0, 0, 0, 9 0, 11, 11, 24, 24 ,; plus 1filll -1: 0, 1, 0, 3, 7 0, 0, 0, 0, 9 0, 11, 11, 24, 24 ,: plus 1filll -1.plus 1filll 0, 1, 0, 3, 7 0, 0, 0, 0, 9 0, 11, 11, 24, 24 ,.-50 0, 1, 0, 3, 7 0, 0, 0, 0, 9 0, 11, 11, 24, 24 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, MASK=M, SEGMENT=S, EXCLUSIVE=.FALSE.) is , 1, 3, 3, 7, 12 0, 0, 8, 9, 19 11, 11, 24, 24, 24 ,, plus 1filll -1; 1, 3, 3, 7, 12 0, 0, 8, 9, 19 11, 11, 24, 24, 24 ,; plus 1filll -1: 1, 3, 3, 7, 12 0, 0, 8, 9, 19 11, 11, 24, 24, 24 ,: plus 1filll -1.plus 1filll 1, 3, 3, 7, 12 0, 0, 8, 9, 19 11, 11, 24, 24, 24 ,.-50 1, 3, 3, 7, 12 0, 0, 8, 9, 19 11, 11, 24, 24, 24 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, MASK=M, EXCLUSIVE=.TRUE.) is , 0, 1, 3, 6, 10 0, 0, 0, 8, 17 0, 11, 11, 24, 24 ,, plus 1filll -1; 0, 1, 3, 6, 10 0, 0, 0, 8, 17 0, 11, 11, 24, 24 ,; plus 1filll -1: 0, 1, 3, 6, 10 0, 0, 0, 8, 17 0, 11, 11, 24, 24 ,: plus 1filll -1.plus 1filll 0, 1, 3, 6, 10 0, 0, 0, 8, 17 0, 11, 11, 24, 24 ,.-50 0, 1, 3, 6, 10 0, 0, 0, 8, 17 0, 11, 11, 24, 24 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, MASK=M, EXCLUSIVE=.FALSE.) is , 1, 3, 6, 10, 15 0, 0, 8, 17, 27 11, 11, 24, 24, 24 ,, plus 1filll -1; 1, 3, 6, 10, 15 0, 0, 8, 17, 27 11, 11, 24, 24, 24 ,; plus 1filll -1: 1, 3, 6, 10, 15 0, 0, 8, 17, 27 11, 11, 24, 24, 24 ,: plus 1filll -1.plus 1filll 1, 3, 6, 10, 15 0, 0, 8, 17, 27 11, 11, 24, 24, 24 ,.-50 1, 3, 6, 10, 15 0, 0, 8, 17, 27 11, 11, 24, 24, 24 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, SEGMENT=S, EXCLUSIVE=.TRUE.) is , 0, 1, 0, 3, 7 0, 0, 7, 0, 9 0, 11, 23, 36, 50 ,, plus 1filll -1; 0, 1, 0, 3, 7 0, 0, 7, 0, 9 0, 11, 23, 36, 50 ,; plus 1filll -1: 0, 1, 0, 3, 7 0, 0, 7, 0, 9 0, 11, 23, 36, 50 ,: plus 1filll -1.plus 1filll 0, 1, 0, 3, 7 0, 0, 7, 0, 9 0, 11, 23, 36, 50 ,.-50 0, 1, 0, 3, 7 0, 0, 7, 0, 9 0, 11, 23, 36, 50 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, SEGMENT=S, EXCLUSIVE=.FALSE.) is , 1, 3, 3, 7, 12 6, 7, 15, 9, 19 11, 23, 36, 50, 65 ,, plus 1filll -1; 1, 3, 3, 7, 12 6, 7, 15, 9, 19 11, 23, 36, 50, 65 ,; plus 1filll -1: 1, 3, 3, 7, 12 6, 7, 15, 9, 19 11, 23, 36, 50, 65 ,: plus 1filll -1.plus 1filll 1, 3, 3, 7, 12 6, 7, 15, 9, 19 11, 23, 36, 50, 65 ,.-50 1, 3, 3, 7, 12 6, 7, 15, 9, 19 11, 23, 36, 50, 65 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, EXCLUSIVE=.TRUE.) is , 0, 1, 3, 6, 10 0, 6, 13, 21, 30 0, 11, 23, 36, 50 ,, plus 1filll -1; 0, 1, 3, 6, 10 0, 6, 13, 21, 30 0, 11, 23, 36, 50 ,; plus 1filll -1: 0, 1, 3, 6, 10 0, 6, 13, 21, 30 0, 11, 23, 36, 50 ,: plus 1filll -1.plus 1filll 0, 1, 3, 6, 10 0, 6, 13, 21, 30 0, 11, 23, 36, 50 ,.-50 0, 1, 3, 6, 10 0, 6, 13, 21, 30 0, 11, 23, 36, 50 , plus 1filll-1.

SUM_PREFIX(B, DIM=2, EXCLUSIVE=.FALSE.) is , 1, 3, 6, 10, 15 6, 13, 21, 30, 40 11, 23, 36, 50, 65 ,, plus 1filll -1; 1, 3, 6, 10, 15 6, 13, 21, 30, 40 11, 23, 36, 50, 65 ,; plus 1filll -1: 1, 3, 6, 10, 15 6, 13, 21, 30, 40 11, 23, 36, 50, 65 ,: plus 1filll -1.plus 1filll 1, 3, 6, 10, 15 6, 13, 21, 30, 40 11, 23, 36, 50, 65 ,.-50 1, 3, 6, 10, 15 6, 13, 21, 30, 40 11, 23, 36, 50, 65 , plus 1filll-1.

SUM_PREFIX(B, MASK=M, SEGMENT=S, EXCLUSIVE=.TRUE.) is , 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 13, 8, 0, 0 ,, plus 1filll -1; 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 13, 8, 0, 0 ,; plus 1filll -1: 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 13, 8, 0, 0 ,: plus 1filll -1.plus 1filll 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 13, 8, 0, 0 ,.-50 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 13, 8, 0, 0 , plus 1filll-1.

SUM_PREFIX(B, MASK=M, SEGMENT=S, EXCLUSIVE=.FALSE.) is , 1, 13, 3, 4, 5 0, 13, 8, 13, 15 11, 13, 21, 0, 0 ,, plus 1filll -1; 1, 13, 3, 4, 5 0, 13, 8, 13, 15 11, 13, 21, 0, 0 ,; plus 1filll -1: 1, 13, 3, 4, 5 0, 13, 8, 13, 15 11, 13, 21, 0, 0 ,: plus 1filll -1.plus 1filll 1, 13, 3, 4, 5 0, 13, 8, 13, 15 11, 13, 21, 0, 0 ,.-50 1, 13, 3, 4, 5 0, 13, 8, 13, 15 11, 13, 21, 0, 0 , plus 1filll-1.

SUM_PREFIX(B, MASK=M, EXCLUSIVE=.TRUE.) is , 0, 12, 14, 38, 51 1, 14, 17, 42, 56 1, 14, 25, 51, 66 ,, plus 1filll -1; 0, 12, 14, 38, 51 1, 14, 17, 42, 56 1, 14, 25, 51, 66 ,; plus 1filll -1: 0, 12, 14, 38, 51 1, 14, 17, 42, 56 1, 14, 25, 51, 66 ,: plus 1filll -1.plus 1filll 0, 12, 14, 38, 51 1, 14, 17, 42, 56 1, 14, 25, 51, 66 ,.-50 0, 12, 14, 38, 51 1, 14, 17, 42, 56 1, 14, 25, 51, 66 , plus 1filll-1.

SUM_PREFIX(B, MASK=M, EXCLUSIVE=.FALSE.) is , 1, 14, 17, 42, 56 1, 14, 25, 51, 66 12, 14, 38, 51, 66 ,, plus 1filll -1; 1, 14, 17, 42, 56 1, 14, 25, 51, 66 12, 14, 38, 51, 66 ,; plus 1filll -1: 1, 14, 17, 42, 56 1, 14, 25, 51, 66 12, 14, 38, 51, 66 ,: plus 1filll -1.plus 1filll 1, 14, 17, 42, 56 1, 14, 25, 51, 66 12, 14, 38, 51, 66 ,.-50 1, 14, 17, 42, 56 1, 14, 25, 51, 66 12, 14, 38, 51, 66 , plus 1filll-1.

SUM_PREFIX(B, SEGMENT=S, EXCLUSIVE=.TRUE.) is , 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 20, 8, 0, 0 ,, plus 1filll -1; 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 20, 8, 0, 0 ,; plus 1filll -1: 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 20, 8, 0, 0 ,: plus 1filll -1.plus 1filll 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 20, 8, 0, 0 ,.-50 0, 11, 0, 0, 0 0, 13, 0, 4, 5 0, 20, 8, 0, 0 , plus 1filll-1.

SUM_PREFIX(B, SEGMENT=S, EXCLUSIVE=.FALSE.) is , 1, 13, 3, 4, 5 6, 20, 8, 13, 15 11, 32, 21, 14, 15 ,, plus 1filll -1; 1, 13, 3, 4, 5 6, 20, 8, 13, 15 11, 32, 21, 14, 15 ,; plus 1filll -1: 1, 13, 3, 4, 5 6, 20, 8, 13, 15 11, 32, 21, 14, 15 ,: plus 1filll -1.plus 1filll 1, 13, 3, 4, 5 6, 20, 8, 13, 15 11, 32, 21, 14, 15 ,.-50 1, 13, 3, 4, 5 6, 20, 8, 13, 15 11, 32, 21, 14, 15 , plus 1filll-1.

SUM_PREFIX(B, EXCLUSIVE=.TRUE.) is , 0, 18, 39, 63, 90 1, 20, 42, 67, 95 7, 27, 50, 76, 105 ,, plus 1filll -1; 0, 18, 39, 63, 90 1, 20, 42, 67, 95 7, 27, 50, 76, 105 ,; plus 1filll -1: 0, 18, 39, 63, 90 1, 20, 42, 67, 95 7, 27, 50, 76, 105 ,: plus 1filll -1.plus 1filll 0, 18, 39, 63, 90 1, 20, 42, 67, 95 7, 27, 50, 76, 105 ,.-50 0, 18, 39, 63, 90 1, 20, 42, 67, 95 7, 27, 50, 76, 105 , plus 1filll-1.

SUM_PREFIX(B, EXCLUSIVE=.FALSE.) is , 1, 20, 42, 67, 95 7, 27, 50, 76, 105 18, 39, 63, 90, 120 ,, plus 1filll -1; 1, 20, 42, 67, 95 7, 27, 50, 76, 105 18, 39, 63, 90, 120 ,; plus 1filll -1: 1, 20, 42, 67, 95 7, 27, 50, 76, 105 18, 39, 63, 90, 120 ,: plus 1filll -1.plus 1filll 1, 20, 42, 67, 95 7, 27, 50, 76, 105 18, 39, 63, 90, 120 ,.-50 1, 20, 42, 67, 95 7, 27, 50, 76, 105 18, 39, 63, 90, 120 , plus 1filll-1.



Next:
Array Sorting Functions Up: Library Procedures Previous: Array Combining Scatter


paula@erc.msstate.edu
Thu Dec 8 16:17:11 CST 1994