[Fortran] Problems with LAPACK routine

In summary: In your code, you have it defined as a 6-element array. You may need to increase the length of the WORK array.
  • #1
Bashkir
31
1
I am trying to use the LAPACK routine dsyev to solve for the eigenvalues of a matrix, and I designed a program to test this and make sure I am getting the right results. It isn't recognizing the subroutine however.

The subroutine is dsyev, which I can post or can be found on the LAPACK site.

My program is

PROGRAM EIGENVALUE

IMPLICIT NONE

! Statements
Double Precision :: A (6,6), w (6), Work (6)
INTEGER :: i, INFO, LWORK, LDA = 6
CHARACTER :: N, U

! External Subroutines
EXTERNAL :: dsyev

! A matrix
A (1, : ) = (/ 0, 1, 0, 0, 0, 0 /)
A (2, : ) = (/ 0, 0, 1, 0, 0, 0 /)
A (3, : ) = (/ 1, 0, 0, 0, 0, 0 /)
A (4, : ) = (/ 0, 0, 0, 0, 0, 1 /)
A (5, : ) = (/ 0, 0, 0, 1, 0, 0 /)
A (6, : ) = (/ 0, 0, 0, 0, 1, 0 /)

CALL dsyev( 'N', 'U', 6, W, LDA, WORK, LWORK, INFO )

! Print the solution
DO i = 1, 6
WRITE (*, 9) i, w (i)
END DO

9 format ('x [' i1 '] =', f5.2)
END PROGRAM EIGENVALUE


And when I try to compile the error I am getting is:

collins@piccard $ gfortran Eigenvalue.f90
/tmp/ccczm4lt.o: In function `MAIN__':
Eigenvalue.f90:(.text+0x1b9): undefined reference to `dsyev_'
collect2: ld returned 1 exit status
 
Technology news on Phys.org
  • #2
You need to link the library that contains dsyev to your program when you compile it, using a command line similar to the following. The quoted text comes from http://www.stanford.edu/class/me200c/tutorial_90/03_unix90.html. In your case the text after the -L switch is the path to the library directory, and after the -l switch is the name of the library file.
It's been some time since I've written any Fortran code, so what I'm saying I believe is correct.
Similarly, we can link to a Fortran 90 compiled library (such as the BLAS/LAPACK library in the class account) by
f90 main.f90 -L/usr/class/me390/lib -lmy_lib90
 
  • #3
That got it to compile, but now I am getting this error.

Memory fault(coredump)
 
  • #4
Based on this documentation - http://www.netlib.org/lapack/explore-html/dd/d4c/dsyev_8f_source.html - you didn't call dsyev correctly. There should be 9 parameters in the call - you have 8.

Code:
CALL dsyev( 'N', 'U', 6, W, LDA, WORK, LWORK, INFO )
Per the documentation, it should be like this:

CALL dsyev( 'N', 'U', 6, A, LDA, W, WORK, LWORK, INFO )

In your call, you're missing the A array, and you have LDA and W in the wrong order. Also, your LWORK variable isn't initialized.
 
  • #5
Also, the documentation says the WORK array must be longer than 6 elements for a 6x6 matrix.
 

FAQ: [Fortran] Problems with LAPACK routine

What is LAPACK?

LAPACK (Linear Algebra Package) is a software library for numerical linear algebra computations, particularly for solving systems of linear equations, least squares problems, and eigenvalue problems. It includes routines for operations such as matrix multiplication, matrix inversion, and matrix factorization.

Why would I encounter problems with LAPACK routines?

There are a few potential reasons why you may encounter problems with LAPACK routines. Some common issues include passing incorrect data types or sizes as arguments, using outdated or incompatible versions of the LAPACK library, or encountering numerical instability in the computations. It is important to carefully check your inputs and consult documentation or support resources for troubleshooting assistance.

How can I troubleshoot issues with LAPACK routines?

If you are experiencing problems with LAPACK routines, there are a few steps you can take to troubleshoot the issue. First, carefully review the inputs you are passing to the routine to ensure they are correct. You may also want to check for any known bugs or compatibility issues with your version of LAPACK. Additionally, it can be helpful to consult documentation or seek support from online forums or the developers of the LAPACK library.

Are there any alternatives to LAPACK for linear algebra computations?

Yes, there are several alternatives to LAPACK for linear algebra computations. Some popular options include BLAS (Basic Linear Algebra Subprograms), which provides basic operations such as vector and matrix multiplication, and Eigen, a C++ template library for linear algebra operations. The choice of which library to use will depend on your specific needs and the programming language you are using.

Do I need to be an expert in linear algebra to use LAPACK routines?

While having a solid understanding of linear algebra can certainly be helpful in using LAPACK routines effectively, it is not necessarily required. Many LAPACK routines have simple interfaces and can be used with minimal knowledge of the underlying mathematics. However, it is important to have a good understanding of the inputs and outputs of the routines to ensure you are using them correctly and interpreting the results accurately.

Similar threads

Replies
1
Views
8K
Replies
4
Views
2K
Replies
5
Views
1K
Replies
2
Views
3K
Replies
6
Views
2K
Replies
18
Views
6K
Replies
22
Views
4K
Replies
2
Views
1K
Replies
7
Views
4K
Back
Top