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