LAPACK 3.3.0

cherfs.f

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