Next: Scalarization of the Up: The FORALL Construct Previous: Interpretation of the

Examples of the FORALL Construct

FORALL ( i=2:n-1, j=2:n-1 ) a(i,j) =index.html a(i,j-1) + a(i,j+1) + a(i-1,j) + a(i+1,j) b(i,j) = a(i,j) END FORALL This FORALL is equivalent to the two Fortran 90 statements

a(2:n-1,2:n-1) =index.html a(2:n-1,1:n-2)+a(2:n-1,3:n) & +a(1:n-2,2:n-1)+a(3:n,2:n-1) b(2:n-1,2:n-1) = a(2:n-1,2:n-1) In particular, note that the assignment to array index.html uses the values of array index.html computed in the first statement, not the values before the FORALL began execution.

FORALL ( i=1:n-1 ) FORALL ( j=i+1:n ) a(i,j) =index.html a(j,i) END FORALL END FORALL This FORALL construct assigns the transpose of the lower triangle of array index.html (i.e., the section below the main diagonal) to the upper triangle of index.html. For example, if index.html and index.html originally contained the matrix index.html then after the FORALL it would contain index.html This cannot be done using array expressions without introducing mask expressions.

FORALL ( i=1:5 ) WHERE ( a(i,:) .NE. 0.0 ) a(i,:) =index.html a(i-1,:) + a(i+1,:) ELSEWHERE b(i,:) = a(6-i,:) END WHERE END FORALL This FORALL construct, when executed with the input arrays index.html will produce as results index.html Note that, as with WHERE statements in ordinary Fortran 90, assignments in the WHERE branch may affect computations in the ELSEWHERE branch.


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