Annotation of rpl/lapack/lapack/zporfs.f, revision 1.18

1.9       bertrand    1: *> \brief \b ZPORFS
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.15      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.9       bertrand    7: *
                      8: *> \htmlonly
1.15      bertrand    9: *> Download ZPORFS + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zporfs.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zporfs.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zporfs.f">
1.9       bertrand   15: *> [TXT]</a>
1.15      bertrand   16: *> \endhtmlonly
1.9       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
                     22: *                          LDX, FERR, BERR, WORK, RWORK, INFO )
1.15      bertrand   23: *
1.9       bertrand   24: *       .. Scalar Arguments ..
                     25: *       CHARACTER          UPLO
                     26: *       INTEGER            INFO, LDA, LDAF, LDB, LDX, N, NRHS
                     27: *       ..
                     28: *       .. Array Arguments ..
                     29: *       DOUBLE PRECISION   BERR( * ), FERR( * ), RWORK( * )
                     30: *       COMPLEX*16         A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
                     31: *      $                   WORK( * ), X( LDX, * )
                     32: *       ..
1.15      bertrand   33: *
1.9       bertrand   34: *
                     35: *> \par Purpose:
                     36: *  =============
                     37: *>
                     38: *> \verbatim
                     39: *>
                     40: *> ZPORFS improves the computed solution to a system of linear
                     41: *> equations when the coefficient matrix is Hermitian positive definite,
                     42: *> and provides error bounds and backward error estimates for the
                     43: *> solution.
                     44: *> \endverbatim
                     45: *
                     46: *  Arguments:
                     47: *  ==========
                     48: *
                     49: *> \param[in] UPLO
                     50: *> \verbatim
                     51: *>          UPLO is CHARACTER*1
                     52: *>          = 'U':  Upper triangle of A is stored;
                     53: *>          = 'L':  Lower triangle of A is stored.
                     54: *> \endverbatim
                     55: *>
                     56: *> \param[in] N
                     57: *> \verbatim
                     58: *>          N is INTEGER
                     59: *>          The order of the matrix A.  N >= 0.
                     60: *> \endverbatim
                     61: *>
                     62: *> \param[in] NRHS
                     63: *> \verbatim
                     64: *>          NRHS is INTEGER
                     65: *>          The number of right hand sides, i.e., the number of columns
                     66: *>          of the matrices B and X.  NRHS >= 0.
                     67: *> \endverbatim
                     68: *>
                     69: *> \param[in] A
                     70: *> \verbatim
                     71: *>          A is COMPLEX*16 array, dimension (LDA,N)
                     72: *>          The Hermitian matrix A.  If UPLO = 'U', the leading N-by-N
                     73: *>          upper triangular part of A contains the upper triangular part
                     74: *>          of the matrix A, and the strictly lower triangular part of A
                     75: *>          is not referenced.  If UPLO = 'L', the leading N-by-N lower
                     76: *>          triangular part of A contains the lower triangular part of
                     77: *>          the matrix A, and the strictly upper triangular part of A is
                     78: *>          not referenced.
                     79: *> \endverbatim
                     80: *>
                     81: *> \param[in] LDA
                     82: *> \verbatim
                     83: *>          LDA is INTEGER
                     84: *>          The leading dimension of the array A.  LDA >= max(1,N).
                     85: *> \endverbatim
                     86: *>
                     87: *> \param[in] AF
                     88: *> \verbatim
                     89: *>          AF is COMPLEX*16 array, dimension (LDAF,N)
                     90: *>          The triangular factor U or L from the Cholesky factorization
                     91: *>          A = U**H*U or A = L*L**H, as computed by ZPOTRF.
                     92: *> \endverbatim
                     93: *>
                     94: *> \param[in] LDAF
                     95: *> \verbatim
                     96: *>          LDAF is INTEGER
                     97: *>          The leading dimension of the array AF.  LDAF >= max(1,N).
                     98: *> \endverbatim
                     99: *>
                    100: *> \param[in] B
                    101: *> \verbatim
                    102: *>          B is COMPLEX*16 array, dimension (LDB,NRHS)
                    103: *>          The right hand side matrix B.
                    104: *> \endverbatim
                    105: *>
                    106: *> \param[in] LDB
                    107: *> \verbatim
                    108: *>          LDB is INTEGER
                    109: *>          The leading dimension of the array B.  LDB >= max(1,N).
                    110: *> \endverbatim
                    111: *>
                    112: *> \param[in,out] X
                    113: *> \verbatim
                    114: *>          X is COMPLEX*16 array, dimension (LDX,NRHS)
                    115: *>          On entry, the solution matrix X, as computed by ZPOTRS.
                    116: *>          On exit, the improved solution matrix X.
                    117: *> \endverbatim
                    118: *>
                    119: *> \param[in] LDX
                    120: *> \verbatim
                    121: *>          LDX is INTEGER
                    122: *>          The leading dimension of the array X.  LDX >= max(1,N).
                    123: *> \endverbatim
                    124: *>
                    125: *> \param[out] FERR
                    126: *> \verbatim
                    127: *>          FERR is DOUBLE PRECISION array, dimension (NRHS)
                    128: *>          The estimated forward error bound for each solution vector
                    129: *>          X(j) (the j-th column of the solution matrix X).
                    130: *>          If XTRUE is the true solution corresponding to X(j), FERR(j)
                    131: *>          is an estimated upper bound for the magnitude of the largest
                    132: *>          element in (X(j) - XTRUE) divided by the magnitude of the
                    133: *>          largest element in X(j).  The estimate is as reliable as
                    134: *>          the estimate for RCOND, and is almost always a slight
                    135: *>          overestimate of the true error.
                    136: *> \endverbatim
                    137: *>
                    138: *> \param[out] BERR
                    139: *> \verbatim
                    140: *>          BERR is DOUBLE PRECISION array, dimension (NRHS)
                    141: *>          The componentwise relative backward error of each solution
                    142: *>          vector X(j) (i.e., the smallest relative change in
                    143: *>          any element of A or B that makes X(j) an exact solution).
                    144: *> \endverbatim
                    145: *>
                    146: *> \param[out] WORK
                    147: *> \verbatim
                    148: *>          WORK is COMPLEX*16 array, dimension (2*N)
                    149: *> \endverbatim
                    150: *>
                    151: *> \param[out] RWORK
                    152: *> \verbatim
                    153: *>          RWORK is DOUBLE PRECISION array, dimension (N)
                    154: *> \endverbatim
                    155: *>
                    156: *> \param[out] INFO
                    157: *> \verbatim
                    158: *>          INFO is INTEGER
                    159: *>          = 0:  successful exit
                    160: *>          < 0:  if INFO = -i, the i-th argument had an illegal value
                    161: *> \endverbatim
                    162: *
                    163: *> \par Internal Parameters:
                    164: *  =========================
                    165: *>
                    166: *> \verbatim
                    167: *>  ITMAX is the maximum number of steps of iterative refinement.
                    168: *> \endverbatim
                    169: *
                    170: *  Authors:
                    171: *  ========
                    172: *
1.15      bertrand  173: *> \author Univ. of Tennessee
                    174: *> \author Univ. of California Berkeley
                    175: *> \author Univ. of Colorado Denver
                    176: *> \author NAG Ltd.
1.9       bertrand  177: *
                    178: *> \ingroup complex16POcomputational
                    179: *
                    180: *  =====================================================================
1.1       bertrand  181:       SUBROUTINE ZPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
                    182:      $                   LDX, FERR, BERR, WORK, RWORK, INFO )
                    183: *
1.18    ! bertrand  184: *  -- LAPACK computational routine --
1.1       bertrand  185: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    186: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    187: *
                    188: *     .. Scalar Arguments ..
                    189:       CHARACTER          UPLO
                    190:       INTEGER            INFO, LDA, LDAF, LDB, LDX, N, NRHS
                    191: *     ..
                    192: *     .. Array Arguments ..
                    193:       DOUBLE PRECISION   BERR( * ), FERR( * ), RWORK( * )
                    194:       COMPLEX*16         A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
                    195:      $                   WORK( * ), X( LDX, * )
                    196: *     ..
                    197: *
                    198: *  ====================================================================
                    199: *
                    200: *     .. Parameters ..
                    201:       INTEGER            ITMAX
                    202:       PARAMETER          ( ITMAX = 5 )
                    203:       DOUBLE PRECISION   ZERO
                    204:       PARAMETER          ( ZERO = 0.0D+0 )
                    205:       COMPLEX*16         ONE
                    206:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ) )
                    207:       DOUBLE PRECISION   TWO
                    208:       PARAMETER          ( TWO = 2.0D+0 )
                    209:       DOUBLE PRECISION   THREE
                    210:       PARAMETER          ( THREE = 3.0D+0 )
                    211: *     ..
                    212: *     .. Local Scalars ..
                    213:       LOGICAL            UPPER
                    214:       INTEGER            COUNT, I, J, K, KASE, NZ
                    215:       DOUBLE PRECISION   EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
                    216:       COMPLEX*16         ZDUM
                    217: *     ..
                    218: *     .. Local Arrays ..
                    219:       INTEGER            ISAVE( 3 )
                    220: *     ..
                    221: *     .. External Subroutines ..
                    222:       EXTERNAL           XERBLA, ZAXPY, ZCOPY, ZHEMV, ZLACN2, ZPOTRS
                    223: *     ..
                    224: *     .. Intrinsic Functions ..
                    225:       INTRINSIC          ABS, DBLE, DIMAG, MAX
                    226: *     ..
                    227: *     .. External Functions ..
                    228:       LOGICAL            LSAME
                    229:       DOUBLE PRECISION   DLAMCH
                    230:       EXTERNAL           LSAME, DLAMCH
                    231: *     ..
                    232: *     .. Statement Functions ..
                    233:       DOUBLE PRECISION   CABS1
                    234: *     ..
                    235: *     .. Statement Function definitions ..
                    236:       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
                    237: *     ..
                    238: *     .. Executable Statements ..
                    239: *
                    240: *     Test the input parameters.
                    241: *
                    242:       INFO = 0
                    243:       UPPER = LSAME( UPLO, 'U' )
                    244:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
                    245:          INFO = -1
                    246:       ELSE IF( N.LT.0 ) THEN
                    247:          INFO = -2
                    248:       ELSE IF( NRHS.LT.0 ) THEN
                    249:          INFO = -3
                    250:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
                    251:          INFO = -5
                    252:       ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
                    253:          INFO = -7
                    254:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
                    255:          INFO = -9
                    256:       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
                    257:          INFO = -11
                    258:       END IF
                    259:       IF( INFO.NE.0 ) THEN
                    260:          CALL XERBLA( 'ZPORFS', -INFO )
                    261:          RETURN
                    262:       END IF
                    263: *
                    264: *     Quick return if possible
                    265: *
                    266:       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
                    267:          DO 10 J = 1, NRHS
                    268:             FERR( J ) = ZERO
                    269:             BERR( J ) = ZERO
                    270:    10    CONTINUE
                    271:          RETURN
                    272:       END IF
                    273: *
                    274: *     NZ = maximum number of nonzero elements in each row of A, plus 1
                    275: *
                    276:       NZ = N + 1
                    277:       EPS = DLAMCH( 'Epsilon' )
                    278:       SAFMIN = DLAMCH( 'Safe minimum' )
                    279:       SAFE1 = NZ*SAFMIN
                    280:       SAFE2 = SAFE1 / EPS
                    281: *
                    282: *     Do for each right hand side
                    283: *
                    284:       DO 140 J = 1, NRHS
                    285: *
                    286:          COUNT = 1
                    287:          LSTRES = THREE
                    288:    20    CONTINUE
                    289: *
                    290: *        Loop until stopping criterion is satisfied.
                    291: *
                    292: *        Compute residual R = B - A * X
                    293: *
                    294:          CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
                    295:          CALL ZHEMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE, WORK, 1 )
                    296: *
                    297: *        Compute componentwise relative backward error from formula
                    298: *
                    299: *        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
                    300: *
                    301: *        where abs(Z) is the componentwise absolute value of the matrix
                    302: *        or vector Z.  If the i-th component of the denominator is less
                    303: *        than SAFE2, then SAFE1 is added to the i-th components of the
                    304: *        numerator and denominator before dividing.
                    305: *
                    306:          DO 30 I = 1, N
                    307:             RWORK( I ) = CABS1( B( I, J ) )
                    308:    30    CONTINUE
                    309: *
                    310: *        Compute abs(A)*abs(X) + abs(B).
                    311: *
                    312:          IF( UPPER ) THEN
                    313:             DO 50 K = 1, N
                    314:                S = ZERO
                    315:                XK = CABS1( X( K, J ) )
                    316:                DO 40 I = 1, K - 1
                    317:                   RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
                    318:                   S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
                    319:    40          CONTINUE
                    320:                RWORK( K ) = RWORK( K ) + ABS( DBLE( A( K, K ) ) )*XK + S
                    321:    50       CONTINUE
                    322:          ELSE
                    323:             DO 70 K = 1, N
                    324:                S = ZERO
                    325:                XK = CABS1( X( K, J ) )
                    326:                RWORK( K ) = RWORK( K ) + ABS( DBLE( A( K, K ) ) )*XK
                    327:                DO 60 I = K + 1, N
                    328:                   RWORK( I ) = RWORK( I ) + CABS1( A( I, K ) )*XK
                    329:                   S = S + CABS1( A( I, K ) )*CABS1( X( I, J ) )
                    330:    60          CONTINUE
                    331:                RWORK( K ) = RWORK( K ) + S
                    332:    70       CONTINUE
                    333:          END IF
                    334:          S = ZERO
                    335:          DO 80 I = 1, N
                    336:             IF( RWORK( I ).GT.SAFE2 ) THEN
                    337:                S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
                    338:             ELSE
                    339:                S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
                    340:      $             ( RWORK( I )+SAFE1 ) )
                    341:             END IF
                    342:    80    CONTINUE
                    343:          BERR( J ) = S
                    344: *
                    345: *        Test stopping criterion. Continue iterating if
                    346: *           1) The residual BERR(J) is larger than machine epsilon, and
                    347: *           2) BERR(J) decreased by at least a factor of 2 during the
                    348: *              last iteration, and
                    349: *           3) At most ITMAX iterations tried.
                    350: *
                    351:          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
                    352:      $       COUNT.LE.ITMAX ) THEN
                    353: *
                    354: *           Update solution and try again.
                    355: *
                    356:             CALL ZPOTRS( UPLO, N, 1, AF, LDAF, WORK, N, INFO )
                    357:             CALL ZAXPY( N, ONE, WORK, 1, X( 1, J ), 1 )
                    358:             LSTRES = BERR( J )
                    359:             COUNT = COUNT + 1
                    360:             GO TO 20
                    361:          END IF
                    362: *
                    363: *        Bound error from formula
                    364: *
                    365: *        norm(X - XTRUE) / norm(X) .le. FERR =
                    366: *        norm( abs(inv(A))*
                    367: *           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
                    368: *
                    369: *        where
                    370: *          norm(Z) is the magnitude of the largest component of Z
                    371: *          inv(A) is the inverse of A
                    372: *          abs(Z) is the componentwise absolute value of the matrix or
                    373: *             vector Z
                    374: *          NZ is the maximum number of nonzeros in any row of A, plus 1
                    375: *          EPS is machine epsilon
                    376: *
                    377: *        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
                    378: *        is incremented by SAFE1 if the i-th component of
                    379: *        abs(A)*abs(X) + abs(B) is less than SAFE2.
                    380: *
                    381: *        Use ZLACN2 to estimate the infinity-norm of the matrix
                    382: *           inv(A) * diag(W),
                    383: *        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
                    384: *
                    385:          DO 90 I = 1, N
                    386:             IF( RWORK( I ).GT.SAFE2 ) THEN
                    387:                RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
                    388:             ELSE
                    389:                RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
                    390:      $                      SAFE1
                    391:             END IF
                    392:    90    CONTINUE
                    393: *
                    394:          KASE = 0
                    395:   100    CONTINUE
                    396:          CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
                    397:          IF( KASE.NE.0 ) THEN
                    398:             IF( KASE.EQ.1 ) THEN
                    399: *
1.8       bertrand  400: *              Multiply by diag(W)*inv(A**H).
1.1       bertrand  401: *
                    402:                CALL ZPOTRS( UPLO, N, 1, AF, LDAF, WORK, N, INFO )
                    403:                DO 110 I = 1, N
                    404:                   WORK( I ) = RWORK( I )*WORK( I )
                    405:   110          CONTINUE
                    406:             ELSE IF( KASE.EQ.2 ) THEN
                    407: *
                    408: *              Multiply by inv(A)*diag(W).
                    409: *
                    410:                DO 120 I = 1, N
                    411:                   WORK( I ) = RWORK( I )*WORK( I )
                    412:   120          CONTINUE
                    413:                CALL ZPOTRS( UPLO, N, 1, AF, LDAF, WORK, N, INFO )
                    414:             END IF
                    415:             GO TO 100
                    416:          END IF
                    417: *
                    418: *        Normalize error.
                    419: *
                    420:          LSTRES = ZERO
                    421:          DO 130 I = 1, N
                    422:             LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
                    423:   130    CONTINUE
                    424:          IF( LSTRES.NE.ZERO )
                    425:      $      FERR( J ) = FERR( J ) / LSTRES
                    426: *
                    427:   140 CONTINUE
                    428: *
                    429:       RETURN
                    430: *
                    431: *     End of ZPORFS
                    432: *
                    433:       END

CVSweb interface <joel.bertrand@systella.fr>