我想计算复矩阵的逆。我发现lapack包含很多与代数计算相关的例程,因此我找到了子程序ZGETRI。出乎意料的是,在使用“ifort -o out -heap-arrays test.f90 -mkl”编译以下代码并运行文件“out”后,我收到了一个错误消息:“glibc detected./out:free():invalid pointer: 0x00007fee68f76010***”,随后是内存映射和最终的“aborted(core dumped)”。这对我来说非常奇怪,我不知道错误出在哪里。顺便问一句,当一些错误不是在编译过程中出现而是在运行过程中出现时,有没有办法检测出错误出在哪里?
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