3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CPBRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cpbrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cpbrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cpbrfs.f">
21 * SUBROUTINE CPBRFS( UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B,
22 * LDB, X, LDX, FERR, BERR, WORK, RWORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
28 * .. Array Arguments ..
29 * REAL BERR( * ), FERR( * ), RWORK( * )
30 * COMPLEX AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
31 * $ WORK( * ), X( LDX, * )
40 *> CPBRFS improves the computed solution to a system of linear
41 *> equations when the coefficient matrix is Hermitian positive definite
42 *> and banded, and provides error bounds and backward error estimates
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 superdiagonals of the matrix A if UPLO = 'U',
66 *> or the number of subdiagonals if UPLO = 'L'. KD >= 0.
72 *> The number of right hand sides, i.e., the number of columns
73 *> of the matrices B and X. NRHS >= 0.
78 *> AB is COMPLEX array, dimension (LDAB,N)
79 *> The upper or lower triangle of the Hermitian band matrix A,
80 *> stored in the first KD+1 rows of the array. The j-th column
81 *> of A is stored in the j-th column of the array AB as follows:
82 *> if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
83 *> if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
89 *> The leading dimension of the array AB. LDAB >= KD+1.
94 *> AFB is COMPLEX array, dimension (LDAFB,N)
95 *> The triangular factor U or L from the Cholesky factorization
96 *> A = U**H*U or A = L*L**H of the band matrix A as computed by
97 *> CPBTRF, in the same storage format as A (see AB).
103 *> The leading dimension of the array AFB. LDAFB >= KD+1.
108 *> B is COMPLEX array, dimension (LDB,NRHS)
109 *> The right hand side matrix B.
115 *> The leading dimension of the array B. LDB >= max(1,N).
120 *> X is COMPLEX array, dimension (LDX,NRHS)
121 *> On entry, the solution matrix X, as computed by CPBTRS.
122 *> On exit, the improved solution matrix X.
128 *> The leading dimension of the array X. LDX >= max(1,N).
133 *> FERR is REAL array, dimension (NRHS)
134 *> The estimated forward error bound for each solution vector
135 *> X(j) (the j-th column of the solution matrix X).
136 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
137 *> is an estimated upper bound for the magnitude of the largest
138 *> element in (X(j) - XTRUE) divided by the magnitude of the
139 *> largest element in X(j). The estimate is as reliable as
140 *> the estimate for RCOND, and is almost always a slight
141 *> overestimate of the true error.
146 *> BERR is REAL array, dimension (NRHS)
147 *> The componentwise relative backward error of each solution
148 *> vector X(j) (i.e., the smallest relative change in
149 *> any element of A or B that makes X(j) an exact solution).
154 *> WORK is COMPLEX array, dimension (2*N)
159 *> RWORK is REAL array, dimension (N)
165 *> = 0: successful exit
166 *> < 0: if INFO = -i, the i-th argument had an illegal value
169 *> \par Internal Parameters:
170 * =========================
173 *> ITMAX is the maximum number of steps of iterative refinement.
179 *> \author Univ. of Tennessee
180 *> \author Univ. of California Berkeley
181 *> \author Univ. of Colorado Denver
184 *> \date November 2011
186 *> \ingroup complexOTHERcomputational
188 * =====================================================================
189 SUBROUTINE CPBRFS( UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B,
190 $ LDB, X, LDX, FERR, BERR, WORK, RWORK, INFO )
192 * -- LAPACK computational routine (version 3.4.0) --
193 * -- LAPACK is a software package provided by Univ. of Tennessee, --
194 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
197 * .. Scalar Arguments ..
199 INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
201 * .. Array Arguments ..
202 REAL BERR( * ), FERR( * ), RWORK( * )
203 COMPLEX AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
204 $ WORK( * ), X( LDX, * )
207 * =====================================================================
211 PARAMETER ( ITMAX = 5 )
213 PARAMETER ( ZERO = 0.0E+0 )
215 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
217 PARAMETER ( TWO = 2.0E+0 )
219 PARAMETER ( THREE = 3.0E+0 )
221 * .. Local Scalars ..
223 INTEGER COUNT, I, J, K, KASE, L, NZ
224 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
230 * .. External Subroutines ..
231 EXTERNAL CAXPY, CCOPY, CHBMV, CLACN2, CPBTRS, XERBLA
233 * .. Intrinsic Functions ..
234 INTRINSIC ABS, AIMAG, MAX, MIN, REAL
236 * .. External Functions ..
239 EXTERNAL LSAME, SLAMCH
241 * .. Statement Functions ..
244 * .. Statement Function definitions ..
245 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
247 * .. Executable Statements ..
249 * Test the input parameters.
252 UPPER = LSAME( UPLO, 'U' )
253 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
255 ELSE IF( N.LT.0 ) THEN
257 ELSE IF( KD.LT.0 ) THEN
259 ELSE IF( NRHS.LT.0 ) THEN
261 ELSE IF( LDAB.LT.KD+1 ) THEN
263 ELSE IF( LDAFB.LT.KD+1 ) THEN
265 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
267 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
271 CALL XERBLA( 'CPBRFS', -INFO )
275 * Quick return if possible
277 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
285 * NZ = maximum number of nonzero elements in each row of A, plus 1
287 NZ = MIN( N+1, 2*KD+2 )
288 EPS = SLAMCH( 'Epsilon' )
289 SAFMIN = SLAMCH( 'Safe minimum' )
293 * Do for each right hand side
301 * Loop until stopping criterion is satisfied.
303 * Compute residual R = B - A * X
305 CALL CCOPY( N, B( 1, J ), 1, WORK, 1 )
306 CALL CHBMV( UPLO, N, KD, -ONE, AB, LDAB, X( 1, J ), 1, ONE,
309 * Compute componentwise relative backward error from formula
311 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
313 * where abs(Z) is the componentwise absolute value of the matrix
314 * or vector Z. If the i-th component of the denominator is less
315 * than SAFE2, then SAFE1 is added to the i-th components of the
316 * numerator and denominator before dividing.
319 RWORK( I ) = CABS1( B( I, J ) )
322 * Compute abs(A)*abs(X) + abs(B).
327 XK = CABS1( X( K, J ) )
329 DO 40 I = MAX( 1, K-KD ), K - 1
330 RWORK( I ) = RWORK( I ) + CABS1( AB( L+I, K ) )*XK
331 S = S + CABS1( AB( L+I, K ) )*CABS1( X( I, J ) )
333 RWORK( K ) = RWORK( K ) + ABS( REAL( AB( KD+1, K ) ) )*
339 XK = CABS1( X( K, J ) )
340 RWORK( K ) = RWORK( K ) + ABS( REAL( AB( 1, K ) ) )*XK
342 DO 60 I = K + 1, MIN( N, K+KD )
343 RWORK( I ) = RWORK( I ) + CABS1( AB( L+I, K ) )*XK
344 S = S + CABS1( AB( L+I, K ) )*CABS1( X( I, J ) )
346 RWORK( K ) = RWORK( K ) + S
351 IF( RWORK( I ).GT.SAFE2 ) THEN
352 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
354 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
355 $ ( RWORK( I )+SAFE1 ) )
360 * Test stopping criterion. Continue iterating if
361 * 1) The residual BERR(J) is larger than machine epsilon, and
362 * 2) BERR(J) decreased by at least a factor of 2 during the
363 * last iteration, and
364 * 3) At most ITMAX iterations tried.
366 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
367 $ COUNT.LE.ITMAX ) THEN
369 * Update solution and try again.
371 CALL CPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK, N, INFO )
372 CALL CAXPY( N, ONE, WORK, 1, X( 1, J ), 1 )
378 * Bound error from formula
380 * norm(X - XTRUE) / norm(X) .le. FERR =
382 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
385 * norm(Z) is the magnitude of the largest component of Z
386 * inv(A) is the inverse of A
387 * abs(Z) is the componentwise absolute value of the matrix or
389 * NZ is the maximum number of nonzeros in any row of A, plus 1
390 * EPS is machine epsilon
392 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
393 * is incremented by SAFE1 if the i-th component of
394 * abs(A)*abs(X) + abs(B) is less than SAFE2.
396 * Use CLACN2 to estimate the infinity-norm of the matrix
398 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
401 IF( RWORK( I ).GT.SAFE2 ) THEN
402 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
404 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
411 CALL CLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
415 * Multiply by diag(W)*inv(A**H).
417 CALL CPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK, N, INFO )
419 WORK( I ) = RWORK( I )*WORK( I )
421 ELSE IF( KASE.EQ.2 ) THEN
423 * Multiply by inv(A)*diag(W).
426 WORK( I ) = RWORK( I )*WORK( I )
428 CALL CPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK, N, INFO )
437 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
440 $ FERR( J ) = FERR( J ) / LSTRES