3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGETRI + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgetri.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgetri.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgetri.f">
21 * SUBROUTINE CGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER INFO, LDA, LWORK, N
26 * .. Array Arguments ..
28 * COMPLEX A( LDA, * ), WORK( * )
37 *> CGETRI computes the inverse of a matrix using the LU factorization
38 *> computed by CGETRF.
40 *> This method inverts U and then computes inv(A) by solving the system
41 *> inv(A)*L = inv(U) for inv(A).
50 *> The order of the matrix A. N >= 0.
55 *> A is COMPLEX array, dimension (LDA,N)
56 *> On entry, the factors L and U from the factorization
57 *> A = P*L*U as computed by CGETRF.
58 *> On exit, if INFO = 0, the inverse of the original matrix A.
64 *> The leading dimension of the array A. LDA >= max(1,N).
69 *> IPIV is INTEGER array, dimension (N)
70 *> The pivot indices from CGETRF; for 1<=i<=N, row i of the
71 *> matrix was interchanged with row IPIV(i).
76 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
77 *> On exit, if INFO=0, then WORK(1) returns the optimal LWORK.
83 *> The dimension of the array WORK. LWORK >= max(1,N).
84 *> For optimal performance LWORK >= N*NB, where NB is
85 *> the optimal blocksize returned by ILAENV.
87 *> If LWORK = -1, then a workspace query is assumed; the routine
88 *> only calculates the optimal size of the WORK array, returns
89 *> this value as the first entry of the WORK array, and no error
90 *> message related to LWORK is issued by XERBLA.
96 *> = 0: successful exit
97 *> < 0: if INFO = -i, the i-th argument had an illegal value
98 *> > 0: if INFO = i, U(i,i) is exactly zero; the matrix is
99 *> singular and its inverse could not be computed.
105 *> \author Univ. of Tennessee
106 *> \author Univ. of California Berkeley
107 *> \author Univ. of Colorado Denver
110 *> \date November 2011
112 *> \ingroup complexGEcomputational
114 * =====================================================================
115 SUBROUTINE CGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO )
117 * -- LAPACK computational routine (version 3.4.0) --
118 * -- LAPACK is a software package provided by Univ. of Tennessee, --
119 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
122 * .. Scalar Arguments ..
123 INTEGER INFO, LDA, LWORK, N
125 * .. Array Arguments ..
127 COMPLEX A( LDA, * ), WORK( * )
130 * =====================================================================
134 PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ),
135 $ ONE = ( 1.0E+0, 0.0E+0 ) )
137 * .. Local Scalars ..
139 INTEGER I, IWS, J, JB, JJ, JP, LDWORK, LWKOPT, NB,
142 * .. External Functions ..
146 * .. External Subroutines ..
147 EXTERNAL CGEMM, CGEMV, CSWAP, CTRSM, CTRTRI, XERBLA
149 * .. Intrinsic Functions ..
152 * .. Executable Statements ..
154 * Test the input parameters.
157 NB = ILAENV( 1, 'CGETRI', ' ', N, -1, -1, -1 )
160 LQUERY = ( LWORK.EQ.-1 )
163 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
165 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
169 CALL XERBLA( 'CGETRI', -INFO )
171 ELSE IF( LQUERY ) THEN
175 * Quick return if possible
180 * Form inv(U). If INFO > 0 from CTRTRI, then U is singular,
181 * and the inverse is not computed.
183 CALL CTRTRI( 'Upper', 'Non-unit', N, A, LDA, INFO )
189 IF( NB.GT.1 .AND. NB.LT.N ) THEN
190 IWS = MAX( LDWORK*NB, 1 )
191 IF( LWORK.LT.IWS ) THEN
193 NBMIN = MAX( 2, ILAENV( 2, 'CGETRI', ' ', N, -1, -1, -1 ) )
199 * Solve the equation inv(A)*L = inv(U) for inv(A).
201 IF( NB.LT.NBMIN .OR. NB.GE.N ) THEN
203 * Use unblocked code.
207 * Copy current column of L to WORK and replace with zeros.
210 WORK( I ) = A( I, J )
214 * Compute current column of inv(A).
217 $ CALL CGEMV( 'No transpose', N, N-J, -ONE, A( 1, J+1 ),
218 $ LDA, WORK( J+1 ), 1, ONE, A( 1, J ), 1 )
224 NN = ( ( N-1 ) / NB )*NB + 1
226 JB = MIN( NB, N-J+1 )
228 * Copy current block column of L to WORK and replace with
231 DO 40 JJ = J, J + JB - 1
233 WORK( I+( JJ-J )*LDWORK ) = A( I, JJ )
238 * Compute current block column of inv(A).
241 $ CALL CGEMM( 'No transpose', 'No transpose', N, JB,
242 $ N-J-JB+1, -ONE, A( 1, J+JB ), LDA,
243 $ WORK( J+JB ), LDWORK, ONE, A( 1, J ), LDA )
244 CALL CTRSM( 'Right', 'Lower', 'No transpose', 'Unit', N, JB,
245 $ ONE, WORK( J ), LDWORK, A( 1, J ), LDA )
249 * Apply column interchanges.
251 DO 60 J = N - 1, 1, -1
254 $ CALL CSWAP( N, A( 1, J ), 1, A( 1, JP ), 1 )