Page 1 of 1

Segmentation fault (core dumped) when using DSYEV

PostPosted: Fri Aug 24, 2007 4:55 pm
by stockhausen
Hello,

I am using DSYEV to compute eigenvalues and compilation is fine under cgywin. Here is a simple self contain C program:

Code: Select all
#include <stdio.h>

int main ()
{
   
   double A[16] = {  0.78623,  0.47213,  1.16720,  1.09982,
                       0.47213,  0.58641,  0.95153,  0.88351,
           1.16720,  0.95153,  2.12836,  1.84319,
           1.09982,  0.88351,  1.84319,  2.16045};
   char JOBZ = 'N';
   char UPLO = 'U';
   int N = 4;
   int info;
   int LDA = 4;
   double WORK[4];
   int LWORK = 4;
   double W[4];
   int index;
   
   dsyev_(&JOBZ, &UPLO, &N, A, &LDA, W, WORK, &LWORK, info);

   for (index = 0; index < 4; index++)
      printf("%f\n", W[index]);
}




When I run the exec file, the error that I get is:

Code: Select all
Segmentation fault (core dumped)


Any ideas?

Thanks,

Karl

PostPosted: Fri Aug 24, 2007 5:08 pm
by Julien Langou
[1] In the call to DSYEV, you need to give the pointer to INFO not its actual value.
[2] LWORK needs to be at least 3*N-1 and WORK needs to be of size LWORK.

Then this should work.

When you work with bigger matrix you will want to use the optimal workspace in
term of time and not the optimal in term of space. (3*N-1 is optimal in term of space.)

Julien.

PostPosted: Fri Aug 24, 2007 5:47 pm
by stockhausen
Worked like a charm, thanks very much!