Loop Constructs

Loops can be formed with the usual DO-END DO and DO WHILE, or by using an IF/GOTO and a label. The loops must have a single entry and a single exit to be vectorized. The following examples illustrate loop constructs that can and cannot be vectorized.

Example: Vectorizable structure

subroutine vec(a, b, c)

  dimension a(100), b(100), c(100)

  integer i

  i = 1

  do while (i .le. 100)

    a(i) = b(i) * c(i)

      if (a(i) .lt. 0.0) a(i) = 0.0

        i = i + 1

  enddo

end subroutine vec

The following example shows a loop that cannot be vectorized because of the inherent potential for an early exit from the loop.

Example: Non-vectorizable structure

subroutine no_vec(a, b, c)

  dimension a(100), b(100), c(100)

  integer i

  i = 1

  do while (i .le. 100)

    a(i) = b(i) * c(i)

! The next statement allows early

! exit from the loop and prevents

! vectorization of the loop.

    if (a(i) .lt. 0.0) go to 10

    i = i + 1

  enddo

  10 continue

end subroutine no_vecN

END