1

I am trying to calculate the eigenvalues and eigenvectors of matrices of different sizes. I am using a piece of very simple Fortran90 code and I am compiling it linking to the appropriate Lapack libraries included in the Intel MKL package, available in my machine, which runs in Ubuntu. The code "matrix_diag_01.f90" is attached at the end of the message. The "random" module just includes the "ran" random number generator from Numerical Recipes. The code compiles well using

ifort -I $(MKLPATH) -o matrix_diag_01 matrix_diag_01.f90 
      random.f90 $(MKLPATH)libmkl_lapack95.a -Wl,--start-group  
      $(MKLPATH)libmkl_intel_lp64.a $(MKLPATH)libmkl_lapack.a 
      $(MKLPATH)libmkl_intel_thread.a $(MKLPATH)libmkl_core.a
       -Wl,--end-group -lguide -lpthread

The executable works nicely when smallish matrices are given. However, for matrices of size 3000x3000 it produces some strange behaviour. First it gives this error

MKL ERROR : Parameter 8 was incorrect on entry to SSYEVD

However, there are only 3 parameters in the call to SSYEVD. Second, it returns the eigenvectors but not the eigenvalues. I have checked by compiling in another machine with larger memory but the outcome was the same.

Can anyone please help?

Thanks!

PROGRAM matrix_diag_01

USE random

IMPLICIT NONE

INTERFACE 
   SUBROUTINE diag(mat,n)
      INTEGER n
      REAL,DIMENSION(n,n) :: mat
   END SUBROUTINE
END INTERFACE 

INTEGER n,i,j,iseed
REAL, DIMENSION(:), ALLOCATABLE  :: w
REAL, DIMENSION(:,:), ALLOCATABLE :: mat

write (*,*) ' Please enter size of matrix'
read (*,*) n
write (*,*) ' Please type seed'
read (*,*) iseed

allocate (mat(n,n))

do i = 1,n
   do j = 1,n
      mat(i,j) = ran(iseed)
   end do
end do

call diag(mat,n)

stop
END
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SUBROUTINE diag(mat,n)

  USE mkl95_lapack
  USE mkl95_precision

  IMPLICIT NONE

  CHARACTER(len=1) :: jobz = 'V'

  INTEGER n,i

  REAL,DIMENSION(n,n) :: mat
  REAL,DIMENSION(:,:),ALLOCATABLE :: matt,a
  REAL,DIMENSION(:),ALLOCATABLE :: w

  allocate (matt(n,n),a(n,n),w(n))

  matt = mat*transpose(mat)
  a = sqrt(matt)
  open (unit=7,file="matrix.dat",status="unknown")
  do i = 1,n
     write (7,100) a(i,:)
  end do
  close (unit=7)

  call syevd(a,w,jobz)

  open (unit=8,file="eig_val.dat",status="unknown")
  do i = 1,n
     write (8,100) w(i)
  end do
  close (unit=8)

  open (unit=9,file="eig_vec.dat",status="unknown")
  do i = 1,n
     write (9,100) a(i,:)
  end do
  close (unit=9)

  return
 100 format(5000f16.5)
end
daviddesancho
  • 427
  • 1
  • 7
  • 20
  • I have no solution for the MKL error, although not having sufficient available memory doesn't sound impossible. Regarding the not returning eigenvalues, have you tried calling `ssyevd` with the `info` argument? – eriktous Jul 06 '11 at 09:02

1 Answers1

2

If you look at the source of the function you are calling, it itself issues the following call: http://software.intel.com/sites/products/documentation/hpc/mkl/lapack/mkl_lapack_examples/ssyevd_ex.f.htm

 LWORK = MIN( LWMAX, INT( WORK( 1 ) ) )

 CALL SSYEVD( 'Vectors', 'Upper', N, A, LDA, W, WORK, LWORK,
         $             IWORK, LIWORK, INFO )

Presumably the parameter LWORK is wrong.

whoplisp
  • 2,508
  • 16
  • 19
  • Thanks very much for your answer, whoplisp, but the way I am calling the function and linking the libraries (i.e. Fortran 95) there is no direct control of the LWORK parameter. See http://software.intel.com/sites/products/documentation/hpc/mkl/mklman/lse/functn_syevd.htm – daviddesancho Jul 06 '11 at 08:07
  • Yes because you are calling a wrapper. Maybe try calling the Fortran77 version instead. Also look at the documentation of the function about the limits. A full 3000x3000 matrix seems quite large. Maybe there will be problems with stability or rounding errors even while using double. – whoplisp Jul 06 '11 at 08:18
  • Thank you very much. This seems the way ahead. Just using Fortran 77 for that part of the code and forget about the wrapper. It works with the 3000x3000 matrix. Thanks! – daviddesancho Jul 06 '11 at 12:31