LAPACK 3.3.1
Linear Algebra PACKage
|
00001 SUBROUTINE DPBRFS( UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, B, 00002 $ LDB, X, LDX, FERR, BERR, WORK, IWORK, INFO ) 00003 * 00004 * -- LAPACK routine (version 3.2) -- 00005 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00006 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00007 * November 2006 00008 * 00009 * Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. 00010 * 00011 * .. Scalar Arguments .. 00012 CHARACTER UPLO 00013 INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS 00014 * .. 00015 * .. Array Arguments .. 00016 INTEGER IWORK( * ) 00017 DOUBLE PRECISION AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ), 00018 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * ) 00019 * .. 00020 * 00021 * Purpose 00022 * ======= 00023 * 00024 * DPBRFS improves the computed solution to a system of linear 00025 * equations when the coefficient matrix is symmetric positive definite 00026 * and banded, and provides error bounds and backward error estimates 00027 * for the solution. 00028 * 00029 * Arguments 00030 * ========= 00031 * 00032 * UPLO (input) CHARACTER*1 00033 * = 'U': Upper triangle of A is stored; 00034 * = 'L': Lower triangle of A is stored. 00035 * 00036 * N (input) INTEGER 00037 * The order of the matrix A. N >= 0. 00038 * 00039 * KD (input) INTEGER 00040 * The number of superdiagonals of the matrix A if UPLO = 'U', 00041 * or the number of subdiagonals if UPLO = 'L'. KD >= 0. 00042 * 00043 * NRHS (input) INTEGER 00044 * The number of right hand sides, i.e., the number of columns 00045 * of the matrices B and X. NRHS >= 0. 00046 * 00047 * AB (input) DOUBLE PRECISION array, dimension (LDAB,N) 00048 * The upper or lower triangle of the symmetric band matrix A, 00049 * stored in the first KD+1 rows of the array. The j-th column 00050 * of A is stored in the j-th column of the array AB as follows: 00051 * if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; 00052 * if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). 00053 * 00054 * LDAB (input) INTEGER 00055 * The leading dimension of the array AB. LDAB >= KD+1. 00056 * 00057 * AFB (input) DOUBLE PRECISION array, dimension (LDAFB,N) 00058 * The triangular factor U or L from the Cholesky factorization 00059 * A = U**T*U or A = L*L**T of the band matrix A as computed by 00060 * DPBTRF, in the same storage format as A (see AB). 00061 * 00062 * LDAFB (input) INTEGER 00063 * The leading dimension of the array AFB. LDAFB >= KD+1. 00064 * 00065 * B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) 00066 * The right hand side matrix B. 00067 * 00068 * LDB (input) INTEGER 00069 * The leading dimension of the array B. LDB >= max(1,N). 00070 * 00071 * X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) 00072 * On entry, the solution matrix X, as computed by DPBTRS. 00073 * On exit, the improved solution matrix X. 00074 * 00075 * LDX (input) INTEGER 00076 * The leading dimension of the array X. LDX >= max(1,N). 00077 * 00078 * FERR (output) DOUBLE PRECISION array, dimension (NRHS) 00079 * The estimated forward error bound for each solution vector 00080 * X(j) (the j-th column of the solution matrix X). 00081 * If XTRUE is the true solution corresponding to X(j), FERR(j) 00082 * is an estimated upper bound for the magnitude of the largest 00083 * element in (X(j) - XTRUE) divided by the magnitude of the 00084 * largest element in X(j). The estimate is as reliable as 00085 * the estimate for RCOND, and is almost always a slight 00086 * overestimate of the true error. 00087 * 00088 * BERR (output) DOUBLE PRECISION array, dimension (NRHS) 00089 * The componentwise relative backward error of each solution 00090 * vector X(j) (i.e., the smallest relative change in 00091 * any element of A or B that makes X(j) an exact solution). 00092 * 00093 * WORK (workspace) DOUBLE PRECISION array, dimension (3*N) 00094 * 00095 * IWORK (workspace) INTEGER array, dimension (N) 00096 * 00097 * INFO (output) INTEGER 00098 * = 0: successful exit 00099 * < 0: if INFO = -i, the i-th argument had an illegal value 00100 * 00101 * Internal Parameters 00102 * =================== 00103 * 00104 * ITMAX is the maximum number of steps of iterative refinement. 00105 * 00106 * ===================================================================== 00107 * 00108 * .. Parameters .. 00109 INTEGER ITMAX 00110 PARAMETER ( ITMAX = 5 ) 00111 DOUBLE PRECISION ZERO 00112 PARAMETER ( ZERO = 0.0D+0 ) 00113 DOUBLE PRECISION ONE 00114 PARAMETER ( ONE = 1.0D+0 ) 00115 DOUBLE PRECISION TWO 00116 PARAMETER ( TWO = 2.0D+0 ) 00117 DOUBLE PRECISION THREE 00118 PARAMETER ( THREE = 3.0D+0 ) 00119 * .. 00120 * .. Local Scalars .. 00121 LOGICAL UPPER 00122 INTEGER COUNT, I, J, K, KASE, L, NZ 00123 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK 00124 * .. 00125 * .. Local Arrays .. 00126 INTEGER ISAVE( 3 ) 00127 * .. 00128 * .. External Subroutines .. 00129 EXTERNAL DAXPY, DCOPY, DLACN2, DPBTRS, DSBMV, XERBLA 00130 * .. 00131 * .. Intrinsic Functions .. 00132 INTRINSIC ABS, MAX, MIN 00133 * .. 00134 * .. External Functions .. 00135 LOGICAL LSAME 00136 DOUBLE PRECISION DLAMCH 00137 EXTERNAL LSAME, DLAMCH 00138 * .. 00139 * .. Executable Statements .. 00140 * 00141 * Test the input parameters. 00142 * 00143 INFO = 0 00144 UPPER = LSAME( UPLO, 'U' ) 00145 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00146 INFO = -1 00147 ELSE IF( N.LT.0 ) THEN 00148 INFO = -2 00149 ELSE IF( KD.LT.0 ) THEN 00150 INFO = -3 00151 ELSE IF( NRHS.LT.0 ) THEN 00152 INFO = -4 00153 ELSE IF( LDAB.LT.KD+1 ) THEN 00154 INFO = -6 00155 ELSE IF( LDAFB.LT.KD+1 ) THEN 00156 INFO = -8 00157 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 00158 INFO = -10 00159 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN 00160 INFO = -12 00161 END IF 00162 IF( INFO.NE.0 ) THEN 00163 CALL XERBLA( 'DPBRFS', -INFO ) 00164 RETURN 00165 END IF 00166 * 00167 * Quick return if possible 00168 * 00169 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN 00170 DO 10 J = 1, NRHS 00171 FERR( J ) = ZERO 00172 BERR( J ) = ZERO 00173 10 CONTINUE 00174 RETURN 00175 END IF 00176 * 00177 * NZ = maximum number of nonzero elements in each row of A, plus 1 00178 * 00179 NZ = MIN( N+1, 2*KD+2 ) 00180 EPS = DLAMCH( 'Epsilon' ) 00181 SAFMIN = DLAMCH( 'Safe minimum' ) 00182 SAFE1 = NZ*SAFMIN 00183 SAFE2 = SAFE1 / EPS 00184 * 00185 * Do for each right hand side 00186 * 00187 DO 140 J = 1, NRHS 00188 * 00189 COUNT = 1 00190 LSTRES = THREE 00191 20 CONTINUE 00192 * 00193 * Loop until stopping criterion is satisfied. 00194 * 00195 * Compute residual R = B - A * X 00196 * 00197 CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 ) 00198 CALL DSBMV( UPLO, N, KD, -ONE, AB, LDAB, X( 1, J ), 1, ONE, 00199 $ WORK( N+1 ), 1 ) 00200 * 00201 * Compute componentwise relative backward error from formula 00202 * 00203 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) 00204 * 00205 * where abs(Z) is the componentwise absolute value of the matrix 00206 * or vector Z. If the i-th component of the denominator is less 00207 * than SAFE2, then SAFE1 is added to the i-th components of the 00208 * numerator and denominator before dividing. 00209 * 00210 DO 30 I = 1, N 00211 WORK( I ) = ABS( B( I, J ) ) 00212 30 CONTINUE 00213 * 00214 * Compute abs(A)*abs(X) + abs(B). 00215 * 00216 IF( UPPER ) THEN 00217 DO 50 K = 1, N 00218 S = ZERO 00219 XK = ABS( X( K, J ) ) 00220 L = KD + 1 - K 00221 DO 40 I = MAX( 1, K-KD ), K - 1 00222 WORK( I ) = WORK( I ) + ABS( AB( L+I, K ) )*XK 00223 S = S + ABS( AB( L+I, K ) )*ABS( X( I, J ) ) 00224 40 CONTINUE 00225 WORK( K ) = WORK( K ) + ABS( AB( KD+1, K ) )*XK + S 00226 50 CONTINUE 00227 ELSE 00228 DO 70 K = 1, N 00229 S = ZERO 00230 XK = ABS( X( K, J ) ) 00231 WORK( K ) = WORK( K ) + ABS( AB( 1, K ) )*XK 00232 L = 1 - K 00233 DO 60 I = K + 1, MIN( N, K+KD ) 00234 WORK( I ) = WORK( I ) + ABS( AB( L+I, K ) )*XK 00235 S = S + ABS( AB( L+I, K ) )*ABS( X( I, J ) ) 00236 60 CONTINUE 00237 WORK( K ) = WORK( K ) + S 00238 70 CONTINUE 00239 END IF 00240 S = ZERO 00241 DO 80 I = 1, N 00242 IF( WORK( I ).GT.SAFE2 ) THEN 00243 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) ) 00244 ELSE 00245 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) / 00246 $ ( WORK( I )+SAFE1 ) ) 00247 END IF 00248 80 CONTINUE 00249 BERR( J ) = S 00250 * 00251 * Test stopping criterion. Continue iterating if 00252 * 1) The residual BERR(J) is larger than machine epsilon, and 00253 * 2) BERR(J) decreased by at least a factor of 2 during the 00254 * last iteration, and 00255 * 3) At most ITMAX iterations tried. 00256 * 00257 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND. 00258 $ COUNT.LE.ITMAX ) THEN 00259 * 00260 * Update solution and try again. 00261 * 00262 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N, 00263 $ INFO ) 00264 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 ) 00265 LSTRES = BERR( J ) 00266 COUNT = COUNT + 1 00267 GO TO 20 00268 END IF 00269 * 00270 * Bound error from formula 00271 * 00272 * norm(X - XTRUE) / norm(X) .le. FERR = 00273 * norm( abs(inv(A))* 00274 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) 00275 * 00276 * where 00277 * norm(Z) is the magnitude of the largest component of Z 00278 * inv(A) is the inverse of A 00279 * abs(Z) is the componentwise absolute value of the matrix or 00280 * vector Z 00281 * NZ is the maximum number of nonzeros in any row of A, plus 1 00282 * EPS is machine epsilon 00283 * 00284 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) 00285 * is incremented by SAFE1 if the i-th component of 00286 * abs(A)*abs(X) + abs(B) is less than SAFE2. 00287 * 00288 * Use DLACN2 to estimate the infinity-norm of the matrix 00289 * inv(A) * diag(W), 00290 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) 00291 * 00292 DO 90 I = 1, N 00293 IF( WORK( I ).GT.SAFE2 ) THEN 00294 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) 00295 ELSE 00296 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1 00297 END IF 00298 90 CONTINUE 00299 * 00300 KASE = 0 00301 100 CONTINUE 00302 CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ), 00303 $ KASE, ISAVE ) 00304 IF( KASE.NE.0 ) THEN 00305 IF( KASE.EQ.1 ) THEN 00306 * 00307 * Multiply by diag(W)*inv(A**T). 00308 * 00309 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N, 00310 $ INFO ) 00311 DO 110 I = 1, N 00312 WORK( N+I ) = WORK( N+I )*WORK( I ) 00313 110 CONTINUE 00314 ELSE IF( KASE.EQ.2 ) THEN 00315 * 00316 * Multiply by inv(A)*diag(W). 00317 * 00318 DO 120 I = 1, N 00319 WORK( N+I ) = WORK( N+I )*WORK( I ) 00320 120 CONTINUE 00321 CALL DPBTRS( UPLO, N, KD, 1, AFB, LDAFB, WORK( N+1 ), N, 00322 $ INFO ) 00323 END IF 00324 GO TO 100 00325 END IF 00326 * 00327 * Normalize error. 00328 * 00329 LSTRES = ZERO 00330 DO 130 I = 1, N 00331 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) ) 00332 130 CONTINUE 00333 IF( LSTRES.NE.ZERO ) 00334 $ FERR( J ) = FERR( J ) / LSTRES 00335 * 00336 140 CONTINUE 00337 * 00338 RETURN 00339 * 00340 * End of DPBRFS 00341 * 00342 END