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