Télécharger dlaqr4.eso

Retour à la liste

Numérotation des lignes :

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

© Cast3M 2003 - Tous droits réservés.
Mentions légales