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