1
votes

I am trying to get the ZGEEV routine in Lapack to work for a test problem and having some difficulties. I just started coding in FORTRAN a week ago, so I think it is probably something very trivial that I am missing.

I have to diagonalize rather large complex symmetric matrices. To get started, using Matlab I created a 200 by 200 matrix, which I have verified is diagonalizable. When I run the code, it brings up no errors and the INFO = 0, suggesting a success. However, all the eigenvalues are (0,0) which I know is wrong.

Attached is my code.

PROGRAM speed_zgeev
  IMPLICIT NONE
  INTEGER(8)  :: N
  COMPLEX*16, DIMENSION(:,:), ALLOCATABLE :: MAT
  INTEGER(8) :: INFO, I, J
  COMPLEX*16, DIMENSION(:), ALLOCATABLE :: RWORK
  COMPLEX*16, DIMENSION(:), ALLOCATABLE :: D
  COMPLEX*16, DIMENSION(1,1) :: VR, VL
  INTEGER(8) :: LWORK = -1
  COMPLEX*16, DIMENSION(:), ALLOCATABLE :: WORK
  DOUBLE PRECISION :: RPART, IPART

  EXTERNAL ZGEEV
  N = 200

  ALLOCATE(D(N))
  ALLOCATE(RWORK(2*N))
  ALLOCATE(WORK(N))
  ALLOCATE(MAT(N,N))

  OPEN(UNIT = 31, FILE = "newmat.txt")
  OPEN(UNIT = 32, FILE = "newmati.txt")
  DO J = 1,N
     DO I = 1,N
    READ(31,*) RPART
    READ(32,*) IPART
    MAT(I,J) = CMPLX(RPART, IPART)
     END DO
  END DO

  CLOSE(31)
  CLOSE(32)

  CALL ZGEEV('N','N', N, MAT, N, D, VL, 1, VR, 1, WORK, LWORK, RWORK, INFO)
  INFO = WORK(1)

  DEALLOCATE(WORK)
  ALLOCATE(WORK(INFO))

  CALL ZGEEV('N','N', N, MAT, N, D, VL, 1, VR, 1, WORK, LWORK, RWORK, INFO)

  IF (INFO .EQ. 0) THEN
     PRINT*, D(1:10)
  ELSE
     PRINT*, INFO
  END IF

  DEALLOCATE(MAT)
  DEALLOCATE(D)
  DEALLOCATE(RWORK)
  DEALLOCATE(WORK)


END PROGRAM speed_zgeev

I have tried the same code on smaller matrices, of size 30 by 30 and they work fine. Any help would be appreciated! Thanks.

I forgot to mention that I am loading the matrices from a test file which I have verified to be working right.

1

1 Answers

3
votes

Maybe LWORK = WORK (1) instead of INFO = WORK(1)? Also change ALLOCATE(WORK(INFO)).