1
votes

I have a symmetric, tridiagonal matrix of which I want to compute the eigenvalues and eigenvectors. I'm using the LAPACK dstevd function to do so. I'm coding in C, so I've the following line at the top of my code so I am able to call the fortran function:

extern "C" void dstevd_( char *jobz, int N, double d, double* e, double *z, int *ldz, int *work, int *lwork, int *iwork, int *liwork, int *info);

I need the eigenvectors, so I need to set *z, *work and *iwork. According to the LAPACK manual (Link) the sizes need to be: z: >= n*n, work: >= 1 + 4*n + n**2, iwork: >= 3 + 5*n.

When using these sizes, I am getting errors saying that dstevd_ is accessing memory that was not allocated in these arrays. It works fine for a small (n=4) problem, but I run into problems at bigger sizes (n=36). If I increase the sizes of z, work and iwork it works.

Any suggestions on how to correctly determine the required sizes for z, work and iwork?

thanks.

1

1 Answers

1
votes

Well, your prototype doesn't match the Fortran prototype, which leads to all kinds of problems.

  • N should be passed as a pointer, not scalar.
  • d is an array, not a scalar.
  • work is of type double precision, not int.

In order to avoid these kinds of problems, why not use the LAPACK C interface which is part of LAPACK since 3.3.0 in 2010. In your case, that would be LAPACKE_dstevd. For more info about using LAPACKE, see http://www.netlib.org/lapack/lapacke .