LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
shseqr.f
Go to the documentation of this file.
1*> \brief \b SHSEQR
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download SHSEQR + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shseqr.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shseqr.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shseqr.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE SHSEQR( JOB, COMPZ, N, ILO, IHI, H, LDH, WR, WI, Z,
20* LDZ, WORK, LWORK, INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER IHI, ILO, INFO, LDH, LDZ, LWORK, N
24* CHARACTER COMPZ, JOB
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*> SHSEQR computes the eigenvalues of a Hessenberg matrix H
38*> and, optionally, the matrices T and Z from the Schur decomposition
39*> H = Z T Z**T, where T is an upper quasi-triangular matrix (the
40*> Schur form), and Z is the orthogonal matrix of Schur vectors.
41*>
42*> Optionally Z may be postmultiplied into an input orthogonal
43*> matrix Q so that this routine can give the Schur factorization
44*> of a matrix A which has been reduced to the Hessenberg form H
45*> by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T.
46*> \endverbatim
47*
48* Arguments:
49* ==========
50*
51*> \param[in] JOB
52*> \verbatim
53*> JOB is CHARACTER*1
54*> = 'E': compute eigenvalues only;
55*> = 'S': compute eigenvalues and the Schur form T.
56*> \endverbatim
57*>
58*> \param[in] COMPZ
59*> \verbatim
60*> COMPZ is CHARACTER*1
61*> = 'N': no Schur vectors are computed;
62*> = 'I': Z is initialized to the unit matrix and the matrix Z
63*> of Schur vectors of H is returned;
64*> = 'V': Z must contain an orthogonal matrix Q on entry, and
65*> the product Q*Z is returned.
66*> \endverbatim
67*>
68*> \param[in] N
69*> \verbatim
70*> N is INTEGER
71*> The order of the matrix H. N >= 0.
72*> \endverbatim
73*>
74*> \param[in] ILO
75*> \verbatim
76*> ILO is INTEGER
77*> \endverbatim
78*>
79*> \param[in] IHI
80*> \verbatim
81*> IHI is INTEGER
82*>
83*> It is assumed that H is already upper triangular in rows
84*> and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
85*> set by a previous call to SGEBAL, and then passed to ZGEHRD
86*> when the matrix output by SGEBAL is reduced to Hessenberg
87*> form. Otherwise ILO and IHI should be set to 1 and N
88*> respectively. If N > 0, then 1 <= ILO <= IHI <= N.
89*> If N = 0, then ILO = 1 and IHI = 0.
90*> \endverbatim
91*>
92*> \param[in,out] H
93*> \verbatim
94*> H is REAL array, dimension (LDH,N)
95*> On entry, the upper Hessenberg matrix H.
96*> On exit, if INFO = 0 and JOB = 'S', then H contains the
97*> upper quasi-triangular matrix T from the Schur decomposition
98*> (the Schur form); 2-by-2 diagonal blocks (corresponding to
99*> complex conjugate pairs of eigenvalues) are returned in
100*> standard form, with H(i,i) = H(i+1,i+1) and
101*> H(i+1,i)*H(i,i+1) < 0. If INFO = 0 and JOB = 'E', the
102*> contents of H are unspecified on exit. (The output value of
103*> H when INFO > 0 is given under the description of INFO
104*> below.)
105*>
106*> Unlike earlier versions of SHSEQR, this subroutine may
107*> explicitly H(i,j) = 0 for i > j and j = 1, 2, ... ILO-1
108*> or j = IHI+1, IHI+2, ... N.
109*> \endverbatim
110*>
111*> \param[in] LDH
112*> \verbatim
113*> LDH is INTEGER
114*> The leading dimension of the array H. LDH >= max(1,N).
115*> \endverbatim
116*>
117*> \param[out] WR
118*> \verbatim
119*> WR is REAL array, dimension (N)
120*> \endverbatim
121*>
122*> \param[out] WI
123*> \verbatim
124*> WI is REAL array, dimension (N)
125*>
126*> The real and imaginary parts, respectively, of the computed
127*> eigenvalues. If two eigenvalues are computed as a complex
128*> conjugate pair, they are stored in consecutive elements of
129*> WR and WI, say the i-th and (i+1)th, with WI(i) > 0 and
130*> WI(i+1) < 0. If JOB = 'S', the eigenvalues are stored in
131*> the same order as on the diagonal of the Schur form returned
132*> in H, with WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2
133*> diagonal block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and
134*> WI(i+1) = -WI(i).
135*> \endverbatim
136*>
137*> \param[in,out] Z
138*> \verbatim
139*> Z is REAL array, dimension (LDZ,N)
140*> If COMPZ = 'N', Z is not referenced.
141*> If COMPZ = 'I', on entry Z need not be set and on exit,
142*> if INFO = 0, Z contains the orthogonal matrix Z of the Schur
143*> vectors of H. If COMPZ = 'V', on entry Z must contain an
144*> N-by-N matrix Q, which is assumed to be equal to the unit
145*> matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit,
146*> if INFO = 0, Z contains Q*Z.
147*> Normally Q is the orthogonal matrix generated by SORGHR
148*> after the call to SGEHRD which formed the Hessenberg matrix
149*> H. (The output value of Z when INFO > 0 is given under
150*> the description of INFO below.)
151*> \endverbatim
152*>
153*> \param[in] LDZ
154*> \verbatim
155*> LDZ is INTEGER
156*> The leading dimension of the array Z. if COMPZ = 'I' or
157*> COMPZ = 'V', then LDZ >= MAX(1,N). Otherwise, LDZ >= 1.
158*> \endverbatim
159*>
160*> \param[out] WORK
161*> \verbatim
162*> WORK is REAL array, dimension (LWORK)
163*> On exit, if INFO = 0, WORK(1) returns an estimate of
164*> the optimal value for LWORK.
165*> \endverbatim
166*>
167*> \param[in] LWORK
168*> \verbatim
169*> LWORK is INTEGER
170*> The dimension of the array WORK. LWORK >= max(1,N)
171*> is sufficient and delivers very good and sometimes
172*> optimal performance. However, LWORK as large as 11*N
173*> may be required for optimal performance. A workspace
174*> query is recommended to determine the optimal workspace
175*> size.
176*>
177*> If LWORK = -1, then SHSEQR does a workspace query.
178*> In this case, SHSEQR checks the input parameters and
179*> estimates the optimal workspace size for the given
180*> values of N, ILO and IHI. The estimate is returned
181*> in WORK(1). No error message related to LWORK is
182*> issued by XERBLA. Neither H nor Z are accessed.
183*> \endverbatim
184*>
185*> \param[out] INFO
186*> \verbatim
187*> INFO is INTEGER
188*> = 0: successful exit
189*> < 0: if INFO = -i, the i-th argument had an illegal
190*> value
191*> > 0: if INFO = i, SHSEQR failed to compute all of
192*> the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
193*> and WI contain those eigenvalues which have been
194*> successfully computed. (Failures are rare.)
195*>
196*> If INFO > 0 and JOB = 'E', then on exit, the
197*> remaining unconverged eigenvalues are the eigen-
198*> values of the upper Hessenberg matrix rows and
199*> columns ILO through INFO of the final, output
200*> value of H.
201*>
202*> If INFO > 0 and JOB = 'S', then on exit
203*>
204*> (*) (initial value of H)*U = U*(final value of H)
205*>
206*> where U is an orthogonal matrix. The final
207*> value of H is upper Hessenberg and quasi-triangular
208*> in rows and columns INFO+1 through IHI.
209*>
210*> If INFO > 0 and COMPZ = 'V', then on exit
211*>
212*> (final value of Z) = (initial value of Z)*U
213*>
214*> where U is the orthogonal matrix in (*) (regard-
215*> less of the value of JOB.)
216*>
217*> If INFO > 0 and COMPZ = 'I', then on exit
218*> (final value of Z) = U
219*> where U is the orthogonal matrix in (*) (regard-
220*> less of the value of JOB.)
221*>
222*> If INFO > 0 and COMPZ = 'N', then Z is not
223*> accessed.
224*> \endverbatim
225*
226* Authors:
227* ========
228*
229*> \author Univ. of Tennessee
230*> \author Univ. of California Berkeley
231*> \author Univ. of Colorado Denver
232*> \author NAG Ltd.
233*
234*> \ingroup hseqr
235*
236*> \par Contributors:
237* ==================
238*>
239*> Karen Braman and Ralph Byers, Department of Mathematics,
240*> University of Kansas, USA
241*
242*> \par Further Details:
243* =====================
244*>
245*> \verbatim
246*>
247*> Default values supplied by
248*> ILAENV(ISPEC,'SHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK).
249*> It is suggested that these defaults be adjusted in order
250*> to attain best performance in each particular
251*> computational environment.
252*>
253*> ISPEC=12: The SLAHQR vs SLAQR0 crossover point.
254*> Default: 75. (Must be at least 11.)
255*>
256*> ISPEC=13: Recommended deflation window size.
257*> This depends on ILO, IHI and NS. NS is the
258*> number of simultaneous shifts returned
259*> by ILAENV(ISPEC=15). (See ISPEC=15 below.)
260*> The default for (IHI-ILO+1) <= 500 is NS.
261*> The default for (IHI-ILO+1) > 500 is 3*NS/2.
262*>
263*> ISPEC=14: Nibble crossover point. (See IPARMQ for
264*> details.) Default: 14% of deflation window
265*> size.
266*>
267*> ISPEC=15: Number of simultaneous shifts in a multishift
268*> QR iteration.
269*>
270*> If IHI-ILO+1 is ...
271*>
272*> greater than ...but less ... the
273*> or equal to ... than default is
274*>
275*> 1 30 NS = 2(+)
276*> 30 60 NS = 4(+)
277*> 60 150 NS = 10(+)
278*> 150 590 NS = **
279*> 590 3000 NS = 64
280*> 3000 6000 NS = 128
281*> 6000 infinity NS = 256
282*>
283*> (+) By default some or all matrices of this order
284*> are passed to the implicit double shift routine
285*> SLAHQR and this parameter is ignored. See
286*> ISPEC=12 above and comments in IPARMQ for
287*> details.
288*>
289*> (**) The asterisks (**) indicate an ad-hoc
290*> function of N increasing from 10 to 64.
291*>
292*> ISPEC=16: Select structured matrix multiply.
293*> If the number of simultaneous shifts (specified
294*> by ISPEC=15) is less than 14, then the default
295*> for ISPEC=16 is 0. Otherwise the default for
296*> ISPEC=16 is 2.
297*> \endverbatim
298*
299*> \par References:
300* ================
301*>
302*> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
303*> Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
304*> Performance, SIAM Journal of Matrix Analysis, volume 23, pages
305*> 929--947, 2002.
306*> \n
307*> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
308*> Algorithm Part II: Aggressive Early Deflation, SIAM Journal
309*> of Matrix Analysis, volume 23, pages 948--973, 2002.
310*
311* =====================================================================
312 SUBROUTINE shseqr( JOB, COMPZ, N, ILO, IHI, H, LDH, WR, WI, Z,
313 $ LDZ, WORK, LWORK, INFO )
314*
315* -- LAPACK computational routine --
316* -- LAPACK is a software package provided by Univ. of Tennessee, --
317* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
318*
319* .. Scalar Arguments ..
320 INTEGER IHI, ILO, INFO, LDH, LDZ, LWORK, N
321 CHARACTER COMPZ, JOB
322* ..
323* .. Array Arguments ..
324 REAL H( LDH, * ), WI( * ), WORK( * ), WR( * ),
325 $ z( ldz, * )
326* ..
327*
328* =====================================================================
329*
330* .. Parameters ..
331*
332* ==== Matrices of order NTINY or smaller must be processed by
333* . SLAHQR because of insufficient subdiagonal scratch space.
334* . (This is a hard limit.) ====
335 INTEGER NTINY
336 parameter( ntiny = 15 )
337*
338* ==== NL allocates some local workspace to help small matrices
339* . through a rare SLAHQR failure. NL > NTINY = 15 is
340* . required and NL <= NMIN = ILAENV(ISPEC=12,...) is recom-
341* . mended. (The default value of NMIN is 75.) Using NL = 49
342* . allows up to six simultaneous shifts and a 16-by-16
343* . deflation window. ====
344 INTEGER NL
345 parameter( nl = 49 )
346 REAL ZERO, ONE
347 parameter( zero = 0.0e0, one = 1.0e0 )
348* ..
349* .. Local Arrays ..
350 REAL HL( NL, NL ), WORKL( NL )
351* ..
352* .. Local Scalars ..
353 INTEGER I, KBOT, NMIN
354 LOGICAL INITZ, LQUERY, WANTT, WANTZ
355* ..
356* .. External Functions ..
357 INTEGER ILAENV
358 LOGICAL LSAME
359 REAL SROUNDUP_LWORK
360 EXTERNAL ilaenv, lsame, sroundup_lwork
361* ..
362* .. External Subroutines ..
363 EXTERNAL slacpy, slahqr, slaqr0, slaset,
364 $ xerbla
365* ..
366* .. Intrinsic Functions ..
367 INTRINSIC max, min, real
368* ..
369* .. Executable Statements ..
370*
371* ==== Decode and check the input parameters. ====
372*
373 wantt = lsame( job, 'S' )
374 initz = lsame( compz, 'I' )
375 wantz = initz .OR. lsame( compz, 'V' )
376 work( 1 ) = sroundup_lwork( max( 1, n ) )
377 lquery = lwork.EQ.-1
378*
379 info = 0
380 IF( .NOT.lsame( job, 'E' ) .AND. .NOT.wantt ) THEN
381 info = -1
382 ELSE IF( .NOT.lsame( compz, 'N' ) .AND. .NOT.wantz ) THEN
383 info = -2
384 ELSE IF( n.LT.0 ) THEN
385 info = -3
386 ELSE IF( ilo.LT.1 .OR. ilo.GT.max( 1, n ) ) THEN
387 info = -4
388 ELSE IF( ihi.LT.min( ilo, n ) .OR. ihi.GT.n ) THEN
389 info = -5
390 ELSE IF( ldh.LT.max( 1, n ) ) THEN
391 info = -7
392 ELSE IF( ldz.LT.1 .OR. ( wantz .AND. ldz.LT.max( 1, n ) ) ) THEN
393 info = -11
394 ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery ) THEN
395 info = -13
396 END IF
397*
398 IF( info.NE.0 ) THEN
399*
400* ==== Quick return in case of invalid argument. ====
401*
402 CALL xerbla( 'SHSEQR', -info )
403 RETURN
404*
405 ELSE IF( n.EQ.0 ) THEN
406*
407* ==== Quick return in case N = 0; nothing to do. ====
408*
409 RETURN
410*
411 ELSE IF( lquery ) THEN
412*
413* ==== Quick return in case of a workspace query ====
414*
415 CALL slaqr0( wantt, wantz, n, ilo, ihi, h, ldh, wr, wi, ilo,
416 $ ihi, z, ldz, work, lwork, info )
417* ==== Ensure reported workspace size is backward-compatible with
418* . previous LAPACK versions. ====
419 work( 1 ) = max( real( max( 1, n ) ), work( 1 ) )
420 RETURN
421*
422 ELSE
423*
424* ==== copy eigenvalues isolated by SGEBAL ====
425*
426 DO 10 i = 1, ilo - 1
427 wr( i ) = h( i, i )
428 wi( i ) = zero
429 10 CONTINUE
430 DO 20 i = ihi + 1, n
431 wr( i ) = h( i, i )
432 wi( i ) = zero
433 20 CONTINUE
434*
435* ==== Initialize Z, if requested ====
436*
437 IF( initz )
438 $ CALL slaset( 'A', n, n, zero, one, z, ldz )
439*
440* ==== Quick return if possible ====
441*
442 IF( ilo.EQ.ihi ) THEN
443 wr( ilo ) = h( ilo, ilo )
444 wi( ilo ) = zero
445 RETURN
446 END IF
447*
448* ==== SLAHQR/SLAQR0 crossover point ====
449*
450 nmin = ilaenv( 12, 'SHSEQR', job( : 1 ) // compz( : 1 ), n,
451 $ ilo, ihi, lwork )
452 nmin = max( ntiny, nmin )
453*
454* ==== SLAQR0 for big matrices; SLAHQR for small ones ====
455*
456 IF( n.GT.nmin ) THEN
457 CALL slaqr0( wantt, wantz, n, ilo, ihi, h, ldh, wr, wi,
458 $ ilo,
459 $ ihi, z, ldz, work, lwork, info )
460 ELSE
461*
462* ==== Small matrix ====
463*
464 CALL slahqr( wantt, wantz, n, ilo, ihi, h, ldh, wr, wi,
465 $ ilo,
466 $ ihi, z, ldz, info )
467*
468 IF( info.GT.0 ) THEN
469*
470* ==== A rare SLAHQR failure! SLAQR0 sometimes succeeds
471* . when SLAHQR fails. ====
472*
473 kbot = info
474*
475 IF( n.GE.nl ) THEN
476*
477* ==== Larger matrices have enough subdiagonal scratch
478* . space to call SLAQR0 directly. ====
479*
480 CALL slaqr0( wantt, wantz, n, ilo, kbot, h, ldh,
481 $ wr,
482 $ wi, ilo, ihi, z, ldz, work, lwork, info )
483*
484 ELSE
485*
486* ==== Tiny matrices don't have enough subdiagonal
487* . scratch space to benefit from SLAQR0. Hence,
488* . tiny matrices must be copied into a larger
489* . array before calling SLAQR0. ====
490*
491 CALL slacpy( 'A', n, n, h, ldh, hl, nl )
492 hl( n+1, n ) = zero
493 CALL slaset( 'A', nl, nl-n, zero, zero, hl( 1,
494 $ n+1 ),
495 $ nl )
496 CALL slaqr0( wantt, wantz, nl, ilo, kbot, hl, nl,
497 $ wr,
498 $ wi, ilo, ihi, z, ldz, workl, nl, info )
499 IF( wantt .OR. info.NE.0 )
500 $ CALL slacpy( 'A', n, n, hl, nl, h, ldh )
501 END IF
502 END IF
503 END IF
504*
505* ==== Clear out the trash, if necessary. ====
506*
507 IF( ( wantt .OR. info.NE.0 ) .AND. n.GT.2 )
508 $ CALL slaset( 'L', n-2, n-2, zero, zero, h( 3, 1 ), ldh )
509*
510* ==== Ensure reported workspace size is backward-compatible with
511* . previous LAPACK versions. ====
512*
513 work( 1 ) = max( real( max( 1, n ) ), work( 1 ) )
514 END IF
515*
516* ==== End of SHSEQR ====
517*
518 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine shseqr(job, compz, n, ilo, ihi, h, ldh, wr, wi, z, ldz, work, lwork, info)
SHSEQR
Definition shseqr.f:314
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 slaqr0(wantt, wantz, n, ilo, ihi, h, ldh, wr, wi, iloz, ihiz, z, ldz, work, lwork, info)
SLAQR0 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Schur de...
Definition slaqr0.f:254
subroutine slaset(uplo, m, n, alpha, beta, a, lda)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition slaset.f:108