Annotation of rpl/lapack/lapack/zlahef.f, revision 1.19

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

CVSweb interface <joel.bertrand@systella.fr>