-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathinverse.f90
60 lines (44 loc) · 1.74 KB
/
inverse.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
subroutine inv(ndim,Amat)
implicit none
integer,parameter :: dp=8
integer :: i
integer :: info
integer,intent(in):: ndim
! IPIV : INTEGER. Array, DIMENSION at least max(1, n). The pivot indices that define
! the permutation matrix P; row i of the matrix was interchanged with
! row ipiv(i). Corresponds to the single precision factorization (if info=
! 0 and iter ≥ 0) or the double precision factorization (if info= 0 and
! iter < 0).
integer,allocatable :: ipiv(:)
complex(dp),parameter :: zzero=(0.0d0,0.0d0)
complex(dp),parameter :: zone=(1.0d0,0.0d0)
complex(dp),parameter :: zi=(0.0d0,1.0d0)
! Amat :
! Overwritten by the factors L and U from the factorization of A = P*L*U;
! the unit diagonal elements of L are not stored.
! If iterative refinement has been successfully used (info= 0 and iter≥
! 0), then A is unchanged.
! If double precision factorization has been used (info= 0 and iter <
! 0), then the array A contains the factors L and U from the factorization
! A = P*L*U; the unit diagonal elements of L are not stored.
complex(dp),intent(inout):: Amat(ndim,ndim)
! Bmat :
! Identity matrix
! Overwritten by the solution matrix X for dgesv, sgesv,zgesv,zgesv.
complex(dp),allocatable :: Bmat(:, :)
allocate(ipiv(ndim))
allocate(Bmat(ndim, ndim))
ipiv= 0
Bmat= zzero
do i=1, ndim
Bmat(i, i)= zone
enddo
call zgesv(ndim,ndim,Amat,ndim,ipiv,Bmat,ndim,info)
if (info.ne.0) then
print *,'something wrong with cpu zgesv','info=',info
stop
endif
Amat=Bmat
deallocate(ipiv)
return
end subroutine inv