Inverse matrix calculation using binding

I want to calculate the inverse of a complex matrix. This happens to me. This lapak contains many subroutines related to algebraic computation, so I found the ZGETRI subroutine. Suddenly, after compiling the following code with "ifort -o out -heap-arrays test.f90 -mkl" and running the file "out", I received an error message

" glibc ./out found: free (): invalid pointer: 0x00007fee68f76010 ***"

followed by a memory card and finally β€œinterrupted (the kernel is reset)”. This is very strange for me, and I do not know where the error is. By the way, when some errors occur not in the compilation process, but in the current process, is there a way to detect where this error is from?

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 
+4
1

:

ZGETRI computes the inverse of a matrix using the LU factorization
computed by ZGETRF.

ZGETRF:

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 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      
end
+2

All Articles