next up previous contents
Next: Prefix and Suffix Functions Up: HPF Library Module Previous: Bit Manipulation Functions

 

Array Combining Scatter Functions

Fortran 90 allows indirect addressing, however if,

    INTEGER, DIMENSION(4) :: A = 1, B = 2
    INTEGER, DIMENSION(3) :: W = (/1,2,2/)

then writing

 A(W) = A(W) + 2*B(1:3)

is incorrect due to the multiple assignments to A(2). The statement is asking for the two assignments:

 A(2) = A(2) + 2*B(2)
 A(2) = A(2) + 2*B(3)

to be made in parallel which is clearly impossible.

The combining scatter functions allow parallel assignments to the same array element to be performed in a structured (defined) way; these functions state how two or more expressions that are supposed to be assigned to the same result element should be combined. The example below here adds the two expressions together before making the assignment:

 A = SUM_SCATTER(2*B(1:3),A,W)

now A equals (/5,9,1,1/). This performs

 A(1) = A(1) + 2*B(1)
 A(2) = A(2) + 2*B(2) + 2*B(3)

Return to corresponding overview page gif  

These functions allow combined assignments to vector subscripted arrays with repeated values. Consider,

 A = PRODUCT_SCATTER(2*B(1:3),A,W)

A is now equal to (/4,16,1,1/). The above call is equivalent to:

 A(1) = A(1)*2*B(1)
 A(2) = A(2)*2*B(2)*B(2)

in parallel.

Consider a further example,

 MINVAL_SCATTER((/10,-2,4,2/),(/1,1,1/),(/2,2,1,1/))

this gives the result (/1,-2,1/). Here, the index vector is now (/2,2,1,1/), the vector being assigned to is (/1,1,1/) and the vector that is being indexed is (/10,-2,4,2/).

Working along the index vector, the result of MINVAL((/10,-2,1/)) is assigned to position 2 (10 and -2 are the first two elements of (/10,-2,4,2/) and the 1 is from the original the array being assigned to).

Likewise, MINVAL((/4,2,1/)) is placed in position 1; position 3 is unaltered as it is not indexed.

values to be assigned       10  -2  4  2
indices to be assigned to    2   2  1  1

The following prefixes are allowed for scatter functions: ALL, ANY, COUNT, IALL, IANY, IPARITY, MAXVAL, MINVAL, PARITY, PRODUCT and SUM.

Return to corresponding overview page gif


next up previous contents
Next: Prefix and Suffix Functions Up: HPF Library Module Previous: Bit Manipulation Functions

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.