LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ cgetri()

subroutine cgetri ( integer n,
complex, dimension( lda, * ) a,
integer lda,
integer, dimension( * ) ipiv,
complex, dimension( * ) work,
integer lwork,
integer info )

CGETRI

Download CGETRI + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> CGETRI computes the inverse of a matrix using the LU factorization
!> computed by CGETRF.
!>
!> This method inverts U and then computes inv(A) by solving the system
!> inv(A)*L = inv(U) for inv(A).
!> 
Parameters
[in]N
!>          N is INTEGER
!>          The order of the matrix A.  N >= 0.
!> 
[in,out]A
!>          A is COMPLEX array, dimension (LDA,N)
!>          On entry, the factors L and U from the factorization
!>          A = P*L*U as computed by CGETRF.
!>          On exit, if INFO = 0, the inverse of the original matrix A.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A.  LDA >= max(1,N).
!> 
[in]IPIV
!>          IPIV is INTEGER array, dimension (N)
!>          The pivot indices from CGETRF; for 1<=i<=N, row i of the
!>          matrix was interchanged with row IPIV(i).
!> 
[out]WORK
!>          WORK is COMPLEX array, dimension (MAX(1,LWORK))
!>          On exit, if INFO=0, then WORK(1) returns the optimal LWORK.
!> 
[in]LWORK
!>          LWORK is INTEGER
!>          The dimension of the array WORK.  LWORK >= max(1,N).
!>          For optimal performance LWORK >= N*NB, where NB is
!>          the optimal blocksize returned by ILAENV.
!>
!>          If LWORK = -1, then a workspace query is assumed; the routine
!>          only calculates the optimal size of the WORK array, returns
!>          this value as the first entry of the WORK array, and no error
!>          message related to LWORK is issued by XERBLA.
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -i, the i-th argument had an illegal value
!>          > 0:  if INFO = i, U(i,i) is exactly zero; the matrix is
!>                singular and its inverse could not be computed.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 111 of file cgetri.f.

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*
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
integer function ilaenv(ispec, name, opts, n1, n2, n3, n4)
ILAENV
Definition ilaenv.f:160
real function sroundup_lwork(lwork)
SROUNDUP_LWORK
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
Here is the call graph for this function:
Here is the caller graph for this function: