LAPACK 3.3.0
|
00001 SUBROUTINE CHSEQR( 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 H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * ) 00014 * .. 00015 * Purpose 00016 * ======= 00017 * 00018 * CHSEQR 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 CGEBAL, and then passed to CGEHRD 00050 * when the matrix output by CGEBAL 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 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 CHSEQR, 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 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 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 CUNGHR 00084 * after the call to CGEHRD 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 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 CHSEQR does a workspace query. 00105 * In this case, CHSEQR 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, CHSEQR 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,'CHSEQR',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 CLAHQR vs CLAQR0 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 * CLAHQR 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 * . CLAHQR 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 CLAHQR 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 ZERO, ONE 00236 PARAMETER ( ZERO = ( 0.0e0, 0.0e0 ), 00237 $ ONE = ( 1.0e0, 0.0e0 ) ) 00238 REAL RZERO 00239 PARAMETER ( RZERO = 0.0e0 ) 00240 * .. 00241 * .. Local Arrays .. 00242 COMPLEX 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 CCOPY, CLACPY, CLAHQR, CLAQR0, CLASET, XERBLA 00255 * .. 00256 * .. Intrinsic Functions .. 00257 INTRINSIC CMPLX, MAX, MIN, REAL 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 ) = CMPLX( REAL( 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( 'CHSEQR', -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 CLAQR0( 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 ) = CMPLX( MAX( REAL( WORK( 1 ) ), REAL( MAX( 1, $ N ) ) ), RZERO ) 00310 RETURN 00311 * 00312 ELSE 00313 * 00314 * ==== copy eigenvalues isolated by CGEBAL ==== 00315 * 00316 IF( ILO.GT.1 ) 00317 $ CALL CCOPY( ILO-1, H, LDH+1, W, 1 ) 00318 IF( IHI.LT.N ) 00319 $ CALL CCOPY( N-IHI, H( IHI+1, IHI+1 ), LDH+1, W( IHI+1 ), 1 ) 00320 * 00321 * ==== Initialize Z, if requested ==== 00322 * 00323 IF( INITZ ) 00324 $ CALL CLASET( 'A', N, N, ZERO, ONE, Z, LDZ ) 00325 * 00326 * ==== Quick return if possible ==== 00327 * 00328 IF( ILO.EQ.IHI ) THEN 00329 W( ILO ) = H( ILO, ILO ) 00330 RETURN 00331 END IF 00332 * 00333 * ==== CLAHQR/CLAQR0 crossover point ==== 00334 * 00335 NMIN = ILAENV( 12, 'CHSEQR', JOB( : 1 ) // COMPZ( : 1 ), N, 00336 $ ILO, IHI, LWORK ) 00337 NMIN = MAX( NTINY, NMIN ) 00338 * 00339 * ==== CLAQR0 for big matrices; CLAHQR for small ones ==== 00340 * 00341 IF( N.GT.NMIN ) THEN 00342 CALL CLAQR0( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILO, IHI, 00343 $ Z, LDZ, WORK, LWORK, INFO ) 00344 ELSE 00345 * 00346 * ==== Small matrix ==== 00347 * 00348 CALL CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILO, IHI, 00349 $ Z, LDZ, INFO ) 00350 * 00351 IF( INFO.GT.0 ) THEN 00352 * 00353 * ==== A rare CLAHQR failure! CLAQR0 sometimes succeeds 00354 * . when CLAHQR fails. ==== 00355 * 00356 KBOT = INFO 00357 * 00358 IF( N.GE.NL ) THEN 00359 * 00360 * ==== Larger matrices have enough subdiagonal scratch 00361 * . space to call CLAQR0 directly. ==== 00362 * 00363 CALL CLAQR0( WANTT, WANTZ, N, ILO, KBOT, H, LDH, W, 00364 $ ILO, IHI, Z, LDZ, WORK, LWORK, INFO ) 00365 * 00366 ELSE 00367 * 00368 * ==== Tiny matrices don't have enough subdiagonal 00369 * . scratch space to benefit from CLAQR0. Hence, 00370 * . tiny matrices must be copied into a larger 00371 * . array before calling CLAQR0. ==== 00372 * 00373 CALL CLACPY( 'A', N, N, H, LDH, HL, NL ) 00374 HL( N+1, N ) = ZERO 00375 CALL CLASET( 'A', NL, NL-N, ZERO, ZERO, HL( 1, N+1 ), 00376 $ NL ) 00377 CALL CLAQR0( WANTT, WANTZ, NL, ILO, KBOT, HL, NL, W, 00378 $ ILO, IHI, Z, LDZ, WORKL, NL, INFO ) 00379 IF( WANTT .OR. INFO.NE.0 ) 00380 $ CALL CLACPY( 'A', N, N, HL, NL, H, LDH ) 00381 END IF 00382 END IF 00383 END IF 00384 * 00385 * ==== Clear out the trash, if necessary. ==== 00386 * 00387 IF( ( WANTT .OR. INFO.NE.0 ) .AND. N.GT.2 ) 00388 $ CALL CLASET( 'L', N-2, N-2, ZERO, ZERO, H( 3, 1 ), LDH ) 00389 * 00390 * ==== Ensure reported workspace size is backward-compatible with 00391 * . previous LAPACK versions. ==== 00392 * 00393 WORK( 1 ) = CMPLX( MAX( REAL( MAX( 1, N ) ), 00394 $ REAL( WORK( 1 ) ) ), RZERO ) 00395 END IF 00396 * 00397 * ==== End of CHSEQR ==== 00398 * 00399 END 00400