Annotation of rpl/lapack/lapack/zlasyf_rook.f, revision 1.6

1.1       bertrand    1: *> \brief \b ZLASYF_ROOK computes a partial factorization of a complex symmetric matrix using the bounded Bunch-Kaufman ("rook") diagonal pivoting method.
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
                      5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
                      7: *
                      8: *> \htmlonly
                      9: *> Download ZLASYF_ROOK + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlasyf_rook.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlasyf_rook.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlasyf_rook.f">
                     15: *> [TXT]</a>
                     16: *> \endhtmlonly
                     17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZLASYF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
                     22: *
                     23: *       .. Scalar Arguments ..
                     24: *       CHARACTER          UPLO
                     25: *       INTEGER            INFO, KB, LDA, LDW, N, NB
                     26: *       ..
                     27: *       .. Array Arguments ..
                     28: *       INTEGER            IPIV( * )
                     29: *       COMPLEX*16         A( LDA, * ), W( LDW, * )
                     30: *       ..
                     31: *
                     32: *
                     33: *> \par Purpose:
                     34: *  =============
                     35: *>
                     36: *> \verbatim
                     37: *>
                     38: *> ZLASYF_ROOK computes a partial factorization of a complex symmetric
                     39: *> matrix A using the bounded Bunch-Kaufman ("rook") diagonal
                     40: *> pivoting method. The partial factorization has the form:
                     41: *>
                     42: *> A  =  ( I  U12 ) ( A11  0  ) (  I       0    )  if UPLO = 'U', or:
                     43: *>       ( 0  U22 ) (  0   D  ) ( U12**T U22**T )
                     44: *>
                     45: *> A  =  ( L11  0 ) (  D   0  ) ( L11**T L21**T )  if UPLO = 'L'
                     46: *>       ( L21  I ) (  0  A22 ) (  0       I    )
                     47: *>
                     48: *> where the order of D is at most NB. The actual order is returned in
                     49: *> the argument KB, and is either NB or NB-1, or N if N <= NB.
                     50: *>
                     51: *> ZLASYF_ROOK is an auxiliary routine called by ZSYTRF_ROOK. It uses
                     52: *> blocked code (calling Level 3 BLAS) to update the submatrix
                     53: *> A11 (if UPLO = 'U') or A22 (if UPLO = 'L').
                     54: *> \endverbatim
                     55: *
                     56: *  Arguments:
                     57: *  ==========
                     58: *
                     59: *> \param[in] UPLO
                     60: *> \verbatim
                     61: *>          UPLO is CHARACTER*1
                     62: *>          Specifies whether the upper or lower triangular part of the
                     63: *>          symmetric matrix A is stored:
                     64: *>          = 'U':  Upper triangular
                     65: *>          = 'L':  Lower triangular
                     66: *> \endverbatim
                     67: *>
                     68: *> \param[in] N
                     69: *> \verbatim
                     70: *>          N is INTEGER
                     71: *>          The order of the matrix A.  N >= 0.
                     72: *> \endverbatim
                     73: *>
                     74: *> \param[in] NB
                     75: *> \verbatim
                     76: *>          NB is INTEGER
                     77: *>          The maximum number of columns of the matrix A that should be
                     78: *>          factored.  NB should be at least 2 to allow for 2-by-2 pivot
                     79: *>          blocks.
                     80: *> \endverbatim
                     81: *>
                     82: *> \param[out] KB
                     83: *> \verbatim
                     84: *>          KB is INTEGER
                     85: *>          The number of columns of A that were actually factored.
                     86: *>          KB is either NB-1 or NB, or N if N <= NB.
                     87: *> \endverbatim
                     88: *>
                     89: *> \param[in,out] A
                     90: *> \verbatim
                     91: *>          A is COMPLEX*16 array, dimension (LDA,N)
                     92: *>          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
                     93: *>          n-by-n upper triangular part of A contains the upper
                     94: *>          triangular part of the matrix A, and the strictly lower
                     95: *>          triangular part of A is not referenced.  If UPLO = 'L', the
                     96: *>          leading n-by-n lower triangular part of A contains the lower
                     97: *>          triangular part of the matrix A, and the strictly upper
                     98: *>          triangular part of A is not referenced.
                     99: *>          On exit, A contains details of the partial factorization.
                    100: *> \endverbatim
                    101: *>
                    102: *> \param[in] LDA
                    103: *> \verbatim
                    104: *>          LDA is INTEGER
                    105: *>          The leading dimension of the array A.  LDA >= max(1,N).
                    106: *> \endverbatim
                    107: *>
                    108: *> \param[out] IPIV
                    109: *> \verbatim
                    110: *>          IPIV is INTEGER array, dimension (N)
                    111: *>          Details of the interchanges and the block structure of D.
                    112: *>
                    113: *>          If UPLO = 'U':
                    114: *>             Only the last KB elements of IPIV are set.
                    115: *>
                    116: *>             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
                    117: *>             interchanged and D(k,k) is a 1-by-1 diagonal block.
                    118: *>
                    119: *>             If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and
                    120: *>             columns k and -IPIV(k) were interchanged and rows and
                    121: *>             columns k-1 and -IPIV(k-1) were inerchaged,
                    122: *>             D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
                    123: *>
                    124: *>          If UPLO = 'L':
                    125: *>             Only the first KB elements of IPIV are set.
                    126: *>
                    127: *>             If IPIV(k) > 0, then rows and columns k and IPIV(k)
                    128: *>             were interchanged and D(k,k) is a 1-by-1 diagonal block.
                    129: *>
                    130: *>             If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and
                    131: *>             columns k and -IPIV(k) were interchanged and rows and
                    132: *>             columns k+1 and -IPIV(k+1) were inerchaged,
                    133: *>             D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
                    134: *> \endverbatim
                    135: *>
                    136: *> \param[out] W
                    137: *> \verbatim
                    138: *>          W is COMPLEX*16 array, dimension (LDW,NB)
                    139: *> \endverbatim
                    140: *>
                    141: *> \param[in] LDW
                    142: *> \verbatim
                    143: *>          LDW is INTEGER
                    144: *>          The leading dimension of the array W.  LDW >= max(1,N).
                    145: *> \endverbatim
                    146: *>
                    147: *> \param[out] INFO
                    148: *> \verbatim
                    149: *>          INFO is INTEGER
                    150: *>          = 0: successful exit
                    151: *>          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization
                    152: *>               has been completed, but the block diagonal matrix D is
                    153: *>               exactly singular.
                    154: *> \endverbatim
                    155: *
                    156: *  Authors:
                    157: *  ========
                    158: *
                    159: *> \author Univ. of Tennessee
                    160: *> \author Univ. of California Berkeley
                    161: *> \author Univ. of Colorado Denver
                    162: *> \author NAG Ltd.
                    163: *
                    164: *> \ingroup complex16SYcomputational
                    165: *
                    166: *> \par Contributors:
                    167: *  ==================
                    168: *>
                    169: *> \verbatim
                    170: *>
                    171: *>  November 2013,  Igor Kozachenko,
                    172: *>                  Computer Science Division,
                    173: *>                  University of California, Berkeley
                    174: *>
                    175: *>  September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
                    176: *>                  School of Mathematics,
                    177: *>                  University of Manchester
                    178: *>
                    179: *> \endverbatim
                    180: *
                    181: *  =====================================================================
                    182:       SUBROUTINE ZLASYF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW,
                    183:      $                        INFO )
                    184: *
1.6     ! bertrand  185: *  -- LAPACK computational routine --
1.1       bertrand  186: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    187: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    188: *
                    189: *     .. Scalar Arguments ..
                    190:       CHARACTER          UPLO
                    191:       INTEGER            INFO, KB, LDA, LDW, N, NB
                    192: *     ..
                    193: *     .. Array Arguments ..
                    194:       INTEGER            IPIV( * )
                    195:       COMPLEX*16         A( LDA, * ), W( LDW, * )
                    196: *     ..
                    197: *
                    198: *  =====================================================================
                    199: *
                    200: *     .. Parameters ..
                    201:       DOUBLE PRECISION   ZERO, ONE
                    202:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
                    203:       DOUBLE PRECISION   EIGHT, SEVTEN
                    204:       PARAMETER          ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
                    205:       COMPLEX*16         CONE, CZERO
                    206:       PARAMETER          ( CONE = ( 1.0D+0, 0.0D+0 ),
                    207:      $                   CZERO = ( 0.0D+0, 0.0D+0 ) )
                    208: *     ..
                    209: *     .. Local Scalars ..
                    210:       LOGICAL            DONE
                    211:       INTEGER            IMAX, ITEMP, J, JB, JJ, JMAX, JP1, JP2, K, KK,
                    212:      $                   KW, KKW, KP, KSTEP, P, II
                    213:       DOUBLE PRECISION   ABSAKK, ALPHA, COLMAX, ROWMAX, DTEMP, SFMIN
                    214:       COMPLEX*16         D11, D12, D21, D22, R1, T, Z
                    215: *     ..
                    216: *     .. External Functions ..
                    217:       LOGICAL            LSAME
                    218:       INTEGER            IZAMAX
                    219:       DOUBLE PRECISION   DLAMCH
                    220:       EXTERNAL           LSAME, IZAMAX, DLAMCH
                    221: *     ..
                    222: *     .. External Subroutines ..
                    223:       EXTERNAL           ZCOPY, ZGEMM, ZGEMV, ZSCAL, ZSWAP
                    224: *     ..
                    225: *     .. Intrinsic Functions ..
                    226:       INTRINSIC          ABS, MAX, MIN, SQRT, DIMAG, DBLE
                    227: *     ..
                    228: *     .. Statement Functions ..
                    229:       DOUBLE PRECISION   CABS1
                    230: *     ..
                    231: *     .. Statement Function definitions ..
                    232:       CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
                    233: *     ..
                    234: *     .. Executable Statements ..
                    235: *
                    236:       INFO = 0
                    237: *
                    238: *     Initialize ALPHA for use in choosing pivot block size.
                    239: *
                    240:       ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
                    241: *
                    242: *     Compute machine safe minimum
                    243: *
                    244:       SFMIN = DLAMCH( 'S' )
                    245: *
                    246:       IF( LSAME( UPLO, 'U' ) ) THEN
                    247: *
                    248: *        Factorize the trailing columns of A using the upper triangle
                    249: *        of A and working backwards, and compute the matrix W = U12*D
                    250: *        for use in updating A11
                    251: *
                    252: *        K is the main loop index, decreasing from N in steps of 1 or 2
                    253: *
                    254:          K = N
                    255:    10    CONTINUE
                    256: *
                    257: *        KW is the column of W which corresponds to column K of A
                    258: *
                    259:          KW = NB + K - N
                    260: *
                    261: *        Exit from loop
                    262: *
                    263:          IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
                    264:      $      GO TO 30
                    265: *
                    266:          KSTEP = 1
                    267:          P = K
                    268: *
                    269: *        Copy column K of A to column KW of W and update it
                    270: *
                    271:          CALL ZCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 )
                    272:          IF( K.LT.N )
                    273:      $      CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ),
                    274:      $                  LDA, W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
                    275: *
                    276: *        Determine rows and columns to be interchanged and whether
                    277: *        a 1-by-1 or 2-by-2 pivot block will be used
                    278: *
                    279:          ABSAKK = CABS1( W( K, KW ) )
                    280: *
                    281: *        IMAX is the row-index of the largest off-diagonal element in
                    282: *        column K, and COLMAX is its absolute value.
                    283: *        Determine both COLMAX and IMAX.
                    284: *
                    285:          IF( K.GT.1 ) THEN
                    286:             IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
                    287:             COLMAX = CABS1( W( IMAX, KW ) )
                    288:          ELSE
                    289:             COLMAX = ZERO
                    290:          END IF
                    291: *
                    292:          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
                    293: *
                    294: *           Column K is zero or underflow: set INFO and continue
                    295: *
                    296:             IF( INFO.EQ.0 )
                    297:      $         INFO = K
                    298:             KP = K
                    299:             CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
                    300:          ELSE
                    301: *
                    302: *           ============================================================
                    303: *
                    304: *           Test for interchange
                    305: *
                    306: *           Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
                    307: *           (used to handle NaN and Inf)
                    308: *
                    309:             IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
                    310: *
                    311: *              no interchange, use 1-by-1 pivot block
                    312: *
                    313:                KP = K
                    314: *
                    315:             ELSE
                    316: *
                    317:                DONE = .FALSE.
                    318: *
                    319: *              Loop until pivot found
                    320: *
                    321:    12          CONTINUE
                    322: *
                    323: *                 Begin pivot search loop body
                    324: *
                    325: *
                    326: *                 Copy column IMAX to column KW-1 of W and update it
                    327: *
                    328:                   CALL ZCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
                    329:                   CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
                    330:      $                        W( IMAX+1, KW-1 ), 1 )
                    331: *
                    332:                   IF( K.LT.N )
                    333:      $               CALL ZGEMV( 'No transpose', K, N-K, -CONE,
                    334:      $                           A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
                    335:      $                           CONE, W( 1, KW-1 ), 1 )
                    336: *
                    337: *                 JMAX is the column-index of the largest off-diagonal
                    338: *                 element in row IMAX, and ROWMAX is its absolute value.
                    339: *                 Determine both ROWMAX and JMAX.
                    340: *
                    341:                   IF( IMAX.NE.K ) THEN
                    342:                      JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ),
                    343:      $                                     1 )
                    344:                      ROWMAX = CABS1( W( JMAX, KW-1 ) )
                    345:                   ELSE
                    346:                      ROWMAX = ZERO
                    347:                   END IF
                    348: *
                    349:                   IF( IMAX.GT.1 ) THEN
                    350:                      ITEMP = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
                    351:                      DTEMP = CABS1( W( ITEMP, KW-1 ) )
                    352:                      IF( DTEMP.GT.ROWMAX ) THEN
                    353:                         ROWMAX = DTEMP
                    354:                         JMAX = ITEMP
                    355:                      END IF
                    356:                   END IF
                    357: *
                    358: *                 Equivalent to testing for
                    359: *                 CABS1( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX
                    360: *                 (used to handle NaN and Inf)
                    361: *
                    362:                   IF( .NOT.(CABS1( W( IMAX, KW-1 ) ).LT.ALPHA*ROWMAX ) )
                    363:      $            THEN
                    364: *
                    365: *                    interchange rows and columns K and IMAX,
                    366: *                    use 1-by-1 pivot block
                    367: *
                    368:                      KP = IMAX
                    369: *
                    370: *                    copy column KW-1 of W to column KW of W
                    371: *
                    372:                      CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
                    373: *
                    374:                      DONE = .TRUE.
                    375: *
                    376: *                 Equivalent to testing for ROWMAX.EQ.COLMAX,
                    377: *                 (used to handle NaN and Inf)
                    378: *
                    379:                   ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
                    380:      $            THEN
                    381: *
                    382: *                    interchange rows and columns K-1 and IMAX,
                    383: *                    use 2-by-2 pivot block
                    384: *
                    385:                      KP = IMAX
                    386:                      KSTEP = 2
                    387:                      DONE = .TRUE.
                    388:                   ELSE
                    389: *
                    390: *                    Pivot not found: set params and repeat
                    391: *
                    392:                      P = IMAX
                    393:                      COLMAX = ROWMAX
                    394:                      IMAX = JMAX
                    395: *
                    396: *                    Copy updated JMAXth (next IMAXth) column to Kth of W
                    397: *
                    398:                      CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
                    399: *
                    400:                   END IF
                    401: *
                    402: *                 End pivot search loop body
                    403: *
                    404:                IF( .NOT. DONE ) GOTO 12
                    405: *
                    406:             END IF
                    407: *
                    408: *           ============================================================
                    409: *
                    410:             KK = K - KSTEP + 1
                    411: *
                    412: *           KKW is the column of W which corresponds to column KK of A
                    413: *
                    414:             KKW = NB + KK - N
                    415: *
                    416:             IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
                    417: *
                    418: *              Copy non-updated column K to column P
                    419: *
                    420:                CALL ZCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA )
                    421:                CALL ZCOPY( P, A( 1, K ), 1, A( 1, P ), 1 )
                    422: *
                    423: *              Interchange rows K and P in last N-K+1 columns of A
                    424: *              and last N-K+2 columns of W
                    425: *
                    426:                CALL ZSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA )
                    427:                CALL ZSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW )
                    428:             END IF
                    429: *
                    430: *           Updated column KP is already stored in column KKW of W
                    431: *
                    432:             IF( KP.NE.KK ) THEN
                    433: *
                    434: *              Copy non-updated column KK to column KP
                    435: *
                    436:                A( KP, K ) = A( KK, K )
                    437:                CALL ZCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
                    438:      $                     LDA )
                    439:                CALL ZCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 )
                    440: *
                    441: *              Interchange rows KK and KP in last N-KK+1 columns
                    442: *              of A and W
                    443: *
                    444:                CALL ZSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), LDA )
                    445:                CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
                    446:      $                     LDW )
                    447:             END IF
                    448: *
                    449:             IF( KSTEP.EQ.1 ) THEN
                    450: *
                    451: *              1-by-1 pivot block D(k): column KW of W now holds
                    452: *
                    453: *              W(k) = U(k)*D(k)
                    454: *
                    455: *              where U(k) is the k-th column of U
                    456: *
                    457: *              Store U(k) in column k of A
                    458: *
                    459:                CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
                    460:                IF( K.GT.1 ) THEN
                    461:                   IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN
                    462:                      R1 = CONE / A( K, K )
                    463:                      CALL ZSCAL( K-1, R1, A( 1, K ), 1 )
                    464:                   ELSE IF( A( K, K ).NE.CZERO ) THEN
                    465:                      DO 14 II = 1, K - 1
                    466:                         A( II, K ) = A( II, K ) / A( K, K )
                    467:    14                CONTINUE
                    468:                   END IF
                    469:                END IF
                    470: *
                    471:             ELSE
                    472: *
                    473: *              2-by-2 pivot block D(k): columns KW and KW-1 of W now
                    474: *              hold
                    475: *
                    476: *              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
                    477: *
                    478: *              where U(k) and U(k-1) are the k-th and (k-1)-th columns
                    479: *              of U
                    480: *
                    481:                IF( K.GT.2 ) THEN
                    482: *
                    483: *                 Store U(k) and U(k-1) in columns k and k-1 of A
                    484: *
                    485:                   D12 = W( K-1, KW )
                    486:                   D11 = W( K, KW ) / D12
                    487:                   D22 = W( K-1, KW-1 ) / D12
                    488:                   T = CONE / ( D11*D22-CONE )
                    489:                   DO 20 J = 1, K - 2
                    490:                      A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) /
                    491:      $                             D12 )
                    492:                      A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) /
                    493:      $                           D12 )
                    494:    20             CONTINUE
                    495:                END IF
                    496: *
                    497: *              Copy D(k) to A
                    498: *
                    499:                A( K-1, K-1 ) = W( K-1, KW-1 )
                    500:                A( K-1, K ) = W( K-1, KW )
                    501:                A( K, K ) = W( K, KW )
                    502:             END IF
                    503:          END IF
                    504: *
                    505: *        Store details of the interchanges in IPIV
                    506: *
                    507:          IF( KSTEP.EQ.1 ) THEN
                    508:             IPIV( K ) = KP
                    509:          ELSE
                    510:             IPIV( K ) = -P
                    511:             IPIV( K-1 ) = -KP
                    512:          END IF
                    513: *
                    514: *        Decrease K and return to the start of the main loop
                    515: *
                    516:          K = K - KSTEP
                    517:          GO TO 10
                    518: *
                    519:    30    CONTINUE
                    520: *
                    521: *        Update the upper triangle of A11 (= A(1:k,1:k)) as
                    522: *
                    523: *        A11 := A11 - U12*D*U12**T = A11 - U12*W**T
                    524: *
                    525: *        computing blocks of NB columns at a time
                    526: *
                    527:          DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
                    528:             JB = MIN( NB, K-J+1 )
                    529: *
                    530: *           Update the upper triangle of the diagonal block
                    531: *
                    532:             DO 40 JJ = J, J + JB - 1
                    533:                CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
                    534:      $                     A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
                    535:      $                     A( J, JJ ), 1 )
                    536:    40       CONTINUE
                    537: *
                    538: *           Update the rectangular superdiagonal block
                    539: *
                    540:             IF( J.GE.2 )
                    541:      $         CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB,
                    542:      $                  N-K, -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
                    543:      $                  CONE, A( 1, J ), LDA )
                    544:    50    CONTINUE
                    545: *
                    546: *        Put U12 in standard form by partially undoing the interchanges
                    547: *        in columns k+1:n
                    548: *
                    549:          J = K + 1
                    550:    60    CONTINUE
                    551: *
                    552:             KSTEP = 1
                    553:             JP1 = 1
                    554:             JJ = J
                    555:             JP2 = IPIV( J )
                    556:             IF( JP2.LT.0 ) THEN
                    557:                JP2 = -JP2
                    558:                J = J + 1
                    559:                JP1 = -IPIV( J )
                    560:                KSTEP = 2
                    561:             END IF
                    562: *
                    563:             J = J + 1
                    564:             IF( JP2.NE.JJ .AND. J.LE.N )
                    565:      $         CALL ZSWAP( N-J+1, A( JP2, J ), LDA, A( JJ, J ), LDA )
                    566:             JJ = J - 1
                    567:             IF( JP1.NE.JJ .AND. KSTEP.EQ.2 )
                    568:      $         CALL ZSWAP( N-J+1, A( JP1, J ), LDA, A( JJ, J ), LDA )
                    569:          IF( J.LE.N )
                    570:      $      GO TO 60
                    571: *
                    572: *        Set KB to the number of columns factorized
                    573: *
                    574:          KB = N - K
                    575: *
                    576:       ELSE
                    577: *
                    578: *        Factorize the leading columns of A using the lower triangle
                    579: *        of A and working forwards, and compute the matrix W = L21*D
                    580: *        for use in updating A22
                    581: *
                    582: *        K is the main loop index, increasing from 1 in steps of 1 or 2
                    583: *
                    584:          K = 1
                    585:    70   CONTINUE
                    586: *
                    587: *        Exit from loop
                    588: *
                    589:          IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
                    590:      $      GO TO 90
                    591: *
                    592:          KSTEP = 1
                    593:          P = K
                    594: *
                    595: *        Copy column K of A to column K of W and update it
                    596: *
                    597:          CALL ZCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 )
                    598:          IF( K.GT.1 )
                    599:      $      CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
                    600:      $                  LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 )
                    601: *
                    602: *        Determine rows and columns to be interchanged and whether
                    603: *        a 1-by-1 or 2-by-2 pivot block will be used
                    604: *
                    605:          ABSAKK = CABS1( W( K, K ) )
                    606: *
                    607: *        IMAX is the row-index of the largest off-diagonal element in
                    608: *        column K, and COLMAX is its absolute value.
                    609: *        Determine both COLMAX and IMAX.
                    610: *
                    611:          IF( K.LT.N ) THEN
                    612:             IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
                    613:             COLMAX = CABS1( W( IMAX, K ) )
                    614:          ELSE
                    615:             COLMAX = ZERO
                    616:          END IF
                    617: *
                    618:          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
                    619: *
                    620: *           Column K is zero or underflow: set INFO and continue
                    621: *
                    622:             IF( INFO.EQ.0 )
                    623:      $         INFO = K
                    624:             KP = K
                    625:             CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
                    626:          ELSE
                    627: *
                    628: *           ============================================================
                    629: *
                    630: *           Test for interchange
                    631: *
                    632: *           Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
                    633: *           (used to handle NaN and Inf)
                    634: *
                    635:             IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
                    636: *
                    637: *              no interchange, use 1-by-1 pivot block
                    638: *
                    639:                KP = K
                    640: *
                    641:             ELSE
                    642: *
                    643:                DONE = .FALSE.
                    644: *
                    645: *              Loop until pivot found
                    646: *
                    647:    72          CONTINUE
                    648: *
                    649: *                 Begin pivot search loop body
                    650: *
                    651: *
                    652: *                 Copy column IMAX to column K+1 of W and update it
                    653: *
                    654:                   CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1)
                    655:                   CALL ZCOPY( N-IMAX+1, A( IMAX, IMAX ), 1,
                    656:      $                        W( IMAX, K+1 ), 1 )
                    657:                   IF( K.GT.1 )
                    658:      $               CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE,
                    659:      $                           A( K, 1 ), LDA, W( IMAX, 1 ), LDW,
                    660:      $                           CONE, W( K, K+1 ), 1 )
                    661: *
                    662: *                 JMAX is the column-index of the largest off-diagonal
                    663: *                 element in row IMAX, and ROWMAX is its absolute value.
                    664: *                 Determine both ROWMAX and JMAX.
                    665: *
                    666:                   IF( IMAX.NE.K ) THEN
                    667:                      JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
                    668:                      ROWMAX = CABS1( W( JMAX, K+1 ) )
                    669:                   ELSE
                    670:                      ROWMAX = ZERO
                    671:                   END IF
                    672: *
                    673:                   IF( IMAX.LT.N ) THEN
                    674:                      ITEMP = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1)
                    675:                      DTEMP = CABS1( W( ITEMP, K+1 ) )
                    676:                      IF( DTEMP.GT.ROWMAX ) THEN
                    677:                         ROWMAX = DTEMP
                    678:                         JMAX = ITEMP
                    679:                      END IF
                    680:                   END IF
                    681: *
                    682: *                 Equivalent to testing for
                    683: *                 CABS1( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX
                    684: *                 (used to handle NaN and Inf)
                    685: *
                    686:                   IF( .NOT.( CABS1( W( IMAX, K+1 ) ).LT.ALPHA*ROWMAX ) )
                    687:      $            THEN
                    688: *
                    689: *                    interchange rows and columns K and IMAX,
                    690: *                    use 1-by-1 pivot block
                    691: *
                    692:                      KP = IMAX
                    693: *
                    694: *                    copy column K+1 of W to column K of W
                    695: *
                    696:                      CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
                    697: *
                    698:                      DONE = .TRUE.
                    699: *
                    700: *                 Equivalent to testing for ROWMAX.EQ.COLMAX,
                    701: *                 (used to handle NaN and Inf)
                    702: *
                    703:                   ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
                    704:      $            THEN
                    705: *
                    706: *                    interchange rows and columns K+1 and IMAX,
                    707: *                    use 2-by-2 pivot block
                    708: *
                    709:                      KP = IMAX
                    710:                      KSTEP = 2
                    711:                      DONE = .TRUE.
                    712:                   ELSE
                    713: *
                    714: *                    Pivot not found: set params and repeat
                    715: *
                    716:                      P = IMAX
                    717:                      COLMAX = ROWMAX
                    718:                      IMAX = JMAX
                    719: *
                    720: *                    Copy updated JMAXth (next IMAXth) column to Kth of W
                    721: *
                    722:                      CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
                    723: *
                    724:                   END IF
                    725: *
                    726: *                 End pivot search loop body
                    727: *
                    728:                IF( .NOT. DONE ) GOTO 72
                    729: *
                    730:             END IF
                    731: *
                    732: *           ============================================================
                    733: *
                    734:             KK = K + KSTEP - 1
                    735: *
                    736:             IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
                    737: *
                    738: *              Copy non-updated column K to column P
                    739: *
                    740:                CALL ZCOPY( P-K, A( K, K ), 1, A( P, K ), LDA )
                    741:                CALL ZCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 )
                    742: *
                    743: *              Interchange rows K and P in first K columns of A
                    744: *              and first K+1 columns of W
                    745: *
                    746:                CALL ZSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA )
                    747:                CALL ZSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW )
                    748:             END IF
                    749: *
                    750: *           Updated column KP is already stored in column KK of W
                    751: *
                    752:             IF( KP.NE.KK ) THEN
                    753: *
                    754: *              Copy non-updated column KK to column KP
                    755: *
                    756:                A( KP, K ) = A( KK, K )
                    757:                CALL ZCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA )
                    758:                CALL ZCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 )
                    759: *
                    760: *              Interchange rows KK and KP in first KK columns of A and W
                    761: *
                    762:                CALL ZSWAP( KK, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
                    763:                CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
                    764:             END IF
                    765: *
                    766:             IF( KSTEP.EQ.1 ) THEN
                    767: *
                    768: *              1-by-1 pivot block D(k): column k of W now holds
                    769: *
                    770: *              W(k) = L(k)*D(k)
                    771: *
                    772: *              where L(k) is the k-th column of L
                    773: *
                    774: *              Store L(k) in column k of A
                    775: *
                    776:                CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
                    777:                IF( K.LT.N ) THEN
                    778:                   IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN
                    779:                      R1 = CONE / A( K, K )
                    780:                      CALL ZSCAL( N-K, R1, A( K+1, K ), 1 )
                    781:                   ELSE IF( A( K, K ).NE.CZERO ) THEN
                    782:                      DO 74 II = K + 1, N
                    783:                         A( II, K ) = A( II, K ) / A( K, K )
                    784:    74                CONTINUE
                    785:                   END IF
                    786:                END IF
                    787: *
                    788:             ELSE
                    789: *
                    790: *              2-by-2 pivot block D(k): columns k and k+1 of W now hold
                    791: *
                    792: *              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
                    793: *
                    794: *              where L(k) and L(k+1) are the k-th and (k+1)-th columns
                    795: *              of L
                    796: *
                    797:                IF( K.LT.N-1 ) THEN
                    798: *
                    799: *                 Store L(k) and L(k+1) in columns k and k+1 of A
                    800: *
                    801:                   D21 = W( K+1, K )
                    802:                   D11 = W( K+1, K+1 ) / D21
                    803:                   D22 = W( K, K ) / D21
                    804:                   T = CONE / ( D11*D22-CONE )
                    805:                   DO 80 J = K + 2, N
                    806:                      A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) /
                    807:      $                           D21 )
                    808:                      A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) /
                    809:      $                             D21 )
                    810:    80             CONTINUE
                    811:                END IF
                    812: *
                    813: *              Copy D(k) to A
                    814: *
                    815:                A( K, K ) = W( K, K )
                    816:                A( K+1, K ) = W( K+1, K )
                    817:                A( K+1, K+1 ) = W( K+1, K+1 )
                    818:             END IF
                    819:          END IF
                    820: *
                    821: *        Store details of the interchanges in IPIV
                    822: *
                    823:          IF( KSTEP.EQ.1 ) THEN
                    824:             IPIV( K ) = KP
                    825:          ELSE
                    826:             IPIV( K ) = -P
                    827:             IPIV( K+1 ) = -KP
                    828:          END IF
                    829: *
                    830: *        Increase K and return to the start of the main loop
                    831: *
                    832:          K = K + KSTEP
                    833:          GO TO 70
                    834: *
                    835:    90    CONTINUE
                    836: *
                    837: *        Update the lower triangle of A22 (= A(k:n,k:n)) as
                    838: *
                    839: *        A22 := A22 - L21*D*L21**T = A22 - L21*W**T
                    840: *
                    841: *        computing blocks of NB columns at a time
                    842: *
                    843:          DO 110 J = K, N, NB
                    844:             JB = MIN( NB, N-J+1 )
                    845: *
                    846: *           Update the lower triangle of the diagonal block
                    847: *
                    848:             DO 100 JJ = J, J + JB - 1
                    849:                CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
                    850:      $                     A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
                    851:      $                     A( JJ, JJ ), 1 )
                    852:   100       CONTINUE
                    853: *
                    854: *           Update the rectangular subdiagonal block
                    855: *
                    856:             IF( J+JB.LE.N )
                    857:      $         CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
                    858:      $                    K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ), LDW,
                    859:      $                    CONE, A( J+JB, J ), LDA )
                    860:   110    CONTINUE
                    861: *
                    862: *        Put L21 in standard form by partially undoing the interchanges
                    863: *        in columns 1:k-1
                    864: *
                    865:          J = K - 1
                    866:   120    CONTINUE
                    867: *
                    868:             KSTEP = 1
                    869:             JP1 = 1
                    870:             JJ = J
                    871:             JP2 = IPIV( J )
                    872:             IF( JP2.LT.0 ) THEN
                    873:                JP2 = -JP2
                    874:                J = J - 1
                    875:                JP1 = -IPIV( J )
                    876:                KSTEP = 2
                    877:             END IF
                    878: *
                    879:             J = J - 1
                    880:             IF( JP2.NE.JJ .AND. J.GE.1 )
                    881:      $         CALL ZSWAP( J, A( JP2, 1 ), LDA, A( JJ, 1 ), LDA )
                    882:             JJ = J + 1
                    883:             IF( JP1.NE.JJ .AND. KSTEP.EQ.2 )
                    884:      $         CALL ZSWAP( J, A( JP1, 1 ), LDA, A( JJ, 1 ), LDA )
                    885:          IF( J.GE.1 )
                    886:      $      GO TO 120
                    887: *
                    888: *        Set KB to the number of columns factorized
                    889: *
                    890:          KB = K - 1
                    891: *
                    892:       END IF
                    893:       RETURN
                    894: *
                    895: *     End of ZLASYF_ROOK
                    896: *
                    897:       END

CVSweb interface <joel.bertrand@systella.fr>