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