1 SUBROUTINE DPBRFS( UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B,
2 $ LDB, X, LDX, FERR, BERR, WORK, IWORK, INFO )
4 * -- LAPACK routine (version 3.2) --
5 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
8 * Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH.
10 * .. Scalar Arguments ..
12 INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
14 * .. Array Arguments ..
16 DOUBLE PRECISION AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
17 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
23 * DPBRFS improves the computed solution to a system of linear
24 * equations when the coefficient matrix is symmetric positive definite
25 * and banded, and provides error bounds and backward error estimates
31 * UPLO (input) CHARACTER*1
32 * = 'U': Upper triangle of A is stored;
33 * = 'L': Lower triangle of A is stored.
36 * The order of the matrix A. N >= 0.
39 * The number of superdiagonals of the matrix A if UPLO = 'U',
40 * or the number of subdiagonals if UPLO = 'L'. KD >= 0.
42 * NRHS (input) INTEGER
43 * The number of right hand sides, i.e., the number of columns
44 * of the matrices B and X. NRHS >= 0.
46 * AB (input) DOUBLE PRECISION array, dimension (LDAB,N)
47 * The upper or lower triangle of the symmetric band matrix A,
48 * stored in the first KD+1 rows of the array. The j-th column
49 * of A is stored in the j-th column of the array AB as follows:
50 * if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
51 * if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
53 * LDAB (input) INTEGER
54 * The leading dimension of the array AB. LDAB >= KD+1.
56 * AFB (input) DOUBLE PRECISION array, dimension (LDAFB,N)
57 * The triangular factor U or L from the Cholesky factorization
58 * A = U**T*U or A = L*L**T of the band matrix A as computed by
59 * DPBTRF, in the same storage format as A (see AB).
61 * LDAFB (input) INTEGER
62 * The leading dimension of the array AFB. LDAFB >= KD+1.
64 * B (input) DOUBLE PRECISION array, dimension (LDB,NRHS)
65 * The right hand side matrix B.
68 * The leading dimension of the array B. LDB >= max(1,N).
70 * X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS)
71 * On entry, the solution matrix X, as computed by DPBTRS.
72 * On exit, the improved solution matrix X.
75 * The leading dimension of the array X. LDX >= max(1,N).
77 * FERR (output) DOUBLE PRECISION array, dimension (NRHS)
78 * The estimated forward error bound for each solution vector
79 * X(j) (the j-th column of the solution matrix X).
80 * If XTRUE is the true solution corresponding to X(j), FERR(j)
81 * is an estimated upper bound for the magnitude of the largest
82 * element in (X(j) - XTRUE) divided by the magnitude of the
83 * largest element in X(j). The estimate is as reliable as
84 * the estimate for RCOND, and is almost always a slight
85 * overestimate of the true error.
87 * BERR (output) DOUBLE PRECISION array, dimension (NRHS)
88 * The componentwise relative backward error of each solution
89 * vector X(j) (i.e., the smallest relative change in
90 * any element of A or B that makes X(j) an exact solution).
92 * WORK (workspace) DOUBLE PRECISION array, dimension (3*N)
94 * IWORK (workspace) INTEGER array, dimension (N)
96 * INFO (output) INTEGER
97 * = 0: successful exit
98 * < 0: if INFO = -i, the i-th argument had an illegal value
100 * Internal Parameters
101 * ===================
103 * ITMAX is the maximum number of steps of iterative refinement.
105 * =====================================================================
109 PARAMETER ( ITMAX = 5 )
110 DOUBLE PRECISION ZERO
111 PARAMETER ( ZERO = 0.0D+0 )
113 PARAMETER ( ONE = 1.0D+0 )
115 PARAMETER ( TWO = 2.0D+0 )
116 DOUBLE PRECISION THREE
117 PARAMETER ( THREE = 3.0D+0 )
119 * .. Local Scalars ..
121 INTEGER COUNT, I, J, K, KASE, L, NZ
122 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
127 * .. External Subroutines ..
128 EXTERNAL DAXPY, DCOPY, DLACN2, DPBTRS, DSBMV, XERBLA
130 * .. Intrinsic Functions ..
131 INTRINSIC ABS, MAX, MIN
133 * .. External Functions ..
135 DOUBLE PRECISION DLAMCH
136 EXTERNAL LSAME, DLAMCH
138 * .. Executable Statements ..
140 * Test the input parameters.
143 UPPER = LSAME( UPLO, 'U' )
144 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
146 ELSE IF( N.LT.0 ) THEN
148 ELSE IF( KD.LT.0 ) THEN
150 ELSE IF( NRHS.LT.0 ) THEN
152 ELSE IF( LDAB.LT.KD+1 ) THEN
154 ELSE IF( LDAFB.LT.KD+1 ) THEN
156 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
158 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
162 CALL XERBLA( 'DPBRFS', -INFO )
166 * Quick return if possible
168 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
176 * NZ = maximum number of nonzero elements in each row of A, plus 1
178 NZ = MIN( N+1, 2*KD+2 )
179 EPS = DLAMCH( 'Epsilon' )
180 SAFMIN = DLAMCH( 'Safe minimum' )
184 * Do for each right hand side
192 * Loop until stopping criterion is satisfied.
194 * Compute residual R = B - A * X
196 CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
197 CALL DSBMV( UPLO, N, KD, -ONE, AB, LDAB, X( 1, J ), 1, ONE,
200 * Compute componentwise relative backward error from formula
202 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
204 * where abs(Z) is the componentwise absolute value of the matrix
205 * or vector Z. If the i-th component of the denominator is less
206 * than SAFE2, then SAFE1 is added to the i-th components of the
207 * numerator and denominator before dividing.
210 WORK( I ) = ABS( B( I, J ) )
213 * Compute abs(A)*abs(X) + abs(B).
218 XK = ABS( X( K, J ) )
220 DO 40 I = MAX( 1, K-KD ), K - 1
221 WORK( I ) = WORK( I ) + ABS( AB( L+I, K ) )*XK
222 S = S + ABS( AB( L+I, K ) )*ABS( X( I, J ) )
224 WORK( K ) = WORK( K ) + ABS( AB( KD+1, K ) )*XK + S
229 XK = ABS( X( K, J ) )
230 WORK( K ) = WORK( K ) + ABS( AB( 1, K ) )*XK
232 DO 60 I = K + 1, MIN( N, K+KD )
233 WORK( I ) = WORK( I ) + ABS( AB( L+I, K ) )*XK
234 S = S + ABS( AB( L+I, K ) )*ABS( X( I, J ) )
236 WORK( K ) = WORK( K ) + S
241 IF( WORK( I ).GT.SAFE2 ) THEN
242 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
244 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
245 $ ( WORK( I )+SAFE1 ) )
250 * Test stopping criterion. Continue iterating if
251 * 1) The residual BERR(J) is larger than machine epsilon, and
252 * 2) BERR(J) decreased by at least a factor of 2 during the
253 * last iteration, and
254 * 3) At most ITMAX iterations tried.
256 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
257 $ COUNT.LE.ITMAX ) THEN
259 * Update solution and try again.
261 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N,
263 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
269 * Bound error from formula
271 * norm(X - XTRUE) / norm(X) .le. FERR =
273 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
276 * norm(Z) is the magnitude of the largest component of Z
277 * inv(A) is the inverse of A
278 * abs(Z) is the componentwise absolute value of the matrix or
280 * NZ is the maximum number of nonzeros in any row of A, plus 1
281 * EPS is machine epsilon
283 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
284 * is incremented by SAFE1 if the i-th component of
285 * abs(A)*abs(X) + abs(B) is less than SAFE2.
287 * Use DLACN2 to estimate the infinity-norm of the matrix
289 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
292 IF( WORK( I ).GT.SAFE2 ) THEN
293 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
295 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
301 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
306 * Multiply by diag(W)*inv(A').
308 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N,
311 WORK( N+I ) = WORK( N+I )*WORK( I )
313 ELSE IF( KASE.EQ.2 ) THEN
315 * Multiply by inv(A)*diag(W).
318 WORK( N+I ) = WORK( N+I )*WORK( I )
320 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N,
330 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
333 $ FERR( J ) = FERR( J ) / LSTRES