LAPACK 3.3.0

dporfs.f

Go to the documentation of this file.
00001       SUBROUTINE DPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
00002      $                   LDX, 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 DLACN2 in place of DLACON, 5 Feb 03, SJH.
00010 *
00011 *     .. Scalar Arguments ..
00012       CHARACTER          UPLO
00013       INTEGER            INFO, LDA, LDAF, LDB, LDX, N, NRHS
00014 *     ..
00015 *     .. Array Arguments ..
00016       INTEGER            IWORK( * )
00017       DOUBLE PRECISION   A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
00018      $                   BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
00019 *     ..
00020 *
00021 *  Purpose
00022 *  =======
00023 *
00024 *  DPORFS improves the computed solution to a system of linear
00025 *  equations when the coefficient matrix is symmetric positive definite,
00026 *  and provides error bounds and backward error estimates for the
00027 *  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 *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
00044 *          The symmetric matrix A.  If UPLO = 'U', the leading N-by-N
00045 *          upper triangular part of A contains the upper triangular part
00046 *          of the matrix A, and the strictly lower triangular part of A
00047 *          is not referenced.  If UPLO = 'L', the leading N-by-N lower
00048 *          triangular part of A contains the lower triangular part of
00049 *          the matrix A, and the strictly upper triangular part of A is
00050 *          not referenced.
00051 *
00052 *  LDA     (input) INTEGER
00053 *          The leading dimension of the array A.  LDA >= max(1,N).
00054 *
00055 *  AF      (input) DOUBLE PRECISION array, dimension (LDAF,N)
00056 *          The triangular factor U or L from the Cholesky factorization
00057 *          A = U**T*U or A = L*L**T, as computed by DPOTRF.
00058 *
00059 *  LDAF    (input) INTEGER
00060 *          The leading dimension of the array AF.  LDAF >= max(1,N).
00061 *
00062 *  B       (input) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (LDX,NRHS)
00069 *          On entry, the solution matrix X, as computed by DPOTRS.
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) DOUBLE PRECISION array, dimension (3*N)
00091 *
00092 *  IWORK   (workspace) INTEGER 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       DOUBLE PRECISION   ONE
00111       PARAMETER          ( ONE = 1.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, J, K, KASE, NZ
00120       DOUBLE PRECISION   EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
00121 *     ..
00122 *     .. Local Arrays ..
00123       INTEGER            ISAVE( 3 )
00124 *     ..
00125 *     .. External Subroutines ..
00126       EXTERNAL           DAXPY, DCOPY, DLACN2, DPOTRS, DSYMV, XERBLA
00127 *     ..
00128 *     .. Intrinsic Functions ..
00129       INTRINSIC          ABS, MAX
00130 *     ..
00131 *     .. External Functions ..
00132       LOGICAL            LSAME
00133       DOUBLE PRECISION   DLAMCH
00134       EXTERNAL           LSAME, DLAMCH
00135 *     ..
00136 *     .. Executable Statements ..
00137 *
00138 *     Test the input parameters.
00139 *
00140       INFO = 0
00141       UPPER = LSAME( UPLO, 'U' )
00142       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00143          INFO = -1
00144       ELSE IF( N.LT.0 ) THEN
00145          INFO = -2
00146       ELSE IF( NRHS.LT.0 ) THEN
00147          INFO = -3
00148       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00149          INFO = -5
00150       ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
00151          INFO = -7
00152       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00153          INFO = -9
00154       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00155          INFO = -11
00156       END IF
00157       IF( INFO.NE.0 ) THEN
00158          CALL XERBLA( 'DPORFS', -INFO )
00159          RETURN
00160       END IF
00161 *
00162 *     Quick return if possible
00163 *
00164       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00165          DO 10 J = 1, NRHS
00166             FERR( J ) = ZERO
00167             BERR( J ) = ZERO
00168    10    CONTINUE
00169          RETURN
00170       END IF
00171 *
00172 *     NZ = maximum number of nonzero elements in each row of A, plus 1
00173 *
00174       NZ = N + 1
00175       EPS = DLAMCH( 'Epsilon' )
00176       SAFMIN = DLAMCH( 'Safe minimum' )
00177       SAFE1 = NZ*SAFMIN
00178       SAFE2 = SAFE1 / EPS
00179 *
00180 *     Do for each right hand side
00181 *
00182       DO 140 J = 1, NRHS
00183 *
00184          COUNT = 1
00185          LSTRES = THREE
00186    20    CONTINUE
00187 *
00188 *        Loop until stopping criterion is satisfied.
00189 *
00190 *        Compute residual R = B - A * X
00191 *
00192          CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
00193          CALL DSYMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE,
00194      $               WORK( N+1 ), 1 )
00195 *
00196 *        Compute componentwise relative backward error from formula
00197 *
00198 *        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
00199 *
00200 *        where abs(Z) is the componentwise absolute value of the matrix
00201 *        or vector Z.  If the i-th component of the denominator is less
00202 *        than SAFE2, then SAFE1 is added to the i-th components of the
00203 *        numerator and denominator before dividing.
00204 *
00205          DO 30 I = 1, N
00206             WORK( I ) = ABS( B( I, J ) )
00207    30    CONTINUE
00208 *
00209 *        Compute abs(A)*abs(X) + abs(B).
00210 *
00211          IF( UPPER ) THEN
00212             DO 50 K = 1, N
00213                S = ZERO
00214                XK = ABS( X( K, J ) )
00215                DO 40 I = 1, K - 1
00216                   WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
00217                   S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
00218    40          CONTINUE
00219                WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK + S
00220    50       CONTINUE
00221          ELSE
00222             DO 70 K = 1, N
00223                S = ZERO
00224                XK = ABS( X( K, J ) )
00225                WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK
00226                DO 60 I = K + 1, N
00227                   WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
00228                   S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
00229    60          CONTINUE
00230                WORK( K ) = WORK( K ) + S
00231    70       CONTINUE
00232          END IF
00233          S = ZERO
00234          DO 80 I = 1, N
00235             IF( WORK( I ).GT.SAFE2 ) THEN
00236                S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
00237             ELSE
00238                S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
00239      $             ( WORK( I )+SAFE1 ) )
00240             END IF
00241    80    CONTINUE
00242          BERR( J ) = S
00243 *
00244 *        Test stopping criterion. Continue iterating if
00245 *           1) The residual BERR(J) is larger than machine epsilon, and
00246 *           2) BERR(J) decreased by at least a factor of 2 during the
00247 *              last iteration, and
00248 *           3) At most ITMAX iterations tried.
00249 *
00250          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00251      $       COUNT.LE.ITMAX ) THEN
00252 *
00253 *           Update solution and try again.
00254 *
00255             CALL DPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
00256             CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
00257             LSTRES = BERR( J )
00258             COUNT = COUNT + 1
00259             GO TO 20
00260          END IF
00261 *
00262 *        Bound error from formula
00263 *
00264 *        norm(X - XTRUE) / norm(X) .le. FERR =
00265 *        norm( abs(inv(A))*
00266 *           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
00267 *
00268 *        where
00269 *          norm(Z) is the magnitude of the largest component of Z
00270 *          inv(A) is the inverse of A
00271 *          abs(Z) is the componentwise absolute value of the matrix or
00272 *             vector Z
00273 *          NZ is the maximum number of nonzeros in any row of A, plus 1
00274 *          EPS is machine epsilon
00275 *
00276 *        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
00277 *        is incremented by SAFE1 if the i-th component of
00278 *        abs(A)*abs(X) + abs(B) is less than SAFE2.
00279 *
00280 *        Use DLACN2 to estimate the infinity-norm of the matrix
00281 *           inv(A) * diag(W),
00282 *        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
00283 *
00284          DO 90 I = 1, N
00285             IF( WORK( I ).GT.SAFE2 ) THEN
00286                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
00287             ELSE
00288                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
00289             END IF
00290    90    CONTINUE
00291 *
00292          KASE = 0
00293   100    CONTINUE
00294          CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
00295      $                KASE, ISAVE )
00296          IF( KASE.NE.0 ) THEN
00297             IF( KASE.EQ.1 ) THEN
00298 *
00299 *              Multiply by diag(W)*inv(A').
00300 *
00301                CALL DPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
00302                DO 110 I = 1, N
00303                   WORK( N+I ) = WORK( I )*WORK( N+I )
00304   110          CONTINUE
00305             ELSE IF( KASE.EQ.2 ) THEN
00306 *
00307 *              Multiply by inv(A)*diag(W).
00308 *
00309                DO 120 I = 1, N
00310                   WORK( N+I ) = WORK( I )*WORK( N+I )
00311   120          CONTINUE
00312                CALL DPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
00313             END IF
00314             GO TO 100
00315          END IF
00316 *
00317 *        Normalize error.
00318 *
00319          LSTRES = ZERO
00320          DO 130 I = 1, N
00321             LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
00322   130    CONTINUE
00323          IF( LSTRES.NE.ZERO )
00324      $      FERR( J ) = FERR( J ) / LSTRES
00325 *
00326   140 CONTINUE
00327 *
00328       RETURN
00329 *
00330 *     End of DPORFS
00331 *
00332       END
 All Files Functions