File:  [local] / rpl / lapack / lapack / dsytrs.f
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Jan 26 15:22:46 2010 UTC (14 years, 3 months ago) by bertrand
Branches: JKB
CVS tags: start, rpl-4_0_14, rpl-4_0_13, rpl-4_0_12, rpl-4_0_11, rpl-4_0_10


Commit initial.

    1:       SUBROUTINE DSYTRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
    2: *
    3: *  -- LAPACK routine (version 3.2) --
    4: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
    5: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
    6: *     November 2006
    7: *
    8: *     .. Scalar Arguments ..
    9:       CHARACTER          UPLO
   10:       INTEGER            INFO, LDA, LDB, N, NRHS
   11: *     ..
   12: *     .. Array Arguments ..
   13:       INTEGER            IPIV( * )
   14:       DOUBLE PRECISION   A( LDA, * ), B( LDB, * )
   15: *     ..
   16: *
   17: *  Purpose
   18: *  =======
   19: *
   20: *  DSYTRS solves a system of linear equations A*X = B with a real
   21: *  symmetric matrix A using the factorization A = U*D*U**T or
   22: *  A = L*D*L**T computed by DSYTRF.
   23: *
   24: *  Arguments
   25: *  =========
   26: *
   27: *  UPLO    (input) CHARACTER*1
   28: *          Specifies whether the details of the factorization are stored
   29: *          as an upper or lower triangular matrix.
   30: *          = 'U':  Upper triangular, form is A = U*D*U**T;
   31: *          = 'L':  Lower triangular, form is A = L*D*L**T.
   32: *
   33: *  N       (input) INTEGER
   34: *          The order of the matrix A.  N >= 0.
   35: *
   36: *  NRHS    (input) INTEGER
   37: *          The number of right hand sides, i.e., the number of columns
   38: *          of the matrix B.  NRHS >= 0.
   39: *
   40: *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
   41: *          The block diagonal matrix D and the multipliers used to
   42: *          obtain the factor U or L as computed by DSYTRF.
   43: *
   44: *  LDA     (input) INTEGER
   45: *          The leading dimension of the array A.  LDA >= max(1,N).
   46: *
   47: *  IPIV    (input) INTEGER array, dimension (N)
   48: *          Details of the interchanges and the block structure of D
   49: *          as determined by DSYTRF.
   50: *
   51: *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
   52: *          On entry, the right hand side matrix B.
   53: *          On exit, the solution matrix X.
   54: *
   55: *  LDB     (input) INTEGER
   56: *          The leading dimension of the array B.  LDB >= max(1,N).
   57: *
   58: *  INFO    (output) INTEGER
   59: *          = 0:  successful exit
   60: *          < 0:  if INFO = -i, the i-th argument had an illegal value
   61: *
   62: *  =====================================================================
   63: *
   64: *     .. Parameters ..
   65:       DOUBLE PRECISION   ONE
   66:       PARAMETER          ( ONE = 1.0D+0 )
   67: *     ..
   68: *     .. Local Scalars ..
   69:       LOGICAL            UPPER
   70:       INTEGER            J, K, KP
   71:       DOUBLE PRECISION   AK, AKM1, AKM1K, BK, BKM1, DENOM
   72: *     ..
   73: *     .. External Functions ..
   74:       LOGICAL            LSAME
   75:       EXTERNAL           LSAME
   76: *     ..
   77: *     .. External Subroutines ..
   78:       EXTERNAL           DGEMV, DGER, DSCAL, DSWAP, XERBLA
   79: *     ..
   80: *     .. Intrinsic Functions ..
   81:       INTRINSIC          MAX
   82: *     ..
   83: *     .. Executable Statements ..
   84: *
   85:       INFO = 0
   86:       UPPER = LSAME( UPLO, 'U' )
   87:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
   88:          INFO = -1
   89:       ELSE IF( N.LT.0 ) THEN
   90:          INFO = -2
   91:       ELSE IF( NRHS.LT.0 ) THEN
   92:          INFO = -3
   93:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
   94:          INFO = -5
   95:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
   96:          INFO = -8
   97:       END IF
   98:       IF( INFO.NE.0 ) THEN
   99:          CALL XERBLA( 'DSYTRS', -INFO )
  100:          RETURN
  101:       END IF
  102: *
  103: *     Quick return if possible
  104: *
  105:       IF( N.EQ.0 .OR. NRHS.EQ.0 )
  106:      $   RETURN
  107: *
  108:       IF( UPPER ) THEN
  109: *
  110: *        Solve A*X = B, where A = U*D*U'.
  111: *
  112: *        First solve U*D*X = B, overwriting B with X.
  113: *
  114: *        K is the main loop index, decreasing from N to 1 in steps of
  115: *        1 or 2, depending on the size of the diagonal blocks.
  116: *
  117:          K = N
  118:    10    CONTINUE
  119: *
  120: *        If K < 1, exit from loop.
  121: *
  122:          IF( K.LT.1 )
  123:      $      GO TO 30
  124: *
  125:          IF( IPIV( K ).GT.0 ) THEN
  126: *
  127: *           1 x 1 diagonal block
  128: *
  129: *           Interchange rows K and IPIV(K).
  130: *
  131:             KP = IPIV( K )
  132:             IF( KP.NE.K )
  133:      $         CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  134: *
  135: *           Multiply by inv(U(K)), where U(K) is the transformation
  136: *           stored in column K of A.
  137: *
  138:             CALL DGER( K-1, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
  139:      $                 B( 1, 1 ), LDB )
  140: *
  141: *           Multiply by the inverse of the diagonal block.
  142: *
  143:             CALL DSCAL( NRHS, ONE / A( K, K ), B( K, 1 ), LDB )
  144:             K = K - 1
  145:          ELSE
  146: *
  147: *           2 x 2 diagonal block
  148: *
  149: *           Interchange rows K-1 and -IPIV(K).
  150: *
  151:             KP = -IPIV( K )
  152:             IF( KP.NE.K-1 )
  153:      $         CALL DSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
  154: *
  155: *           Multiply by inv(U(K)), where U(K) is the transformation
  156: *           stored in columns K-1 and K of A.
  157: *
  158:             CALL DGER( K-2, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
  159:      $                 B( 1, 1 ), LDB )
  160:             CALL DGER( K-2, NRHS, -ONE, A( 1, K-1 ), 1, B( K-1, 1 ),
  161:      $                 LDB, B( 1, 1 ), LDB )
  162: *
  163: *           Multiply by the inverse of the diagonal block.
  164: *
  165:             AKM1K = A( K-1, K )
  166:             AKM1 = A( K-1, K-1 ) / AKM1K
  167:             AK = A( K, K ) / AKM1K
  168:             DENOM = AKM1*AK - ONE
  169:             DO 20 J = 1, NRHS
  170:                BKM1 = B( K-1, J ) / AKM1K
  171:                BK = B( K, J ) / AKM1K
  172:                B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
  173:                B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
  174:    20       CONTINUE
  175:             K = K - 2
  176:          END IF
  177: *
  178:          GO TO 10
  179:    30    CONTINUE
  180: *
  181: *        Next solve U'*X = B, overwriting B with X.
  182: *
  183: *        K is the main loop index, increasing from 1 to N in steps of
  184: *        1 or 2, depending on the size of the diagonal blocks.
  185: *
  186:          K = 1
  187:    40    CONTINUE
  188: *
  189: *        If K > N, exit from loop.
  190: *
  191:          IF( K.GT.N )
  192:      $      GO TO 50
  193: *
  194:          IF( IPIV( K ).GT.0 ) THEN
  195: *
  196: *           1 x 1 diagonal block
  197: *
  198: *           Multiply by inv(U'(K)), where U(K) is the transformation
  199: *           stored in column K of A.
  200: *
  201:             CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, A( 1, K ),
  202:      $                  1, ONE, B( K, 1 ), LDB )
  203: *
  204: *           Interchange rows K and IPIV(K).
  205: *
  206:             KP = IPIV( K )
  207:             IF( KP.NE.K )
  208:      $         CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  209:             K = K + 1
  210:          ELSE
  211: *
  212: *           2 x 2 diagonal block
  213: *
  214: *           Multiply by inv(U'(K+1)), where U(K+1) is the transformation
  215: *           stored in columns K and K+1 of A.
  216: *
  217:             CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, A( 1, K ),
  218:      $                  1, ONE, B( K, 1 ), LDB )
  219:             CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB,
  220:      $                  A( 1, K+1 ), 1, ONE, B( K+1, 1 ), LDB )
  221: *
  222: *           Interchange rows K and -IPIV(K).
  223: *
  224:             KP = -IPIV( K )
  225:             IF( KP.NE.K )
  226:      $         CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  227:             K = K + 2
  228:          END IF
  229: *
  230:          GO TO 40
  231:    50    CONTINUE
  232: *
  233:       ELSE
  234: *
  235: *        Solve A*X = B, where A = L*D*L'.
  236: *
  237: *        First solve L*D*X = B, overwriting B with X.
  238: *
  239: *        K is the main loop index, increasing from 1 to N in steps of
  240: *        1 or 2, depending on the size of the diagonal blocks.
  241: *
  242:          K = 1
  243:    60    CONTINUE
  244: *
  245: *        If K > N, exit from loop.
  246: *
  247:          IF( K.GT.N )
  248:      $      GO TO 80
  249: *
  250:          IF( IPIV( K ).GT.0 ) THEN
  251: *
  252: *           1 x 1 diagonal block
  253: *
  254: *           Interchange rows K and IPIV(K).
  255: *
  256:             KP = IPIV( K )
  257:             IF( KP.NE.K )
  258:      $         CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  259: *
  260: *           Multiply by inv(L(K)), where L(K) is the transformation
  261: *           stored in column K of A.
  262: *
  263:             IF( K.LT.N )
  264:      $         CALL DGER( N-K, NRHS, -ONE, A( K+1, K ), 1, B( K, 1 ),
  265:      $                    LDB, B( K+1, 1 ), LDB )
  266: *
  267: *           Multiply by the inverse of the diagonal block.
  268: *
  269:             CALL DSCAL( NRHS, ONE / A( K, K ), B( K, 1 ), LDB )
  270:             K = K + 1
  271:          ELSE
  272: *
  273: *           2 x 2 diagonal block
  274: *
  275: *           Interchange rows K+1 and -IPIV(K).
  276: *
  277:             KP = -IPIV( K )
  278:             IF( KP.NE.K+1 )
  279:      $         CALL DSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
  280: *
  281: *           Multiply by inv(L(K)), where L(K) is the transformation
  282: *           stored in columns K and K+1 of A.
  283: *
  284:             IF( K.LT.N-1 ) THEN
  285:                CALL DGER( N-K-1, NRHS, -ONE, A( K+2, K ), 1, B( K, 1 ),
  286:      $                    LDB, B( K+2, 1 ), LDB )
  287:                CALL DGER( N-K-1, NRHS, -ONE, A( K+2, K+1 ), 1,
  288:      $                    B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
  289:             END IF
  290: *
  291: *           Multiply by the inverse of the diagonal block.
  292: *
  293:             AKM1K = A( K+1, K )
  294:             AKM1 = A( K, K ) / AKM1K
  295:             AK = A( K+1, K+1 ) / AKM1K
  296:             DENOM = AKM1*AK - ONE
  297:             DO 70 J = 1, NRHS
  298:                BKM1 = B( K, J ) / AKM1K
  299:                BK = B( K+1, J ) / AKM1K
  300:                B( K, J ) = ( AK*BKM1-BK ) / DENOM
  301:                B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
  302:    70       CONTINUE
  303:             K = K + 2
  304:          END IF
  305: *
  306:          GO TO 60
  307:    80    CONTINUE
  308: *
  309: *        Next solve L'*X = B, overwriting B with X.
  310: *
  311: *        K is the main loop index, decreasing from N to 1 in steps of
  312: *        1 or 2, depending on the size of the diagonal blocks.
  313: *
  314:          K = N
  315:    90    CONTINUE
  316: *
  317: *        If K < 1, exit from loop.
  318: *
  319:          IF( K.LT.1 )
  320:      $      GO TO 100
  321: *
  322:          IF( IPIV( K ).GT.0 ) THEN
  323: *
  324: *           1 x 1 diagonal block
  325: *
  326: *           Multiply by inv(L'(K)), where L(K) is the transformation
  327: *           stored in column K of A.
  328: *
  329:             IF( K.LT.N )
  330:      $         CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
  331:      $                     LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
  332: *
  333: *           Interchange rows K and IPIV(K).
  334: *
  335:             KP = IPIV( K )
  336:             IF( KP.NE.K )
  337:      $         CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  338:             K = K - 1
  339:          ELSE
  340: *
  341: *           2 x 2 diagonal block
  342: *
  343: *           Multiply by inv(L'(K-1)), where L(K-1) is the transformation
  344: *           stored in columns K-1 and K of A.
  345: *
  346:             IF( K.LT.N ) THEN
  347:                CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
  348:      $                     LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
  349:                CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
  350:      $                     LDB, A( K+1, K-1 ), 1, ONE, B( K-1, 1 ),
  351:      $                     LDB )
  352:             END IF
  353: *
  354: *           Interchange rows K and -IPIV(K).
  355: *
  356:             KP = -IPIV( K )
  357:             IF( KP.NE.K )
  358:      $         CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
  359:             K = K - 2
  360:          END IF
  361: *
  362:          GO TO 90
  363:   100    CONTINUE
  364:       END IF
  365: *
  366:       RETURN
  367: *
  368: *     End of DSYTRS
  369: *
  370:       END

CVSweb interface <joel.bertrand@systella.fr>