KTH framework for Nek5000 toolboxes; testing version  0.0.1
dlahqr.f
Go to the documentation of this file.
1  SUBROUTINE dlahqr( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
2  $ ILOZ, IHIZ, Z, LDZ, INFO )
3 *
4 * -- LAPACK auxiliary routine (version 3.0) --
5 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
6 * Courant Institute, Argonne National Lab, and Rice University
7 * June 30, 1999
8 *
9 * .. Scalar Arguments ..
10  LOGICAL WANTT, WANTZ
11  INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
12 * ..
13 * .. Array Arguments ..
14  DOUBLE PRECISION H( LDH, * ), WI( * ), WR( * ), Z( LDZ, * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * DLAHQR is an auxiliary routine called by DHSEQR to update the
21 * eigenvalues and Schur decomposition already computed by DHSEQR, by
22 * dealing with the Hessenberg submatrix in rows and columns ILO to IHI.
23 *
24 * Arguments
25 * =========
26 *
27 * WANTT (input) LOGICAL
28 * = .TRUE. : the full Schur form T is required;
29 * = .FALSE.: only eigenvalues are required.
30 *
31 * WANTZ (input) LOGICAL
32 * = .TRUE. : the matrix of Schur vectors Z is required;
33 * = .FALSE.: Schur vectors are not required.
34 *
35 * N (input) INTEGER
36 * The order of the matrix H. N >= 0.
37 *
38 * ILO (input) INTEGER
39 * IHI (input) INTEGER
40 * It is assumed that H is already upper quasi-triangular in
41 * rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless
42 * ILO = 1). DLAHQR works primarily with the Hessenberg
43 * submatrix in rows and columns ILO to IHI, but applies
44 * transformations to all of H if WANTT is .TRUE..
45 * 1 <= ILO <= max(1,IHI); IHI <= N.
46 *
47 * H (input/output) DOUBLE PRECISION array, dimension (LDH,N)
48 * On entry, the upper Hessenberg matrix H.
49 * On exit, if WANTT is .TRUE., H is upper quasi-triangular in
50 * rows and columns ILO:IHI, with any 2-by-2 diagonal blocks in
51 * standard form. If WANTT is .FALSE., the contents of H are
52 * unspecified on exit.
53 *
54 * LDH (input) INTEGER
55 * The leading dimension of the array H. LDH >= max(1,N).
56 *
57 * WR (output) DOUBLE PRECISION array, dimension (N)
58 * WI (output) DOUBLE PRECISION array, dimension (N)
59 * The real and imaginary parts, respectively, of the computed
60 * eigenvalues ILO to IHI are stored in the corresponding
61 * elements of WR and WI. If two eigenvalues are computed as a
62 * complex conjugate pair, they are stored in consecutive
63 * elements of WR and WI, say the i-th and (i+1)th, with
64 * WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the
65 * eigenvalues are stored in the same order as on the diagonal
66 * of the Schur form returned in H, with WR(i) = H(i,i), and, if
67 * H(i:i+1,i:i+1) is a 2-by-2 diagonal block,
68 * WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i).
69 *
70 * ILOZ (input) INTEGER
71 * IHIZ (input) INTEGER
72 * Specify the rows of Z to which transformations must be
73 * applied if WANTZ is .TRUE..
74 * 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
75 *
76 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
77 * If WANTZ is .TRUE., on entry Z must contain the current
78 * matrix Z of transformations accumulated by DHSEQR, and on
79 * exit Z has been updated; transformations are applied only to
80 * the submatrix Z(ILOZ:IHIZ,ILO:IHI).
81 * If WANTZ is .FALSE., Z is not referenced.
82 *
83 * LDZ (input) INTEGER
84 * The leading dimension of the array Z. LDZ >= max(1,N).
85 *
86 * INFO (output) INTEGER
87 * = 0: successful exit
88 * > 0: DLAHQR failed to compute all the eigenvalues ILO to IHI
89 * in a total of 30*(IHI-ILO+1) iterations; if INFO = i,
90 * elements i+1:ihi of WR and WI contain those eigenvalues
91 * which have been successfully computed.
92 *
93 * Further Details
94 * ===============
95 *
96 * 2-96 Based on modifications by
97 * David Day, Sandia National Laboratory, USA
98 *
99 * =====================================================================
100 *
101 * .. Parameters ..
102  DOUBLE PRECISION ZERO, ONE, HALF
103  parameter( zero = 0.0d+0, one = 1.0d+0, half = 0.5d0 )
104  DOUBLE PRECISION DAT1, DAT2
105  parameter( dat1 = 0.75d+0, dat2 = -0.4375d+0 )
106 * ..
107 * .. Local Scalars ..
108  INTEGER I, I1, I2, ITN, ITS, J, K, L, M, NH, NR, NZ
109  DOUBLE PRECISION AVE, CS, DISC, H00, H10, H11, H12, H21, H22,
110  $ h33, h33s, h43h34, h44, h44s, ovfl, s, smlnum,
111  $ sn, sum, t1, t2, t3, tst1, ulp, unfl, v1, v2,
112  $ v3
113 * ..
114 * .. Local Arrays ..
115  DOUBLE PRECISION V( 3 ), WORK( 1 )
116 * ..
117 * .. External Functions ..
118  DOUBLE PRECISION DLAMCH, DLANHS
119  EXTERNAL dlamch, dlanhs
120 * ..
121 * .. External Subroutines ..
122  EXTERNAL dcopy, dlanv2, dlarfg, drot
123 * ..
124 * .. Intrinsic Functions ..
125  INTRINSIC abs, max, min, sign, sqrt
126 * ..
127 * .. Executable Statements ..
128 *
129  info = 0
130 *
131 * Quick return if possible
132 *
133  IF( n.EQ.0 )
134  $ RETURN
135  IF( ilo.EQ.ihi ) THEN
136  wr( ilo ) = h( ilo, ilo )
137  wi( ilo ) = zero
138  RETURN
139  END IF
140 *
141  nh = ihi - ilo + 1
142  nz = ihiz - iloz + 1
143 *
144 * Set machine-dependent constants for the stopping criterion.
145 * If norm(H) <= sqrt(OVFL), overflow should not occur.
146 *
147  unfl = dlamch( 'Safe minimum' )
148  ovfl = one / unfl
149  CALL dlabad( unfl, ovfl )
150  ulp = dlamch( 'Precision' )
151  smlnum = unfl*( nh / ulp )
152 *
153 * I1 and I2 are the indices of the first row and last column of H
154 * to which transformations must be applied. If eigenvalues only are
155 * being computed, I1 and I2 are set inside the main loop.
156 *
157  IF( wantt ) THEN
158  i1 = 1
159  i2 = n
160  END IF
161 *
162 * ITN is the total number of QR iterations allowed.
163 *
164  itn = 30*nh
165 *
166 * The main loop begins here. I is the loop index and decreases from
167 * IHI to ILO in steps of 1 or 2. Each iteration of the loop works
168 * with the active submatrix in rows and columns L to I.
169 * Eigenvalues I+1 to IHI have already converged. Either L = ILO or
170 * H(L,L-1) is negligible so that the matrix splits.
171 *
172  i = ihi
173  10 CONTINUE
174  l = ilo
175  IF( i.LT.ilo )
176  $ GO TO 150
177 *
178 * Perform QR iterations on rows and columns ILO to I until a
179 * submatrix of order 1 or 2 splits off at the bottom because a
180 * subdiagonal element has become negligible.
181 *
182  DO 130 its = 0, itn
183 *
184 * Look for a single small subdiagonal element.
185 *
186  DO 20 k = i, l + 1, -1
187  tst1 = abs( h( k-1, k-1 ) ) + abs( h( k, k ) )
188  IF( tst1.EQ.zero )
189  $ tst1 = dlanhs( '1', i-l+1, h( l, l ), ldh, work )
190  IF( abs( h( k, k-1 ) ).LE.max( ulp*tst1, smlnum ) )
191  $ GO TO 30
192  20 CONTINUE
193  30 CONTINUE
194  l = k
195  IF( l.GT.ilo ) THEN
196 *
197 * H(L,L-1) is negligible
198 *
199  h( l, l-1 ) = zero
200  END IF
201 *
202 * Exit from loop if a submatrix of order 1 or 2 has split off.
203 *
204  IF( l.GE.i-1 )
205  $ GO TO 140
206 *
207 * Now the active submatrix is in rows and columns L to I. If
208 * eigenvalues only are being computed, only the active submatrix
209 * need be transformed.
210 *
211  IF( .NOT.wantt ) THEN
212  i1 = l
213  i2 = i
214  END IF
215 *
216  IF( its.EQ.10 .OR. its.EQ.20 ) THEN
217 *
218 * Exceptional shift.
219 *
220  s = abs( h( i, i-1 ) ) + abs( h( i-1, i-2 ) )
221  h44 = dat1*s + h( i, i )
222  h33 = h44
223  h43h34 = dat2*s*s
224  ELSE
225 *
226 * Prepare to use Francis' double shift
227 * (i.e. 2nd degree generalized Rayleigh quotient)
228 *
229  h44 = h( i, i )
230  h33 = h( i-1, i-1 )
231  h43h34 = h( i, i-1 )*h( i-1, i )
232  s = h( i-1, i-2 )*h( i-1, i-2 )
233  disc = ( h33-h44 )*half
234  disc = disc*disc + h43h34
235  IF( disc.GT.zero ) THEN
236 *
237 * Real roots: use Wilkinson's shift twice
238 *
239  disc = sqrt( disc )
240  ave = half*( h33+h44 )
241  IF( abs( h33 )-abs( h44 ).GT.zero ) THEN
242  h33 = h33*h44 - h43h34
243  h44 = h33 / ( sign( disc, ave )+ave )
244  ELSE
245  h44 = sign( disc, ave ) + ave
246  END IF
247  h33 = h44
248  h43h34 = zero
249  END IF
250  END IF
251 *
252 * Look for two consecutive small subdiagonal elements.
253 *
254  DO 40 m = i - 2, l, -1
255 * Determine the effect of starting the double-shift QR
256 * iteration at row M, and see if this would make H(M,M-1)
257 * negligible.
258 *
259  h11 = h( m, m )
260  h22 = h( m+1, m+1 )
261  h21 = h( m+1, m )
262  h12 = h( m, m+1 )
263  h44s = h44 - h11
264  h33s = h33 - h11
265  v1 = ( h33s*h44s-h43h34 ) / h21 + h12
266  v2 = h22 - h11 - h33s - h44s
267  v3 = h( m+2, m+1 )
268  s = abs( v1 ) + abs( v2 ) + abs( v3 )
269  v1 = v1 / s
270  v2 = v2 / s
271  v3 = v3 / s
272  v( 1 ) = v1
273  v( 2 ) = v2
274  v( 3 ) = v3
275  IF( m.EQ.l )
276  $ GO TO 50
277  h00 = h( m-1, m-1 )
278  h10 = h( m, m-1 )
279  tst1 = abs( v1 )*( abs( h00 )+abs( h11 )+abs( h22 ) )
280  IF( abs( h10 )*( abs( v2 )+abs( v3 ) ).LE.ulp*tst1 )
281  $ GO TO 50
282  40 CONTINUE
283  50 CONTINUE
284 *
285 * Double-shift QR step
286 *
287  DO 120 k = m, i - 1
288 *
289 * The first iteration of this loop determines a reflection G
290 * from the vector V and applies it from left and right to H,
291 * thus creating a nonzero bulge below the subdiagonal.
292 *
293 * Each subsequent iteration determines a reflection G to
294 * restore the Hessenberg form in the (K-1)th column, and thus
295 * chases the bulge one step toward the bottom of the active
296 * submatrix. NR is the order of G.
297 *
298  nr = min( 3, i-k+1 )
299  IF( k.GT.m )
300  $ CALL dcopy( nr, h( k, k-1 ), 1, v, 1 )
301  CALL dlarfg( nr, v( 1 ), v( 2 ), 1, t1 )
302  IF( k.GT.m ) THEN
303  h( k, k-1 ) = v( 1 )
304  h( k+1, k-1 ) = zero
305  IF( k.LT.i-1 )
306  $ h( k+2, k-1 ) = zero
307  ELSE IF( m.GT.l ) THEN
308  h( k, k-1 ) = -h( k, k-1 )
309  END IF
310  v2 = v( 2 )
311  t2 = t1*v2
312  IF( nr.EQ.3 ) THEN
313  v3 = v( 3 )
314  t3 = t1*v3
315 *
316 * Apply G from the left to transform the rows of the matrix
317 * in columns K to I2.
318 *
319  DO 60 j = k, i2
320  sum = h( k, j ) + v2*h( k+1, j ) + v3*h( k+2, j )
321  h( k, j ) = h( k, j ) - sum*t1
322  h( k+1, j ) = h( k+1, j ) - sum*t2
323  h( k+2, j ) = h( k+2, j ) - sum*t3
324  60 CONTINUE
325 *
326 * Apply G from the right to transform the columns of the
327 * matrix in rows I1 to min(K+3,I).
328 *
329  DO 70 j = i1, min( k+3, i )
330  sum = h( j, k ) + v2*h( j, k+1 ) + v3*h( j, k+2 )
331  h( j, k ) = h( j, k ) - sum*t1
332  h( j, k+1 ) = h( j, k+1 ) - sum*t2
333  h( j, k+2 ) = h( j, k+2 ) - sum*t3
334  70 CONTINUE
335 *
336  IF( wantz ) THEN
337 *
338 * Accumulate transformations in the matrix Z
339 *
340  DO 80 j = iloz, ihiz
341  sum = z( j, k ) + v2*z( j, k+1 ) + v3*z( j, k+2 )
342  z( j, k ) = z( j, k ) - sum*t1
343  z( j, k+1 ) = z( j, k+1 ) - sum*t2
344  z( j, k+2 ) = z( j, k+2 ) - sum*t3
345  80 CONTINUE
346  END IF
347  ELSE IF( nr.EQ.2 ) THEN
348 *
349 * Apply G from the left to transform the rows of the matrix
350 * in columns K to I2.
351 *
352  DO 90 j = k, i2
353  sum = h( k, j ) + v2*h( k+1, j )
354  h( k, j ) = h( k, j ) - sum*t1
355  h( k+1, j ) = h( k+1, j ) - sum*t2
356  90 CONTINUE
357 *
358 * Apply G from the right to transform the columns of the
359 * matrix in rows I1 to min(K+3,I).
360 *
361  DO 100 j = i1, i
362  sum = h( j, k ) + v2*h( j, k+1 )
363  h( j, k ) = h( j, k ) - sum*t1
364  h( j, k+1 ) = h( j, k+1 ) - sum*t2
365  100 CONTINUE
366 *
367  IF( wantz ) THEN
368 *
369 * Accumulate transformations in the matrix Z
370 *
371  DO 110 j = iloz, ihiz
372  sum = z( j, k ) + v2*z( j, k+1 )
373  z( j, k ) = z( j, k ) - sum*t1
374  z( j, k+1 ) = z( j, k+1 ) - sum*t2
375  110 CONTINUE
376  END IF
377  END IF
378  120 CONTINUE
379 *
380  130 CONTINUE
381 *
382 * Failure to converge in remaining number of iterations
383 *
384  info = i
385  RETURN
386 *
387  140 CONTINUE
388 *
389  IF( l.EQ.i ) THEN
390 *
391 * H(I,I-1) is negligible: one eigenvalue has converged.
392 *
393  wr( i ) = h( i, i )
394  wi( i ) = zero
395  ELSE IF( l.EQ.i-1 ) THEN
396 *
397 * H(I-1,I-2) is negligible: a pair of eigenvalues have converged.
398 *
399 * Transform the 2-by-2 submatrix to standard Schur form,
400 * and compute and store the eigenvalues.
401 *
402  CALL dlanv2( h( i-1, i-1 ), h( i-1, i ), h( i, i-1 ),
403  $ h( i, i ), wr( i-1 ), wi( i-1 ), wr( i ), wi( i ),
404  $ cs, sn )
405 *
406  IF( wantt ) THEN
407 *
408 * Apply the transformation to the rest of H.
409 *
410  IF( i2.GT.i )
411  $ CALL drot( i2-i, h( i-1, i+1 ), ldh, h( i, i+1 ), ldh,
412  $ cs, sn )
413  CALL drot( i-i1-1, h( i1, i-1 ), 1, h( i1, i ), 1, cs, sn )
414  END IF
415  IF( wantz ) THEN
416 *
417 * Apply the transformation to Z.
418 *
419  CALL drot( nz, z( iloz, i-1 ), 1, z( iloz, i ), 1, cs, sn )
420  END IF
421  END IF
422 *
423 * Decrement number of remaining iterations, and return to start of
424 * the main loop with new value of I.
425 *
426  itn = itn - its
427  i = l - 1
428  GO TO 10
429 *
430  150 CONTINUE
431  RETURN
432 *
433 * End of DLAHQR
434 *
435  END
subroutine dcopy(n, dx, incx, dy, incy)
Definition: dcopy.f:2
subroutine dlabad(SMALL, LARGE)
Definition: dlabad.f:2
subroutine dlahqr(WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI, ILOZ, IHIZ, Z, LDZ, INFO)
Definition: dlahqr.f:3
subroutine dlanv2(A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN)
Definition: dlanv2.f:2
subroutine dlarfg(N, ALPHA, X, INCX, TAU)
Definition: dlarfg.f:2
subroutine drot(n, dx, incx, dy, incy, c, s)
Definition: drot.f:2