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

1.11      bertrand    1: *> \brief \b ZLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Schur decomposition.
1.8       bertrand    2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.15      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.8       bertrand    7: *
                      8: *> \htmlonly
1.15      bertrand    9: *> Download ZLAQR4 + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlaqr4.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlaqr4.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlaqr4.f">
1.8       bertrand   15: *> [TXT]</a>
1.15      bertrand   16: *> \endhtmlonly
1.8       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
                     22: *                          IHIZ, Z, LDZ, WORK, LWORK, INFO )
1.15      bertrand   23: *
1.8       bertrand   24: *       .. Scalar Arguments ..
                     25: *       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
                     26: *       LOGICAL            WANTT, WANTZ
                     27: *       ..
                     28: *       .. Array Arguments ..
                     29: *       COMPLEX*16         H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
                     30: *       ..
1.15      bertrand   31: *
1.8       bertrand   32: *
                     33: *> \par Purpose:
                     34: *  =============
                     35: *>
                     36: *> \verbatim
                     37: *>
                     38: *>    ZLAQR4 implements one level of recursion for ZLAQR0.
                     39: *>    It is a complete implementation of the small bulge multi-shift
                     40: *>    QR algorithm.  It may be called by ZLAQR0 and, for large enough
                     41: *>    deflation window size, it may be called by ZLAQR3.  This
                     42: *>    subroutine is identical to ZLAQR0 except that it calls ZLAQR2
                     43: *>    instead of ZLAQR3.
                     44: *>
                     45: *>    ZLAQR4 computes the eigenvalues of a Hessenberg matrix H
                     46: *>    and, optionally, the matrices T and Z from the Schur decomposition
                     47: *>    H = Z T Z**H, where T is an upper triangular matrix (the
                     48: *>    Schur form), and Z is the unitary matrix of Schur vectors.
                     49: *>
                     50: *>    Optionally Z may be postmultiplied into an input unitary
                     51: *>    matrix Q so that this routine can give the Schur factorization
                     52: *>    of a matrix A which has been reduced to the Hessenberg form H
                     53: *>    by the unitary matrix Q:  A = Q*H*Q**H = (QZ)*H*(QZ)**H.
                     54: *> \endverbatim
                     55: *
                     56: *  Arguments:
                     57: *  ==========
                     58: *
                     59: *> \param[in] WANTT
                     60: *> \verbatim
                     61: *>          WANTT is LOGICAL
                     62: *>          = .TRUE. : the full Schur form T is required;
                     63: *>          = .FALSE.: only eigenvalues are required.
                     64: *> \endverbatim
                     65: *>
                     66: *> \param[in] WANTZ
                     67: *> \verbatim
                     68: *>          WANTZ is LOGICAL
                     69: *>          = .TRUE. : the matrix of Schur vectors Z is required;
                     70: *>          = .FALSE.: Schur vectors are not required.
                     71: *> \endverbatim
                     72: *>
                     73: *> \param[in] N
                     74: *> \verbatim
                     75: *>          N is INTEGER
1.18      bertrand   76: *>           The order of the matrix H.  N >= 0.
1.8       bertrand   77: *> \endverbatim
                     78: *>
                     79: *> \param[in] ILO
                     80: *> \verbatim
                     81: *>          ILO is INTEGER
                     82: *> \endverbatim
                     83: *>
                     84: *> \param[in] IHI
                     85: *> \verbatim
                     86: *>          IHI is INTEGER
                     87: *>           It is assumed that H is already upper triangular in rows
1.18      bertrand   88: *>           and columns 1:ILO-1 and IHI+1:N and, if ILO > 1,
1.8       bertrand   89: *>           H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
                     90: *>           previous call to ZGEBAL, and then passed to ZGEHRD when the
                     91: *>           matrix output by ZGEBAL is reduced to Hessenberg form.
                     92: *>           Otherwise, ILO and IHI should be set to 1 and N,
1.18      bertrand   93: *>           respectively.  If N > 0, then 1 <= ILO <= IHI <= N.
1.8       bertrand   94: *>           If N = 0, then ILO = 1 and IHI = 0.
                     95: *> \endverbatim
                     96: *>
                     97: *> \param[in,out] H
                     98: *> \verbatim
                     99: *>          H is COMPLEX*16 array, dimension (LDH,N)
                    100: *>           On entry, the upper Hessenberg matrix H.
                    101: *>           On exit, if INFO = 0 and WANTT is .TRUE., then H
                    102: *>           contains the upper triangular matrix T from the Schur
                    103: *>           decomposition (the Schur form). If INFO = 0 and WANT is
                    104: *>           .FALSE., then the contents of H are unspecified on exit.
1.18      bertrand  105: *>           (The output value of H when INFO > 0 is given under the
1.8       bertrand  106: *>           description of INFO below.)
                    107: *>
1.18      bertrand  108: *>           This subroutine may explicitly set H(i,j) = 0 for i > j and
1.8       bertrand  109: *>           j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
                    110: *> \endverbatim
                    111: *>
                    112: *> \param[in] LDH
                    113: *> \verbatim
                    114: *>          LDH is INTEGER
1.18      bertrand  115: *>           The leading dimension of the array H. LDH >= max(1,N).
1.8       bertrand  116: *> \endverbatim
                    117: *>
                    118: *> \param[out] W
                    119: *> \verbatim
                    120: *>          W is COMPLEX*16 array, dimension (N)
                    121: *>           The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored
                    122: *>           in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are
                    123: *>           stored in the same order as on the diagonal of the Schur
                    124: *>           form returned in H, with W(i) = H(i,i).
                    125: *> \endverbatim
                    126: *>
                    127: *> \param[in] ILOZ
                    128: *> \verbatim
                    129: *>          ILOZ is INTEGER
                    130: *> \endverbatim
                    131: *>
                    132: *> \param[in] IHIZ
                    133: *> \verbatim
                    134: *>          IHIZ is INTEGER
                    135: *>           Specify the rows of Z to which transformations must be
                    136: *>           applied if WANTZ is .TRUE..
1.18      bertrand  137: *>           1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
1.8       bertrand  138: *> \endverbatim
                    139: *>
                    140: *> \param[in,out] Z
                    141: *> \verbatim
                    142: *>          Z is COMPLEX*16 array, dimension (LDZ,IHI)
                    143: *>           If WANTZ is .FALSE., then Z is not referenced.
                    144: *>           If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
                    145: *>           replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
                    146: *>           orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
1.18      bertrand  147: *>           (The output value of Z when INFO > 0 is given under
1.8       bertrand  148: *>           the description of INFO below.)
                    149: *> \endverbatim
                    150: *>
                    151: *> \param[in] LDZ
                    152: *> \verbatim
                    153: *>          LDZ is INTEGER
                    154: *>           The leading dimension of the array Z.  if WANTZ is .TRUE.
1.18      bertrand  155: *>           then LDZ >= MAX(1,IHIZ).  Otherwise, LDZ >= 1.
1.8       bertrand  156: *> \endverbatim
                    157: *>
                    158: *> \param[out] WORK
                    159: *> \verbatim
                    160: *>          WORK is COMPLEX*16 array, dimension LWORK
                    161: *>           On exit, if LWORK = -1, WORK(1) returns an estimate of
                    162: *>           the optimal value for LWORK.
                    163: *> \endverbatim
                    164: *>
                    165: *> \param[in] LWORK
                    166: *> \verbatim
                    167: *>          LWORK is INTEGER
1.18      bertrand  168: *>           The dimension of the array WORK.  LWORK >= max(1,N)
1.8       bertrand  169: *>           is sufficient, but LWORK typically as large as 6*N may
                    170: *>           be required for optimal performance.  A workspace query
                    171: *>           to determine the optimal workspace size is recommended.
                    172: *>
                    173: *>           If LWORK = -1, then ZLAQR4 does a workspace query.
                    174: *>           In this case, ZLAQR4 checks the input parameters and
                    175: *>           estimates the optimal workspace size for the given
                    176: *>           values of N, ILO and IHI.  The estimate is returned
                    177: *>           in WORK(1).  No error message related to LWORK is
                    178: *>           issued by XERBLA.  Neither H nor Z are accessed.
                    179: *> \endverbatim
                    180: *>
                    181: *> \param[out] INFO
                    182: *> \verbatim
                    183: *>          INFO is INTEGER
                    184: *>             =  0:  successful exit
1.18      bertrand  185: *>             > 0:  if INFO = i, ZLAQR4 failed to compute all of
1.8       bertrand  186: *>                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
                    187: *>                and WI contain those eigenvalues which have been
                    188: *>                successfully computed.  (Failures are rare.)
                    189: *>
1.18      bertrand  190: *>                If INFO > 0 and WANT is .FALSE., then on exit,
1.8       bertrand  191: *>                the remaining unconverged eigenvalues are the eigen-
                    192: *>                values of the upper Hessenberg matrix rows and
                    193: *>                columns ILO through INFO of the final, output
                    194: *>                value of H.
                    195: *>
1.18      bertrand  196: *>                If INFO > 0 and WANTT is .TRUE., then on exit
1.8       bertrand  197: *>
                    198: *>           (*)  (initial value of H)*U  = U*(final value of H)
                    199: *>
                    200: *>                where U is a unitary matrix.  The final
                    201: *>                value of  H is upper Hessenberg and triangular in
                    202: *>                rows and columns INFO+1 through IHI.
                    203: *>
1.18      bertrand  204: *>                If INFO > 0 and WANTZ is .TRUE., then on exit
1.8       bertrand  205: *>
                    206: *>                  (final value of Z(ILO:IHI,ILOZ:IHIZ)
                    207: *>                   =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
                    208: *>
                    209: *>                where U is the unitary matrix in (*) (regard-
                    210: *>                less of the value of WANTT.)
                    211: *>
1.18      bertrand  212: *>                If INFO > 0 and WANTZ is .FALSE., then Z is not
1.8       bertrand  213: *>                accessed.
                    214: *> \endverbatim
                    215: *
                    216: *  Authors:
                    217: *  ========
                    218: *
1.15      bertrand  219: *> \author Univ. of Tennessee
                    220: *> \author Univ. of California Berkeley
                    221: *> \author Univ. of Colorado Denver
                    222: *> \author NAG Ltd.
1.8       bertrand  223: *
                    224: *> \ingroup complex16OTHERauxiliary
                    225: *
                    226: *> \par Contributors:
                    227: *  ==================
                    228: *>
                    229: *>       Karen Braman and Ralph Byers, Department of Mathematics,
                    230: *>       University of Kansas, USA
                    231: *
                    232: *> \par References:
                    233: *  ================
                    234: *>
                    235: *>       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
                    236: *>       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
                    237: *>       Performance, SIAM Journal of Matrix Analysis, volume 23, pages
                    238: *>       929--947, 2002.
                    239: *> \n
                    240: *>       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
                    241: *>       Algorithm Part II: Aggressive Early Deflation, SIAM Journal
                    242: *>       of Matrix Analysis, volume 23, pages 948--973, 2002.
                    243: *>
                    244: *  =====================================================================
1.1       bertrand  245:       SUBROUTINE ZLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
                    246:      $                   IHIZ, Z, LDZ, WORK, LWORK, INFO )
                    247: *
1.19    ! bertrand  248: *  -- LAPACK auxiliary routine --
1.8       bertrand  249: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    250: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1.1       bertrand  251: *
                    252: *     .. Scalar Arguments ..
                    253:       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
                    254:       LOGICAL            WANTT, WANTZ
                    255: *     ..
                    256: *     .. Array Arguments ..
                    257:       COMPLEX*16         H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
                    258: *     ..
                    259: *
1.8       bertrand  260: *  ================================================================
1.1       bertrand  261: *
                    262: *     .. Parameters ..
                    263: *
                    264: *     ==== Matrices of order NTINY or smaller must be processed by
                    265: *     .    ZLAHQR because of insufficient subdiagonal scratch space.
                    266: *     .    (This is a hard limit.) ====
                    267:       INTEGER            NTINY
1.19    ! bertrand  268:       PARAMETER          ( NTINY = 15 )
1.1       bertrand  269: *
                    270: *     ==== Exceptional deflation windows:  try to cure rare
                    271: *     .    slow convergence by varying the size of the
                    272: *     .    deflation window after KEXNW iterations. ====
                    273:       INTEGER            KEXNW
                    274:       PARAMETER          ( KEXNW = 5 )
                    275: *
                    276: *     ==== Exceptional shifts: try to cure rare slow convergence
                    277: *     .    with ad-hoc exceptional shifts every KEXSH iterations.
                    278: *     .    ====
                    279:       INTEGER            KEXSH
                    280:       PARAMETER          ( KEXSH = 6 )
                    281: *
                    282: *     ==== The constant WILK1 is used to form the exceptional
                    283: *     .    shifts. ====
                    284:       DOUBLE PRECISION   WILK1
                    285:       PARAMETER          ( WILK1 = 0.75d0 )
                    286:       COMPLEX*16         ZERO, ONE
                    287:       PARAMETER          ( ZERO = ( 0.0d0, 0.0d0 ),
                    288:      $                   ONE = ( 1.0d0, 0.0d0 ) )
                    289:       DOUBLE PRECISION   TWO
                    290:       PARAMETER          ( TWO = 2.0d0 )
                    291: *     ..
                    292: *     .. Local Scalars ..
                    293:       COMPLEX*16         AA, BB, CC, CDUM, DD, DET, RTDISC, SWAP, TR2
                    294:       DOUBLE PRECISION   S
                    295:       INTEGER            I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
                    296:      $                   KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS,
                    297:      $                   LWKOPT, NDEC, NDFL, NH, NHO, NIBBLE, NMIN, NS,
                    298:      $                   NSMAX, NSR, NVE, NW, NWMAX, NWR, NWUPBD
                    299:       LOGICAL            SORTED
                    300:       CHARACTER          JBCMPZ*2
                    301: *     ..
                    302: *     .. External Functions ..
                    303:       INTEGER            ILAENV
                    304:       EXTERNAL           ILAENV
                    305: *     ..
                    306: *     .. Local Arrays ..
                    307:       COMPLEX*16         ZDUM( 1, 1 )
                    308: *     ..
                    309: *     .. External Subroutines ..
                    310:       EXTERNAL           ZLACPY, ZLAHQR, ZLAQR2, ZLAQR5
                    311: *     ..
                    312: *     .. Intrinsic Functions ..
                    313:       INTRINSIC          ABS, DBLE, DCMPLX, DIMAG, INT, MAX, MIN, MOD,
                    314:      $                   SQRT
                    315: *     ..
                    316: *     .. Statement Functions ..
                    317:       DOUBLE PRECISION   CABS1
                    318: *     ..
                    319: *     .. Statement Function definitions ..
                    320:       CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
                    321: *     ..
                    322: *     .. Executable Statements ..
                    323:       INFO = 0
                    324: *
                    325: *     ==== Quick return for N = 0: nothing to do. ====
                    326: *
                    327:       IF( N.EQ.0 ) THEN
                    328:          WORK( 1 ) = ONE
                    329:          RETURN
                    330:       END IF
                    331: *
                    332:       IF( N.LE.NTINY ) THEN
                    333: *
                    334: *        ==== Tiny matrices must use ZLAHQR. ====
                    335: *
                    336:          LWKOPT = 1
                    337:          IF( LWORK.NE.-1 )
                    338:      $      CALL ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
                    339:      $                   IHIZ, Z, LDZ, INFO )
                    340:       ELSE
                    341: *
                    342: *        ==== Use small bulge multi-shift QR with aggressive early
                    343: *        .    deflation on larger-than-tiny matrices. ====
                    344: *
                    345: *        ==== Hope for the best. ====
                    346: *
                    347:          INFO = 0
                    348: *
                    349: *        ==== Set up job flags for ILAENV. ====
                    350: *
                    351:          IF( WANTT ) THEN
                    352:             JBCMPZ( 1: 1 ) = 'S'
                    353:          ELSE
                    354:             JBCMPZ( 1: 1 ) = 'E'
                    355:          END IF
                    356:          IF( WANTZ ) THEN
                    357:             JBCMPZ( 2: 2 ) = 'V'
                    358:          ELSE
                    359:             JBCMPZ( 2: 2 ) = 'N'
                    360:          END IF
                    361: *
                    362: *        ==== NWR = recommended deflation window size.  At this
1.19    ! bertrand  363: *        .    point,  N .GT. NTINY = 15, so there is enough
1.1       bertrand  364: *        .    subdiagonal workspace for NWR.GE.2 as required.
                    365: *        .    (In fact, there is enough subdiagonal space for
1.19    ! bertrand  366: *        .    NWR.GE.4.) ====
1.1       bertrand  367: *
                    368:          NWR = ILAENV( 13, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
                    369:          NWR = MAX( 2, NWR )
                    370:          NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
                    371: *
                    372: *        ==== NSR = recommended number of simultaneous shifts.
1.19    ! bertrand  373: *        .    At this point N .GT. NTINY = 15, so there is at
1.1       bertrand  374: *        .    enough subdiagonal workspace for NSR to be even
                    375: *        .    and greater than or equal to two as required. ====
                    376: *
                    377:          NSR = ILAENV( 15, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
1.19    ! bertrand  378:          NSR = MIN( NSR, ( N-3 ) / 6, IHI-ILO )
1.1       bertrand  379:          NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
                    380: *
                    381: *        ==== Estimate optimal workspace ====
                    382: *
                    383: *        ==== Workspace query call to ZLAQR2 ====
                    384: *
                    385:          CALL ZLAQR2( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ,
                    386:      $                IHIZ, Z, LDZ, LS, LD, W, H, LDH, N, H, LDH, N, H,
                    387:      $                LDH, WORK, -1 )
                    388: *
                    389: *        ==== Optimal workspace = MAX(ZLAQR5, ZLAQR2) ====
                    390: *
                    391:          LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) )
                    392: *
                    393: *        ==== Quick return in case of workspace query. ====
                    394: *
                    395:          IF( LWORK.EQ.-1 ) THEN
                    396:             WORK( 1 ) = DCMPLX( LWKOPT, 0 )
                    397:             RETURN
                    398:          END IF
                    399: *
                    400: *        ==== ZLAHQR/ZLAQR0 crossover point ====
                    401: *
                    402:          NMIN = ILAENV( 12, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
                    403:          NMIN = MAX( NTINY, NMIN )
                    404: *
                    405: *        ==== Nibble crossover point ====
                    406: *
                    407:          NIBBLE = ILAENV( 14, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
                    408:          NIBBLE = MAX( 0, NIBBLE )
                    409: *
                    410: *        ==== Accumulate reflections during ttswp?  Use block
                    411: *        .    2-by-2 structure during matrix-matrix multiply? ====
                    412: *
                    413:          KACC22 = ILAENV( 16, 'ZLAQR4', JBCMPZ, N, ILO, IHI, LWORK )
                    414:          KACC22 = MAX( 0, KACC22 )
                    415:          KACC22 = MIN( 2, KACC22 )
                    416: *
                    417: *        ==== NWMAX = the largest possible deflation window for
                    418: *        .    which there is sufficient workspace. ====
                    419: *
                    420:          NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 )
                    421:          NW = NWMAX
                    422: *
                    423: *        ==== NSMAX = the Largest number of simultaneous shifts
                    424: *        .    for which there is sufficient workspace. ====
                    425: *
1.19    ! bertrand  426:          NSMAX = MIN( ( N-3 ) / 6, 2*LWORK / 3 )
1.1       bertrand  427:          NSMAX = NSMAX - MOD( NSMAX, 2 )
                    428: *
                    429: *        ==== NDFL: an iteration count restarted at deflation. ====
                    430: *
                    431:          NDFL = 1
                    432: *
                    433: *        ==== ITMAX = iteration limit ====
                    434: *
                    435:          ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) )
                    436: *
                    437: *        ==== Last row and column in the active block ====
                    438: *
                    439:          KBOT = IHI
                    440: *
                    441: *        ==== Main Loop ====
                    442: *
                    443:          DO 70 IT = 1, ITMAX
                    444: *
                    445: *           ==== Done when KBOT falls below ILO ====
                    446: *
                    447:             IF( KBOT.LT.ILO )
                    448:      $         GO TO 80
                    449: *
                    450: *           ==== Locate active block ====
                    451: *
                    452:             DO 10 K = KBOT, ILO + 1, -1
                    453:                IF( H( K, K-1 ).EQ.ZERO )
                    454:      $            GO TO 20
                    455:    10       CONTINUE
                    456:             K = ILO
                    457:    20       CONTINUE
                    458:             KTOP = K
                    459: *
                    460: *           ==== Select deflation window size:
                    461: *           .    Typical Case:
                    462: *           .      If possible and advisable, nibble the entire
                    463: *           .      active block.  If not, use size MIN(NWR,NWMAX)
                    464: *           .      or MIN(NWR+1,NWMAX) depending upon which has
                    465: *           .      the smaller corresponding subdiagonal entry
                    466: *           .      (a heuristic).
                    467: *           .
                    468: *           .    Exceptional Case:
                    469: *           .      If there have been no deflations in KEXNW or
                    470: *           .      more iterations, then vary the deflation window
                    471: *           .      size.   At first, because, larger windows are,
                    472: *           .      in general, more powerful than smaller ones,
                    473: *           .      rapidly increase the window to the maximum possible.
                    474: *           .      Then, gradually reduce the window size. ====
                    475: *
                    476:             NH = KBOT - KTOP + 1
                    477:             NWUPBD = MIN( NH, NWMAX )
                    478:             IF( NDFL.LT.KEXNW ) THEN
                    479:                NW = MIN( NWUPBD, NWR )
                    480:             ELSE
                    481:                NW = MIN( NWUPBD, 2*NW )
                    482:             END IF
                    483:             IF( NW.LT.NWMAX ) THEN
                    484:                IF( NW.GE.NH-1 ) THEN
                    485:                   NW = NH
                    486:                ELSE
                    487:                   KWTOP = KBOT - NW + 1
                    488:                   IF( CABS1( H( KWTOP, KWTOP-1 ) ).GT.
                    489:      $                CABS1( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1
                    490:                END IF
                    491:             END IF
                    492:             IF( NDFL.LT.KEXNW ) THEN
                    493:                NDEC = -1
                    494:             ELSE IF( NDEC.GE.0 .OR. NW.GE.NWUPBD ) THEN
                    495:                NDEC = NDEC + 1
                    496:                IF( NW-NDEC.LT.2 )
                    497:      $            NDEC = 0
                    498:                NW = NW - NDEC
                    499:             END IF
                    500: *
                    501: *           ==== Aggressive early deflation:
                    502: *           .    split workspace under the subdiagonal into
                    503: *           .      - an nw-by-nw work array V in the lower
                    504: *           .        left-hand-corner,
                    505: *           .      - an NW-by-at-least-NW-but-more-is-better
                    506: *           .        (NW-by-NHO) horizontal work array along
                    507: *           .        the bottom edge,
                    508: *           .      - an at-least-NW-but-more-is-better (NHV-by-NW)
                    509: *           .        vertical work array along the left-hand-edge.
                    510: *           .        ====
                    511: *
                    512:             KV = N - NW + 1
                    513:             KT = NW + 1
                    514:             NHO = ( N-NW-1 ) - KT + 1
                    515:             KWV = NW + 2
                    516:             NVE = ( N-NW ) - KWV + 1
                    517: *
                    518: *           ==== Aggressive early deflation ====
                    519: *
                    520:             CALL ZLAQR2( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
                    521:      $                   IHIZ, Z, LDZ, LS, LD, W, H( KV, 1 ), LDH, NHO,
                    522:      $                   H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH, WORK,
                    523:      $                   LWORK )
                    524: *
                    525: *           ==== Adjust KBOT accounting for new deflations. ====
                    526: *
                    527:             KBOT = KBOT - LD
                    528: *
                    529: *           ==== KS points to the shifts. ====
                    530: *
                    531:             KS = KBOT - LS + 1
                    532: *
                    533: *           ==== Skip an expensive QR sweep if there is a (partly
                    534: *           .    heuristic) reason to expect that many eigenvalues
                    535: *           .    will deflate without it.  Here, the QR sweep is
                    536: *           .    skipped if many eigenvalues have just been deflated
                    537: *           .    or if the remaining active block is small.
                    538: *
                    539:             IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT-
                    540:      $          KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN
                    541: *
                    542: *              ==== NS = nominal number of simultaneous shifts.
                    543: *              .    This may be lowered (slightly) if ZLAQR2
                    544: *              .    did not provide that many shifts. ====
                    545: *
                    546:                NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) )
                    547:                NS = NS - MOD( NS, 2 )
                    548: *
                    549: *              ==== If there have been no deflations
                    550: *              .    in a multiple of KEXSH iterations,
                    551: *              .    then try exceptional shifts.
                    552: *              .    Otherwise use shifts provided by
                    553: *              .    ZLAQR2 above or from the eigenvalues
                    554: *              .    of a trailing principal submatrix. ====
                    555: *
                    556:                IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN
                    557:                   KS = KBOT - NS + 1
                    558:                   DO 30 I = KBOT, KS + 1, -2
                    559:                      W( I ) = H( I, I ) + WILK1*CABS1( H( I, I-1 ) )
                    560:                      W( I-1 ) = W( I )
                    561:    30             CONTINUE
                    562:                ELSE
                    563: *
                    564: *                 ==== Got NS/2 or fewer shifts? Use ZLAHQR
                    565: *                 .    on a trailing principal submatrix to
1.19    ! bertrand  566: *                 .    get more. (Since NS.LE.NSMAX.LE.(N-3)/6,
1.1       bertrand  567: *                 .    there is enough space below the subdiagonal
                    568: *                 .    to fit an NS-by-NS scratch array.) ====
                    569: *
                    570:                   IF( KBOT-KS+1.LE.NS / 2 ) THEN
                    571:                      KS = KBOT - NS + 1
                    572:                      KT = N - NS + 1
                    573:                      CALL ZLACPY( 'A', NS, NS, H( KS, KS ), LDH,
                    574:      $                            H( KT, 1 ), LDH )
                    575:                      CALL ZLAHQR( .false., .false., NS, 1, NS,
                    576:      $                            H( KT, 1 ), LDH, W( KS ), 1, 1, ZDUM,
                    577:      $                            1, INF )
                    578:                      KS = KS + INF
                    579: *
                    580: *                    ==== In case of a rare QR failure use
                    581: *                    .    eigenvalues of the trailing 2-by-2
                    582: *                    .    principal submatrix.  Scale to avoid
                    583: *                    .    overflows, underflows and subnormals.
                    584: *                    .    (The scale factor S can not be zero,
                    585: *                    .    because H(KBOT,KBOT-1) is nonzero.) ====
                    586: *
                    587:                      IF( KS.GE.KBOT ) THEN
                    588:                         S = CABS1( H( KBOT-1, KBOT-1 ) ) +
                    589:      $                      CABS1( H( KBOT, KBOT-1 ) ) +
                    590:      $                      CABS1( H( KBOT-1, KBOT ) ) +
                    591:      $                      CABS1( H( KBOT, KBOT ) )
                    592:                         AA = H( KBOT-1, KBOT-1 ) / S
                    593:                         CC = H( KBOT, KBOT-1 ) / S
                    594:                         BB = H( KBOT-1, KBOT ) / S
                    595:                         DD = H( KBOT, KBOT ) / S
                    596:                         TR2 = ( AA+DD ) / TWO
                    597:                         DET = ( AA-TR2 )*( DD-TR2 ) - BB*CC
                    598:                         RTDISC = SQRT( -DET )
                    599:                         W( KBOT-1 ) = ( TR2+RTDISC )*S
                    600:                         W( KBOT ) = ( TR2-RTDISC )*S
                    601: *
                    602:                         KS = KBOT - 1
                    603:                      END IF
                    604:                   END IF
                    605: *
                    606:                   IF( KBOT-KS+1.GT.NS ) THEN
                    607: *
                    608: *                    ==== Sort the shifts (Helps a little) ====
                    609: *
                    610:                      SORTED = .false.
                    611:                      DO 50 K = KBOT, KS + 1, -1
                    612:                         IF( SORTED )
                    613:      $                     GO TO 60
                    614:                         SORTED = .true.
                    615:                         DO 40 I = KS, K - 1
                    616:                            IF( CABS1( W( I ) ).LT.CABS1( W( I+1 ) ) )
                    617:      $                          THEN
                    618:                               SORTED = .false.
                    619:                               SWAP = W( I )
                    620:                               W( I ) = W( I+1 )
                    621:                               W( I+1 ) = SWAP
                    622:                            END IF
                    623:    40                   CONTINUE
                    624:    50                CONTINUE
                    625:    60                CONTINUE
                    626:                   END IF
                    627:                END IF
                    628: *
                    629: *              ==== If there are only two shifts, then use
                    630: *              .    only one.  ====
                    631: *
                    632:                IF( KBOT-KS+1.EQ.2 ) THEN
                    633:                   IF( CABS1( W( KBOT )-H( KBOT, KBOT ) ).LT.
                    634:      $                CABS1( W( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN
                    635:                      W( KBOT-1 ) = W( KBOT )
                    636:                   ELSE
                    637:                      W( KBOT ) = W( KBOT-1 )
                    638:                   END IF
                    639:                END IF
                    640: *
1.18      bertrand  641: *              ==== Use up to NS of the the smallest magnitude
1.1       bertrand  642: *              .    shifts.  If there aren't NS shifts available,
                    643: *              .    then use them all, possibly dropping one to
                    644: *              .    make the number of shifts even. ====
                    645: *
                    646:                NS = MIN( NS, KBOT-KS+1 )
                    647:                NS = NS - MOD( NS, 2 )
                    648:                KS = KBOT - NS + 1
                    649: *
                    650: *              ==== Small-bulge multi-shift QR sweep:
                    651: *              .    split workspace under the subdiagonal into
                    652: *              .    - a KDU-by-KDU work array U in the lower
                    653: *              .      left-hand-corner,
                    654: *              .    - a KDU-by-at-least-KDU-but-more-is-better
                    655: *              .      (KDU-by-NHo) horizontal work array WH along
                    656: *              .      the bottom edge,
                    657: *              .    - and an at-least-KDU-but-more-is-better-by-KDU
                    658: *              .      (NVE-by-KDU) vertical work WV arrow along
                    659: *              .      the left-hand-edge. ====
                    660: *
1.19    ! bertrand  661:                KDU = 2*NS
1.1       bertrand  662:                KU = N - KDU + 1
                    663:                KWH = KDU + 1
                    664:                NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1
                    665:                KWV = KDU + 4
                    666:                NVE = N - KDU - KWV + 1
                    667: *
                    668: *              ==== Small-bulge multi-shift QR sweep ====
                    669: *
                    670:                CALL ZLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS,
                    671:      $                      W( KS ), H, LDH, ILOZ, IHIZ, Z, LDZ, WORK,
                    672:      $                      3, H( KU, 1 ), LDH, NVE, H( KWV, 1 ), LDH,
                    673:      $                      NHO, H( KU, KWH ), LDH )
                    674:             END IF
                    675: *
                    676: *           ==== Note progress (or the lack of it). ====
                    677: *
                    678:             IF( LD.GT.0 ) THEN
                    679:                NDFL = 1
                    680:             ELSE
                    681:                NDFL = NDFL + 1
                    682:             END IF
                    683: *
                    684: *           ==== End of main loop ====
                    685:    70    CONTINUE
                    686: *
                    687: *        ==== Iteration limit exceeded.  Set INFO to show where
                    688: *        .    the problem occurred and exit. ====
                    689: *
                    690:          INFO = KBOT
                    691:    80    CONTINUE
                    692:       END IF
                    693: *
                    694: *     ==== Return the optimal value of LWORK. ====
                    695: *
                    696:       WORK( 1 ) = DCMPLX( LWKOPT, 0 )
                    697: *
                    698: *     ==== End of ZLAQR4 ====
                    699: *
                    700:       END

CVSweb interface <joel.bertrand@systella.fr>