I'm calculating the eigenvalues of a dense non symmetric matrix A. For that purpose I use xGEHRD and xHSEQR Lapack routines in order to calculate first the upper Hessenberg form of A and then to calculate the only the eigenvalues of the obtained matrix.
Both routines require the parameter LWORK and both provide a mechanism to calculate its optimal value. I believe that this parameter is related to an internal blocking of buffer technique, but I don't know how it is determined.
Using the query mechanism to obtain the optimal value of LWORK the workflow should be like:
int LWORK = -1;
float* OPT_LWORK = (float*) malloc( sizeof(float));
sgehrd_ (..., OPT_LWORK ,&LWORK, ...) // query optimal value for sgehrd
LWORK = (int) OPT_WORK
float* WORK = (float*) malloc( (int) sizeof(float) * LWORK );
sgehrd_ (..., WORK ,&LWORK, ...) // calculate Hessenberg
int LWORK = -1;
shseqr_ (..., OPT_LWORK ,&LWORK, ...) // query optimal value for shseqr
LWORK = (int) OPT_WORK
float* WORK = // possibly realloc with the new LWORK value
shseqr_ (..., WORK ,&LWORK, ...) // finally obtain eigenvalues
I've done some testing, obtaining always the same optimal values for the dimension of WORK array. If the values were the same, I could simplify my code a lot (no need for realloc and only one call to determine the value of LWORK, less error checking...).
My question is, for the same matrix and the same values of ILO and IHI, can I assume that the values are going to be equal the both routines?
Looking at sgehrd.f, it seems that the optimal size of
WORK
for routinesgehrd()
isN*NB
, whereNB
iswhere
NBMAX=64
. Hence, the optimalLWORK
depends onN
,ILO
andIHI
.Looking at shseqr.f, the computation of the optimal length
LWORK
is more complex : the routineslaqr0()
is called... But the documentation in the file states :The optimal length of
WORK
may be different forsgehrd()
andshseqr()
. Here is an example :Compile by
gcc main.c -o main -llapack -lblas
My output is :