我想计算一个复杂矩阵的求逆。突然想到lapack里面有很多代数计算相关的例程,于是找到了子例程ZGETRI。没想到,用“ifort -o out -heap-arrays test.f90 -mkl”编译以下代码并运行文件“out”后,出现错误
“检测到 glibc ./out:free():invalid pointer: 0x00007fee68f76010***”
其次是内存映射,最后是“中止(核心转储)”。这对我来说很奇怪,我不知道错误在哪里。顺便问一下,当一些错误不是在编译过程中而是在运行过程中出现时,有什么方法可以检测到这个错误来自哪里?
program test
Implicit none
integer,parameter::M=300
complex*16,allocatable,dimension(:,:)::A
complex*16,allocatable,dimension(:)::WORK
integer,allocatable,dimension(:)::IPIV
integer i,j,info,error
allocate(A(M,M),WORK(M),IPIV(M),stat=error)
if (error.ne.0)then
print *,"error:not enough memory"
stop
end if
!definition of the test matrix A
do i=1,M
do j=1,M
if(j.eq.i)then
A(i,j)=(1,0)
else
A(i,j)=0
end if
end do
end do
call ZGETRI(M,A,M,IPIV,WORK,M,info)
if(info .eq. 0) then
write(*,*)"succeded"
else
write(*,*)"failed"
end if
deallocate(A,IPIV,WORK,stat=error)
if (error.ne.0)then
print *,"error:fail to release"
stop
end if
end