LAPACK 3.3.1
Linear Algebra PACKage

cporfs.f

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