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开发者_如何学JAVA
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
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.
精彩评论