LAPACK dgeev: parameter had illegal value

  • #1
48
0

Main Question or Discussion Point

Mod note: I revised the code below slightly, changing the loop control variable i to either j or k. The reason for this is that the browser mistakes the letter i in brackets for the BBCode italics tag, which causes some array expressions to partially disappear.

Hello,

I am trying for the first time to use LAPACK from C to diagonalize a matrix and I am stuck.

I try to modify this example http://rcabreral.blogspot.co.uk/2010/05/eigenvalues-clapack.html from zgeev to degeev. I have looked at the DGEEV input parameters, but it seems I don't understand the well enough.

Below is my code. Running it produces:
** On entry to DGEEV parameter number 9 had an illegal value

EDIT: The error occurs in the call of degeev spanning lines 48 to (including) 53.


#include<stdio.h>
#include<math.h>

#include<complex.h>
#include <stdlib.h>

//.......................................................................................................
void dgeTranspose( double *Transposed, double *M ,int n)
{

int i,j;
for(i=0;i<n;i++)

for(j=0;j<n;j++) Transposed[i+n*j] = M[i*n+j];
}

//......................................................................................................
// MatrixComplexEigensystem: computes the eigenvectors and eigenValues of input matrix A
// The eigenvectors are stored in columns
//.....................................................................................................
void MatrixComplexEigensystem( double *eigenvectorsVR, double *eigenvaluesW, double *A, int N)
{

int i;

double *AT = (double *) malloc( N*N*sizeof(double ) );

dgeTranspose( AT, A , N);

char JOBVL ='N'; // Compute Right eigenvectors

char JOBVR ='V'; // Do not compute Left eigenvectors

double VL[1];

int LDVL = 1;
int LDVR = N;

int LWORK = 4*N;

double *WORK = (double *)malloc( LWORK*sizeof(double));

double *RWORK = (double *)malloc( 2*N*sizeof(double));

int INFO;

dgeev_( &JOBVL, &JOBVR, &N, AT , &N , eigenvaluesW ,

VL, &LDVL,
eigenvectorsVR, &LDVR,
WORK,
&LWORK, RWORK, &INFO );

dgeTranspose( AT, eigenvectorsVR , N);

for(j=0;j<N*N;j++) eigenvectorsVR[j]=AT[j];

free(WORK);
free(RWORK);
free(AT);
}


int main()
{
int i,j;
const int N = 3;


double A[] = { 1.+I , 2. , 3 , 4. , 5.+I , 6. , 7., 8., 9. + I};

double eigenVectors[N*N];
double eigenValues[N];


MatrixComplexEigensystem( eigenVectors, eigenValues, A, N);

printf("\nEigenvectors\n");

for(k=0;k<N;k++){
for(j=0;j<N;j++) printf("%e", eigenVectors[k*N + j]);

printf("\n");
}

printf("\nEigenvalues \n");
for(j=0;i<N;j++) printf("%e", eigenValues[j] );


printf("\n------------------------------------------------------------\n");
return 0;


}
Any help much appreciated!!
 
Last edited by a moderator:

Answers and Replies

  • #3
48
0
Thanks. This code appears to work.

#include<stdio.h>
#include<math.h>

#include <stdlib.h>

//.......................................................................................................
void dgeTranspose( double *Transposed, double *M ,int n)
{

int i,j;
for(i=0;i<n;i++)

for(j=0;j<n;j++) Transposed[i+n*j] = M[i*n+j];
}

//......................................................................................................
// MatrixComplexEigensystem: computes the eigenvectors and eigenValues of input matrix A
// The eigenvectors are stored in columns
//.....................................................................................................
void MatrixComplexEigensystem( double *eigenvectorsVR, double *eigenvaluesW, double *A, int N)
{

int i;

double *AT = (double *) malloc( N*N*sizeof(double ) );

dgeTranspose( AT, A , N);

char JOBVL ='N'; // Compute Right eigenvectors

char JOBVR ='V'; // Do not compute Left eigenvectors

double VL[1];

int LDVL = 1;
int LDVR = N;

int LWORK = 4*N;

double *WORK = (double *)malloc( LWORK*sizeof(double));

double *RWORK = (double *)malloc( 2*N*sizeof(double));

int INFO;
printf("\nping2\n");
double *eigenvaluesWR =eigenvaluesW;
double *eigenvaluesWI = eigenvaluesW + N;
dgeev_( &JOBVL, &JOBVR, &N, AT , &N,
eigenvaluesWR, eigenvaluesWI,
VL, &LDVL,
eigenvectorsVR, &LDVR,
WORK,
&LWORK, &INFO );
printf("\nping1\n");
dgeTranspose( AT, eigenvectorsVR , N);

for(j=0;i<N*N;j++) eigenvectorsVR[j]=AT[j];

free(WORK);
free(RWORK);
free(AT);
}


int main()
{
int i,j;
const int N = 3;


double A[] = { 1. , 0. , 0. , 0. , 1., 0. , 0., 0., 1.};

double eigenVectors[N*N];
double eigenValues[2*N];


MatrixComplexEigensystem( eigenVectors, eigenValues, A, N);

printf("\nEigenvectors\n");

for(i=0;i<N;i++){
for(j=0;j<N;j++) printf("%e ", eigenVectors[i*N + j]);

printf("\n");
}

printf("\nEigenvalues \n");
for(j=0;i<N;j++) printf("%e ", eigenValues[j] );


printf("\n------------------------------------------------------------\n");
return 0;


}​
 
Last edited by a moderator:
  • #4
33,724
5,419
Did this work? Note that your code as it appear here is not the same as what you pasted in. Anywhere you have [ i ] (without spaces), the browser strips out, thinking that you want the text that follows it to be in italics. That's why I modified your code in post #1.

As far as I know, there's not a workaround, other than to not use i as an index in arrays.
 
  • Like
Likes Angelos K
  • #5
48
0
Did this work? Note that your code as it appear here is not the same as what you pasted in. Anywhere you have [ i ] (without spaces), the browser strips out, thinking that you want the text that follows it to be in italics. That's why I modified your code in post #1.

As far as I know, there's not a workaround, other than to not use i as an index in arrays.
Thank you. It appears to work, but I have only tested trivial cases.

I saw your warning earlier, but understood it just now (blush). It seems I am not able to modify my post anymore. So I should replace [ i ] by [k] evereywhere and then make the corresponding logical adjustments, right?

What trubled me most - and I am a newbie - is that I understand the documentation here
http://www.netlib.org/lapack/explore-html/d9/d28/dgeev_8f.html
as asking for an integer N. while the code (the prototype and my version) uses &N.

It turns out that this is needed for translating the Fortran routines to C.
http://www.physics.orst.edu/~rubin/nacphy/lapack/cprogp.html
 
Last edited by a moderator:
  • #6
33,724
5,419
Thank you. It appears to work, but I have only tested trivial cases.

I saw your warning earlier, but understood it just now (blush). It seems I am not able to modify my post anymore. So I should replace [ i ] by [k] evereywhere and then make the corresponding logical adjustments, right?
Or you could replace [ i ] by [ii] - that should work. Keep in mind that is only for code that you post here, and it is an artifact of the browser thinking that you are entering BBCode markup, which changes how text is rendered.

There is a limited-time window for members to change their posts, but we mentors don't have that limit, so I edited your post.
Angelos K said:
What trubled me most - and I am a newbie - is that I understand the documentation here
http://www.netlib.org/lapack/explore-html/d9/d28/dgeev_8f.html
as asking for an integer N. while the code (the prototype and my version) uses &N.

It turns out that this is needed for translating the Fortran routines to C.
You shouldn't have to do that, at least not for any parameters that are marked [in] in the documentation. A major difference between Fortran and C is how parameters are passed. In Fortran, they are passed by reference, but in C, they are passed by value. A Fortran subroutine or function is free to modify any of its parameters. In C, this can only be simulated by passing the address of (a pointer to) the thing whose value is to be changed.

In the DGEEV subroutine, the N parameter is marked as [in], which says that DGEEV is going to treat it as read-only. The parameters you need to watch out for (and for which addresses are needed) are the ones marked in the documentation with [in,out] or [out], such as A, WR, WI, VL, VR, and a couple of others. The error you showed in post #1 pertained to VL.

Any parameter that is marked [in] you shouldn't need to supply an address.
Angelos K said:
 
  • Like
Likes Angelos K
  • #7
48
0
Thank you very much for the clarification about [in] parameters! As you resolved all problems: Should I mark this thread as solved, and if so, how?
 
Last edited:
  • #8
33,724
5,419
Typically we don't do anything special, such as marking a thread "solved."
 

Related Threads on LAPACK dgeev: parameter had illegal value

Replies
22
Views
3K
Replies
1
Views
4K
  • Last Post
Replies
1
Views
6K
Replies
5
Views
310
Replies
5
Views
5K
Replies
6
Views
1K
Replies
4
Views
5K
Replies
2
Views
1K
Replies
7
Views
5K
Replies
4
Views
881
Top