Each BLAS and LAPACK routine comes in several versions, one for each precision (data type). The first letter of the subprogram name indicates the precision used:
S Real single precision.
D Real double precision.
C Complex single precision.
Z Complex double precision.
Complex double precision is not strictly defined in Fortran 77,
but most compilers will accept one of the following declarations:
double complex list-of-variables
complex*16 list-of-variables
call SSCAL ( n, a, x, incx )
Here x is the vector, n is the length (number of
elements in x we wish to use), and a is the scalar
by which we want to multiply x.
The last argument incx is the increment.
Usually, incx=1 and the vector x corresponds directly
to the one-dimensional Fortran array x.
For incx>1 it specifies how many elements in the array we
should "jump" between each element of the vector x.
For example, if incx=2 it means we should only scale every other
element (note: the physical dimension of the array x should then be
at least 2n-1). Consider these examples where x has been
declared as real x(100).
call SSCAL(100, a, x, 1)
call SSCAL( 50, a, x(50), 1)
call SSCAL( 50, a, x(2), 2)
The first line will scale all 100 elements of x by a.
The next line will only scale the last 50 elements of x by a.
The last line will scale all the even indices of x by a.
Observe that the array x will be overwritten by the new values. If you need to preserve a copy of the old x, you have to make a copy first, e.g., by using SCOPY.
Now consider a more complicated example. Suppose you have two 2-dimensional arrays A and B, and you are asked to find the (i,j) entry of the product A*B. This is easily done by computing the inner product of row i from A and column j of B. We can use the BLAS 1 subroutine SDOT. The only difficulty is to figure out the correct indices and increments. The call sequence for SDOT is
SDOT ( n, x, incx, y, incy )
Suppose the array declarations were
real A(lda,lda)
real B(ldb,ldb)
but in the program you know that the actual size of A is m*p
and for B it is p*n. The i'th row of A starts at
the element A(i,1). But since Fortran stores 2-dimensional
arrays down columns, the next row element A(i,2) will
be stored lda elements later in memory (since lda is the
length of a column). Hence we set incx = lda.
For the column in B there is no such problem, the elements are
stored consecutively so incy = 1. The length of the
inner product calculation is p. Hence the answer is
SDOT ( p, A(i,1), lda, B(1,j), 1 )
Copyright © 1995-7 by Stanford University. All rights reserved.