LAPACK dgeev: parameter had illegal value

Click For Summary

Discussion Overview

The discussion revolves around the use of the LAPACK function DGEEV for diagonalizing a matrix in C. Participants share code snippets, troubleshoot errors related to parameter values, and clarify the differences between C and Fortran in terms of parameter passing. The scope includes technical explanations and debugging related to numerical linear algebra.

Discussion Character

  • Technical explanation
  • Debugging
  • Exploratory

Main Points Raised

  • One participant encounters an error indicating that parameter number 9 had an illegal value when calling DGEEV, specifically related to the leading dimension of the array VL.
  • Another participant references the documentation for DGEEV, clarifying that parameter numbering starts at 1 and that LDVL is an integer representing the leading dimension of VL.
  • A participant shares modified code that appears to work, but notes that they have only tested trivial cases.
  • Concerns are raised about the browser's handling of the index variable 'i' in code snippets, which can lead to formatting issues when posting on the forum.
  • There is a discussion about the need to replace 'i' with another variable in code to avoid rendering issues, as well as the implications of this for code logic.
  • Participants discuss the difference between passing parameters by reference in Fortran and by value in C, particularly regarding the treatment of parameters marked as [in] versus [in,out] or [out].
  • Clarifications are made about which parameters require addresses when calling DGEEV, emphasizing that only certain parameters need to be passed by reference.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the error and the need for clarity regarding parameter passing between Fortran and C. However, there are differing views on the best practices for modifying code to avoid browser-related issues, and the discussion remains open regarding the effectiveness of the proposed solutions.

Contextual Notes

Participants express uncertainty about the implications of the LAPACK documentation and the specific requirements for parameter passing in C. There are unresolved questions about the best way to modify code for clarity and functionality in the forum's posting environment.

Who May Find This Useful

This discussion may be useful for programmers working with LAPACK in C, particularly those transitioning from Fortran or encountering similar parameter-related issues in numerical linear algebra.

Angelos K
Messages
43
Reaction score
0
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:
Technology news on Phys.org
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:
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   Reactions: Angelos K
Mark44 said:
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:
Angelos K said:
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:
http://www.physics.orst.edu/~rubin/nacphy/lapack/cprogp.html
 
  • Like
Likes   Reactions: Angelos K
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:
Typically we don't do anything special, such as marking a thread "solved."
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 18 ·
Replies
18
Views
7K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K