LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgetri.f
Go to the documentation of this file.
1*> \brief \b CGETRI
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGETRI + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgetri.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgetri.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgetri.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO )
20*
21* .. Scalar Arguments ..
22* INTEGER INFO, LDA, LWORK, N
23* ..
24* .. Array Arguments ..
25* INTEGER IPIV( * )
26* COMPLEX A( LDA, * ), WORK( * )
27* ..
28*
29*
30*> \par Purpose:
31* =============
32*>
33*> \verbatim
34*>
35*> CGETRI computes the inverse of a matrix using the LU factorization
36*> computed by CGETRF.
37*>
38*> This method inverts U and then computes inv(A) by solving the system
39*> inv(A)*L = inv(U) for inv(A).
40*> \endverbatim
41*
42* Arguments:
43* ==========
44*
45*> \param[in] N
46*> \verbatim
47*> N is INTEGER
48*> The order of the matrix A. N >= 0.
49*> \endverbatim
50*>
51*> \param[in,out] A
52*> \verbatim
53*> A is COMPLEX array, dimension (LDA,N)
54*> On entry, the factors L and U from the factorization
55*> A = P*L*U as computed by CGETRF.
56*> On exit, if INFO = 0, the inverse of the original matrix A.
57*> \endverbatim
58*>
59*> \param[in] LDA
60*> \verbatim
61*> LDA is INTEGER
62*> The leading dimension of the array A. LDA >= max(1,N).
63*> \endverbatim
64*>
65*> \param[in] IPIV
66*> \verbatim
67*> IPIV is INTEGER array, dimension (N)
68*> The pivot indices from CGETRF; for 1<=i<=N, row i of the
69*> matrix was interchanged with row IPIV(i).
70*> \endverbatim
71*>
72*> \param[out] WORK
73*> \verbatim
74*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
75*> On exit, if INFO=0, then WORK(1) returns the optimal LWORK.
76*> \endverbatim
77*>
78*> \param[in] LWORK
79*> \verbatim
80*> LWORK is INTEGER
81*> The dimension of the array WORK. LWORK >= max(1,N).
82*> For optimal performance LWORK >= N*NB, where NB is
83*> the optimal blocksize returned by ILAENV.
84*>
85*> If LWORK = -1, then a workspace query is assumed; the routine
86*> only calculates the optimal size of the WORK array, returns
87*> this value as the first entry of the WORK array, and no error
88*> message related to LWORK is issued by XERBLA.
89*> \endverbatim
90*>
91*> \param[out] INFO
92*> \verbatim
93*> INFO is INTEGER
94*> = 0: successful exit
95*> < 0: if INFO = -i, the i-th argument had an illegal value
96*> > 0: if INFO = i, U(i,i) is exactly zero; the matrix is
97*> singular and its inverse could not be computed.
98*> \endverbatim
99*
100* Authors:
101* ========
102*
103*> \author Univ. of Tennessee
104*> \author Univ. of California Berkeley
105*> \author Univ. of Colorado Denver
106*> \author NAG Ltd.
107*
108*> \ingroup getri
109*
110* =====================================================================
111 SUBROUTINE cgetri( N, A, LDA, IPIV, WORK, LWORK, INFO )
112*
113* -- LAPACK computational routine --
114* -- LAPACK is a software package provided by Univ. of Tennessee, --
115* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
116*
117* .. Scalar Arguments ..
118 INTEGER INFO, LDA, LWORK, N
119* ..
120* .. Array Arguments ..
121 INTEGER IPIV( * )
122 COMPLEX A( LDA, * ), WORK( * )
123* ..
124*
125* =====================================================================
126*
127* .. Parameters ..
128 COMPLEX ZERO, ONE
129 parameter( zero = ( 0.0e+0, 0.0e+0 ),
130 $ one = ( 1.0e+0, 0.0e+0 ) )
131* ..
132* .. Local Scalars ..
133 LOGICAL LQUERY
134 INTEGER I, IWS, J, JB, JJ, JP, LDWORK, LWKOPT, NB,
135 $ NBMIN, NN
136* ..
137* .. External Functions ..
138 INTEGER ILAENV
139 REAL SROUNDUP_LWORK
140 EXTERNAL ilaenv, sroundup_lwork
141* ..
142* .. External Subroutines ..
143 EXTERNAL cgemm, cgemv, cswap, ctrsm, ctrtri,
144 $ xerbla
145* ..
146* .. Intrinsic Functions ..
147 INTRINSIC max, min
148* ..
149* .. Executable Statements ..
150*
151* Test the input parameters.
152*
153 info = 0
154 nb = ilaenv( 1, 'CGETRI', ' ', n, -1, -1, -1 )
155 lwkopt = max( 1, n*nb )
156 work( 1 ) = sroundup_lwork( lwkopt )
157 lquery = ( lwork.EQ.-1 )
158 IF( n.LT.0 ) THEN
159 info = -1
160 ELSE IF( lda.LT.max( 1, n ) ) THEN
161 info = -3
162 ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery ) THEN
163 info = -6
164 END IF
165 IF( info.NE.0 ) THEN
166 CALL xerbla( 'CGETRI', -info )
167 RETURN
168 ELSE IF( lquery ) THEN
169 RETURN
170 END IF
171*
172* Quick return if possible
173*
174 IF( n.EQ.0 )
175 $ RETURN
176*
177* Form inv(U). If INFO > 0 from CTRTRI, then U is singular,
178* and the inverse is not computed.
179*
180 CALL ctrtri( 'Upper', 'Non-unit', n, a, lda, info )
181 IF( info.GT.0 )
182 $ RETURN
183*
184 nbmin = 2
185 ldwork = n
186 IF( nb.GT.1 .AND. nb.LT.n ) THEN
187 iws = max( ldwork*nb, 1 )
188 IF( lwork.LT.iws ) THEN
189 nb = lwork / ldwork
190 nbmin = max( 2, ilaenv( 2, 'CGETRI', ' ', n, -1, -1,
191 $ -1 ) )
192 END IF
193 ELSE
194 iws = n
195 END IF
196*
197* Solve the equation inv(A)*L = inv(U) for inv(A).
198*
199 IF( nb.LT.nbmin .OR. nb.GE.n ) THEN
200*
201* Use unblocked code.
202*
203 DO 20 j = n, 1, -1
204*
205* Copy current column of L to WORK and replace with zeros.
206*
207 DO 10 i = j + 1, n
208 work( i ) = a( i, j )
209 a( i, j ) = zero
210 10 CONTINUE
211*
212* Compute current column of inv(A).
213*
214 IF( j.LT.n )
215 $ CALL cgemv( 'No transpose', n, n-j, -one, a( 1, j+1 ),
216 $ lda, work( j+1 ), 1, one, a( 1, j ), 1 )
217 20 CONTINUE
218 ELSE
219*
220* Use blocked code.
221*
222 nn = ( ( n-1 ) / nb )*nb + 1
223 DO 50 j = nn, 1, -nb
224 jb = min( nb, n-j+1 )
225*
226* Copy current block column of L to WORK and replace with
227* zeros.
228*
229 DO 40 jj = j, j + jb - 1
230 DO 30 i = jj + 1, n
231 work( i+( jj-j )*ldwork ) = a( i, jj )
232 a( i, jj ) = zero
233 30 CONTINUE
234 40 CONTINUE
235*
236* Compute current block column of inv(A).
237*
238 IF( j+jb.LE.n )
239 $ CALL cgemm( 'No transpose', 'No transpose', n, jb,
240 $ n-j-jb+1, -one, a( 1, j+jb ), lda,
241 $ work( j+jb ), ldwork, one, a( 1, j ), lda )
242 CALL ctrsm( 'Right', 'Lower', 'No transpose', 'Unit', n,
243 $ jb,
244 $ one, work( j ), ldwork, a( 1, j ), lda )
245 50 CONTINUE
246 END IF
247*
248* Apply column interchanges.
249*
250 DO 60 j = n - 1, 1, -1
251 jp = ipiv( j )
252 IF( jp.NE.j )
253 $ CALL cswap( n, a( 1, j ), 1, a( 1, jp ), 1 )
254 60 CONTINUE
255*
256 work( 1 ) = sroundup_lwork( iws )
257 RETURN
258*
259* End of CGETRI
260*
261 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
CGEMM
Definition cgemm.f:188
subroutine cgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
CGEMV
Definition cgemv.f:160
subroutine cgetri(n, a, lda, ipiv, work, lwork, info)
CGETRI
Definition cgetri.f:112
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
Definition cswap.f:81
subroutine ctrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
CTRSM
Definition ctrsm.f:180
subroutine ctrtri(uplo, diag, n, a, lda, info)
CTRTRI
Definition ctrtri.f:107