我试图计算不同大小的矩阵的特征值和特征向量。我正在使用一段非常简单的Fortran90代码,我正在编译它链接到英特尔MKL包中包含的相应Lapack库,这些库可以在我的机器中运行,该机器在Ubuntu中运行。代码“matrix_diag_01.f90”附在消息的末尾。 “随机”模块只包含Numerical Recipes的“ran”随机数生成器。代码使用
很好地编译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
当给出小的矩阵时,可执行文件很好地工作。但是,对于大小为3000x3000的矩阵,它会产生一些奇怪的行为。首先它给出了这个错误
MKL ERROR : Parameter 8 was incorrect on entry to SSYEVD
但是,SSYEVD调用中只有3个参数。其次,它返回特征向量而不是特征值。我通过在另一台具有更大内存的机器上进行检查来检查但结果是相同的。
有人可以帮忙吗?
谢谢!
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
答案 0 :(得分:2)
如果查看要调用的函数的来源,它本身会发出以下调用: 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 )
据推测,参数LWORK是错误的。