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 * -- LAPACK is a software package provided by Univ. of Tennessee, --
6 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9 * Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH.
11 * .. Scalar Arguments ..
13 INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS
15 * .. Array Arguments ..
17 DOUBLE PRECISION AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
18 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
24 * DPBRFS improves the computed solution to a system of linear
25 * equations when the coefficient matrix is symmetric positive definite
26 * and banded, and provides error bounds and backward error estimates
32 * UPLO (input) CHARACTER*1
33 * = 'U': Upper triangle of A is stored;
34 * = 'L': Lower triangle of A is stored.
37 * The order of the matrix A. N >= 0.
40 * The number of superdiagonals of the matrix A if UPLO = 'U',
41 * or the number of subdiagonals if UPLO = 'L'. KD >= 0.
43 * NRHS (input) INTEGER
44 * The number of right hand sides, i.e., the number of columns
45 * of the matrices B and X. NRHS >= 0.
47 * AB (input) DOUBLE PRECISION array, dimension (LDAB,N)
48 * The upper or lower triangle of the symmetric band matrix A,
49 * stored in the first KD+1 rows of the array. The j-th column
50 * of A is stored in the j-th column of the array AB as follows:
51 * if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
52 * if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd).
54 * LDAB (input) INTEGER
55 * The leading dimension of the array AB. LDAB >= KD+1.
57 * AFB (input) DOUBLE PRECISION array, dimension (LDAFB,N)
58 * The triangular factor U or L from the Cholesky factorization
59 * A = U**T*U or A = L*L**T of the band matrix A as computed by
60 * DPBTRF, in the same storage format as A (see AB).
62 * LDAFB (input) INTEGER
63 * The leading dimension of the array AFB. LDAFB >= KD+1.
65 * B (input) DOUBLE PRECISION array, dimension (LDB,NRHS)
66 * The right hand side matrix B.
69 * The leading dimension of the array B. LDB >= max(1,N).
71 * X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS)
72 * On entry, the solution matrix X, as computed by DPBTRS.
73 * On exit, the improved solution matrix X.
76 * The leading dimension of the array X. LDX >= max(1,N).
78 * FERR (output) DOUBLE PRECISION array, dimension (NRHS)
79 * The estimated forward error bound for each solution vector
80 * X(j) (the j-th column of the solution matrix X).
81 * If XTRUE is the true solution corresponding to X(j), FERR(j)
82 * is an estimated upper bound for the magnitude of the largest
83 * element in (X(j) - XTRUE) divided by the magnitude of the
84 * largest element in X(j). The estimate is as reliable as
85 * the estimate for RCOND, and is almost always a slight
86 * overestimate of the true error.
88 * BERR (output) DOUBLE PRECISION array, dimension (NRHS)
89 * The componentwise relative backward error of each solution
90 * vector X(j) (i.e., the smallest relative change in
91 * any element of A or B that makes X(j) an exact solution).
93 * WORK (workspace) DOUBLE PRECISION array, dimension (3*N)
95 * IWORK (workspace) INTEGER array, dimension (N)
97 * INFO (output) INTEGER
98 * = 0: successful exit
99 * < 0: if INFO = -i, the i-th argument had an illegal value
101 * Internal Parameters
102 * ===================
104 * ITMAX is the maximum number of steps of iterative refinement.
106 * =====================================================================
110 PARAMETER ( ITMAX = 5 )
111 DOUBLE PRECISION ZERO
112 PARAMETER ( ZERO = 0.0D+0 )
114 PARAMETER ( ONE = 1.0D+0 )
116 PARAMETER ( TWO = 2.0D+0 )
117 DOUBLE PRECISION THREE
118 PARAMETER ( THREE = 3.0D+0 )
120 * .. Local Scalars ..
122 INTEGER COUNT, I, J, K, KASE, L, NZ
123 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
128 * .. External Subroutines ..
129 EXTERNAL DAXPY, DCOPY, DLACN2, DPBTRS, DSBMV, XERBLA
131 * .. Intrinsic Functions ..
132 INTRINSIC ABS, MAX, MIN
134 * .. External Functions ..
136 DOUBLE PRECISION DLAMCH
137 EXTERNAL LSAME, DLAMCH
139 * .. Executable Statements ..
141 * Test the input parameters.
144 UPPER = LSAME( UPLO, 'U' )
145 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
147 ELSE IF( N.LT.0 ) THEN
149 ELSE IF( KD.LT.0 ) THEN
151 ELSE IF( NRHS.LT.0 ) THEN
153 ELSE IF( LDAB.LT.KD+1 ) THEN
155 ELSE IF( LDAFB.LT.KD+1 ) THEN
157 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
159 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
163 CALL XERBLA( 'DPBRFS', -INFO )
167 * Quick return if possible
169 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
177 * NZ = maximum number of nonzero elements in each row of A, plus 1
179 NZ = MIN( N+1, 2*KD+2 )
180 EPS = DLAMCH( 'Epsilon' )
181 SAFMIN = DLAMCH( 'Safe minimum' )
185 * Do for each right hand side
193 * Loop until stopping criterion is satisfied.
195 * Compute residual R = B - A * X
197 CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
198 CALL DSBMV( UPLO, N, KD, -ONE, AB, LDAB, X( 1, J ), 1, ONE,
201 * Compute componentwise relative backward error from formula
203 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
205 * where abs(Z) is the componentwise absolute value of the matrix
206 * or vector Z. If the i-th component of the denominator is less
207 * than SAFE2, then SAFE1 is added to the i-th components of the
208 * numerator and denominator before dividing.
211 WORK( I ) = ABS( B( I, J ) )
214 * Compute abs(A)*abs(X) + abs(B).
219 XK = ABS( X( K, J ) )
221 DO 40 I = MAX( 1, K-KD ), K - 1
222 WORK( I ) = WORK( I ) + ABS( AB( L+I, K ) )*XK
223 S = S + ABS( AB( L+I, K ) )*ABS( X( I, J ) )
225 WORK( K ) = WORK( K ) + ABS( AB( KD+1, K ) )*XK + S
230 XK = ABS( X( K, J ) )
231 WORK( K ) = WORK( K ) + ABS( AB( 1, K ) )*XK
233 DO 60 I = K + 1, MIN( N, K+KD )
234 WORK( I ) = WORK( I ) + ABS( AB( L+I, K ) )*XK
235 S = S + ABS( AB( L+I, K ) )*ABS( X( I, J ) )
237 WORK( K ) = WORK( K ) + S
242 IF( WORK( I ).GT.SAFE2 ) THEN
243 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
245 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
246 $ ( WORK( I )+SAFE1 ) )
251 * Test stopping criterion. Continue iterating if
252 * 1) The residual BERR(J) is larger than machine epsilon, and
253 * 2) BERR(J) decreased by at least a factor of 2 during the
254 * last iteration, and
255 * 3) At most ITMAX iterations tried.
257 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
258 $ COUNT.LE.ITMAX ) THEN
260 * Update solution and try again.
262 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N,
264 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
270 * Bound error from formula
272 * norm(X - XTRUE) / norm(X) .le. FERR =
274 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
277 * norm(Z) is the magnitude of the largest component of Z
278 * inv(A) is the inverse of A
279 * abs(Z) is the componentwise absolute value of the matrix or
281 * NZ is the maximum number of nonzeros in any row of A, plus 1
282 * EPS is machine epsilon
284 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
285 * is incremented by SAFE1 if the i-th component of
286 * abs(A)*abs(X) + abs(B) is less than SAFE2.
288 * Use DLACN2 to estimate the infinity-norm of the matrix
290 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
293 IF( WORK( I ).GT.SAFE2 ) THEN
294 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
296 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
302 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
307 * Multiply by diag(W)*inv(A**T).
309 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N,
312 WORK( N+I ) = WORK( N+I )*WORK( I )
314 ELSE IF( KASE.EQ.2 ) THEN
316 * Multiply by inv(A)*diag(W).
319 WORK( N+I ) = WORK( N+I )*WORK( I )
321 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N,
331 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
334 $ FERR( J ) = FERR( J ) / LSTRES