LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
zlaqr0.f
Go to the documentation of this file.
00001 *> \brief \b ZLAQR0
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download ZLAQR0 + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlaqr0.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlaqr0.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlaqr0.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE ZLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
00022 *                          IHIZ, Z, LDZ, WORK, LWORK, INFO )
00023 * 
00024 *       .. Scalar Arguments ..
00025 *       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
00026 *       LOGICAL            WANTT, WANTZ
00027 *       ..
00028 *       .. Array Arguments ..
00029 *       COMPLEX*16         H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
00030 *       ..
00031 *  
00032 *
00033 *> \par Purpose:
00034 *  =============
00035 *>
00036 *> \verbatim
00037 *>
00038 *>    ZLAQR0 computes the eigenvalues of a Hessenberg matrix H
00039 *>    and, optionally, the matrices T and Z from the Schur decomposition
00040 *>    H = Z T Z**H, where T is an upper triangular matrix (the
00041 *>    Schur form), and Z is the unitary matrix of Schur vectors.
00042 *>
00043 *>    Optionally Z may be postmultiplied into an input unitary
00044 *>    matrix Q so that this routine can give the Schur factorization
00045 *>    of a matrix A which has been reduced to the Hessenberg form H
00046 *>    by the unitary matrix Q:  A = Q*H*Q**H = (QZ)*H*(QZ)**H.
00047 *> \endverbatim
00048 *
00049 *  Arguments:
00050 *  ==========
00051 *
00052 *> \param[in] WANTT
00053 *> \verbatim
00054 *>          WANTT is LOGICAL
00055 *>          = .TRUE. : the full Schur form T is required;
00056 *>          = .FALSE.: only eigenvalues are required.
00057 *> \endverbatim
00058 *>
00059 *> \param[in] WANTZ
00060 *> \verbatim
00061 *>          WANTZ is LOGICAL
00062 *>          = .TRUE. : the matrix of Schur vectors Z is required;
00063 *>          = .FALSE.: Schur vectors are not required.
00064 *> \endverbatim
00065 *>
00066 *> \param[in] N
00067 *> \verbatim
00068 *>          N is INTEGER
00069 *>           The order of the matrix H.  N .GE. 0.
00070 *> \endverbatim
00071 *>
00072 *> \param[in] ILO
00073 *> \verbatim
00074 *>          ILO is INTEGER
00075 *> \endverbatim
00076 *>
00077 *> \param[in] IHI
00078 *> \verbatim
00079 *>          IHI is INTEGER
00080 *>
00081 *>           It is assumed that H is already upper triangular in rows
00082 *>           and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
00083 *>           H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
00084 *>           previous call to ZGEBAL, and then passed to ZGEHRD when the
00085 *>           matrix output by ZGEBAL is reduced to Hessenberg form.
00086 *>           Otherwise, ILO and IHI should be set to 1 and N,
00087 *>           respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
00088 *>           If N = 0, then ILO = 1 and IHI = 0.
00089 *> \endverbatim
00090 *>
00091 *> \param[in,out] H
00092 *> \verbatim
00093 *>          H is COMPLEX*16 array, dimension (LDH,N)
00094 *>           On entry, the upper Hessenberg matrix H.
00095 *>           On exit, if INFO = 0 and WANTT is .TRUE., then H
00096 *>           contains the upper triangular matrix T from the Schur
00097 *>           decomposition (the Schur form). If INFO = 0 and WANT is
00098 *>           .FALSE., then the contents of H are unspecified on exit.
00099 *>           (The output value of H when INFO.GT.0 is given under the
00100 *>           description of INFO below.)
00101 *>
00102 *>           This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
00103 *>           j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
00104 *> \endverbatim
00105 *>
00106 *> \param[in] LDH
00107 *> \verbatim
00108 *>          LDH is INTEGER
00109 *>           The leading dimension of the array H. LDH .GE. max(1,N).
00110 *> \endverbatim
00111 *>
00112 *> \param[out] W
00113 *> \verbatim
00114 *>          W is COMPLEX*16 array, dimension (N)
00115 *>           The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored
00116 *>           in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are
00117 *>           stored in the same order as on the diagonal of the Schur
00118 *>           form returned in H, with W(i) = H(i,i).
00119 *> \endverbatim
00120 *>
00121 *> \param[in] ILOZ
00122 *> \verbatim
00123 *>          ILOZ is INTEGER
00124 *> \endverbatim
00125 *>
00126 *> \param[in] IHIZ
00127 *> \verbatim
00128 *>          IHIZ is INTEGER
00129 *>           Specify the rows of Z to which transformations must be
00130 *>           applied if WANTZ is .TRUE..
00131 *>           1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N.
00132 *> \endverbatim
00133 *>
00134 *> \param[in,out] Z
00135 *> \verbatim
00136 *>          Z is COMPLEX*16 array, dimension (LDZ,IHI)
00137 *>           If WANTZ is .FALSE., then Z is not referenced.
00138 *>           If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
00139 *>           replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
00140 *>           orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
00141 *>           (The output value of Z when INFO.GT.0 is given under
00142 *>           the description of INFO below.)
00143 *> \endverbatim
00144 *>
00145 *> \param[in] LDZ
00146 *> \verbatim
00147 *>          LDZ is INTEGER
00148 *>           The leading dimension of the array Z.  if WANTZ is .TRUE.
00149 *>           then LDZ.GE.MAX(1,IHIZ).  Otherwize, LDZ.GE.1.
00150 *> \endverbatim
00151 *>
00152 *> \param[out] WORK
00153 *> \verbatim
00154 *>          WORK is COMPLEX*16 array, dimension LWORK
00155 *>           On exit, if LWORK = -1, WORK(1) returns an estimate of
00156 *>           the optimal value for LWORK.
00157 *> \endverbatim
00158 *>
00159 *> \param[in] LWORK
00160 *> \verbatim
00161 *>          LWORK is INTEGER
00162 *>           The dimension of the array WORK.  LWORK .GE. max(1,N)
00163 *>           is sufficient, but LWORK typically as large as 6*N may
00164 *>           be required for optimal performance.  A workspace query
00165 *>           to determine the optimal workspace size is recommended.
00166 *>
00167 *>           If LWORK = -1, then ZLAQR0 does a workspace query.
00168 *>           In this case, ZLAQR0 checks the input parameters and
00169 *>           estimates the optimal workspace size for the given
00170 *>           values of N, ILO and IHI.  The estimate is returned
00171 *>           in WORK(1).  No error message related to LWORK is
00172 *>           issued by XERBLA.  Neither H nor Z are accessed.
00173 *> \endverbatim
00174 *>
00175 *> \param[out] INFO
00176 *> \verbatim
00177 *>          INFO is INTEGER
00178 *>             =  0:  successful exit
00179 *>           .GT. 0:  if INFO = i, ZLAQR0 failed to compute all of
00180 *>                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
00181 *>                and WI contain those eigenvalues which have been
00182 *>                successfully computed.  (Failures are rare.)
00183 *>
00184 *>                If INFO .GT. 0 and WANT is .FALSE., then on exit,
00185 *>                the remaining unconverged eigenvalues are the eigen-
00186 *>                values of the upper Hessenberg matrix rows and
00187 *>                columns ILO through INFO of the final, output
00188 *>                value of H.
00189 *>
00190 *>                If INFO .GT. 0 and WANTT is .TRUE., then on exit
00191 *>
00192 *>           (*)  (initial value of H)*U  = U*(final value of H)
00193 *>
00194 *>                where U is a unitary matrix.  The final
00195 *>                value of  H is upper Hessenberg and triangular in
00196 *>                rows and columns INFO+1 through IHI.
00197 *>
00198 *>                If INFO .GT. 0 and WANTZ is .TRUE., then on exit
00199 *>
00200 *>                  (final value of Z(ILO:IHI,ILOZ:IHIZ)
00201 *>                   =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
00202 *>
00203 *>                where U is the unitary matrix in (*) (regard-
00204 *>                less of the value of WANTT.)
00205 *>
00206 *>                If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
00207 *>                accessed.
00208 *> \endverbatim
00209 *
00210 *  Authors:
00211 *  ========
00212 *
00213 *> \author Univ. of Tennessee 
00214 *> \author Univ. of California Berkeley 
00215 *> \author Univ. of Colorado Denver 
00216 *> \author NAG Ltd. 
00217 *
00218 *> \date November 2011
00219 *
00220 *> \ingroup complex16OTHERauxiliary
00221 *
00222 *> \par Contributors:
00223 *  ==================
00224 *>
00225 *>       Karen Braman and Ralph Byers, Department of Mathematics,
00226 *>       University of Kansas, USA
00227 *
00228 *> \par References:
00229 *  ================
00230 *>
00231 *>       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
00232 *>       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
00233 *>       Performance, SIAM Journal of Matrix Analysis, volume 23, pages
00234 *>       929--947, 2002.
00235 *> \n
00236 *>       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
00237 *>       Algorithm Part II: Aggressive Early Deflation, SIAM Journal
00238 *>       of Matrix Analysis, volume 23, pages 948--973, 2002.
00239 *>
00240 *  =====================================================================
00241       SUBROUTINE ZLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
00242      $                   IHIZ, Z, LDZ, WORK, LWORK, INFO )
00243 *
00244 *  -- LAPACK auxiliary routine (version 3.4.0) --
00245 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00246 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00247 *     November 2011
00248 *
00249 *     .. Scalar Arguments ..
00250       INTEGER            IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
00251       LOGICAL            WANTT, WANTZ
00252 *     ..
00253 *     .. Array Arguments ..
00254       COMPLEX*16         H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
00255 *     ..
00256 *
00257 *  ================================================================
00258 *
00259 *     .. Parameters ..
00260 *
00261 *     ==== Matrices of order NTINY or smaller must be processed by
00262 *     .    ZLAHQR because of insufficient subdiagonal scratch space.
00263 *     .    (This is a hard limit.) ====
00264       INTEGER            NTINY
00265       PARAMETER          ( NTINY = 11 )
00266 *
00267 *     ==== Exceptional deflation windows:  try to cure rare
00268 *     .    slow convergence by varying the size of the
00269 *     .    deflation window after KEXNW iterations. ====
00270       INTEGER            KEXNW
00271       PARAMETER          ( KEXNW = 5 )
00272 *
00273 *     ==== Exceptional shifts: try to cure rare slow convergence
00274 *     .    with ad-hoc exceptional shifts every KEXSH iterations.
00275 *     .    ====
00276       INTEGER            KEXSH
00277       PARAMETER          ( KEXSH = 6 )
00278 *
00279 *     ==== The constant WILK1 is used to form the exceptional
00280 *     .    shifts. ====
00281       DOUBLE PRECISION   WILK1
00282       PARAMETER          ( WILK1 = 0.75d0 )
00283       COMPLEX*16         ZERO, ONE
00284       PARAMETER          ( ZERO = ( 0.0d0, 0.0d0 ),
00285      $                   ONE = ( 1.0d0, 0.0d0 ) )
00286       DOUBLE PRECISION   TWO
00287       PARAMETER          ( TWO = 2.0d0 )
00288 *     ..
00289 *     .. Local Scalars ..
00290       COMPLEX*16         AA, BB, CC, CDUM, DD, DET, RTDISC, SWAP, TR2
00291       DOUBLE PRECISION   S
00292       INTEGER            I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
00293      $                   KT, KTOP, KU, KV, KWH, KWTOP, KWV, LD, LS,
00294      $                   LWKOPT, NDEC, NDFL, NH, NHO, NIBBLE, NMIN, NS,
00295      $                   NSMAX, NSR, NVE, NW, NWMAX, NWR, NWUPBD
00296       LOGICAL            SORTED
00297       CHARACTER          JBCMPZ*2
00298 *     ..
00299 *     .. External Functions ..
00300       INTEGER            ILAENV
00301       EXTERNAL           ILAENV
00302 *     ..
00303 *     .. Local Arrays ..
00304       COMPLEX*16         ZDUM( 1, 1 )
00305 *     ..
00306 *     .. External Subroutines ..
00307       EXTERNAL           ZLACPY, ZLAHQR, ZLAQR3, ZLAQR4, ZLAQR5
00308 *     ..
00309 *     .. Intrinsic Functions ..
00310       INTRINSIC          ABS, DBLE, DCMPLX, DIMAG, INT, MAX, MIN, MOD,
00311      $                   SQRT
00312 *     ..
00313 *     .. Statement Functions ..
00314       DOUBLE PRECISION   CABS1
00315 *     ..
00316 *     .. Statement Function definitions ..
00317       CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
00318 *     ..
00319 *     .. Executable Statements ..
00320       INFO = 0
00321 *
00322 *     ==== Quick return for N = 0: nothing to do. ====
00323 *
00324       IF( N.EQ.0 ) THEN
00325          WORK( 1 ) = ONE
00326          RETURN
00327       END IF
00328 *
00329       IF( N.LE.NTINY ) THEN
00330 *
00331 *        ==== Tiny matrices must use ZLAHQR. ====
00332 *
00333          LWKOPT = 1
00334          IF( LWORK.NE.-1 )
00335      $      CALL ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
00336      $                   IHIZ, Z, LDZ, INFO )
00337       ELSE
00338 *
00339 *        ==== Use small bulge multi-shift QR with aggressive early
00340 *        .    deflation on larger-than-tiny matrices. ====
00341 *
00342 *        ==== Hope for the best. ====
00343 *
00344          INFO = 0
00345 *
00346 *        ==== Set up job flags for ILAENV. ====
00347 *
00348          IF( WANTT ) THEN
00349             JBCMPZ( 1: 1 ) = 'S'
00350          ELSE
00351             JBCMPZ( 1: 1 ) = 'E'
00352          END IF
00353          IF( WANTZ ) THEN
00354             JBCMPZ( 2: 2 ) = 'V'
00355          ELSE
00356             JBCMPZ( 2: 2 ) = 'N'
00357          END IF
00358 *
00359 *        ==== NWR = recommended deflation window size.  At this
00360 *        .    point,  N .GT. NTINY = 11, so there is enough
00361 *        .    subdiagonal workspace for NWR.GE.2 as required.
00362 *        .    (In fact, there is enough subdiagonal space for
00363 *        .    NWR.GE.3.) ====
00364 *
00365          NWR = ILAENV( 13, 'ZLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00366          NWR = MAX( 2, NWR )
00367          NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
00368 *
00369 *        ==== NSR = recommended number of simultaneous shifts.
00370 *        .    At this point N .GT. NTINY = 11, so there is at
00371 *        .    enough subdiagonal workspace for NSR to be even
00372 *        .    and greater than or equal to two as required. ====
00373 *
00374          NSR = ILAENV( 15, 'ZLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00375          NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO )
00376          NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
00377 *
00378 *        ==== Estimate optimal workspace ====
00379 *
00380 *        ==== Workspace query call to ZLAQR3 ====
00381 *
00382          CALL ZLAQR3( WANTT, WANTZ, N, ILO, IHI, NWR+1, H, LDH, ILOZ,
00383      $                IHIZ, Z, LDZ, LS, LD, W, H, LDH, N, H, LDH, N, H,
00384      $                LDH, WORK, -1 )
00385 *
00386 *        ==== Optimal workspace = MAX(ZLAQR5, ZLAQR3) ====
00387 *
00388          LWKOPT = MAX( 3*NSR / 2, INT( WORK( 1 ) ) )
00389 *
00390 *        ==== Quick return in case of workspace query. ====
00391 *
00392          IF( LWORK.EQ.-1 ) THEN
00393             WORK( 1 ) = DCMPLX( LWKOPT, 0 )
00394             RETURN
00395          END IF
00396 *
00397 *        ==== ZLAHQR/ZLAQR0 crossover point ====
00398 *
00399          NMIN = ILAENV( 12, 'ZLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00400          NMIN = MAX( NTINY, NMIN )
00401 *
00402 *        ==== Nibble crossover point ====
00403 *
00404          NIBBLE = ILAENV( 14, 'ZLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00405          NIBBLE = MAX( 0, NIBBLE )
00406 *
00407 *        ==== Accumulate reflections during ttswp?  Use block
00408 *        .    2-by-2 structure during matrix-matrix multiply? ====
00409 *
00410          KACC22 = ILAENV( 16, 'ZLAQR0', JBCMPZ, N, ILO, IHI, LWORK )
00411          KACC22 = MAX( 0, KACC22 )
00412          KACC22 = MIN( 2, KACC22 )
00413 *
00414 *        ==== NWMAX = the largest possible deflation window for
00415 *        .    which there is sufficient workspace. ====
00416 *
00417          NWMAX = MIN( ( N-1 ) / 3, LWORK / 2 )
00418          NW = NWMAX
00419 *
00420 *        ==== NSMAX = the Largest number of simultaneous shifts
00421 *        .    for which there is sufficient workspace. ====
00422 *
00423          NSMAX = MIN( ( N+6 ) / 9, 2*LWORK / 3 )
00424          NSMAX = NSMAX - MOD( NSMAX, 2 )
00425 *
00426 *        ==== NDFL: an iteration count restarted at deflation. ====
00427 *
00428          NDFL = 1
00429 *
00430 *        ==== ITMAX = iteration limit ====
00431 *
00432          ITMAX = MAX( 30, 2*KEXSH )*MAX( 10, ( IHI-ILO+1 ) )
00433 *
00434 *        ==== Last row and column in the active block ====
00435 *
00436          KBOT = IHI
00437 *
00438 *        ==== Main Loop ====
00439 *
00440          DO 70 IT = 1, ITMAX
00441 *
00442 *           ==== Done when KBOT falls below ILO ====
00443 *
00444             IF( KBOT.LT.ILO )
00445      $         GO TO 80
00446 *
00447 *           ==== Locate active block ====
00448 *
00449             DO 10 K = KBOT, ILO + 1, -1
00450                IF( H( K, K-1 ).EQ.ZERO )
00451      $            GO TO 20
00452    10       CONTINUE
00453             K = ILO
00454    20       CONTINUE
00455             KTOP = K
00456 *
00457 *           ==== Select deflation window size:
00458 *           .    Typical Case:
00459 *           .      If possible and advisable, nibble the entire
00460 *           .      active block.  If not, use size MIN(NWR,NWMAX)
00461 *           .      or MIN(NWR+1,NWMAX) depending upon which has
00462 *           .      the smaller corresponding subdiagonal entry
00463 *           .      (a heuristic).
00464 *           .
00465 *           .    Exceptional Case:
00466 *           .      If there have been no deflations in KEXNW or
00467 *           .      more iterations, then vary the deflation window
00468 *           .      size.   At first, because, larger windows are,
00469 *           .      in general, more powerful than smaller ones,
00470 *           .      rapidly increase the window to the maximum possible.
00471 *           .      Then, gradually reduce the window size. ====
00472 *
00473             NH = KBOT - KTOP + 1
00474             NWUPBD = MIN( NH, NWMAX )
00475             IF( NDFL.LT.KEXNW ) THEN
00476                NW = MIN( NWUPBD, NWR )
00477             ELSE
00478                NW = MIN( NWUPBD, 2*NW )
00479             END IF
00480             IF( NW.LT.NWMAX ) THEN
00481                IF( NW.GE.NH-1 ) THEN
00482                   NW = NH
00483                ELSE
00484                   KWTOP = KBOT - NW + 1
00485                   IF( CABS1( H( KWTOP, KWTOP-1 ) ).GT.
00486      $                CABS1( H( KWTOP-1, KWTOP-2 ) ) )NW = NW + 1
00487                END IF
00488             END IF
00489             IF( NDFL.LT.KEXNW ) THEN
00490                NDEC = -1
00491             ELSE IF( NDEC.GE.0 .OR. NW.GE.NWUPBD ) THEN
00492                NDEC = NDEC + 1
00493                IF( NW-NDEC.LT.2 )
00494      $            NDEC = 0
00495                NW = NW - NDEC
00496             END IF
00497 *
00498 *           ==== Aggressive early deflation:
00499 *           .    split workspace under the subdiagonal into
00500 *           .      - an nw-by-nw work array V in the lower
00501 *           .        left-hand-corner,
00502 *           .      - an NW-by-at-least-NW-but-more-is-better
00503 *           .        (NW-by-NHO) horizontal work array along
00504 *           .        the bottom edge,
00505 *           .      - an at-least-NW-but-more-is-better (NHV-by-NW)
00506 *           .        vertical work array along the left-hand-edge.
00507 *           .        ====
00508 *
00509             KV = N - NW + 1
00510             KT = NW + 1
00511             NHO = ( N-NW-1 ) - KT + 1
00512             KWV = NW + 2
00513             NVE = ( N-NW ) - KWV + 1
00514 *
00515 *           ==== Aggressive early deflation ====
00516 *
00517             CALL ZLAQR3( WANTT, WANTZ, N, KTOP, KBOT, NW, H, LDH, ILOZ,
00518      $                   IHIZ, Z, LDZ, LS, LD, W, H( KV, 1 ), LDH, NHO,
00519      $                   H( KV, KT ), LDH, NVE, H( KWV, 1 ), LDH, WORK,
00520      $                   LWORK )
00521 *
00522 *           ==== Adjust KBOT accounting for new deflations. ====
00523 *
00524             KBOT = KBOT - LD
00525 *
00526 *           ==== KS points to the shifts. ====
00527 *
00528             KS = KBOT - LS + 1
00529 *
00530 *           ==== Skip an expensive QR sweep if there is a (partly
00531 *           .    heuristic) reason to expect that many eigenvalues
00532 *           .    will deflate without it.  Here, the QR sweep is
00533 *           .    skipped if many eigenvalues have just been deflated
00534 *           .    or if the remaining active block is small.
00535 *
00536             IF( ( LD.EQ.0 ) .OR. ( ( 100*LD.LE.NW*NIBBLE ) .AND. ( KBOT-
00537      $          KTOP+1.GT.MIN( NMIN, NWMAX ) ) ) ) THEN
00538 *
00539 *              ==== NS = nominal number of simultaneous shifts.
00540 *              .    This may be lowered (slightly) if ZLAQR3
00541 *              .    did not provide that many shifts. ====
00542 *
00543                NS = MIN( NSMAX, NSR, MAX( 2, KBOT-KTOP ) )
00544                NS = NS - MOD( NS, 2 )
00545 *
00546 *              ==== If there have been no deflations
00547 *              .    in a multiple of KEXSH iterations,
00548 *              .    then try exceptional shifts.
00549 *              .    Otherwise use shifts provided by
00550 *              .    ZLAQR3 above or from the eigenvalues
00551 *              .    of a trailing principal submatrix. ====
00552 *
00553                IF( MOD( NDFL, KEXSH ).EQ.0 ) THEN
00554                   KS = KBOT - NS + 1
00555                   DO 30 I = KBOT, KS + 1, -2
00556                      W( I ) = H( I, I ) + WILK1*CABS1( H( I, I-1 ) )
00557                      W( I-1 ) = W( I )
00558    30             CONTINUE
00559                ELSE
00560 *
00561 *                 ==== Got NS/2 or fewer shifts? Use ZLAQR4 or
00562 *                 .    ZLAHQR on a trailing principal submatrix to
00563 *                 .    get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
00564 *                 .    there is enough space below the subdiagonal
00565 *                 .    to fit an NS-by-NS scratch array.) ====
00566 *
00567                   IF( KBOT-KS+1.LE.NS / 2 ) THEN
00568                      KS = KBOT - NS + 1
00569                      KT = N - NS + 1
00570                      CALL ZLACPY( 'A', NS, NS, H( KS, KS ), LDH,
00571      $                            H( KT, 1 ), LDH )
00572                      IF( NS.GT.NMIN ) THEN
00573                         CALL ZLAQR4( .false., .false., NS, 1, NS,
00574      $                               H( KT, 1 ), LDH, W( KS ), 1, 1,
00575      $                               ZDUM, 1, WORK, LWORK, INF )
00576                      ELSE
00577                         CALL ZLAHQR( .false., .false., NS, 1, NS,
00578      $                               H( KT, 1 ), LDH, W( KS ), 1, 1,
00579      $                               ZDUM, 1, INF )
00580                      END IF
00581                      KS = KS + INF
00582 *
00583 *                    ==== In case of a rare QR failure use
00584 *                    .    eigenvalues of the trailing 2-by-2
00585 *                    .    principal submatrix.  Scale to avoid
00586 *                    .    overflows, underflows and subnormals.
00587 *                    .    (The scale factor S can not be zero,
00588 *                    .    because H(KBOT,KBOT-1) is nonzero.) ====
00589 *
00590                      IF( KS.GE.KBOT ) THEN
00591                         S = CABS1( H( KBOT-1, KBOT-1 ) ) +
00592      $                      CABS1( H( KBOT, KBOT-1 ) ) +
00593      $                      CABS1( H( KBOT-1, KBOT ) ) +
00594      $                      CABS1( H( KBOT, KBOT ) )
00595                         AA = H( KBOT-1, KBOT-1 ) / S
00596                         CC = H( KBOT, KBOT-1 ) / S
00597                         BB = H( KBOT-1, KBOT ) / S
00598                         DD = H( KBOT, KBOT ) / S
00599                         TR2 = ( AA+DD ) / TWO
00600                         DET = ( AA-TR2 )*( DD-TR2 ) - BB*CC
00601                         RTDISC = SQRT( -DET )
00602                         W( KBOT-1 ) = ( TR2+RTDISC )*S
00603                         W( KBOT ) = ( TR2-RTDISC )*S
00604 *
00605                         KS = KBOT - 1
00606                      END IF
00607                   END IF
00608 *
00609                   IF( KBOT-KS+1.GT.NS ) THEN
00610 *
00611 *                    ==== Sort the shifts (Helps a little) ====
00612 *
00613                      SORTED = .false.
00614                      DO 50 K = KBOT, KS + 1, -1
00615                         IF( SORTED )
00616      $                     GO TO 60
00617                         SORTED = .true.
00618                         DO 40 I = KS, K - 1
00619                            IF( CABS1( W( I ) ).LT.CABS1( W( I+1 ) ) )
00620      $                          THEN
00621                               SORTED = .false.
00622                               SWAP = W( I )
00623                               W( I ) = W( I+1 )
00624                               W( I+1 ) = SWAP
00625                            END IF
00626    40                   CONTINUE
00627    50                CONTINUE
00628    60                CONTINUE
00629                   END IF
00630                END IF
00631 *
00632 *              ==== If there are only two shifts, then use
00633 *              .    only one.  ====
00634 *
00635                IF( KBOT-KS+1.EQ.2 ) THEN
00636                   IF( CABS1( W( KBOT )-H( KBOT, KBOT ) ).LT.
00637      $                CABS1( W( KBOT-1 )-H( KBOT, KBOT ) ) ) THEN
00638                      W( KBOT-1 ) = W( KBOT )
00639                   ELSE
00640                      W( KBOT ) = W( KBOT-1 )
00641                   END IF
00642                END IF
00643 *
00644 *              ==== Use up to NS of the the smallest magnatiude
00645 *              .    shifts.  If there aren't NS shifts available,
00646 *              .    then use them all, possibly dropping one to
00647 *              .    make the number of shifts even. ====
00648 *
00649                NS = MIN( NS, KBOT-KS+1 )
00650                NS = NS - MOD( NS, 2 )
00651                KS = KBOT - NS + 1
00652 *
00653 *              ==== Small-bulge multi-shift QR sweep:
00654 *              .    split workspace under the subdiagonal into
00655 *              .    - a KDU-by-KDU work array U in the lower
00656 *              .      left-hand-corner,
00657 *              .    - a KDU-by-at-least-KDU-but-more-is-better
00658 *              .      (KDU-by-NHo) horizontal work array WH along
00659 *              .      the bottom edge,
00660 *              .    - and an at-least-KDU-but-more-is-better-by-KDU
00661 *              .      (NVE-by-KDU) vertical work WV arrow along
00662 *              .      the left-hand-edge. ====
00663 *
00664                KDU = 3*NS - 3
00665                KU = N - KDU + 1
00666                KWH = KDU + 1
00667                NHO = ( N-KDU+1-4 ) - ( KDU+1 ) + 1
00668                KWV = KDU + 4
00669                NVE = N - KDU - KWV + 1
00670 *
00671 *              ==== Small-bulge multi-shift QR sweep ====
00672 *
00673                CALL ZLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NS,
00674      $                      W( KS ), H, LDH, ILOZ, IHIZ, Z, LDZ, WORK,
00675      $                      3, H( KU, 1 ), LDH, NVE, H( KWV, 1 ), LDH,
00676      $                      NHO, H( KU, KWH ), LDH )
00677             END IF
00678 *
00679 *           ==== Note progress (or the lack of it). ====
00680 *
00681             IF( LD.GT.0 ) THEN
00682                NDFL = 1
00683             ELSE
00684                NDFL = NDFL + 1
00685             END IF
00686 *
00687 *           ==== End of main loop ====
00688    70    CONTINUE
00689 *
00690 *        ==== Iteration limit exceeded.  Set INFO to show where
00691 *        .    the problem occurred and exit. ====
00692 *
00693          INFO = KBOT
00694    80    CONTINUE
00695       END IF
00696 *
00697 *     ==== Return the optimal value of LWORK. ====
00698 *
00699       WORK( 1 ) = DCMPLX( LWKOPT, 0 )
00700 *
00701 *     ==== End of ZLAQR0 ====
00702 *
00703       END
 All Files Functions