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