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

CVSweb interface <joel.bertrand@systella.fr>