LAPACK 3.3.0

zhseqr.f

Go to the documentation of this file.
00001       SUBROUTINE ZHSEQR( JOB, COMPZ, N, ILO, IHI, H, LDH, W, Z, LDZ,
00002      $                   WORK, LWORK, INFO )
00003 *
00004 *  -- LAPACK computational routine (version 3.2.2) --
00005 *     Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
00006 *     June 2010
00007 *
00008 *     .. Scalar Arguments ..
00009       INTEGER            IHI, ILO, INFO, LDH, LDZ, LWORK, N
00010       CHARACTER          COMPZ, JOB
00011 *     ..
00012 *     .. Array Arguments ..
00013       COMPLEX*16         H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * )
00014 *     ..
00015 *     Purpose
00016 *     =======
00017 *
00018 *     ZHSEQR computes the eigenvalues of a Hessenberg matrix H
00019 *     and, optionally, the matrices T and Z from the Schur decomposition
00020 *     H = Z T Z**H, where T is an upper triangular matrix (the
00021 *     Schur form), and Z is the unitary matrix of Schur vectors.
00022 *
00023 *     Optionally Z may be postmultiplied into an input unitary
00024 *     matrix Q so that this routine can give the Schur factorization
00025 *     of a matrix A which has been reduced to the Hessenberg form H
00026 *     by the unitary matrix Q:  A = Q*H*Q**H = (QZ)*H*(QZ)**H.
00027 *
00028 *     Arguments
00029 *     =========
00030 *
00031 *     JOB   (input) CHARACTER*1
00032 *           = 'E':  compute eigenvalues only;
00033 *           = 'S':  compute eigenvalues and the Schur form T.
00034 *
00035 *     COMPZ (input) CHARACTER*1
00036 *           = 'N':  no Schur vectors are computed;
00037 *           = 'I':  Z is initialized to the unit matrix and the matrix Z
00038 *                   of Schur vectors of H is returned;
00039 *           = 'V':  Z must contain an unitary matrix Q on entry, and
00040 *                   the product Q*Z is returned.
00041 *
00042 *     N     (input) INTEGER
00043 *           The order of the matrix H.  N .GE. 0.
00044 *
00045 *     ILO   (input) INTEGER
00046 *     IHI   (input) INTEGER
00047 *           It is assumed that H is already upper triangular in rows
00048 *           and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
00049 *           set by a previous call to ZGEBAL, and then passed to ZGEHRD
00050 *           when the matrix output by ZGEBAL is reduced to Hessenberg
00051 *           form. Otherwise ILO and IHI should be set to 1 and N
00052 *           respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
00053 *           If N = 0, then ILO = 1 and IHI = 0.
00054 *
00055 *     H     (input/output) COMPLEX*16 array, dimension (LDH,N)
00056 *           On entry, the upper Hessenberg matrix H.
00057 *           On exit, if INFO = 0 and JOB = 'S', H contains the upper
00058 *           triangular matrix T from the Schur decomposition (the
00059 *           Schur form). If INFO = 0 and JOB = 'E', the contents of
00060 *           H are unspecified on exit.  (The output value of H when
00061 *           INFO.GT.0 is given under the description of INFO below.)
00062 *
00063 *           Unlike earlier versions of ZHSEQR, this subroutine may
00064 *           explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1
00065 *           or j = IHI+1, IHI+2, ... N.
00066 *
00067 *     LDH   (input) INTEGER
00068 *           The leading dimension of the array H. LDH .GE. max(1,N).
00069 *
00070 *     W        (output) COMPLEX*16 array, dimension (N)
00071 *           The computed eigenvalues. If JOB = 'S', the eigenvalues are
00072 *           stored in the same order as on the diagonal of the Schur
00073 *           form returned in H, with W(i) = H(i,i).
00074 *
00075 *     Z     (input/output) COMPLEX*16 array, dimension (LDZ,N)
00076 *           If COMPZ = 'N', Z is not referenced.
00077 *           If COMPZ = 'I', on entry Z need not be set and on exit,
00078 *           if INFO = 0, Z contains the unitary matrix Z of the Schur
00079 *           vectors of H.  If COMPZ = 'V', on entry Z must contain an
00080 *           N-by-N matrix Q, which is assumed to be equal to the unit
00081 *           matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit,
00082 *           if INFO = 0, Z contains Q*Z.
00083 *           Normally Q is the unitary matrix generated by ZUNGHR
00084 *           after the call to ZGEHRD which formed the Hessenberg matrix
00085 *           H. (The output value of Z when INFO.GT.0 is given under
00086 *           the description of INFO below.)
00087 *
00088 *     LDZ   (input) INTEGER
00089 *           The leading dimension of the array Z.  if COMPZ = 'I' or
00090 *           COMPZ = 'V', then LDZ.GE.MAX(1,N).  Otherwize, LDZ.GE.1.
00091 *
00092 *     WORK  (workspace/output) COMPLEX*16 array, dimension (LWORK)
00093 *           On exit, if INFO = 0, WORK(1) returns an estimate of
00094 *           the optimal value for LWORK.
00095 *
00096 *     LWORK (input) INTEGER
00097 *           The dimension of the array WORK.  LWORK .GE. max(1,N)
00098 *           is sufficient and delivers very good and sometimes
00099 *           optimal performance.  However, LWORK as large as 11*N
00100 *           may be required for optimal performance.  A workspace
00101 *           query is recommended to determine the optimal workspace
00102 *           size.
00103 *
00104 *           If LWORK = -1, then ZHSEQR does a workspace query.
00105 *           In this case, ZHSEQR checks the input parameters and
00106 *           estimates the optimal workspace size for the given
00107 *           values of N, ILO and IHI.  The estimate is returned
00108 *           in WORK(1).  No error message related to LWORK is
00109 *           issued by XERBLA.  Neither H nor Z are accessed.
00110 *
00111 *
00112 *     INFO  (output) INTEGER
00113 *             =  0:  successful exit
00114 *           .LT. 0:  if INFO = -i, the i-th argument had an illegal
00115 *                    value
00116 *           .GT. 0:  if INFO = i, ZHSEQR failed to compute all of
00117 *                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR
00118 *                and WI contain those eigenvalues which have been
00119 *                successfully computed.  (Failures are rare.)
00120 *
00121 *                If INFO .GT. 0 and JOB = 'E', then on exit, the
00122 *                remaining unconverged eigenvalues are the eigen-
00123 *                values of the upper Hessenberg matrix rows and
00124 *                columns ILO through INFO of the final, output
00125 *                value of H.
00126 *
00127 *                If INFO .GT. 0 and JOB   = 'S', then on exit
00128 *
00129 *           (*)  (initial value of H)*U  = U*(final value of H)
00130 *
00131 *                where U is a unitary matrix.  The final
00132 *                value of  H is upper Hessenberg and triangular in
00133 *                rows and columns INFO+1 through IHI.
00134 *
00135 *                If INFO .GT. 0 and COMPZ = 'V', then on exit
00136 *
00137 *                  (final value of Z)  =  (initial value of Z)*U
00138 *
00139 *                where U is the unitary matrix in (*) (regard-
00140 *                less of the value of JOB.)
00141 *
00142 *                If INFO .GT. 0 and COMPZ = 'I', then on exit
00143 *                      (final value of Z)  = U
00144 *                where U is the unitary matrix in (*) (regard-
00145 *                less of the value of JOB.)
00146 *
00147 *                If INFO .GT. 0 and COMPZ = 'N', then Z is not
00148 *                accessed.
00149 *
00150 *     ================================================================
00151 *             Default values supplied by
00152 *             ILAENV(ISPEC,'ZHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK).
00153 *             It is suggested that these defaults be adjusted in order
00154 *             to attain best performance in each particular
00155 *             computational environment.
00156 *
00157 *            ISPEC=12: The ZLAHQR vs ZLAQR0 crossover point.
00158 *                      Default: 75. (Must be at least 11.)
00159 *
00160 *            ISPEC=13: Recommended deflation window size.
00161 *                      This depends on ILO, IHI and NS.  NS is the
00162 *                      number of simultaneous shifts returned
00163 *                      by ILAENV(ISPEC=15).  (See ISPEC=15 below.)
00164 *                      The default for (IHI-ILO+1).LE.500 is NS.
00165 *                      The default for (IHI-ILO+1).GT.500 is 3*NS/2.
00166 *
00167 *            ISPEC=14: Nibble crossover point. (See IPARMQ for
00168 *                      details.)  Default: 14% of deflation window
00169 *                      size.
00170 *
00171 *            ISPEC=15: Number of simultaneous shifts in a multishift
00172 *                      QR iteration.
00173 *
00174 *                      If IHI-ILO+1 is ...
00175 *
00176 *                      greater than      ...but less    ... the
00177 *                      or equal to ...      than        default is
00178 *
00179 *                           1               30          NS =   2(+)
00180 *                          30               60          NS =   4(+)
00181 *                          60              150          NS =  10(+)
00182 *                         150              590          NS =  **
00183 *                         590             3000          NS =  64
00184 *                        3000             6000          NS = 128
00185 *                        6000             infinity      NS = 256
00186 *
00187 *                  (+)  By default some or all matrices of this order
00188 *                       are passed to the implicit double shift routine
00189 *                       ZLAHQR and this parameter is ignored.  See
00190 *                       ISPEC=12 above and comments in IPARMQ for
00191 *                       details.
00192 *
00193 *                 (**)  The asterisks (**) indicate an ad-hoc
00194 *                       function of N increasing from 10 to 64.
00195 *
00196 *            ISPEC=16: Select structured matrix multiply.
00197 *                      If the number of simultaneous shifts (specified
00198 *                      by ISPEC=15) is less than 14, then the default
00199 *                      for ISPEC=16 is 0.  Otherwise the default for
00200 *                      ISPEC=16 is 2.
00201 *
00202 *     ================================================================
00203 *     Based on contributions by
00204 *        Karen Braman and Ralph Byers, Department of Mathematics,
00205 *        University of Kansas, USA
00206 *
00207 *     ================================================================
00208 *     References:
00209 *       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
00210 *       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
00211 *       Performance, SIAM Journal of Matrix Analysis, volume 23, pages
00212 *       929--947, 2002.
00213 *
00214 *       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
00215 *       Algorithm Part II: Aggressive Early Deflation, SIAM Journal
00216 *       of Matrix Analysis, volume 23, pages 948--973, 2002.
00217 *
00218 *     ================================================================
00219 *     .. Parameters ..
00220 *
00221 *     ==== Matrices of order NTINY or smaller must be processed by
00222 *     .    ZLAHQR because of insufficient subdiagonal scratch space.
00223 *     .    (This is a hard limit.) ====
00224       INTEGER            NTINY
00225       PARAMETER          ( NTINY = 11 )
00226 *
00227 *     ==== NL allocates some local workspace to help small matrices
00228 *     .    through a rare ZLAHQR failure.  NL .GT. NTINY = 11 is
00229 *     .    required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom-
00230 *     .    mended.  (The default value of NMIN is 75.)  Using NL = 49
00231 *     .    allows up to six simultaneous shifts and a 16-by-16
00232 *     .    deflation window.  ====
00233       INTEGER            NL
00234       PARAMETER          ( NL = 49 )
00235       COMPLEX*16         ZERO, ONE
00236       PARAMETER          ( ZERO = ( 0.0d0, 0.0d0 ),
00237      $                   ONE = ( 1.0d0, 0.0d0 ) )
00238       DOUBLE PRECISION   RZERO
00239       PARAMETER          ( RZERO = 0.0d0 )
00240 *     ..
00241 *     .. Local Arrays ..
00242       COMPLEX*16         HL( NL, NL ), WORKL( NL )
00243 *     ..
00244 *     .. Local Scalars ..
00245       INTEGER            KBOT, NMIN
00246       LOGICAL            INITZ, LQUERY, WANTT, WANTZ
00247 *     ..
00248 *     .. External Functions ..
00249       INTEGER            ILAENV
00250       LOGICAL            LSAME
00251       EXTERNAL           ILAENV, LSAME
00252 *     ..
00253 *     .. External Subroutines ..
00254       EXTERNAL           XERBLA, ZCOPY, ZLACPY, ZLAHQR, ZLAQR0, ZLASET
00255 *     ..
00256 *     .. Intrinsic Functions ..
00257       INTRINSIC          DBLE, DCMPLX, MAX, MIN
00258 *     ..
00259 *     .. Executable Statements ..
00260 *
00261 *     ==== Decode and check the input parameters. ====
00262 *
00263       WANTT = LSAME( JOB, 'S' )
00264       INITZ = LSAME( COMPZ, 'I' )
00265       WANTZ = INITZ .OR. LSAME( COMPZ, 'V' )
00266       WORK( 1 ) = DCMPLX( DBLE( MAX( 1, N ) ), RZERO )
00267       LQUERY = LWORK.EQ.-1
00268 *
00269       INFO = 0
00270       IF( .NOT.LSAME( JOB, 'E' ) .AND. .NOT.WANTT ) THEN
00271          INFO = -1
00272       ELSE IF( .NOT.LSAME( COMPZ, 'N' ) .AND. .NOT.WANTZ ) THEN
00273          INFO = -2
00274       ELSE IF( N.LT.0 ) THEN
00275          INFO = -3
00276       ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
00277          INFO = -4
00278       ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
00279          INFO = -5
00280       ELSE IF( LDH.LT.MAX( 1, N ) ) THEN
00281          INFO = -7
00282       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.MAX( 1, N ) ) ) THEN
00283          INFO = -10
00284       ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
00285          INFO = -12
00286       END IF
00287 *
00288       IF( INFO.NE.0 ) THEN
00289 *
00290 *        ==== Quick return in case of invalid argument. ====
00291 *
00292          CALL XERBLA( 'ZHSEQR', -INFO )
00293          RETURN
00294 *
00295       ELSE IF( N.EQ.0 ) THEN
00296 *
00297 *        ==== Quick return in case N = 0; nothing to do. ====
00298 *
00299          RETURN
00300 *
00301       ELSE IF( LQUERY ) THEN
00302 *
00303 *        ==== Quick return in case of a workspace query ====
00304 *
00305          CALL ZLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILO, IHI, Z,
00306      $                LDZ, WORK, LWORK, INFO )
00307 *        ==== Ensure reported workspace size is backward-compatible with
00308 *        .    previous LAPACK versions. ====
00309          WORK( 1 ) = DCMPLX( MAX( DBLE( WORK( 1 ) ), DBLE( MAX( 1,
00310      $               N ) ) ), RZERO )
00311          RETURN
00312 *
00313       ELSE
00314 *
00315 *        ==== copy eigenvalues isolated by ZGEBAL ====
00316 *
00317          IF( ILO.GT.1 )
00318      $      CALL ZCOPY( ILO-1, H, LDH+1, W, 1 )
00319          IF( IHI.LT.N )
00320      $      CALL ZCOPY( N-IHI, H( IHI+1, IHI+1 ), LDH+1, W( IHI+1 ), 1 )
00321 *
00322 *        ==== Initialize Z, if requested ====
00323 *
00324          IF( INITZ )
00325      $      CALL ZLASET( 'A', N, N, ZERO, ONE, Z, LDZ )
00326 *
00327 *        ==== Quick return if possible ====
00328 *
00329          IF( ILO.EQ.IHI ) THEN
00330             W( ILO ) = H( ILO, ILO )
00331             RETURN
00332          END IF
00333 *
00334 *        ==== ZLAHQR/ZLAQR0 crossover point ====
00335 *
00336          NMIN = ILAENV( 12, 'ZHSEQR', JOB( : 1 ) // COMPZ( : 1 ), N,
00337      $          ILO, IHI, LWORK )
00338          NMIN = MAX( NTINY, NMIN )
00339 *
00340 *        ==== ZLAQR0 for big matrices; ZLAHQR for small ones ====
00341 *
00342          IF( N.GT.NMIN ) THEN
00343             CALL ZLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILO, IHI,
00344      $                   Z, LDZ, WORK, LWORK, INFO )
00345          ELSE
00346 *
00347 *           ==== Small matrix ====
00348 *
00349             CALL ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILO, IHI,
00350      $                   Z, LDZ, INFO )
00351 *
00352             IF( INFO.GT.0 ) THEN
00353 *
00354 *              ==== A rare ZLAHQR failure!  ZLAQR0 sometimes succeeds
00355 *              .    when ZLAHQR fails. ====
00356 *
00357                KBOT = INFO
00358 *
00359                IF( N.GE.NL ) THEN
00360 *
00361 *                 ==== Larger matrices have enough subdiagonal scratch
00362 *                 .    space to call ZLAQR0 directly. ====
00363 *
00364                   CALL ZLAQR0( WANTT, WANTZ, N, ILO, KBOT, H, LDH, W,
00365      $                         ILO, IHI, Z, LDZ, WORK, LWORK, INFO )
00366 *
00367                ELSE
00368 *
00369 *                 ==== Tiny matrices don't have enough subdiagonal
00370 *                 .    scratch space to benefit from ZLAQR0.  Hence,
00371 *                 .    tiny matrices must be copied into a larger
00372 *                 .    array before calling ZLAQR0. ====
00373 *
00374                   CALL ZLACPY( 'A', N, N, H, LDH, HL, NL )
00375                   HL( N+1, N ) = ZERO
00376                   CALL ZLASET( 'A', NL, NL-N, ZERO, ZERO, HL( 1, N+1 ),
00377      $                         NL )
00378                   CALL ZLAQR0( WANTT, WANTZ, NL, ILO, KBOT, HL, NL, W,
00379      $                         ILO, IHI, Z, LDZ, WORKL, NL, INFO )
00380                   IF( WANTT .OR. INFO.NE.0 )
00381      $               CALL ZLACPY( 'A', N, N, HL, NL, H, LDH )
00382                END IF
00383             END IF
00384          END IF
00385 *
00386 *        ==== Clear out the trash, if necessary. ====
00387 *
00388          IF( ( WANTT .OR. INFO.NE.0 ) .AND. N.GT.2 )
00389      $      CALL ZLASET( 'L', N-2, N-2, ZERO, ZERO, H( 3, 1 ), LDH )
00390 *
00391 *        ==== Ensure reported workspace size is backward-compatible with
00392 *        .    previous LAPACK versions. ====
00393 *
00394          WORK( 1 ) = DCMPLX( MAX( DBLE( MAX( 1, N ) ),
00395      $               DBLE( WORK( 1 ) ) ), RZERO )
00396       END IF
00397 *
00398 *     ==== End of ZHSEQR ====
00399 *
00400       END
 All Files Functions