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