LAPACK 3.3.0

dpprfs.f

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