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