Annotation of rpl/lapack/lapack/dpstrf.f, revision 1.9

1.6       bertrand    1: *> \brief \b DPSTRF
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
                      5: * Online html documentation available at 
                      6: *            http://www.netlib.org/lapack/explore-html/ 
                      7: *
                      8: *> \htmlonly
                      9: *> Download DPSTRF + dependencies 
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpstrf.f"> 
                     11: *> [TGZ]</a> 
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpstrf.f"> 
                     13: *> [ZIP]</a> 
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpstrf.f"> 
                     15: *> [TXT]</a>
                     16: *> \endhtmlonly 
                     17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE DPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
                     22: * 
                     23: *       .. Scalar Arguments ..
                     24: *       DOUBLE PRECISION   TOL
                     25: *       INTEGER            INFO, LDA, N, RANK
                     26: *       CHARACTER          UPLO
                     27: *       ..
                     28: *       .. Array Arguments ..
                     29: *       DOUBLE PRECISION   A( LDA, * ), WORK( 2*N )
                     30: *       INTEGER            PIV( N )
                     31: *       ..
                     32: *  
                     33: *
                     34: *> \par Purpose:
                     35: *  =============
                     36: *>
                     37: *> \verbatim
                     38: *>
                     39: *> DPSTRF computes the Cholesky factorization with complete
                     40: *> pivoting of a real symmetric positive semidefinite matrix A.
                     41: *>
                     42: *> The factorization has the form
                     43: *>    P**T * A * P = U**T * U ,  if UPLO = 'U',
                     44: *>    P**T * A * P = L  * L**T,  if UPLO = 'L',
                     45: *> where U is an upper triangular matrix and L is lower triangular, and
                     46: *> P is stored as vector PIV.
                     47: *>
                     48: *> This algorithm does not attempt to check that A is positive
                     49: *> semidefinite. This version of the algorithm calls level 3 BLAS.
                     50: *> \endverbatim
                     51: *
                     52: *  Arguments:
                     53: *  ==========
                     54: *
                     55: *> \param[in] UPLO
                     56: *> \verbatim
                     57: *>          UPLO is CHARACTER*1
                     58: *>          Specifies whether the upper or lower triangular part of the
                     59: *>          symmetric matrix A is stored.
                     60: *>          = 'U':  Upper triangular
                     61: *>          = 'L':  Lower triangular
                     62: *> \endverbatim
                     63: *>
                     64: *> \param[in] N
                     65: *> \verbatim
                     66: *>          N is INTEGER
                     67: *>          The order of the matrix A.  N >= 0.
                     68: *> \endverbatim
                     69: *>
                     70: *> \param[in,out] A
                     71: *> \verbatim
                     72: *>          A is DOUBLE PRECISION array, dimension (LDA,N)
                     73: *>          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
                     74: *>          n by n upper triangular part of A contains the upper
                     75: *>          triangular part of the matrix A, and the strictly lower
                     76: *>          triangular part of A is not referenced.  If UPLO = 'L', the
                     77: *>          leading n by n lower triangular part of A contains the lower
                     78: *>          triangular part of the matrix A, and the strictly upper
                     79: *>          triangular part of A is not referenced.
                     80: *>
                     81: *>          On exit, if INFO = 0, the factor U or L from the Cholesky
                     82: *>          factorization as above.
                     83: *> \endverbatim
                     84: *>
                     85: *> \param[in] LDA
                     86: *> \verbatim
                     87: *>          LDA is INTEGER
                     88: *>          The leading dimension of the array A.  LDA >= max(1,N).
                     89: *> \endverbatim
                     90: *>
                     91: *> \param[out] PIV
                     92: *> \verbatim
                     93: *>          PIV is INTEGER array, dimension (N)
                     94: *>          PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
                     95: *> \endverbatim
                     96: *>
                     97: *> \param[out] RANK
                     98: *> \verbatim
                     99: *>          RANK is INTEGER
                    100: *>          The rank of A given by the number of steps the algorithm
                    101: *>          completed.
                    102: *> \endverbatim
                    103: *>
                    104: *> \param[in] TOL
                    105: *> \verbatim
                    106: *>          TOL is DOUBLE PRECISION
                    107: *>          User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) )
                    108: *>          will be used. The algorithm terminates at the (K-1)st step
                    109: *>          if the pivot <= TOL.
                    110: *> \endverbatim
                    111: *>
                    112: *> \param[out] WORK
                    113: *> \verbatim
                    114: *>          WORK is DOUBLE PRECISION array, dimension (2*N)
                    115: *>          Work space.
                    116: *> \endverbatim
                    117: *>
                    118: *> \param[out] INFO
                    119: *> \verbatim
                    120: *>          INFO is INTEGER
                    121: *>          < 0: If INFO = -K, the K-th argument had an illegal value,
                    122: *>          = 0: algorithm completed successfully, and
                    123: *>          > 0: the matrix A is either rank deficient with computed rank
                    124: *>               as returned in RANK, or is indefinite.  See Section 7 of
                    125: *>               LAPACK Working Note #161 for further information.
                    126: *> \endverbatim
                    127: *
                    128: *  Authors:
                    129: *  ========
                    130: *
                    131: *> \author Univ. of Tennessee 
                    132: *> \author Univ. of California Berkeley 
                    133: *> \author Univ. of Colorado Denver 
                    134: *> \author NAG Ltd. 
                    135: *
                    136: *> \date November 2011
                    137: *
                    138: *> \ingroup doubleOTHERcomputational
                    139: *
                    140: *  =====================================================================
1.1       bertrand  141:       SUBROUTINE DPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
                    142: *
1.6       bertrand  143: *  -- LAPACK computational routine (version 3.4.0) --
                    144: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    145: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    146: *     November 2011
1.1       bertrand  147: *
                    148: *     .. Scalar Arguments ..
                    149:       DOUBLE PRECISION   TOL
                    150:       INTEGER            INFO, LDA, N, RANK
                    151:       CHARACTER          UPLO
                    152: *     ..
                    153: *     .. Array Arguments ..
                    154:       DOUBLE PRECISION   A( LDA, * ), WORK( 2*N )
                    155:       INTEGER            PIV( N )
                    156: *     ..
                    157: *
                    158: *  =====================================================================
                    159: *
                    160: *     .. Parameters ..
                    161:       DOUBLE PRECISION   ONE, ZERO
                    162:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
                    163: *     ..
                    164: *     .. Local Scalars ..
                    165:       DOUBLE PRECISION   AJJ, DSTOP, DTEMP
                    166:       INTEGER            I, ITEMP, J, JB, K, NB, PVT
                    167:       LOGICAL            UPPER
                    168: *     ..
                    169: *     .. External Functions ..
                    170:       DOUBLE PRECISION   DLAMCH
                    171:       INTEGER            ILAENV
                    172:       LOGICAL            LSAME, DISNAN
                    173:       EXTERNAL           DLAMCH, ILAENV, LSAME, DISNAN
                    174: *     ..
                    175: *     .. External Subroutines ..
                    176:       EXTERNAL           DGEMV, DPSTF2, DSCAL, DSWAP, DSYRK, XERBLA
                    177: *     ..
                    178: *     .. Intrinsic Functions ..
                    179:       INTRINSIC          MAX, MIN, SQRT, MAXLOC
                    180: *     ..
                    181: *     .. Executable Statements ..
                    182: *
                    183: *     Test the input parameters.
                    184: *
                    185:       INFO = 0
                    186:       UPPER = LSAME( UPLO, 'U' )
                    187:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
                    188:          INFO = -1
                    189:       ELSE IF( N.LT.0 ) THEN
                    190:          INFO = -2
                    191:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
                    192:          INFO = -4
                    193:       END IF
                    194:       IF( INFO.NE.0 ) THEN
                    195:          CALL XERBLA( 'DPSTRF', -INFO )
                    196:          RETURN
                    197:       END IF
                    198: *
                    199: *     Quick return if possible
                    200: *
                    201:       IF( N.EQ.0 )
                    202:      $   RETURN
                    203: *
                    204: *     Get block size
                    205: *
                    206:       NB = ILAENV( 1, 'DPOTRF', UPLO, N, -1, -1, -1 )
                    207:       IF( NB.LE.1 .OR. NB.GE.N ) THEN
                    208: *
                    209: *        Use unblocked code
                    210: *
                    211:          CALL DPSTF2( UPLO, N, A( 1, 1 ), LDA, PIV, RANK, TOL, WORK,
                    212:      $                INFO )
                    213:          GO TO 200
                    214: *
                    215:       ELSE
                    216: *
                    217: *     Initialize PIV
                    218: *
                    219:          DO 100 I = 1, N
                    220:             PIV( I ) = I
                    221:   100    CONTINUE
                    222: *
                    223: *     Compute stopping value
                    224: *
                    225:          PVT = 1
                    226:          AJJ = A( PVT, PVT )
                    227:          DO I = 2, N
                    228:             IF( A( I, I ).GT.AJJ ) THEN
                    229:                PVT = I
                    230:                AJJ = A( PVT, PVT )
                    231:             END IF
                    232:          END DO
                    233:          IF( AJJ.EQ.ZERO.OR.DISNAN( AJJ ) ) THEN
                    234:             RANK = 0
                    235:             INFO = 1
                    236:             GO TO 200
                    237:          END IF
                    238: *
                    239: *     Compute stopping value if not supplied
                    240: *
                    241:          IF( TOL.LT.ZERO ) THEN
                    242:             DSTOP = N * DLAMCH( 'Epsilon' ) * AJJ
                    243:          ELSE
                    244:             DSTOP = TOL
                    245:          END IF
                    246: *
                    247: *
                    248:          IF( UPPER ) THEN
                    249: *
1.5       bertrand  250: *           Compute the Cholesky factorization P**T * A * P = U**T * U
1.1       bertrand  251: *
                    252:             DO 140 K = 1, N, NB
                    253: *
                    254: *              Account for last block not being NB wide
                    255: *
                    256:                JB = MIN( NB, N-K+1 )
                    257: *
                    258: *              Set relevant part of first half of WORK to zero,
                    259: *              holds dot products
                    260: *
                    261:                DO 110 I = K, N
                    262:                   WORK( I ) = 0
                    263:   110          CONTINUE
                    264: *
                    265:                DO 130 J = K, K + JB - 1
                    266: *
                    267: *              Find pivot, test for exit, else swap rows and columns
                    268: *              Update dot products, compute possible pivots which are
                    269: *              stored in the second half of WORK
                    270: *
                    271:                   DO 120 I = J, N
                    272: *
                    273:                      IF( J.GT.K ) THEN
                    274:                         WORK( I ) = WORK( I ) + A( J-1, I )**2
                    275:                      END IF
                    276:                      WORK( N+I ) = A( I, I ) - WORK( I )
                    277: *
                    278:   120             CONTINUE
                    279: *
                    280:                   IF( J.GT.1 ) THEN
                    281:                      ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
                    282:                      PVT = ITEMP + J - 1
                    283:                      AJJ = WORK( N+PVT )
                    284:                      IF( AJJ.LE.DSTOP.OR.DISNAN( AJJ ) ) THEN
                    285:                         A( J, J ) = AJJ
                    286:                         GO TO 190
                    287:                      END IF
                    288:                   END IF
                    289: *
                    290:                   IF( J.NE.PVT ) THEN
                    291: *
                    292: *                    Pivot OK, so can now swap pivot rows and columns
                    293: *
                    294:                      A( PVT, PVT ) = A( J, J )
                    295:                      CALL DSWAP( J-1, A( 1, J ), 1, A( 1, PVT ), 1 )
                    296:                      IF( PVT.LT.N )
                    297:      $                  CALL DSWAP( N-PVT, A( J, PVT+1 ), LDA,
                    298:      $                              A( PVT, PVT+1 ), LDA )
                    299:                      CALL DSWAP( PVT-J-1, A( J, J+1 ), LDA,
                    300:      $                           A( J+1, PVT ), 1 )
                    301: *
                    302: *                    Swap dot products and PIV
                    303: *
                    304:                      DTEMP = WORK( J )
                    305:                      WORK( J ) = WORK( PVT )
                    306:                      WORK( PVT ) = DTEMP
                    307:                      ITEMP = PIV( PVT )
                    308:                      PIV( PVT ) = PIV( J )
                    309:                      PIV( J ) = ITEMP
                    310:                   END IF
                    311: *
                    312:                   AJJ = SQRT( AJJ )
                    313:                   A( J, J ) = AJJ
                    314: *
                    315: *                 Compute elements J+1:N of row J.
                    316: *
                    317:                   IF( J.LT.N ) THEN
                    318:                      CALL DGEMV( 'Trans', J-K, N-J, -ONE, A( K, J+1 ),
                    319:      $                           LDA, A( K, J ), 1, ONE, A( J, J+1 ),
                    320:      $                           LDA )
                    321:                      CALL DSCAL( N-J, ONE / AJJ, A( J, J+1 ), LDA )
                    322:                   END IF
                    323: *
                    324:   130          CONTINUE
                    325: *
                    326: *              Update trailing matrix, J already incremented
                    327: *
                    328:                IF( K+JB.LE.N ) THEN
                    329:                   CALL DSYRK( 'Upper', 'Trans', N-J+1, JB, -ONE,
                    330:      $                        A( K, J ), LDA, ONE, A( J, J ), LDA )
                    331:                END IF
                    332: *
                    333:   140       CONTINUE
                    334: *
                    335:          ELSE
                    336: *
1.5       bertrand  337: *        Compute the Cholesky factorization P**T * A * P = L * L**T
1.1       bertrand  338: *
                    339:             DO 180 K = 1, N, NB
                    340: *
                    341: *              Account for last block not being NB wide
                    342: *
                    343:                JB = MIN( NB, N-K+1 )
                    344: *
                    345: *              Set relevant part of first half of WORK to zero,
                    346: *              holds dot products
                    347: *
                    348:                DO 150 I = K, N
                    349:                   WORK( I ) = 0
                    350:   150          CONTINUE
                    351: *
                    352:                DO 170 J = K, K + JB - 1
                    353: *
                    354: *              Find pivot, test for exit, else swap rows and columns
                    355: *              Update dot products, compute possible pivots which are
                    356: *              stored in the second half of WORK
                    357: *
                    358:                   DO 160 I = J, N
                    359: *
                    360:                      IF( J.GT.K ) THEN
                    361:                         WORK( I ) = WORK( I ) + A( I, J-1 )**2
                    362:                      END IF
                    363:                      WORK( N+I ) = A( I, I ) - WORK( I )
                    364: *
                    365:   160             CONTINUE
                    366: *
                    367:                   IF( J.GT.1 ) THEN
                    368:                      ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
                    369:                      PVT = ITEMP + J - 1
                    370:                      AJJ = WORK( N+PVT )
                    371:                      IF( AJJ.LE.DSTOP.OR.DISNAN( AJJ ) ) THEN
                    372:                         A( J, J ) = AJJ
                    373:                         GO TO 190
                    374:                      END IF
                    375:                   END IF
                    376: *
                    377:                   IF( J.NE.PVT ) THEN
                    378: *
                    379: *                    Pivot OK, so can now swap pivot rows and columns
                    380: *
                    381:                      A( PVT, PVT ) = A( J, J )
                    382:                      CALL DSWAP( J-1, A( J, 1 ), LDA, A( PVT, 1 ), LDA )
                    383:                      IF( PVT.LT.N )
                    384:      $                  CALL DSWAP( N-PVT, A( PVT+1, J ), 1,
                    385:      $                              A( PVT+1, PVT ), 1 )
                    386:                      CALL DSWAP( PVT-J-1, A( J+1, J ), 1, A( PVT, J+1 ),
                    387:      $                           LDA )
                    388: *
                    389: *                    Swap dot products and PIV
                    390: *
                    391:                      DTEMP = WORK( J )
                    392:                      WORK( J ) = WORK( PVT )
                    393:                      WORK( PVT ) = DTEMP
                    394:                      ITEMP = PIV( PVT )
                    395:                      PIV( PVT ) = PIV( J )
                    396:                      PIV( J ) = ITEMP
                    397:                   END IF
                    398: *
                    399:                   AJJ = SQRT( AJJ )
                    400:                   A( J, J ) = AJJ
                    401: *
                    402: *                 Compute elements J+1:N of column J.
                    403: *
                    404:                   IF( J.LT.N ) THEN
                    405:                      CALL DGEMV( 'No Trans', N-J, J-K, -ONE,
                    406:      $                           A( J+1, K ), LDA, A( J, K ), LDA, ONE,
                    407:      $                           A( J+1, J ), 1 )
                    408:                      CALL DSCAL( N-J, ONE / AJJ, A( J+1, J ), 1 )
                    409:                   END IF
                    410: *
                    411:   170          CONTINUE
                    412: *
                    413: *              Update trailing matrix, J already incremented
                    414: *
                    415:                IF( K+JB.LE.N ) THEN
                    416:                   CALL DSYRK( 'Lower', 'No Trans', N-J+1, JB, -ONE,
                    417:      $                        A( J, K ), LDA, ONE, A( J, J ), LDA )
                    418:                END IF
                    419: *
                    420:   180       CONTINUE
                    421: *
                    422:          END IF
                    423:       END IF
                    424: *
                    425: *     Ran to completion, A has full rank
                    426: *
                    427:       RANK = N
                    428: *
                    429:       GO TO 200
                    430:   190 CONTINUE
                    431: *
                    432: *     Rank is the number of steps completed.  Set INFO = 1 to signal
                    433: *     that the factorization cannot be used to solve a system.
                    434: *
                    435:       RANK = J - 1
                    436:       INFO = 1
                    437: *
                    438:   200 CONTINUE
                    439:       RETURN
                    440: *
                    441: *     End of DPSTRF
                    442: *
                    443:       END

CVSweb interface <joel.bertrand@systella.fr>