next up previous contents
Next: Program layout Up: The FORTRAN-77 programming Previous: Names of subroutines

Some advices about vectorization

  In order to make full advantage of vector computers it is necessary that the code is highly vectorizable. Below we shall give some advices of how to improve the vectorizability of a code without reducing the scalar performance.

  1. Use only clean loops without IF, GOTO or CALL statements. For example:
                    do 100i = 1,n
                         if (var > 0) then
                               a(i) = 0d0
                         else
                               a(i) = b(i)
                         endif
              100   continue
    
    should be replaced by:
                    if (var > 0) then
                          do 100i = 1,n
                             a(i) = 0d0
              100         continue
                    else
                          do 110i = 1,n
                             a(i) = b(i)
              110         continue
                    endif
    
  2. Use if possible and meaningful BLAS subroutines to perform simple linear algebraic operations. In most vector and parallel computers efficient implementations of these routines are available.
  3. Make sure that the inner loop is the longest one of a series of nested do-loops. In that case the vector speed can be best utilized.
  4. Use the inner loop for the first index of more-dimensional arrays in case of nested loops. This may increase the efficiency, provided the inner loop is long enough.
  5. Avoid indirect addressing if possible.
  6. Avoid division in a do-loop.
  7. Avoid (seemingly) recursions in a loop.


ISNaS ontwikkeling
Wed May 24 08:37:14 METDST 1995