3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CHERFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cherfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cherfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cherfs.f">
21 * SUBROUTINE CHERFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
22 * X, LDX, FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
30 * REAL BERR( * ), FERR( * ), RWORK( * )
31 * COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
32 * $ WORK( * ), X( LDX, * )
41 *> CHERFS improves the computed solution to a system of linear
42 *> equations when the coefficient matrix is Hermitian indefinite, and
43 *> provides error bounds and backward error estimates for the solution.
51 *> UPLO is CHARACTER*1
52 *> = 'U': Upper triangle of A is stored;
53 *> = 'L': Lower triangle of A is stored.
59 *> The order of the matrix A. N >= 0.
65 *> The number of right hand sides, i.e., the number of columns
66 *> of the matrices B and X. NRHS >= 0.
71 *> A is COMPLEX array, dimension (LDA,N)
72 *> The Hermitian matrix A. If UPLO = 'U', the leading N-by-N
73 *> upper triangular part of A contains the upper triangular part
74 *> of the matrix A, and the strictly lower triangular part of A
75 *> is not referenced. If UPLO = 'L', the leading N-by-N lower
76 *> triangular part of A contains the lower triangular part of
77 *> the matrix A, and the strictly upper triangular part of A is
84 *> The leading dimension of the array A. LDA >= max(1,N).
89 *> AF is COMPLEX array, dimension (LDAF,N)
90 *> The factored form of the matrix A. AF contains the block
91 *> diagonal matrix D and the multipliers used to obtain the
92 *> factor U or L from the factorization A = U*D*U**H or
93 *> A = L*D*L**H as computed by CHETRF.
99 *> The leading dimension of the array AF. LDAF >= max(1,N).
104 *> IPIV is INTEGER array, dimension (N)
105 *> Details of the interchanges and the block structure of D
106 *> as determined by CHETRF.
111 *> B is COMPLEX array, dimension (LDB,NRHS)
112 *> The right hand side matrix B.
118 *> The leading dimension of the array B. LDB >= max(1,N).
123 *> X is COMPLEX array, dimension (LDX,NRHS)
124 *> On entry, the solution matrix X, as computed by CHETRS.
125 *> On exit, the improved solution matrix X.
131 *> The leading dimension of the array X. LDX >= max(1,N).
136 *> FERR is REAL array, dimension (NRHS)
137 *> The estimated forward error bound for each solution vector
138 *> X(j) (the j-th column of the solution matrix X).
139 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
140 *> is an estimated upper bound for the magnitude of the largest
141 *> element in (X(j) - XTRUE) divided by the magnitude of the
142 *> largest element in X(j). The estimate is as reliable as
143 *> the estimate for RCOND, and is almost always a slight
144 *> overestimate of the true error.
149 *> BERR is REAL array, dimension (NRHS)
150 *> The componentwise relative backward error of each solution
151 *> vector X(j) (i.e., the smallest relative change in
152 *> any element of A or B that makes X(j) an exact solution).
157 *> WORK is COMPLEX array, dimension (2*N)
162 *> RWORK is REAL array, dimension (N)
168 *> = 0: successful exit
169 *> < 0: if INFO = -i, the i-th argument had an illegal value
172 *> \par Internal Parameters:
173 * =========================
176 *> ITMAX is the maximum number of steps of iterative refinement.
182 *> \author Univ. of Tennessee
183 *> \author Univ. of California Berkeley
184 *> \author Univ. of Colorado Denver
187 *> \date November 2011
189 *> \ingroup complexHEcomputational
191 * =====================================================================
192 SUBROUTINE CHERFS( UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
193 $ X, LDX, FERR, BERR, WORK, RWORK, INFO )
195 * -- LAPACK computational routine (version 3.4.0) --
196 * -- LAPACK is a software package provided by Univ. of Tennessee, --
197 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
200 * .. Scalar Arguments ..
202 INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
204 * .. Array Arguments ..
206 REAL BERR( * ), FERR( * ), RWORK( * )
207 COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
208 $ WORK( * ), X( LDX, * )
211 * =====================================================================
215 PARAMETER ( ITMAX = 5 )
217 PARAMETER ( ZERO = 0.0E+0 )
219 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
221 PARAMETER ( TWO = 2.0E+0 )
223 PARAMETER ( THREE = 3.0E+0 )
225 * .. Local Scalars ..
227 INTEGER COUNT, I, J, K, KASE, NZ
228 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
234 * .. External Subroutines ..
235 EXTERNAL CAXPY, CCOPY, CHEMV, CHETRS, CLACN2, XERBLA
237 * .. Intrinsic Functions ..
238 INTRINSIC ABS, AIMAG, MAX, REAL
240 * .. External Functions ..
243 EXTERNAL LSAME, SLAMCH
245 * .. Statement Functions ..
248 * .. Statement Function definitions ..
249 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
251 * .. Executable Statements ..
253 * Test the input parameters.
256 UPPER = LSAME( UPLO, 'U' )
257 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
259 ELSE IF( N.LT.0 ) THEN
261 ELSE IF( NRHS.LT.0 ) THEN
263 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
265 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
267 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
269 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
273 CALL XERBLA( 'CHERFS', -INFO )
277 * Quick return if possible
279 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
287 * NZ = maximum number of nonzero elements in each row of A, plus 1
290 EPS = SLAMCH( 'Epsilon' )
291 SAFMIN = SLAMCH( 'Safe minimum' )
295 * Do for each right hand side
303 * Loop until stopping criterion is satisfied.
305 * Compute residual R = B - A * X
307 CALL CCOPY( N, B( 1, J ), 1, WORK, 1 )
308 CALL CHEMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE, WORK, 1 )
310 * Compute componentwise relative backward error from formula
312 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
314 * where abs(Z) is the componentwise absolute value of the matrix
315 * or vector Z. If the i-th component of the denominator is less
316 * than SAFE2, then SAFE1 is added to the i-th components of the
317 * numerator and denominator before dividing.
320 RWORK( I ) = CABS1( B( I, J ) )
323 * Compute abs(A)*abs(X) + abs(B).
328 XK = CABS1( X( K, J ) )
330 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
331 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
333 RWORK( K ) = RWORK( K ) + ABS( REAL( A( K, K ) ) )*XK + S
338 XK = CABS1( X( K, J ) )
339 RWORK( K ) = RWORK( K ) + ABS( REAL( A( K, K ) ) )*XK
341 RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
342 S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
344 RWORK( K ) = RWORK( K ) + S
349 IF( RWORK( I ).GT.SAFE2 ) THEN
350 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
352 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
353 $ ( RWORK( I )+SAFE1 ) )
358 * Test stopping criterion. Continue iterating if
359 * 1) The residual BERR(J) is larger than machine epsilon, and
360 * 2) BERR(J) decreased by at least a factor of 2 during the
361 * last iteration, and
362 * 3) At most ITMAX iterations tried.
364 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
365 $ COUNT.LE.ITMAX ) THEN
367 * Update solution and try again.
369 CALL CHETRS( UPLO, N, 1, AF, LDAF, IPIV, WORK, N, INFO )
370 CALL CAXPY( N, ONE, WORK, 1, X( 1, J ), 1 )
376 * Bound error from formula
378 * norm(X - XTRUE) / norm(X) .le. FERR =
380 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
383 * norm(Z) is the magnitude of the largest component of Z
384 * inv(A) is the inverse of A
385 * abs(Z) is the componentwise absolute value of the matrix or
387 * NZ is the maximum number of nonzeros in any row of A, plus 1
388 * EPS is machine epsilon
390 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
391 * is incremented by SAFE1 if the i-th component of
392 * abs(A)*abs(X) + abs(B) is less than SAFE2.
394 * Use CLACN2 to estimate the infinity-norm of the matrix
396 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
399 IF( RWORK( I ).GT.SAFE2 ) THEN
400 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
402 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
409 CALL CLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
413 * Multiply by diag(W)*inv(A**H).
415 CALL CHETRS( UPLO, N, 1, AF, LDAF, IPIV, WORK, N, INFO )
417 WORK( I ) = RWORK( I )*WORK( I )
419 ELSE IF( KASE.EQ.2 ) THEN
421 * Multiply by inv(A)*diag(W).
424 WORK( I ) = RWORK( I )*WORK( I )
426 CALL CHETRS( UPLO, N, 1, AF, LDAF, IPIV, WORK, N, INFO )
435 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
438 $ FERR( J ) = FERR( J ) / LSTRES