![]() |
LAPACK
3.4.1
LAPACK: Linear Algebra PACKage
|
00001 *> \brief \b CSPRFS 00002 * 00003 * =========== DOCUMENTATION =========== 00004 * 00005 * Online html documentation available at 00006 * http://www.netlib.org/lapack/explore-html/ 00007 * 00008 *> \htmlonly 00009 *> Download CSPRFS + dependencies 00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csprfs.f"> 00011 *> [TGZ]</a> 00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csprfs.f"> 00013 *> [ZIP]</a> 00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csprfs.f"> 00015 *> [TXT]</a> 00016 *> \endhtmlonly 00017 * 00018 * Definition: 00019 * =========== 00020 * 00021 * SUBROUTINE CSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX, 00022 * FERR, BERR, WORK, RWORK, INFO ) 00023 * 00024 * .. Scalar Arguments .. 00025 * CHARACTER UPLO 00026 * INTEGER INFO, LDB, LDX, N, NRHS 00027 * .. 00028 * .. Array Arguments .. 00029 * INTEGER IPIV( * ) 00030 * REAL BERR( * ), FERR( * ), RWORK( * ) 00031 * COMPLEX AFP( * ), AP( * ), B( LDB, * ), WORK( * ), 00032 * $ X( LDX, * ) 00033 * .. 00034 * 00035 * 00036 *> \par Purpose: 00037 * ============= 00038 *> 00039 *> \verbatim 00040 *> 00041 *> CSPRFS improves the computed solution to a system of linear 00042 *> equations when the coefficient matrix is symmetric indefinite 00043 *> and packed, and provides error bounds and backward error estimates 00044 *> for the solution. 00045 *> \endverbatim 00046 * 00047 * Arguments: 00048 * ========== 00049 * 00050 *> \param[in] UPLO 00051 *> \verbatim 00052 *> UPLO is CHARACTER*1 00053 *> = 'U': Upper triangle of A is stored; 00054 *> = 'L': Lower triangle of A is stored. 00055 *> \endverbatim 00056 *> 00057 *> \param[in] N 00058 *> \verbatim 00059 *> N is INTEGER 00060 *> The order of the matrix A. N >= 0. 00061 *> \endverbatim 00062 *> 00063 *> \param[in] NRHS 00064 *> \verbatim 00065 *> NRHS is INTEGER 00066 *> The number of right hand sides, i.e., the number of columns 00067 *> of the matrices B and X. NRHS >= 0. 00068 *> \endverbatim 00069 *> 00070 *> \param[in] AP 00071 *> \verbatim 00072 *> AP is COMPLEX array, dimension (N*(N+1)/2) 00073 *> The upper or lower triangle of the symmetric matrix A, packed 00074 *> columnwise in a linear array. The j-th column of A is stored 00075 *> in the array AP as follows: 00076 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; 00077 *> if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. 00078 *> \endverbatim 00079 *> 00080 *> \param[in] AFP 00081 *> \verbatim 00082 *> AFP is COMPLEX array, dimension (N*(N+1)/2) 00083 *> The factored form of the matrix A. AFP contains the block 00084 *> diagonal matrix D and the multipliers used to obtain the 00085 *> factor U or L from the factorization A = U*D*U**T or 00086 *> A = L*D*L**T as computed by CSPTRF, stored as a packed 00087 *> triangular matrix. 00088 *> \endverbatim 00089 *> 00090 *> \param[in] IPIV 00091 *> \verbatim 00092 *> IPIV is INTEGER array, dimension (N) 00093 *> Details of the interchanges and the block structure of D 00094 *> as determined by CSPTRF. 00095 *> \endverbatim 00096 *> 00097 *> \param[in] B 00098 *> \verbatim 00099 *> B is COMPLEX array, dimension (LDB,NRHS) 00100 *> The right hand side matrix B. 00101 *> \endverbatim 00102 *> 00103 *> \param[in] LDB 00104 *> \verbatim 00105 *> LDB is INTEGER 00106 *> The leading dimension of the array B. LDB >= max(1,N). 00107 *> \endverbatim 00108 *> 00109 *> \param[in,out] X 00110 *> \verbatim 00111 *> X is COMPLEX array, dimension (LDX,NRHS) 00112 *> On entry, the solution matrix X, as computed by CSPTRS. 00113 *> On exit, the improved solution matrix X. 00114 *> \endverbatim 00115 *> 00116 *> \param[in] LDX 00117 *> \verbatim 00118 *> LDX is INTEGER 00119 *> The leading dimension of the array X. LDX >= max(1,N). 00120 *> \endverbatim 00121 *> 00122 *> \param[out] FERR 00123 *> \verbatim 00124 *> FERR is REAL array, dimension (NRHS) 00125 *> The estimated forward error bound for each solution vector 00126 *> X(j) (the j-th column of the solution matrix X). 00127 *> If XTRUE is the true solution corresponding to X(j), FERR(j) 00128 *> is an estimated upper bound for the magnitude of the largest 00129 *> element in (X(j) - XTRUE) divided by the magnitude of the 00130 *> largest element in X(j). The estimate is as reliable as 00131 *> the estimate for RCOND, and is almost always a slight 00132 *> overestimate of the true error. 00133 *> \endverbatim 00134 *> 00135 *> \param[out] BERR 00136 *> \verbatim 00137 *> BERR is REAL array, dimension (NRHS) 00138 *> The componentwise relative backward error of each solution 00139 *> vector X(j) (i.e., the smallest relative change in 00140 *> any element of A or B that makes X(j) an exact solution). 00141 *> \endverbatim 00142 *> 00143 *> \param[out] WORK 00144 *> \verbatim 00145 *> WORK is COMPLEX array, dimension (2*N) 00146 *> \endverbatim 00147 *> 00148 *> \param[out] RWORK 00149 *> \verbatim 00150 *> RWORK is REAL array, dimension (N) 00151 *> \endverbatim 00152 *> 00153 *> \param[out] INFO 00154 *> \verbatim 00155 *> INFO is INTEGER 00156 *> = 0: successful exit 00157 *> < 0: if INFO = -i, the i-th argument had an illegal value 00158 *> \endverbatim 00159 * 00160 *> \par Internal Parameters: 00161 * ========================= 00162 *> 00163 *> \verbatim 00164 *> ITMAX is the maximum number of steps of iterative refinement. 00165 *> \endverbatim 00166 * 00167 * Authors: 00168 * ======== 00169 * 00170 *> \author Univ. of Tennessee 00171 *> \author Univ. of California Berkeley 00172 *> \author Univ. of Colorado Denver 00173 *> \author NAG Ltd. 00174 * 00175 *> \date November 2011 00176 * 00177 *> \ingroup complexOTHERcomputational 00178 * 00179 * ===================================================================== 00180 SUBROUTINE CSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX, 00181 $ FERR, BERR, WORK, RWORK, INFO ) 00182 * 00183 * -- LAPACK computational routine (version 3.4.0) -- 00184 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00185 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00186 * November 2011 00187 * 00188 * .. Scalar Arguments .. 00189 CHARACTER UPLO 00190 INTEGER INFO, LDB, LDX, N, NRHS 00191 * .. 00192 * .. Array Arguments .. 00193 INTEGER IPIV( * ) 00194 REAL BERR( * ), FERR( * ), RWORK( * ) 00195 COMPLEX AFP( * ), AP( * ), B( LDB, * ), WORK( * ), 00196 $ X( LDX, * ) 00197 * .. 00198 * 00199 * ===================================================================== 00200 * 00201 * .. Parameters .. 00202 INTEGER ITMAX 00203 PARAMETER ( ITMAX = 5 ) 00204 REAL ZERO 00205 PARAMETER ( ZERO = 0.0E+0 ) 00206 COMPLEX ONE 00207 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) ) 00208 REAL TWO 00209 PARAMETER ( TWO = 2.0E+0 ) 00210 REAL THREE 00211 PARAMETER ( THREE = 3.0E+0 ) 00212 * .. 00213 * .. Local Scalars .. 00214 LOGICAL UPPER 00215 INTEGER COUNT, I, IK, J, K, KASE, KK, NZ 00216 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK 00217 COMPLEX ZDUM 00218 * .. 00219 * .. Local Arrays .. 00220 INTEGER ISAVE( 3 ) 00221 * .. 00222 * .. External Subroutines .. 00223 EXTERNAL CAXPY, CCOPY, CLACN2, CSPMV, CSPTRS, XERBLA 00224 * .. 00225 * .. Intrinsic Functions .. 00226 INTRINSIC ABS, AIMAG, MAX, REAL 00227 * .. 00228 * .. External Functions .. 00229 LOGICAL LSAME 00230 REAL SLAMCH 00231 EXTERNAL LSAME, SLAMCH 00232 * .. 00233 * .. Statement Functions .. 00234 REAL CABS1 00235 * .. 00236 * .. Statement Function definitions .. 00237 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) ) 00238 * .. 00239 * .. Executable Statements .. 00240 * 00241 * Test the input parameters. 00242 * 00243 INFO = 0 00244 UPPER = LSAME( UPLO, 'U' ) 00245 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00246 INFO = -1 00247 ELSE IF( N.LT.0 ) THEN 00248 INFO = -2 00249 ELSE IF( NRHS.LT.0 ) THEN 00250 INFO = -3 00251 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 00252 INFO = -8 00253 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN 00254 INFO = -10 00255 END IF 00256 IF( INFO.NE.0 ) THEN 00257 CALL XERBLA( 'CSPRFS', -INFO ) 00258 RETURN 00259 END IF 00260 * 00261 * Quick return if possible 00262 * 00263 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN 00264 DO 10 J = 1, NRHS 00265 FERR( J ) = ZERO 00266 BERR( J ) = ZERO 00267 10 CONTINUE 00268 RETURN 00269 END IF 00270 * 00271 * NZ = maximum number of nonzero elements in each row of A, plus 1 00272 * 00273 NZ = N + 1 00274 EPS = SLAMCH( 'Epsilon' ) 00275 SAFMIN = SLAMCH( 'Safe minimum' ) 00276 SAFE1 = NZ*SAFMIN 00277 SAFE2 = SAFE1 / EPS 00278 * 00279 * Do for each right hand side 00280 * 00281 DO 140 J = 1, NRHS 00282 * 00283 COUNT = 1 00284 LSTRES = THREE 00285 20 CONTINUE 00286 * 00287 * Loop until stopping criterion is satisfied. 00288 * 00289 * Compute residual R = B - A * X 00290 * 00291 CALL CCOPY( N, B( 1, J ), 1, WORK, 1 ) 00292 CALL CSPMV( UPLO, N, -ONE, AP, X( 1, J ), 1, ONE, WORK, 1 ) 00293 * 00294 * Compute componentwise relative backward error from formula 00295 * 00296 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) 00297 * 00298 * where abs(Z) is the componentwise absolute value of the matrix 00299 * or vector Z. If the i-th component of the denominator is less 00300 * than SAFE2, then SAFE1 is added to the i-th components of the 00301 * numerator and denominator before dividing. 00302 * 00303 DO 30 I = 1, N 00304 RWORK( I ) = CABS1( B( I, J ) ) 00305 30 CONTINUE 00306 * 00307 * Compute abs(A)*abs(X) + abs(B). 00308 * 00309 KK = 1 00310 IF( UPPER ) THEN 00311 DO 50 K = 1, N 00312 S = ZERO 00313 XK = CABS1( X( K, J ) ) 00314 IK = KK 00315 DO 40 I = 1, K - 1 00316 RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK 00317 S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) ) 00318 IK = IK + 1 00319 40 CONTINUE 00320 RWORK( K ) = RWORK( K ) + CABS1( AP( KK+K-1 ) )*XK + S 00321 KK = KK + K 00322 50 CONTINUE 00323 ELSE 00324 DO 70 K = 1, N 00325 S = ZERO 00326 XK = CABS1( X( K, J ) ) 00327 RWORK( K ) = RWORK( K ) + CABS1( AP( KK ) )*XK 00328 IK = KK + 1 00329 DO 60 I = K + 1, N 00330 RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK 00331 S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) ) 00332 IK = IK + 1 00333 60 CONTINUE 00334 RWORK( K ) = RWORK( K ) + S 00335 KK = KK + ( N-K+1 ) 00336 70 CONTINUE 00337 END IF 00338 S = ZERO 00339 DO 80 I = 1, N 00340 IF( RWORK( I ).GT.SAFE2 ) THEN 00341 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) ) 00342 ELSE 00343 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) / 00344 $ ( RWORK( I )+SAFE1 ) ) 00345 END IF 00346 80 CONTINUE 00347 BERR( J ) = S 00348 * 00349 * Test stopping criterion. Continue iterating if 00350 * 1) The residual BERR(J) is larger than machine epsilon, and 00351 * 2) BERR(J) decreased by at least a factor of 2 during the 00352 * last iteration, and 00353 * 3) At most ITMAX iterations tried. 00354 * 00355 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND. 00356 $ COUNT.LE.ITMAX ) THEN 00357 * 00358 * Update solution and try again. 00359 * 00360 CALL CSPTRS( UPLO, N, 1, AFP, IPIV, WORK, N, INFO ) 00361 CALL CAXPY( N, ONE, WORK, 1, X( 1, J ), 1 ) 00362 LSTRES = BERR( J ) 00363 COUNT = COUNT + 1 00364 GO TO 20 00365 END IF 00366 * 00367 * Bound error from formula 00368 * 00369 * norm(X - XTRUE) / norm(X) .le. FERR = 00370 * norm( abs(inv(A))* 00371 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) 00372 * 00373 * where 00374 * norm(Z) is the magnitude of the largest component of Z 00375 * inv(A) is the inverse of A 00376 * abs(Z) is the componentwise absolute value of the matrix or 00377 * vector Z 00378 * NZ is the maximum number of nonzeros in any row of A, plus 1 00379 * EPS is machine epsilon 00380 * 00381 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) 00382 * is incremented by SAFE1 if the i-th component of 00383 * abs(A)*abs(X) + abs(B) is less than SAFE2. 00384 * 00385 * Use CLACN2 to estimate the infinity-norm of the matrix 00386 * inv(A) * diag(W), 00387 * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) 00388 * 00389 DO 90 I = 1, N 00390 IF( RWORK( I ).GT.SAFE2 ) THEN 00391 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) 00392 ELSE 00393 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) + 00394 $ SAFE1 00395 END IF 00396 90 CONTINUE 00397 * 00398 KASE = 0 00399 100 CONTINUE 00400 CALL CLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE ) 00401 IF( KASE.NE.0 ) THEN 00402 IF( KASE.EQ.1 ) THEN 00403 * 00404 * Multiply by diag(W)*inv(A**T). 00405 * 00406 CALL CSPTRS( UPLO, N, 1, AFP, IPIV, WORK, N, INFO ) 00407 DO 110 I = 1, N 00408 WORK( I ) = RWORK( I )*WORK( I ) 00409 110 CONTINUE 00410 ELSE IF( KASE.EQ.2 ) THEN 00411 * 00412 * Multiply by inv(A)*diag(W). 00413 * 00414 DO 120 I = 1, N 00415 WORK( I ) = RWORK( I )*WORK( I ) 00416 120 CONTINUE 00417 CALL CSPTRS( UPLO, N, 1, AFP, IPIV, WORK, N, INFO ) 00418 END IF 00419 GO TO 100 00420 END IF 00421 * 00422 * Normalize error. 00423 * 00424 LSTRES = ZERO 00425 DO 130 I = 1, N 00426 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) ) 00427 130 CONTINUE 00428 IF( LSTRES.NE.ZERO ) 00429 $ FERR( J ) = FERR( J ) / LSTRES 00430 * 00431 140 CONTINUE 00432 * 00433 RETURN 00434 * 00435 * End of CSPRFS 00436 * 00437 END