You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dlaqr5.f 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. *> \brief \b DLAQR5 performs a single small-bulge multi-shift QR sweep.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DLAQR5 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaqr5.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaqr5.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaqr5.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS,
  22. * SR, SI, H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U,
  23. * LDU, NV, WV, LDWV, NH, WH, LDWH )
  24. *
  25. * .. Scalar Arguments ..
  26. * INTEGER IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV,
  27. * $ LDWH, LDWV, LDZ, N, NH, NSHFTS, NV
  28. * LOGICAL WANTT, WANTZ
  29. * ..
  30. * .. Array Arguments ..
  31. * DOUBLE PRECISION H( LDH, * ), SI( * ), SR( * ), U( LDU, * ),
  32. * $ V( LDV, * ), WH( LDWH, * ), WV( LDWV, * ),
  33. * $ Z( LDZ, * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> DLAQR5, called by DLAQR0, performs a
  43. *> single small-bulge multi-shift QR sweep.
  44. *> \endverbatim
  45. *
  46. * Arguments:
  47. * ==========
  48. *
  49. *> \param[in] WANTT
  50. *> \verbatim
  51. *> WANTT is LOGICAL
  52. *> WANTT = .true. if the quasi-triangular Schur factor
  53. *> is being computed. WANTT is set to .false. otherwise.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] WANTZ
  57. *> \verbatim
  58. *> WANTZ is LOGICAL
  59. *> WANTZ = .true. if the orthogonal Schur factor is being
  60. *> computed. WANTZ is set to .false. otherwise.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] KACC22
  64. *> \verbatim
  65. *> KACC22 is INTEGER with value 0, 1, or 2.
  66. *> Specifies the computation mode of far-from-diagonal
  67. *> orthogonal updates.
  68. *> = 0: DLAQR5 does not accumulate reflections and does not
  69. *> use matrix-matrix multiply to update far-from-diagonal
  70. *> matrix entries.
  71. *> = 1: DLAQR5 accumulates reflections and uses matrix-matrix
  72. *> multiply to update the far-from-diagonal matrix entries.
  73. *> = 2: Same as KACC22 = 1. This option used to enable exploiting
  74. *> the 2-by-2 structure during matrix multiplications, but
  75. *> this is no longer supported.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] N
  79. *> \verbatim
  80. *> N is INTEGER
  81. *> N is the order of the Hessenberg matrix H upon which this
  82. *> subroutine operates.
  83. *> \endverbatim
  84. *>
  85. *> \param[in] KTOP
  86. *> \verbatim
  87. *> KTOP is INTEGER
  88. *> \endverbatim
  89. *>
  90. *> \param[in] KBOT
  91. *> \verbatim
  92. *> KBOT is INTEGER
  93. *> These are the first and last rows and columns of an
  94. *> isolated diagonal block upon which the QR sweep is to be
  95. *> applied. It is assumed without a check that
  96. *> either KTOP = 1 or H(KTOP,KTOP-1) = 0
  97. *> and
  98. *> either KBOT = N or H(KBOT+1,KBOT) = 0.
  99. *> \endverbatim
  100. *>
  101. *> \param[in] NSHFTS
  102. *> \verbatim
  103. *> NSHFTS is INTEGER
  104. *> NSHFTS gives the number of simultaneous shifts. NSHFTS
  105. *> must be positive and even.
  106. *> \endverbatim
  107. *>
  108. *> \param[in,out] SR
  109. *> \verbatim
  110. *> SR is DOUBLE PRECISION array, dimension (NSHFTS)
  111. *> \endverbatim
  112. *>
  113. *> \param[in,out] SI
  114. *> \verbatim
  115. *> SI is DOUBLE PRECISION array, dimension (NSHFTS)
  116. *> SR contains the real parts and SI contains the imaginary
  117. *> parts of the NSHFTS shifts of origin that define the
  118. *> multi-shift QR sweep. On output SR and SI may be
  119. *> reordered.
  120. *> \endverbatim
  121. *>
  122. *> \param[in,out] H
  123. *> \verbatim
  124. *> H is DOUBLE PRECISION array, dimension (LDH,N)
  125. *> On input H contains a Hessenberg matrix. On output a
  126. *> multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied
  127. *> to the isolated diagonal block in rows and columns KTOP
  128. *> through KBOT.
  129. *> \endverbatim
  130. *>
  131. *> \param[in] LDH
  132. *> \verbatim
  133. *> LDH is INTEGER
  134. *> LDH is the leading dimension of H just as declared in the
  135. *> calling procedure. LDH >= MAX(1,N).
  136. *> \endverbatim
  137. *>
  138. *> \param[in] ILOZ
  139. *> \verbatim
  140. *> ILOZ is INTEGER
  141. *> \endverbatim
  142. *>
  143. *> \param[in] IHIZ
  144. *> \verbatim
  145. *> IHIZ is INTEGER
  146. *> Specify the rows of Z to which transformations must be
  147. *> applied if WANTZ is .TRUE.. 1 <= ILOZ <= IHIZ <= N
  148. *> \endverbatim
  149. *>
  150. *> \param[in,out] Z
  151. *> \verbatim
  152. *> Z is DOUBLE PRECISION array, dimension (LDZ,IHIZ)
  153. *> If WANTZ = .TRUE., then the QR Sweep orthogonal
  154. *> similarity transformation is accumulated into
  155. *> Z(ILOZ:IHIZ,ILOZ:IHIZ) from the right.
  156. *> If WANTZ = .FALSE., then Z is unreferenced.
  157. *> \endverbatim
  158. *>
  159. *> \param[in] LDZ
  160. *> \verbatim
  161. *> LDZ is INTEGER
  162. *> LDA is the leading dimension of Z just as declared in
  163. *> the calling procedure. LDZ >= N.
  164. *> \endverbatim
  165. *>
  166. *> \param[out] V
  167. *> \verbatim
  168. *> V is DOUBLE PRECISION array, dimension (LDV,NSHFTS/2)
  169. *> \endverbatim
  170. *>
  171. *> \param[in] LDV
  172. *> \verbatim
  173. *> LDV is INTEGER
  174. *> LDV is the leading dimension of V as declared in the
  175. *> calling procedure. LDV >= 3.
  176. *> \endverbatim
  177. *>
  178. *> \param[out] U
  179. *> \verbatim
  180. *> U is DOUBLE PRECISION array, dimension (LDU,2*NSHFTS)
  181. *> \endverbatim
  182. *>
  183. *> \param[in] LDU
  184. *> \verbatim
  185. *> LDU is INTEGER
  186. *> LDU is the leading dimension of U just as declared in the
  187. *> in the calling subroutine. LDU >= 2*NSHFTS.
  188. *> \endverbatim
  189. *>
  190. *> \param[in] NV
  191. *> \verbatim
  192. *> NV is INTEGER
  193. *> NV is the number of rows in WV agailable for workspace.
  194. *> NV >= 1.
  195. *> \endverbatim
  196. *>
  197. *> \param[out] WV
  198. *> \verbatim
  199. *> WV is DOUBLE PRECISION array, dimension (LDWV,2*NSHFTS)
  200. *> \endverbatim
  201. *>
  202. *> \param[in] LDWV
  203. *> \verbatim
  204. *> LDWV is INTEGER
  205. *> LDWV is the leading dimension of WV as declared in the
  206. *> in the calling subroutine. LDWV >= NV.
  207. *> \endverbatim
  208. *
  209. *> \param[in] NH
  210. *> \verbatim
  211. *> NH is INTEGER
  212. *> NH is the number of columns in array WH available for
  213. *> workspace. NH >= 1.
  214. *> \endverbatim
  215. *>
  216. *> \param[out] WH
  217. *> \verbatim
  218. *> WH is DOUBLE PRECISION array, dimension (LDWH,NH)
  219. *> \endverbatim
  220. *>
  221. *> \param[in] LDWH
  222. *> \verbatim
  223. *> LDWH is INTEGER
  224. *> Leading dimension of WH just as declared in the
  225. *> calling procedure. LDWH >= 2*NSHFTS.
  226. *> \endverbatim
  227. *>
  228. * Authors:
  229. * ========
  230. *
  231. *> \author Univ. of Tennessee
  232. *> \author Univ. of California Berkeley
  233. *> \author Univ. of Colorado Denver
  234. *> \author NAG Ltd.
  235. *
  236. *> \date January 2021
  237. *
  238. *> \ingroup doubleOTHERauxiliary
  239. *
  240. *> \par Contributors:
  241. * ==================
  242. *>
  243. *> Karen Braman and Ralph Byers, Department of Mathematics,
  244. *> University of Kansas, USA
  245. *>
  246. *> Lars Karlsson, Daniel Kressner, and Bruno Lang
  247. *>
  248. *> Thijs Steel, Department of Computer science,
  249. *> KU Leuven, Belgium
  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. *>
  259. *> Lars Karlsson, Daniel Kressner, and Bruno Lang, Optimally packed
  260. *> chains of bulges in multishift QR algorithms.
  261. *> ACM Trans. Math. Softw. 40, 2, Article 12 (February 2014).
  262. *>
  263. * =====================================================================
  264. SUBROUTINE DLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS,
  265. $ SR, SI, H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U,
  266. $ LDU, NV, WV, LDWV, NH, WH, LDWH )
  267. IMPLICIT NONE
  268. *
  269. * -- LAPACK auxiliary routine (version 3.7.1) --
  270. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  271. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  272. * June 2016
  273. *
  274. * .. Scalar Arguments ..
  275. INTEGER IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV,
  276. $ LDWH, LDWV, LDZ, N, NH, NSHFTS, NV
  277. LOGICAL WANTT, WANTZ
  278. * ..
  279. * .. Array Arguments ..
  280. DOUBLE PRECISION H( LDH, * ), SI( * ), SR( * ), U( LDU, * ),
  281. $ V( LDV, * ), WH( LDWH, * ), WV( LDWV, * ),
  282. $ Z( LDZ, * )
  283. * ..
  284. *
  285. * ================================================================
  286. * .. Parameters ..
  287. DOUBLE PRECISION ZERO, ONE
  288. PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0 )
  289. * ..
  290. * .. Local Scalars ..
  291. DOUBLE PRECISION ALPHA, BETA, H11, H12, H21, H22, REFSUM,
  292. $ SAFMAX, SAFMIN, SCL, SMLNUM, SWAP, TST1, TST2,
  293. $ ULP
  294. INTEGER I, I2, I4, INCOL, J, JBOT, JCOL, JLEN,
  295. $ JROW, JTOP, K, K1, KDU, KMS, KRCOL,
  296. $ M, M22, MBOT, MTOP, NBMPS, NDCOL,
  297. $ NS, NU
  298. LOGICAL ACCUM, BMP22
  299. * ..
  300. * .. External Functions ..
  301. DOUBLE PRECISION DLAMCH
  302. EXTERNAL DLAMCH
  303. * ..
  304. * .. Intrinsic Functions ..
  305. *
  306. INTRINSIC ABS, DBLE, MAX, MIN, MOD
  307. * ..
  308. * .. Local Arrays ..
  309. DOUBLE PRECISION VT( 3 )
  310. * ..
  311. * .. External Subroutines ..
  312. EXTERNAL DGEMM, DLABAD, DLACPY, DLAQR1, DLARFG, DLASET,
  313. $ DTRMM
  314. * ..
  315. * .. Executable Statements ..
  316. *
  317. * ==== If there are no shifts, then there is nothing to do. ====
  318. *
  319. IF( NSHFTS.LT.2 )
  320. $ RETURN
  321. *
  322. * ==== If the active block is empty or 1-by-1, then there
  323. * . is nothing to do. ====
  324. *
  325. IF( KTOP.GE.KBOT )
  326. $ RETURN
  327. *
  328. * ==== Shuffle shifts into pairs of real shifts and pairs
  329. * . of complex conjugate shifts assuming complex
  330. * . conjugate shifts are already adjacent to one
  331. * . another. ====
  332. *
  333. DO 10 I = 1, NSHFTS - 2, 2
  334. IF( SI( I ).NE.-SI( I+1 ) ) THEN
  335. *
  336. SWAP = SR( I )
  337. SR( I ) = SR( I+1 )
  338. SR( I+1 ) = SR( I+2 )
  339. SR( I+2 ) = SWAP
  340. *
  341. SWAP = SI( I )
  342. SI( I ) = SI( I+1 )
  343. SI( I+1 ) = SI( I+2 )
  344. SI( I+2 ) = SWAP
  345. END IF
  346. 10 CONTINUE
  347. *
  348. * ==== NSHFTS is supposed to be even, but if it is odd,
  349. * . then simply reduce it by one. The shuffle above
  350. * . ensures that the dropped shift is real and that
  351. * . the remaining shifts are paired. ====
  352. *
  353. NS = NSHFTS - MOD( NSHFTS, 2 )
  354. *
  355. * ==== Machine constants for deflation ====
  356. *
  357. SAFMIN = DLAMCH( 'SAFE MINIMUM' )
  358. SAFMAX = ONE / SAFMIN
  359. CALL DLABAD( SAFMIN, SAFMAX )
  360. ULP = DLAMCH( 'PRECISION' )
  361. SMLNUM = SAFMIN*( DBLE( N ) / ULP )
  362. *
  363. * ==== Use accumulated reflections to update far-from-diagonal
  364. * . entries ? ====
  365. *
  366. ACCUM = ( KACC22.EQ.1 ) .OR. ( KACC22.EQ.2 )
  367. *
  368. * ==== clear trash ====
  369. *
  370. IF( KTOP+2.LE.KBOT )
  371. $ H( KTOP+2, KTOP ) = ZERO
  372. *
  373. * ==== NBMPS = number of 2-shift bulges in the chain ====
  374. *
  375. NBMPS = NS / 2
  376. *
  377. * ==== KDU = width of slab ====
  378. *
  379. KDU = 4*NBMPS
  380. *
  381. * ==== Create and chase chains of NBMPS bulges ====
  382. *
  383. DO 180 INCOL = KTOP - 2*NBMPS + 1, KBOT - 2, 2*NBMPS
  384. *
  385. * JTOP = Index from which updates from the right start.
  386. *
  387. IF( ACCUM ) THEN
  388. JTOP = MAX( KTOP, INCOL )
  389. ELSE IF( WANTT ) THEN
  390. JTOP = 1
  391. ELSE
  392. JTOP = KTOP
  393. END IF
  394. *
  395. NDCOL = INCOL + KDU
  396. IF( ACCUM )
  397. $ CALL DLASET( 'ALL', KDU, KDU, ZERO, ONE, U, LDU )
  398. *
  399. * ==== Near-the-diagonal bulge chase. The following loop
  400. * . performs the near-the-diagonal part of a small bulge
  401. * . multi-shift QR sweep. Each 4*NBMPS column diagonal
  402. * . chunk extends from column INCOL to column NDCOL
  403. * . (including both column INCOL and column NDCOL). The
  404. * . following loop chases a 2*NBMPS+1 column long chain of
  405. * . NBMPS bulges 2*NBMPS columns to the right. (INCOL
  406. * . may be less than KTOP and and NDCOL may be greater than
  407. * . KBOT indicating phantom columns from which to chase
  408. * . bulges before they are actually introduced or to which
  409. * . to chase bulges beyond column KBOT.) ====
  410. *
  411. DO 145 KRCOL = INCOL, MIN( INCOL+2*NBMPS-1, KBOT-2 )
  412. *
  413. * ==== Bulges number MTOP to MBOT are active double implicit
  414. * . shift bulges. There may or may not also be small
  415. * . 2-by-2 bulge, if there is room. The inactive bulges
  416. * . (if any) must wait until the active bulges have moved
  417. * . down the diagonal to make room. The phantom matrix
  418. * . paradigm described above helps keep track. ====
  419. *
  420. MTOP = MAX( 1, ( KTOP-KRCOL ) / 2+1 )
  421. MBOT = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 2 )
  422. M22 = MBOT + 1
  423. BMP22 = ( MBOT.LT.NBMPS ) .AND. ( KRCOL+2*( M22-1 ) ).EQ.
  424. $ ( KBOT-2 )
  425. *
  426. * ==== Generate reflections to chase the chain right
  427. * . one column. (The minimum value of K is KTOP-1.) ====
  428. *
  429. IF ( BMP22 ) THEN
  430. *
  431. * ==== Special case: 2-by-2 reflection at bottom treated
  432. * . separately ====
  433. *
  434. K = KRCOL + 2*( M22-1 )
  435. IF( K.EQ.KTOP-1 ) THEN
  436. CALL DLAQR1( 2, H( K+1, K+1 ), LDH, SR( 2*M22-1 ),
  437. $ SI( 2*M22-1 ), SR( 2*M22 ), SI( 2*M22 ),
  438. $ V( 1, M22 ) )
  439. BETA = V( 1, M22 )
  440. CALL DLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
  441. ELSE
  442. BETA = H( K+1, K )
  443. V( 2, M22 ) = H( K+2, K )
  444. CALL DLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
  445. H( K+1, K ) = BETA
  446. H( K+2, K ) = ZERO
  447. END IF
  448. *
  449. * ==== Perform update from right within
  450. * . computational window. ====
  451. *
  452. DO 30 J = JTOP, MIN( KBOT, K+3 )
  453. REFSUM = V( 1, M22 )*( H( J, K+1 )+V( 2, M22 )*
  454. $ H( J, K+2 ) )
  455. H( J, K+1 ) = H( J, K+1 ) - REFSUM
  456. H( J, K+2 ) = H( J, K+2 ) - REFSUM*V( 2, M22 )
  457. 30 CONTINUE
  458. *
  459. * ==== Perform update from left within
  460. * . computational window. ====
  461. *
  462. IF( ACCUM ) THEN
  463. JBOT = MIN( NDCOL, KBOT )
  464. ELSE IF( WANTT ) THEN
  465. JBOT = N
  466. ELSE
  467. JBOT = KBOT
  468. END IF
  469. DO 40 J = K+1, JBOT
  470. REFSUM = V( 1, M22 )*( H( K+1, J )+V( 2, M22 )*
  471. $ H( K+2, J ) )
  472. H( K+1, J ) = H( K+1, J ) - REFSUM
  473. H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M22 )
  474. 40 CONTINUE
  475. *
  476. * ==== The following convergence test requires that
  477. * . the tradition small-compared-to-nearby-diagonals
  478. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  479. * . criteria both be satisfied. The latter improves
  480. * . accuracy in some examples. Falling back on an
  481. * . alternate convergence criterion when TST1 or TST2
  482. * . is zero (as done here) is traditional but probably
  483. * . unnecessary. ====
  484. *
  485. IF( K.GE.KTOP ) THEN
  486. IF( H( K+1, K ).NE.ZERO ) THEN
  487. TST1 = ABS( H( K, K ) ) + ABS( H( K+1, K+1 ) )
  488. IF( TST1.EQ.ZERO ) THEN
  489. IF( K.GE.KTOP+1 )
  490. $ TST1 = TST1 + ABS( H( K, K-1 ) )
  491. IF( K.GE.KTOP+2 )
  492. $ TST1 = TST1 + ABS( H( K, K-2 ) )
  493. IF( K.GE.KTOP+3 )
  494. $ TST1 = TST1 + ABS( H( K, K-3 ) )
  495. IF( K.LE.KBOT-2 )
  496. $ TST1 = TST1 + ABS( H( K+2, K+1 ) )
  497. IF( K.LE.KBOT-3 )
  498. $ TST1 = TST1 + ABS( H( K+3, K+1 ) )
  499. IF( K.LE.KBOT-4 )
  500. $ TST1 = TST1 + ABS( H( K+4, K+1 ) )
  501. END IF
  502. IF( ABS( H( K+1, K ) )
  503. $ .LE.MAX( SMLNUM, ULP*TST1 ) ) THEN
  504. H12 = MAX( ABS( H( K+1, K ) ),
  505. $ ABS( H( K, K+1 ) ) )
  506. H21 = MIN( ABS( H( K+1, K ) ),
  507. $ ABS( H( K, K+1 ) ) )
  508. H11 = MAX( ABS( H( K+1, K+1 ) ),
  509. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  510. H22 = MIN( ABS( H( K+1, K+1 ) ),
  511. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  512. SCL = H11 + H12
  513. TST2 = H22*( H11 / SCL )
  514. *
  515. IF( TST2.EQ.ZERO .OR. H21*( H12 / SCL ).LE.
  516. $ MAX( SMLNUM, ULP*TST2 ) ) THEN
  517. H( K+1, K ) = ZERO
  518. END IF
  519. END IF
  520. END IF
  521. END IF
  522. *
  523. * ==== Accumulate orthogonal transformations. ====
  524. *
  525. IF( ACCUM ) THEN
  526. KMS = K - INCOL
  527. DO 50 J = MAX( 1, KTOP-INCOL ), KDU
  528. REFSUM = V( 1, M22 )*( U( J, KMS+1 )+
  529. $ V( 2, M22 )*U( J, KMS+2 ) )
  530. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
  531. U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*V( 2, M22 )
  532. 50 CONTINUE
  533. ELSE IF( WANTZ ) THEN
  534. DO 60 J = ILOZ, IHIZ
  535. REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )*
  536. $ Z( J, K+2 ) )
  537. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
  538. Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*V( 2, M22 )
  539. 60 CONTINUE
  540. END IF
  541. END IF
  542. *
  543. * ==== Normal case: Chain of 3-by-3 reflections ====
  544. *
  545. DO 80 M = MBOT, MTOP, -1
  546. K = KRCOL + 2*( M-1 )
  547. IF( K.EQ.KTOP-1 ) THEN
  548. CALL DLAQR1( 3, H( KTOP, KTOP ), LDH, SR( 2*M-1 ),
  549. $ SI( 2*M-1 ), SR( 2*M ), SI( 2*M ),
  550. $ V( 1, M ) )
  551. ALPHA = V( 1, M )
  552. CALL DLARFG( 3, ALPHA, V( 2, M ), 1, V( 1, M ) )
  553. ELSE
  554. *
  555. * ==== Perform delayed transformation of row below
  556. * . Mth bulge. Exploit fact that first two elements
  557. * . of row are actually zero. ====
  558. *
  559. REFSUM = V( 1, M )*V( 3, M )*H( K+3, K+2 )
  560. H( K+3, K ) = -REFSUM
  561. H( K+3, K+1 ) = -REFSUM*V( 2, M )
  562. H( K+3, K+2 ) = H( K+3, K+2 ) - REFSUM*V( 3, M )
  563. *
  564. * ==== Calculate reflection to move
  565. * . Mth bulge one step. ====
  566. *
  567. BETA = H( K+1, K )
  568. V( 2, M ) = H( K+2, K )
  569. V( 3, M ) = H( K+3, K )
  570. CALL DLARFG( 3, BETA, V( 2, M ), 1, V( 1, M ) )
  571. *
  572. * ==== A Bulge may collapse because of vigilant
  573. * . deflation or destructive underflow. In the
  574. * . underflow case, try the two-small-subdiagonals
  575. * . trick to try to reinflate the bulge. ====
  576. *
  577. IF( H( K+3, K ).NE.ZERO .OR. H( K+3, K+1 ).NE.
  578. $ ZERO .OR. H( K+3, K+2 ).EQ.ZERO ) THEN
  579. *
  580. * ==== Typical case: not collapsed (yet). ====
  581. *
  582. H( K+1, K ) = BETA
  583. H( K+2, K ) = ZERO
  584. H( K+3, K ) = ZERO
  585. ELSE
  586. *
  587. * ==== Atypical case: collapsed. Attempt to
  588. * . reintroduce ignoring H(K+1,K) and H(K+2,K).
  589. * . If the fill resulting from the new
  590. * . reflector is too large, then abandon it.
  591. * . Otherwise, use the new one. ====
  592. *
  593. CALL DLAQR1( 3, H( K+1, K+1 ), LDH, SR( 2*M-1 ),
  594. $ SI( 2*M-1 ), SR( 2*M ), SI( 2*M ),
  595. $ VT )
  596. ALPHA = VT( 1 )
  597. CALL DLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
  598. REFSUM = VT( 1 )*( H( K+1, K )+VT( 2 )*
  599. $ H( K+2, K ) )
  600. *
  601. IF( ABS( H( K+2, K )-REFSUM*VT( 2 ) )+
  602. $ ABS( REFSUM*VT( 3 ) ).GT.ULP*
  603. $ ( ABS( H( K, K ) )+ABS( H( K+1,
  604. $ K+1 ) )+ABS( H( K+2, K+2 ) ) ) ) THEN
  605. *
  606. * ==== Starting a new bulge here would
  607. * . create non-negligible fill. Use
  608. * . the old one with trepidation. ====
  609. *
  610. H( K+1, K ) = BETA
  611. H( K+2, K ) = ZERO
  612. H( K+3, K ) = ZERO
  613. ELSE
  614. *
  615. * ==== Starting a new bulge here would
  616. * . create only negligible fill.
  617. * . Replace the old reflector with
  618. * . the new one. ====
  619. *
  620. H( K+1, K ) = H( K+1, K ) - REFSUM
  621. H( K+2, K ) = ZERO
  622. H( K+3, K ) = ZERO
  623. V( 1, M ) = VT( 1 )
  624. V( 2, M ) = VT( 2 )
  625. V( 3, M ) = VT( 3 )
  626. END IF
  627. END IF
  628. END IF
  629. *
  630. * ==== Apply reflection from the right and
  631. * . the first column of update from the left.
  632. * . These updates are required for the vigilant
  633. * . deflation check. We still delay most of the
  634. * . updates from the left for efficiency. ====
  635. *
  636. DO 70 J = JTOP, MIN( KBOT, K+3 )
  637. REFSUM = V( 1, M )*( H( J, K+1 )+V( 2, M )*
  638. $ H( J, K+2 )+V( 3, M )*H( J, K+3 ) )
  639. H( J, K+1 ) = H( J, K+1 ) - REFSUM
  640. H( J, K+2 ) = H( J, K+2 ) - REFSUM*V( 2, M )
  641. H( J, K+3 ) = H( J, K+3 ) - REFSUM*V( 3, M )
  642. 70 CONTINUE
  643. *
  644. * ==== Perform update from left for subsequent
  645. * . column. ====
  646. *
  647. REFSUM = V( 1, M )*( H( K+1, K+1 )+V( 2, M )*
  648. $ H( K+2, K+1 )+V( 3, M )*H( K+3, K+1 ) )
  649. H( K+1, K+1 ) = H( K+1, K+1 ) - REFSUM
  650. H( K+2, K+1 ) = H( K+2, K+1 ) - REFSUM*V( 2, M )
  651. H( K+3, K+1 ) = H( K+3, K+1 ) - REFSUM*V( 3, M )
  652. *
  653. * ==== The following convergence test requires that
  654. * . the tradition small-compared-to-nearby-diagonals
  655. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  656. * . criteria both be satisfied. The latter improves
  657. * . accuracy in some examples. Falling back on an
  658. * . alternate convergence criterion when TST1 or TST2
  659. * . is zero (as done here) is traditional but probably
  660. * . unnecessary. ====
  661. *
  662. IF( K.LT.KTOP)
  663. $ CYCLE
  664. IF( H( K+1, K ).NE.ZERO ) THEN
  665. TST1 = ABS( H( K, K ) ) + ABS( H( K+1, K+1 ) )
  666. IF( TST1.EQ.ZERO ) THEN
  667. IF( K.GE.KTOP+1 )
  668. $ TST1 = TST1 + ABS( H( K, K-1 ) )
  669. IF( K.GE.KTOP+2 )
  670. $ TST1 = TST1 + ABS( H( K, K-2 ) )
  671. IF( K.GE.KTOP+3 )
  672. $ TST1 = TST1 + ABS( H( K, K-3 ) )
  673. IF( K.LE.KBOT-2 )
  674. $ TST1 = TST1 + ABS( H( K+2, K+1 ) )
  675. IF( K.LE.KBOT-3 )
  676. $ TST1 = TST1 + ABS( H( K+3, K+1 ) )
  677. IF( K.LE.KBOT-4 )
  678. $ TST1 = TST1 + ABS( H( K+4, K+1 ) )
  679. END IF
  680. IF( ABS( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
  681. $ THEN
  682. H12 = MAX( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
  683. H21 = MIN( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
  684. H11 = MAX( ABS( H( K+1, K+1 ) ),
  685. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  686. H22 = MIN( ABS( H( K+1, K+1 ) ),
  687. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  688. SCL = H11 + H12
  689. TST2 = H22*( H11 / SCL )
  690. *
  691. IF( TST2.EQ.ZERO .OR. H21*( H12 / SCL ).LE.
  692. $ MAX( SMLNUM, ULP*TST2 ) ) THEN
  693. H( K+1, K ) = ZERO
  694. END IF
  695. END IF
  696. END IF
  697. 80 CONTINUE
  698. *
  699. * ==== Multiply H by reflections from the left ====
  700. *
  701. IF( ACCUM ) THEN
  702. JBOT = MIN( NDCOL, KBOT )
  703. ELSE IF( WANTT ) THEN
  704. JBOT = N
  705. ELSE
  706. JBOT = KBOT
  707. END IF
  708. *
  709. DO 100 M = MBOT, MTOP, -1
  710. K = KRCOL + 2*( M-1 )
  711. DO 90 J = MAX( KTOP, KRCOL + 2*M ), JBOT
  712. REFSUM = V( 1, M )*( H( K+1, J )+V( 2, M )*
  713. $ H( K+2, J )+V( 3, M )*H( K+3, J ) )
  714. H( K+1, J ) = H( K+1, J ) - REFSUM
  715. H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M )
  716. H( K+3, J ) = H( K+3, J ) - REFSUM*V( 3, M )
  717. 90 CONTINUE
  718. 100 CONTINUE
  719. *
  720. * ==== Accumulate orthogonal transformations. ====
  721. *
  722. IF( ACCUM ) THEN
  723. *
  724. * ==== Accumulate U. (If needed, update Z later
  725. * . with an efficient matrix-matrix
  726. * . multiply.) ====
  727. *
  728. DO 120 M = MBOT, MTOP, -1
  729. K = KRCOL + 2*( M-1 )
  730. KMS = K - INCOL
  731. I2 = MAX( 1, KTOP-INCOL )
  732. I2 = MAX( I2, KMS-(KRCOL-INCOL)+1 )
  733. I4 = MIN( KDU, KRCOL + 2*( MBOT-1 ) - INCOL + 5 )
  734. DO 110 J = I2, I4
  735. REFSUM = V( 1, M )*( U( J, KMS+1 )+V( 2, M )*
  736. $ U( J, KMS+2 )+V( 3, M )*U( J, KMS+3 ) )
  737. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
  738. U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*V( 2, M )
  739. U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*V( 3, M )
  740. 110 CONTINUE
  741. 120 CONTINUE
  742. ELSE IF( WANTZ ) THEN
  743. *
  744. * ==== U is not accumulated, so update Z
  745. * . now by multiplying by reflections
  746. * . from the right. ====
  747. *
  748. DO 140 M = MBOT, MTOP, -1
  749. K = KRCOL + 2*( M-1 )
  750. DO 130 J = ILOZ, IHIZ
  751. REFSUM = V( 1, M )*( Z( J, K+1 )+V( 2, M )*
  752. $ Z( J, K+2 )+V( 3, M )*Z( J, K+3 ) )
  753. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
  754. Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*V( 2, M )
  755. Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*V( 3, M )
  756. 130 CONTINUE
  757. 140 CONTINUE
  758. END IF
  759. *
  760. * ==== End of near-the-diagonal bulge chase. ====
  761. *
  762. 145 CONTINUE
  763. *
  764. * ==== Use U (if accumulated) to update far-from-diagonal
  765. * . entries in H. If required, use U to update Z as
  766. * . well. ====
  767. *
  768. IF( ACCUM ) THEN
  769. IF( WANTT ) THEN
  770. JTOP = 1
  771. JBOT = N
  772. ELSE
  773. JTOP = KTOP
  774. JBOT = KBOT
  775. END IF
  776. K1 = MAX( 1, KTOP-INCOL )
  777. NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
  778. *
  779. * ==== Horizontal Multiply ====
  780. *
  781. DO 150 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
  782. JLEN = MIN( NH, JBOT-JCOL+1 )
  783. CALL DGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
  784. $ LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH,
  785. $ LDWH )
  786. CALL DLACPY( 'ALL', NU, JLEN, WH, LDWH,
  787. $ H( INCOL+K1, JCOL ), LDH )
  788. 150 CONTINUE
  789. *
  790. * ==== Vertical multiply ====
  791. *
  792. DO 160 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
  793. JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
  794. CALL DGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  795. $ H( JROW, INCOL+K1 ), LDH, U( K1, K1 ),
  796. $ LDU, ZERO, WV, LDWV )
  797. CALL DLACPY( 'ALL', JLEN, NU, WV, LDWV,
  798. $ H( JROW, INCOL+K1 ), LDH )
  799. 160 CONTINUE
  800. *
  801. * ==== Z multiply (also vertical) ====
  802. *
  803. IF( WANTZ ) THEN
  804. DO 170 JROW = ILOZ, IHIZ, NV
  805. JLEN = MIN( NV, IHIZ-JROW+1 )
  806. CALL DGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  807. $ Z( JROW, INCOL+K1 ), LDZ, U( K1, K1 ),
  808. $ LDU, ZERO, WV, LDWV )
  809. CALL DLACPY( 'ALL', JLEN, NU, WV, LDWV,
  810. $ Z( JROW, INCOL+K1 ), LDZ )
  811. 170 CONTINUE
  812. END IF
  813. END IF
  814. 180 CONTINUE
  815. *
  816. * ==== End of DLAQR5 ====
  817. *
  818. END