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

displaymath28778

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

displaymath28779

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.

Return to corresponding overview page gif


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

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