LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
slaqr4.f
Go to the documentation of this file.
1*> \brief \b SLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Schur decomposition.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download SLAQR4 + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaqr4.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaqr4.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaqr4.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE SLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
20* ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
24* LOGICAL WANTT, WANTZ
25* ..
26* .. Array Arguments ..
27* REAL H( LDH, * ), WI( * ), WORK( * ), WR( * ),
28* $ Z( LDZ, * )
29* ..
30*
31*
32*> \par Purpose:
33* =============
34*>
35*> \verbatim
36*>
37*> SLAQR4 implements one level of recursion for SLAQR0.
38*> It is a complete implementation of the small bulge multi-shift
39*> QR algorithm. It may be called by SLAQR0 and, for large enough
40*> deflation window size, it may be called by SLAQR3. This
41*> subroutine is identical to SLAQR0 except that it calls SLAQR2
42*> instead of SLAQR3.
43*>
44*> SLAQR4 computes the eigenvalues of a Hessenberg matrix H
45*> and, optionally, the matrices T and Z from the Schur decomposition
46*> H = Z T Z**T, where T is an upper quasi-triangular matrix (the
47*> Schur form), and Z is the orthogonal matrix of Schur vectors.
48*>
49*> Optionally Z may be postmultiplied into an input orthogonal
50*> matrix Q so that this routine can give the Schur factorization
51*> of a matrix A which has been reduced to the Hessenberg form H
52*> by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T.
53*> \endverbatim
54*
55* Arguments:
56* ==========
57*
58*> \param[in] WANTT
59*> \verbatim
60*> WANTT is LOGICAL
61*> = .TRUE. : the full Schur form T is required;
62*> = .FALSE.: only eigenvalues are required.
63*> \endverbatim
64*>
65*> \param[in] WANTZ
66*> \verbatim
67*> WANTZ is LOGICAL
68*> = .TRUE. : the matrix of Schur vectors Z is required;
69*> = .FALSE.: Schur vectors are not required.
70*> \endverbatim
71*>
72*> \param[in] N
73*> \verbatim
74*> N is INTEGER
75*> The order of the matrix H. N >= 0.
76*> \endverbatim
77*>
78*> \param[in] ILO
79*> \verbatim
80*> ILO is INTEGER
81*> \endverbatim
82*>
83*> \param[in] IHI
84*> \verbatim
85*> IHI is INTEGER
86*> It is assumed that H is already upper triangular in rows
87*> and columns 1:ILO-1 and IHI+1:N and, if ILO > 1,
88*> H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
89*> previous call to SGEBAL, and then passed to SGEHRD when the
90*> matrix output by SGEBAL is reduced to Hessenberg form.
91*> Otherwise, ILO and IHI should be set to 1 and N,
92*> respectively. If N > 0, then 1 <= ILO <= IHI <= N.
93*> If N = 0, then ILO = 1 and IHI = 0.
94*> \endverbatim
95*>
96*> \param[in,out] H
97*> \verbatim
98*> H is REAL array, dimension (LDH,N)
99*> On entry, the upper Hessenberg matrix H.
100*> On exit, if INFO = 0 and WANTT is .TRUE., then H contains
101*> the upper quasi-triangular matrix T from the Schur
102*> decomposition (the Schur form); 2-by-2 diagonal blocks
103*> (corresponding to complex conjugate pairs of eigenvalues)
104*> are returned in standard form, with H(i,i) = H(i+1,i+1)
105*> and H(i+1,i)*H(i,i+1) < 0. If INFO = 0 and WANTT is
106*> .FALSE., then the contents of H are unspecified on exit.
107*> (The output value of H when INFO > 0 is given under the
108*> description of INFO below.)
109*>
110*> This subroutine may explicitly set H(i,j) = 0 for i > j and
111*> j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
112*> \endverbatim
113*>
114*> \param[in] LDH
115*> \verbatim
116*> LDH is INTEGER
117*> The leading dimension of the array H. LDH >= max(1,N).
118*> \endverbatim
119*>
120*> \param[out] WR
121*> \verbatim
122*> WR is REAL array, dimension (IHI)
123*> \endverbatim
124*>
125*> \param[out] WI
126*> \verbatim
127*> WI is REAL array, dimension (IHI)
128*> The real and imaginary parts, respectively, of the computed
129*> eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI)
130*> and WI(ILO:IHI). If two eigenvalues are computed as a
131*> complex conjugate pair, they are stored in consecutive
132*> elements of WR and WI, say the i-th and (i+1)th, with
133*> WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., then
134*> the eigenvalues are stored in the same order as on the
135*> diagonal of the Schur form returned in H, with
136*> WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal
137*> block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
138*> WI(i+1) = -WI(i).
139*> \endverbatim
140*>
141*> \param[in] ILOZ
142*> \verbatim
143*> ILOZ is INTEGER
144*> \endverbatim
145*>
146*> \param[in] IHIZ
147*> \verbatim
148*> IHIZ is INTEGER
149*> Specify the rows of Z to which transformations must be
150*> applied if WANTZ is .TRUE..
151*> 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
152*> \endverbatim
153*>
154*> \param[in,out] Z
155*> \verbatim
156*> Z is REAL array, dimension (LDZ,IHI)
157*> If WANTZ is .FALSE., then Z is not referenced.
158*> If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
159*> replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
160*> orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
161*> (The output value of Z when INFO > 0 is given under
162*> the description of INFO below.)
163*> \endverbatim
164*>
165*> \param[in] LDZ
166*> \verbatim
167*> LDZ is INTEGER
168*> The leading dimension of the array Z. if WANTZ is .TRUE.
169*> then LDZ >= MAX(1,IHIZ). Otherwise, LDZ >= 1.
170*> \endverbatim
171*>
172*> \param[out] WORK
173*> \verbatim
174*> WORK is REAL array, dimension LWORK
175*> On exit, if LWORK = -1, WORK(1) returns an estimate of
176*> the optimal value for LWORK.
177*> \endverbatim
178*>
179*> \param[in] LWORK
180*> \verbatim
181*> LWORK is INTEGER
182*> The dimension of the array WORK. LWORK >= max(1,N)
183*> is sufficient, but LWORK typically as large as 6*N may
184*> be required for optimal performance. A workspace query
185*> to determine the optimal workspace size is recommended.
186*>
187*> If LWORK = -1, then SLAQR4 does a workspace query.
188*> In this case, SLAQR4 checks the input parameters and
189*> estimates the optimal workspace size for the given
190*> values of N, ILO and IHI. The estimate is returned
191*> in WORK(1). No error message related to LWORK is
192*> issued by XERBLA. Neither H nor Z are accessed.
193*> \endverbatim
194*>
195*> \param[out] INFO
196*> \verbatim
197*> INFO is INTEGER
198*> \verbatim
199*> INFO is INTEGER
200*> = 0: successful exit
201*> > 0: if INFO = i, SLAQR4 failed to compute all of
202*> the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
203*> and WI contain those eigenvalues which have been
204*> successfully computed. (Failures are rare.)
205*>
206*> If INFO > 0 and WANT is .FALSE., then on exit,
207*> the remaining unconverged eigenvalues are the eigen-
208*> values of the upper Hessenberg matrix rows and
209*> columns ILO through INFO of the final, output
210*> value of H.
211*>
212*> If INFO > 0 and WANTT is .TRUE., then on exit
213*>
214*> (*) (initial value of H)*U = U*(final value of H)
215*>
216*> where U is a orthogonal matrix. The final
217*> value of H is upper Hessenberg and triangular in
218*> rows and columns INFO+1 through IHI.
219*>
220*> If INFO > 0 and WANTZ is .TRUE., then on exit
221*>
222*> (final value of Z(ILO:IHI,ILOZ:IHIZ)
223*> = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
224*>
225*> where U is the orthogonal matrix in (*) (regard-
226*> less of the value of WANTT.)
227*>
228*> If INFO > 0 and WANTZ is .FALSE., then Z is not
229*> accessed.
230*> \endverbatim
231*
232* Authors:
233* ========
234*
235*> \author Univ. of Tennessee
236*> \author Univ. of California Berkeley
237*> \author Univ. of Colorado Denver
238*> \author NAG Ltd.
239*
240*> \ingroup laqr4
241*
242*> \par Contributors:
243* ==================
244*>
245*> Karen Braman and Ralph Byers, Department of Mathematics,
246*> University of Kansas, USA
247*
248*> \par References:
249* ================
250*>
251*> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
252*> Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
253*> Performance, SIAM Journal of Matrix Analysis, volume 23, pages
254*> 929--947, 2002.
255*> \n
256*> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
257*> Algorithm Part II: Aggressive Early Deflation, SIAM Journal
258*> of Matrix Analysis, volume 23, pages 948--973, 2002.
259*>
260* =====================================================================
261 SUBROUTINE slaqr4( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
262 $ ILOZ, IHIZ, Z, LDZ, WORK, LWORK, INFO )
263*
264* -- LAPACK auxiliary routine --
265* -- LAPACK is a software package provided by Univ. of Tennessee, --
266* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
267*
268* .. Scalar Arguments ..
269 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N
270 LOGICAL WANTT, WANTZ
271* ..
272* .. Array Arguments ..
273 REAL H( LDH, * ), WI( * ), WORK( * ), WR( * ),
274 $ z( ldz, * )
275* ..
276*
277* ================================================================
278*
279* .. Parameters ..
280*
281* ==== Matrices of order NTINY or smaller must be processed by
282* . SLAHQR because of insufficient subdiagonal scratch space.
283* . (This is a hard limit.) ====
284 INTEGER NTINY
285 parameter( ntiny = 15 )
286*
287* ==== Exceptional deflation windows: try to cure rare
288* . slow convergence by varying the size of the
289* . deflation window after KEXNW iterations. ====
290 INTEGER KEXNW
291 parameter( kexnw = 5 )
292*
293* ==== Exceptional shifts: try to cure rare slow convergence
294* . with ad-hoc exceptional shifts every KEXSH iterations.
295* . ====
296 INTEGER KEXSH
297 parameter( kexsh = 6 )
298*
299* ==== The constants WILK1 and WILK2 are used to form the
300* . exceptional shifts. ====
301 REAL WILK1, WILK2
302 parameter( wilk1 = 0.75e0, wilk2 = -0.4375e0 )
303 REAL ZERO, ONE
304 parameter( zero = 0.0e0, one = 1.0e0 )
305* ..
306* .. Local Scalars ..
307 REAL AA, BB, CC, CS, DD, SN, SS, SWAP
308 INTEGER I, INF, IT, ITMAX, K, KACC22, KBOT, KDU, KS,
309 $ kt, ktop, ku, kv, kwh, kwtop, kwv, ld, ls,
310 $ lwkopt, ndec, ndfl, nh, nho, nibble, nmin, ns,
311 $ nsmax, nsr, nve, nw, nwmax, nwr, nwupbd
312 LOGICAL SORTED
313 CHARACTER JBCMPZ*2
314* ..
315* .. External Functions ..
316 INTEGER ILAENV
317 REAL SROUNDUP_LWORK
318 EXTERNAL ilaenv, sroundup_lwork
319* ..
320* .. Local Arrays ..
321 REAL ZDUM( 1, 1 )
322* ..
323* .. External Subroutines ..
324 EXTERNAL slacpy, slahqr, slanv2, slaqr2,
325 $ slaqr5
326* ..
327* .. Intrinsic Functions ..
328 INTRINSIC abs, int, max, min, mod
329* ..
330* .. Executable Statements ..
331 info = 0
332*
333* ==== Quick return for N = 0: nothing to do. ====
334*
335 IF( n.EQ.0 ) THEN
336 work( 1 ) = one
337 RETURN
338 END IF
339*
340 IF( n.LE.ntiny ) THEN
341*
342* ==== Tiny matrices must use SLAHQR. ====
343*
344 lwkopt = 1
345 IF( lwork.NE.-1 )
346 $ CALL slahqr( wantt, wantz, n, ilo, ihi, h, ldh, wr, wi,
347 $ iloz, ihiz, z, ldz, info )
348 ELSE
349*
350* ==== Use small bulge multi-shift QR with aggressive early
351* . deflation on larger-than-tiny matrices. ====
352*
353* ==== Hope for the best. ====
354*
355 info = 0
356*
357* ==== Set up job flags for ILAENV. ====
358*
359 IF( wantt ) THEN
360 jbcmpz( 1: 1 ) = 'S'
361 ELSE
362 jbcmpz( 1: 1 ) = 'E'
363 END IF
364 IF( wantz ) THEN
365 jbcmpz( 2: 2 ) = 'V'
366 ELSE
367 jbcmpz( 2: 2 ) = 'N'
368 END IF
369*
370* ==== NWR = recommended deflation window size. At this
371* . point, N .GT. NTINY = 15, so there is enough
372* . subdiagonal workspace for NWR.GE.2 as required.
373* . (In fact, there is enough subdiagonal space for
374* . NWR.GE.4.) ====
375*
376 nwr = ilaenv( 13, 'SLAQR4', jbcmpz, n, ilo, ihi, lwork )
377 nwr = max( 2, nwr )
378 nwr = min( ihi-ilo+1, ( n-1 ) / 3, nwr )
379*
380* ==== NSR = recommended number of simultaneous shifts.
381* . At this point N .GT. NTINY = 15, so there is at
382* . enough subdiagonal workspace for NSR to be even
383* . and greater than or equal to two as required. ====
384*
385 nsr = ilaenv( 15, 'SLAQR4', jbcmpz, n, ilo, ihi, lwork )
386 nsr = min( nsr, ( n-3 ) / 6, ihi-ilo )
387 nsr = max( 2, nsr-mod( nsr, 2 ) )
388*
389* ==== Estimate optimal workspace ====
390*
391* ==== Workspace query call to SLAQR2 ====
392*
393 CALL slaqr2( wantt, wantz, n, ilo, ihi, nwr+1, h, ldh, iloz,
394 $ ihiz, z, ldz, ls, ld, wr, wi, h, ldh, n, h, ldh,
395 $ n, h, ldh, work, -1 )
396*
397* ==== Optimal workspace = MAX(SLAQR5, SLAQR2) ====
398*
399 lwkopt = max( 3*nsr / 2, int( work( 1 ) ) )
400*
401* ==== Quick return in case of workspace query. ====
402*
403 IF( lwork.EQ.-1 ) THEN
404 work( 1 ) = sroundup_lwork( lwkopt )
405 RETURN
406 END IF
407*
408* ==== SLAHQR/SLAQR0 crossover point ====
409*
410 nmin = ilaenv( 12, 'SLAQR4', jbcmpz, n, ilo, ihi, lwork )
411 nmin = max( ntiny, nmin )
412*
413* ==== Nibble crossover point ====
414*
415 nibble = ilaenv( 14, 'SLAQR4', jbcmpz, n, ilo, ihi, lwork )
416 nibble = max( 0, nibble )
417*
418* ==== Accumulate reflections during ttswp? Use block
419* . 2-by-2 structure during matrix-matrix multiply? ====
420*
421 kacc22 = ilaenv( 16, 'SLAQR4', jbcmpz, n, ilo, ihi, lwork )
422 kacc22 = max( 0, kacc22 )
423 kacc22 = min( 2, kacc22 )
424*
425* ==== NWMAX = the largest possible deflation window for
426* . which there is sufficient workspace. ====
427*
428 nwmax = min( ( n-1 ) / 3, lwork / 2 )
429 nw = nwmax
430*
431* ==== NSMAX = the Largest number of simultaneous shifts
432* . for which there is sufficient workspace. ====
433*
434 nsmax = min( ( n-3 ) / 6, 2*lwork / 3 )
435 nsmax = nsmax - mod( nsmax, 2 )
436*
437* ==== NDFL: an iteration count restarted at deflation. ====
438*
439 ndfl = 1
440*
441* ==== ITMAX = iteration limit ====
442*
443 itmax = max( 30, 2*kexsh )*max( 10, ( ihi-ilo+1 ) )
444*
445* ==== Last row and column in the active block ====
446*
447 kbot = ihi
448*
449* ==== Main Loop ====
450*
451 DO 80 it = 1, itmax
452*
453* ==== Done when KBOT falls below ILO ====
454*
455 IF( kbot.LT.ilo )
456 $ GO TO 90
457*
458* ==== Locate active block ====
459*
460 DO 10 k = kbot, ilo + 1, -1
461 IF( h( k, k-1 ).EQ.zero )
462 $ GO TO 20
463 10 CONTINUE
464 k = ilo
465 20 CONTINUE
466 ktop = k
467*
468* ==== Select deflation window size:
469* . Typical Case:
470* . If possible and advisable, nibble the entire
471* . active block. If not, use size MIN(NWR,NWMAX)
472* . or MIN(NWR+1,NWMAX) depending upon which has
473* . the smaller corresponding subdiagonal entry
474* . (a heuristic).
475* .
476* . Exceptional Case:
477* . If there have been no deflations in KEXNW or
478* . more iterations, then vary the deflation window
479* . size. At first, because, larger windows are,
480* . in general, more powerful than smaller ones,
481* . rapidly increase the window to the maximum possible.
482* . Then, gradually reduce the window size. ====
483*
484 nh = kbot - ktop + 1
485 nwupbd = min( nh, nwmax )
486 IF( ndfl.LT.kexnw ) THEN
487 nw = min( nwupbd, nwr )
488 ELSE
489 nw = min( nwupbd, 2*nw )
490 END IF
491 IF( nw.LT.nwmax ) THEN
492 IF( nw.GE.nh-1 ) THEN
493 nw = nh
494 ELSE
495 kwtop = kbot - nw + 1
496 IF( abs( h( kwtop, kwtop-1 ) ).GT.
497 $ abs( h( kwtop-1, kwtop-2 ) ) )nw = nw + 1
498 END IF
499 END IF
500 IF( ndfl.LT.kexnw ) THEN
501 ndec = -1
502 ELSE IF( ndec.GE.0 .OR. nw.GE.nwupbd ) THEN
503 ndec = ndec + 1
504 IF( nw-ndec.LT.2 )
505 $ ndec = 0
506 nw = nw - ndec
507 END IF
508*
509* ==== Aggressive early deflation:
510* . split workspace under the subdiagonal into
511* . - an nw-by-nw work array V in the lower
512* . left-hand-corner,
513* . - an NW-by-at-least-NW-but-more-is-better
514* . (NW-by-NHO) horizontal work array along
515* . the bottom edge,
516* . - an at-least-NW-but-more-is-better (NHV-by-NW)
517* . vertical work array along the left-hand-edge.
518* . ====
519*
520 kv = n - nw + 1
521 kt = nw + 1
522 nho = ( n-nw-1 ) - kt + 1
523 kwv = nw + 2
524 nve = ( n-nw ) - kwv + 1
525*
526* ==== Aggressive early deflation ====
527*
528 CALL slaqr2( wantt, wantz, n, ktop, kbot, nw, h, ldh,
529 $ iloz,
530 $ ihiz, z, ldz, ls, ld, wr, wi, h( kv, 1 ), ldh,
531 $ nho, h( kv, kt ), ldh, nve, h( kwv, 1 ), ldh,
532 $ work, lwork )
533*
534* ==== Adjust KBOT accounting for new deflations. ====
535*
536 kbot = kbot - ld
537*
538* ==== KS points to the shifts. ====
539*
540 ks = kbot - ls + 1
541*
542* ==== Skip an expensive QR sweep if there is a (partly
543* . heuristic) reason to expect that many eigenvalues
544* . will deflate without it. Here, the QR sweep is
545* . skipped if many eigenvalues have just been deflated
546* . or if the remaining active block is small.
547*
548 IF( ( ld.EQ.0 ) .OR. ( ( 100*ld.LE.nw*nibble ) .AND. ( kbot-
549 $ ktop+1.GT.min( nmin, nwmax ) ) ) ) THEN
550*
551* ==== NS = nominal number of simultaneous shifts.
552* . This may be lowered (slightly) if SLAQR2
553* . did not provide that many shifts. ====
554*
555 ns = min( nsmax, nsr, max( 2, kbot-ktop ) )
556 ns = ns - mod( ns, 2 )
557*
558* ==== If there have been no deflations
559* . in a multiple of KEXSH iterations,
560* . then try exceptional shifts.
561* . Otherwise use shifts provided by
562* . SLAQR2 above or from the eigenvalues
563* . of a trailing principal submatrix. ====
564*
565 IF( mod( ndfl, kexsh ).EQ.0 ) THEN
566 ks = kbot - ns + 1
567 DO 30 i = kbot, max( ks+1, ktop+2 ), -2
568 ss = abs( h( i, i-1 ) ) + abs( h( i-1, i-2 ) )
569 aa = wilk1*ss + h( i, i )
570 bb = ss
571 cc = wilk2*ss
572 dd = aa
573 CALL slanv2( aa, bb, cc, dd, wr( i-1 ),
574 $ wi( i-1 ),
575 $ wr( i ), wi( i ), cs, sn )
576 30 CONTINUE
577 IF( ks.EQ.ktop ) THEN
578 wr( ks+1 ) = h( ks+1, ks+1 )
579 wi( ks+1 ) = zero
580 wr( ks ) = wr( ks+1 )
581 wi( ks ) = wi( ks+1 )
582 END IF
583 ELSE
584*
585* ==== Got NS/2 or fewer shifts? Use SLAHQR
586* . on a trailing principal submatrix to
587* . get more. (Since NS.LE.NSMAX.LE.(N-3)/6,
588* . there is enough space below the subdiagonal
589* . to fit an NS-by-NS scratch array.) ====
590*
591 IF( kbot-ks+1.LE.ns / 2 ) THEN
592 ks = kbot - ns + 1
593 kt = n - ns + 1
594 CALL slacpy( 'A', ns, ns, h( ks, ks ), ldh,
595 $ h( kt, 1 ), ldh )
596 CALL slahqr( .false., .false., ns, 1, ns,
597 $ h( kt, 1 ), ldh, wr( ks ), wi( ks ),
598 $ 1, 1, zdum, 1, inf )
599 ks = ks + inf
600*
601* ==== In case of a rare QR failure use
602* . eigenvalues of the trailing 2-by-2
603* . principal submatrix. ====
604*
605 IF( ks.GE.kbot ) THEN
606 aa = h( kbot-1, kbot-1 )
607 cc = h( kbot, kbot-1 )
608 bb = h( kbot-1, kbot )
609 dd = h( kbot, kbot )
610 CALL slanv2( aa, bb, cc, dd, wr( kbot-1 ),
611 $ wi( kbot-1 ), wr( kbot ),
612 $ wi( kbot ), cs, sn )
613 ks = kbot - 1
614 END IF
615 END IF
616*
617 IF( kbot-ks+1.GT.ns ) THEN
618*
619* ==== Sort the shifts (Helps a little)
620* . Bubble sort keeps complex conjugate
621* . pairs together. ====
622*
623 sorted = .false.
624 DO 50 k = kbot, ks + 1, -1
625 IF( sorted )
626 $ GO TO 60
627 sorted = .true.
628 DO 40 i = ks, k - 1
629 IF( abs( wr( i ) )+abs( wi( i ) ).LT.
630 $ abs( wr( i+1 ) )+abs( wi( i+1 ) ) ) THEN
631 sorted = .false.
632*
633 swap = wr( i )
634 wr( i ) = wr( i+1 )
635 wr( i+1 ) = swap
636*
637 swap = wi( i )
638 wi( i ) = wi( i+1 )
639 wi( i+1 ) = swap
640 END IF
641 40 CONTINUE
642 50 CONTINUE
643 60 CONTINUE
644 END IF
645*
646* ==== Shuffle shifts into pairs of real shifts
647* . and pairs of complex conjugate shifts
648* . assuming complex conjugate shifts are
649* . already adjacent to one another. (Yes,
650* . they are.) ====
651*
652 DO 70 i = kbot, ks + 2, -2
653 IF( wi( i ).NE.-wi( i-1 ) ) THEN
654*
655 swap = wr( i )
656 wr( i ) = wr( i-1 )
657 wr( i-1 ) = wr( i-2 )
658 wr( i-2 ) = swap
659*
660 swap = wi( i )
661 wi( i ) = wi( i-1 )
662 wi( i-1 ) = wi( i-2 )
663 wi( i-2 ) = swap
664 END IF
665 70 CONTINUE
666 END IF
667*
668* ==== If there are only two shifts and both are
669* . real, then use only one. ====
670*
671 IF( kbot-ks+1.EQ.2 ) THEN
672 IF( wi( kbot ).EQ.zero ) THEN
673 IF( abs( wr( kbot )-h( kbot, kbot ) ).LT.
674 $ abs( wr( kbot-1 )-h( kbot, kbot ) ) ) THEN
675 wr( kbot-1 ) = wr( kbot )
676 ELSE
677 wr( kbot ) = wr( kbot-1 )
678 END IF
679 END IF
680 END IF
681*
682* ==== Use up to NS of the the smallest magnitude
683* . shifts. If there aren't NS shifts available,
684* . then use them all, possibly dropping one to
685* . make the number of shifts even. ====
686*
687 ns = min( ns, kbot-ks+1 )
688 ns = ns - mod( ns, 2 )
689 ks = kbot - ns + 1
690*
691* ==== Small-bulge multi-shift QR sweep:
692* . split workspace under the subdiagonal into
693* . - a KDU-by-KDU work array U in the lower
694* . left-hand-corner,
695* . - a KDU-by-at-least-KDU-but-more-is-better
696* . (KDU-by-NHo) horizontal work array WH along
697* . the bottom edge,
698* . - and an at-least-KDU-but-more-is-better-by-KDU
699* . (NVE-by-KDU) vertical work WV arrow along
700* . the left-hand-edge. ====
701*
702 kdu = 2*ns
703 ku = n - kdu + 1
704 kwh = kdu + 1
705 nho = ( n-kdu+1-4 ) - ( kdu+1 ) + 1
706 kwv = kdu + 4
707 nve = n - kdu - kwv + 1
708*
709* ==== Small-bulge multi-shift QR sweep ====
710*
711 CALL slaqr5( wantt, wantz, kacc22, n, ktop, kbot, ns,
712 $ wr( ks ), wi( ks ), h, ldh, iloz, ihiz, z,
713 $ ldz, work, 3, h( ku, 1 ), ldh, nve,
714 $ h( kwv, 1 ), ldh, nho, h( ku, kwh ), ldh )
715 END IF
716*
717* ==== Note progress (or the lack of it). ====
718*
719 IF( ld.GT.0 ) THEN
720 ndfl = 1
721 ELSE
722 ndfl = ndfl + 1
723 END IF
724*
725* ==== End of main loop ====
726 80 CONTINUE
727*
728* ==== Iteration limit exceeded. Set INFO to show where
729* . the problem occurred and exit. ====
730*
731 info = kbot
732 90 CONTINUE
733 END IF
734*
735* ==== Return the optimal value of LWORK. ====
736*
737 work( 1 ) = sroundup_lwork( lwkopt )
738*
739* ==== End of SLAQR4 ====
740*
741 END
subroutine slacpy(uplo, m, n, a, lda, b, ldb)
SLACPY copies all or part of one two-dimensional array to another.
Definition slacpy.f:101
subroutine slahqr(wantt, wantz, n, ilo, ihi, h, ldh, wr, wi, iloz, ihiz, z, ldz, info)
SLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix,...
Definition slahqr.f:205
subroutine slanv2(a, b, c, d, rt1r, rt1i, rt2r, rt2i, cs, sn)
SLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric matrix in standard form.
Definition slanv2.f:125
subroutine slaqr2(wantt, wantz, n, ktop, kbot, nw, h, ldh, iloz, ihiz, z, ldz, ns, nd, sr, si, v, ldv, nh, t, ldt, nv, wv, ldwv, work, lwork)
SLAQR2 performs the orthogonal similarity transformation of a Hessenberg matrix to detect and deflate...
Definition slaqr2.f:277
subroutine slaqr4(wantt, wantz, n, ilo, ihi, h, ldh, wr, wi, iloz, ihiz, z, ldz, work, lwork, info)
SLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Schur de...
Definition slaqr4.f:263
subroutine slaqr5(wantt, wantz, kacc22, n, ktop, kbot, nshfts, sr, si, h, ldh, iloz, ihiz, z, ldz, v, ldv, u, ldu, nv, wv, ldwv, nh, wh, ldwh)
SLAQR5 performs a single small-bulge multi-shift QR sweep.
Definition slaqr5.f:263