我试图了解 Fortran 中的 BLAS 和 LAPACK 如何工作等等,所以我编写了一个生成矩阵并将其反转的代码。
这是代码
program test
Implicit none
external ZGETRF
external ZGETRI
integer ::M
complex*16,allocatable,dimension(:,:)::A
complex*16,allocatable,dimension(:)::WORK
integer,allocatable,dimension(:)::IPIV
integer i,j,info,error
Print*, 'Enter size of the matrix'
Read*, M
Print*, 'Enter file of the matrix'
READ(*,*), A
OPEN(UNIT=10,FILE = '(/A/)' ,STATUS='OLD',ACTION='READ')
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 ZGETRF(M,M,A,M,IPIV,info)
if(info .eq. 0) then
write(*,*)"succeded"
else
write(*,*)"failed"
end if
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
close (10)
end program test
矩阵 A 位于我正在调用的文件中,并且我还表示矩阵的大小 (M )。当我用 gfortran 复制它们时,我收到这些消息
/tmp/ccVkb1zY.o:功能中MAIN__':
test.f03:(.text+0x751): undefined reference to
zgetrf_'
test.f03:(.text+0x85d): 对“zgetri_”的未定义引用
collect2:错误:ld 返回 1 退出状态
我已经安装了 BLAS 和 LAPACK,所以我不知道我是否以正确的方式调用库。
有什么建议吗?