1 SUBROUTINE DGETRI
( N
, A
, LDA
, IPIV
, WORK
, LWORK
, INFO
)
3 * -- LAPACK routine
(version
3.1) --
4 * Univ
. of Tennessee
, Univ
. of California Berkeley and NAG Ltd
..
7 * .. Scalar Arguments
..
8 INTEGER INFO
, LDA
, LWORK
, N
10 * .. Array Arguments
..
12 DOUBLE PRECISION A
( LDA
, * ), WORK
( * )
18 * DGETRI computes the inverse of a matrix using the LU factorization
21 * This method inverts U and
then computes inv
(A
) by solving the system
22 * inv
(A
)*L
= inv
(U
) for inv
(A
).
28 * The order of the matrix A
. N
>= 0.
30 * A
(input
/output
) DOUBLE PRECISION array
, dimension (LDA
,N
)
31 * On entry
, the factors L and U from the factorization
32 * A
= P*L*U as computed by DGETRF
.
33 * On exit
, if INFO
= 0, the inverse of the original matrix A
.
36 * The leading
dimension of the array A
. LDA
>= max
(1,N
).
38 * IPIV
(input
) INTEGER array
, dimension (N
)
39 * The pivot indices from DGETRF
; for 1<=i
<=N
, row i of the
40 * matrix was interchanged with row IPIV
(i
).
42 * WORK
(workspace
/output
) DOUBLE PRECISION array
, dimension (MAX
(1,LWORK
))
43 * On exit
, if INFO
=0, then WORK
(1) returns the optimal LWORK
.
45 * LWORK
(input
) INTEGER
46 * The
dimension of the array WORK
. LWORK
>= max
(1,N
).
47 * For optimal performance LWORK
>= N*NB
, where NB is
48 * the optimal blocksize returned by ILAENV
.
50 * If LWORK
= -1, then a workspace query is assumed
; the routine
51 * only calculates the optimal size of the WORK array
, returns
52 * this value as the first entry of the WORK array
, and no error
53 * message related
to LWORK is issued by XERBLA
.
55 * INFO
(output
) INTEGER
56 * = 0: successful exit
57 * < 0: if INFO
= -i
, the i
-th argument had an illegal value
58 * > 0: if INFO
= i
, U
(i
,i
) is exactly zero
; the matrix is
59 * singular and its inverse could not be computed
.
61 * =====================================================================
64 DOUBLE PRECISION ZERO
, ONE
65 PARAMETER ( ZERO
= 0.0D
+0, ONE
= 1.0D
+0 )
69 INTEGER I
, IWS
, J
, JB
, JJ
, JP
, LDWORK
, LWKOPT
, NB
,
72 * .. External Functions
..
76 * .. External Subroutines
..
77 EXTERNAL DGEMM
, DGEMV
, DSWAP
, DTRSM
, DTRTRI
, XERBLA
79 * .. Intrinsic Functions
..
82 * .. Executable Statements
..
84 * Test the input parameters
.
87 NB
= ILAENV
( 1, 'DGETRI', ' ', N
, -1, -1, -1 )
90 LQUERY
= ( LWORK
.EQ
.-1 )
93 ELSE IF( LDA
.LT
.MAX
( 1, N
) ) THEN
95 ELSE IF( LWORK
.LT
.MAX
( 1, N
) .AND
. .NOT
.LQUERY
) THEN
99 CALL XERBLA
( 'DGETRI', -INFO
)
101 ELSE IF( LQUERY
) THEN
105 * Quick
return if possible
110 * Form inv
(U
). If INFO
> 0 from DTRTRI
, then U is singular
,
111 * and the inverse is not computed
.
113 CALL DTRTRI
( 'Upper', 'Non-unit', N
, A
, LDA
, INFO
)
119 IF( NB
.GT
.1 .AND
. NB
.LT
.N
) THEN
120 IWS
= MAX
( LDWORK*NB
, 1 )
121 IF( LWORK
.LT
.IWS
) THEN
123 NBMIN
= MAX
( 2, ILAENV
( 2, 'DGETRI', ' ', N
, -1, -1, -1 ) )
129 * Solve the equation inv
(A
)*L
= inv
(U
) for inv
(A
).
131 IF( NB
.LT
.NBMIN
.OR
. NB
.GE
.N
) THEN
133 * Use unblocked code
.
137 * Copy current column of L
to WORK and replace with zeros
.
140 WORK
( I
) = A
( I
, J
)
144 * Compute current column of inv
(A
).
147 $
CALL DGEMV
( 'No transpose', N
, N
-J
, -ONE
, A
( 1, J
+1 ),
148 $ LDA
, WORK
( J
+1 ), 1, ONE
, A
( 1, J
), 1 )
154 NN
= ( ( N
-1 ) / NB
)*NB
+ 1
156 JB
= MIN
( NB
, N
-J
+1 )
158 * Copy current block column of L
to WORK and replace with
161 DO 40 JJ
= J
, J
+ JB
- 1
163 WORK
( I
+( JJ
-J
)*LDWORK
) = A
( I
, JJ
)
168 * Compute current block column of inv
(A
).
171 $
CALL DGEMM
( 'No transpose', 'No transpose', N
, JB
,
172 $ N
-J
-JB
+1, -ONE
, A
( 1, J
+JB
), LDA
,
173 $ WORK
( J
+JB
), LDWORK
, ONE
, A
( 1, J
), LDA
)
174 CALL DTRSM
( 'Right', 'Lower', 'No transpose', 'Unit', N
, JB
,
175 $ ONE
, WORK
( J
), LDWORK
, A
( 1, J
), LDA
)
179 * Apply column interchanges
.
181 DO 60 J
= N
- 1, 1, -1
184 $
CALL DSWAP
( N
, A
( 1, J
), 1, A
( 1, JP
), 1 )