File:  [local] / rpl / lapack / lapack / dgtrfs.f
Revision 1.18: download - view: text, annotated - select for diffs - revision graph
Mon Aug 7 08:38:51 2023 UTC (8 months, 3 weeks ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_35, rpl-4_1_34, HEAD
Première mise à jour de lapack et blas.

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

CVSweb interface <joel.bertrand@systella.fr>