next up previous contents
Next: PACK Intrinsic Up: Array Construction Intrinsics Previous: MERGE Intrinsic

 

SPREAD Intrinsic

SPREAD(SOURCE,DIM,NCOPIES)

This function replicates an array by adding NCOPIES of in the direction of a stated dimension.

For example, if A is (/5, 7/), then

displaymath23440

As DIM= 2 the vector (/ 5, 7/) is spread along dimension 2 (the direction of a row).

displaymath23441

In this case DIM= 1 so the vector (/ 5, 7/) is spread along dimension 1 (the direction of a column).

A good use for this intrinsic is during vectorisation when, say, a doubly nested DO loop is combining a vector with each column of an array at the centre of the loop, the statement can be rewritten as a 2D array assignment by creating a copy of the vector for each column of the array. For example,

    DO i = 1,100
     DO j = 1,100
      A(i,j) = B(i)*2
     END DO
    END DO

can be transformed to

    A(1:100,1:100) = SPREAD(B(:),2,100)*2

which exploits Fortran 90 array syntax.


next up previous contents
Next: PACK Intrinsic Up: Array Construction Intrinsics Previous: MERGE Intrinsic

Adam Marshall ©University of Liverpool, 1996
Tue Nov 26 17:50:42 GMT 1996