module RandMat
implicit none
double complex, dimension(:,:), allocatable :: A, L, U
integer :: n
contains
function Diag() result(Eigenvalues)
implicit none
double complex, dimension(n) :: Eigenvalues
double complex, dimension(2*n-1) :: work
double precision, dimension(n,n) :: eigenmatrix
integer :: Lwork
integer :: info, ii
double precision :: rwork(3*n-2)
double complex :: check(n,n), alpha, beta
check=A
info=0
lwork =2*n-1
!call routine to diagonalize A
call zheev('V','U',n, check, n, Eigenvalues, work, lwork, rwork, info )
end function
end module
此函数在模块中声明。 A
是我在模块中定义的n x n
Hermitian矩阵,所以我可以在这里使用它。 n
也在模块中定义,并且是A
的维度。
问题是我总是遇到运行时错误:
Intel MKL ERROR: Parameter 8 was incorrect on entry to ZHEEV
致电zheev
时。
编辑:我在模块中添加了变量声明。矩阵A使用以下例程进行分配和初始化:
subroutine Initialize
implicit none
integer, dimension(2) :: clock
integer , dimension(:), allocatable :: seed
integer :: ii,jj
double precision :: c,d
!create random complex matrix of dimension nxn
!-----------------------------------------------------------------------
!allocate A
if (.not.allocated(A)) then
allocate(A(N,N))
else if (size(A,1).neqv.N) then
allocate(A(N,N))
end if
!get execution time--> will be used as seed
call System_clock(count=clock(1))
call random_seed(put=clock)
!initialize matrix with random values
do ii=1,n
!since we are only interested in hermitian matrices is it enough to only !initialize the upper diagonal matrix
do jj=ii,n
call random_number(c)
Call random_number(d)
A(ii,jj)=cmplx(c, d)
end do
end do
!make matrix hermitian
!---------------------------------------------------------------------------
do ii=2, n
do jj=1, ii-1
A(ii,jj)=conjg(A(jj,ii))
end do
end do
end subroutine