using a lapack routine
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
using a lapack routine         

Group: comp.lang.fortran · Group Profile
Author: Ron Ford
Date: Sep 18, 2008 18:37

I downloaded lapack recently and wanted to put a dent in it by calling one
of its subroutines. I hoped to call one that would determine the
eigenvalues of a real matrix, but that doesn't seem to be on the menu. A
person seems to need to put quite a bit of effort to determine exactly what
the subroutines do, and deciphering the titles is one step on that path.

I found SGEHRD.f, where I think the S is single precision, the GE is a
general matrix, the H is Hessenberg and RD might be reduction. So I'll be
hoping to take a eal matrix and use lapack to give me the Hessenberg form,
which, I can then use for bigger and better things.

With the fortran, so far I've got:

implicit none
integer, parameter ::n = 5
integer, dimension(n,n):: a
integer, dimension(n,n):: b

a=RESHAPE( (/ -8, -9, -7, 6, &
3, 7, -3, 4,&
-6, -9, 2, 9, 9, -2,&
7, -5, -10, 3,&
-2, 4, 9, -3, 3, &
6, 5/),SHAPE(A))

print *, a

b = matmul(A,A)
print *, "b=", b

end program

, which compiles and behaves. B has nothing to do with the Hessenberg
form, but it let's me believe that I've got A in there the way it needs to
be, and I think I'm going to want to have another array around of the same
shape as the original.

The call to sgehrd is:

SUBROUTINE SGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
*
* -- LAPACK routine (version 3.1) --
* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
* November 2006
*
* .. Scalar Arguments ..
INTEGER IHI, ILO, INFO, LDA, LWORK, N
* ..
* .. Array Arguments ..
REAL A( LDA, * ), TAU( * ), WORK( * )
* ..
*
* Purpose
* =======
*
* SGEHRD reduces a real general matrix A to upper Hessenberg form H by
* an orthogonal similarity transformation: Q' * A * Q = H .
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* ILO (input) INTEGER
* IHI (input) INTEGER
* It is assumed that A is already upper triangular in rows
* and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
* set by a previous call to SGEBAL; otherwise they should be
* set to 1 and N respectively. See Further Details.
* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
*
* A (input/output) REAL array, dimension (LDA,N)
* On entry, the N-by-N general matrix to be reduced.
* On exit, the upper triangle and the first subdiagonal of A
* are overwritten with the upper Hessenberg matrix H, and the
* elements below the first subdiagonal, with the array TAU,
* represent the orthogonal matrix Q as a product of elementary
* reflectors. See Further Details.
*
* LDA (input) INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
* TAU (output) REAL array, dimension (N-1)
* The scalar factors of the elementary reflectors (see Further
* Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
* zero.
*
* WORK (workspace/output) REAL array, dimension (LWORK)
* On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*
* LWORK (input) INTEGER
* The length of the array WORK. LWORK >= max(1,N).
* For optimum performance LWORK >= N*NB, where NB is the
* optimal blocksize.
*
* If LWORK = -1, then a workspace query is assumed; the routine
* only calculates the optimal size of the WORK array, returns
* this value as the first entry of the WORK array, and no error
* message related to LWORK is issued by XERBLA.
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value.

So, the arguments are well-documented and aren't a whole lot more than what
I have in my little prog.

I'm hoping to get this done by putting sgehrd.f where I keep the source for
gfortran. I would like to write the caller in f90 or f95 but certainly in
free form. sgehrd.f looks like fixed form f77.

My first question is how do I deal with calling an f77 routine with main
compiled in contemporary gfortran?

--
A good politician is quite as unthinkable as an honest burglar.
H. L. Mencken
10 Comments
diggit! del.icio.us! reddit!