LAPACK 3.3.0

ssyrfs.f

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