HP Fortran Programmer Guide (766160-001, March 2014)
For a detailed description of the *$* [NO]VECTORIZE directive, see the HP Fortran Programmer's
Reference.
NOTE: The + Ovectorizeoption is valid only on the PA-RISC systems.
Calling BLAS library routines
The HP Fortran compiler is bundled with the Basic Linear Algebra Subroutine (BLAS) library. This
library consists of specially tuned routines that perform low-level vector and matrix operations that
conform to a de facto,
1
. The BLAS routines are widely available, making them portable across
many implementations of Fortran.
HP Fortran includes a library of the BLAS routines that have been especially tuned for performance
on PA-RISC machines. You can call any of these routines in an HP Fortran program by compiling
it with the -lblasoption.
Consider the following program, which contains a loop that performs an operation on two arrays
that is identical to the saxpy routine in the BLAS library, as noted in the comments:
Example 19 Example 6-1 axpy.f90
Example 6-1 saxpy.f90
PROGRAM main
INTEGER :: i, inc_x, inc_y, dim_num
REAL, DIMENSION(5) :: x, y
REAL :: b
b = 3.0
dim_num = 5
inc_x = 1
inc_y = 1
! initialize the two arrays x and y
DO i = 1, 5
y(i) = i
x(i) = i + 3.0
END DO
PRINT *, y
! add a scalar multiple of x to y
DO i = 1, 5
y(i) = y(i) + b * x(i)
END DO
PRINT *, y
END PROGRAM main
The following command lines compile and execute the program, and show the output from a
sample run:
$ f90 saxpy.f90
$ a.out
1.0 2.0 3.0 4.0 5.0
13.0 17.0 21.0 25.0 29.0
If you call a BLAS routine that is a function, be sure to declare the return value of the routine in a
data declaration statement and specify the EXTERNALattribute, as in the following:
REAL, EXTERNAL :: sdot
Fortran uses implicit typing by default. Unless a function is explicitly declared as having a certain
type, the type is determined by the first character of the BLAS routine. If that character implies a
type other than that of the returned value, the result will be meaningless.
See the HP Fortran Programmer's Referencefor information about the BLAS library.
1. industry-wide standard
See the LAPACK User’s Guide, ed. J. Dongarra et al (Philadelphia, 1992). Each of the BLAS routines has its own man
page; see blas(3X) for an introduction. Also, see the URL: http://www.netlib.org.
Vectorization 105