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.

slaqr5.f 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. *> \brief \b SLAQR5 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 SLAQR5 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaqr5.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaqr5.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaqr5.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLAQR5( 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. * REAL 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. *> SLAQR5, called by SLAQR0, 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: SLAQR5 does not accumulate reflections and does not
  69. *> use matrix-matrix multiply to update far-from-diagonal
  70. *> matrix entries.
  71. *> = 1: SLAQR5 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 REAL array, dimension (NSHFTS)
  111. *> \endverbatim
  112. *>
  113. *> \param[in,out] SI
  114. *> \verbatim
  115. *> SI is REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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. *> \ingroup realOTHERauxiliary
  237. *
  238. *> \par Contributors:
  239. * ==================
  240. *>
  241. *> Karen Braman and Ralph Byers, Department of Mathematics,
  242. *> University of Kansas, USA
  243. *>
  244. *> Lars Karlsson, Daniel Kressner, and Bruno Lang
  245. *>
  246. *> Thijs Steel, Department of Computer science,
  247. *> KU Leuven, Belgium
  248. *
  249. *> \par References:
  250. * ================
  251. *>
  252. *> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
  253. *> Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
  254. *> Performance, SIAM Journal of Matrix Analysis, volume 23, pages
  255. *> 929--947, 2002.
  256. *>
  257. *> Lars Karlsson, Daniel Kressner, and Bruno Lang, Optimally packed
  258. *> chains of bulges in multishift QR algorithms.
  259. *> ACM Trans. Math. Softw. 40, 2, Article 12 (February 2014).
  260. *>
  261. * =====================================================================
  262. SUBROUTINE SLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS,
  263. $ SR, SI, H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U,
  264. $ LDU, NV, WV, LDWV, NH, WH, LDWH )
  265. IMPLICIT NONE
  266. *
  267. * -- LAPACK auxiliary routine --
  268. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  269. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  270. *
  271. * .. Scalar Arguments ..
  272. INTEGER IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV,
  273. $ LDWH, LDWV, LDZ, N, NH, NSHFTS, NV
  274. LOGICAL WANTT, WANTZ
  275. * ..
  276. * .. Array Arguments ..
  277. REAL H( LDH, * ), SI( * ), SR( * ), U( LDU, * ),
  278. $ V( LDV, * ), WH( LDWH, * ), WV( LDWV, * ),
  279. $ Z( LDZ, * )
  280. * ..
  281. *
  282. * ================================================================
  283. * .. Parameters ..
  284. REAL ZERO, ONE
  285. PARAMETER ( ZERO = 0.0e0, ONE = 1.0e0 )
  286. * ..
  287. * .. Local Scalars ..
  288. REAL ALPHA, BETA, H11, H12, H21, H22, REFSUM,
  289. $ SAFMAX, SAFMIN, SCL, SMLNUM, SWAP, T1, T2,
  290. $ T3, TST1, TST2, ULP
  291. INTEGER I, I2, I4, INCOL, J, JBOT, JCOL, JLEN,
  292. $ JROW, JTOP, K, K1, KDU, KMS, KRCOL,
  293. $ M, M22, MBOT, MTOP, NBMPS, NDCOL,
  294. $ NS, NU
  295. LOGICAL ACCUM, BMP22
  296. * ..
  297. * .. External Functions ..
  298. REAL SLAMCH
  299. EXTERNAL SLAMCH
  300. * ..
  301. * .. Intrinsic Functions ..
  302. *
  303. INTRINSIC ABS, MAX, MIN, MOD, REAL
  304. * ..
  305. * .. Local Arrays ..
  306. REAL VT( 3 )
  307. * ..
  308. * .. External Subroutines ..
  309. EXTERNAL SGEMM, SLABAD, SLACPY, SLAQR1, SLARFG, SLASET,
  310. $ STRMM
  311. * ..
  312. * .. Executable Statements ..
  313. *
  314. * ==== If there are no shifts, then there is nothing to do. ====
  315. *
  316. IF( NSHFTS.LT.2 )
  317. $ RETURN
  318. *
  319. * ==== If the active block is empty or 1-by-1, then there
  320. * . is nothing to do. ====
  321. *
  322. IF( KTOP.GE.KBOT )
  323. $ RETURN
  324. *
  325. * ==== Shuffle shifts into pairs of real shifts and pairs
  326. * . of complex conjugate shifts assuming complex
  327. * . conjugate shifts are already adjacent to one
  328. * . another. ====
  329. *
  330. DO 10 I = 1, NSHFTS - 2, 2
  331. IF( SI( I ).NE.-SI( I+1 ) ) THEN
  332. *
  333. SWAP = SR( I )
  334. SR( I ) = SR( I+1 )
  335. SR( I+1 ) = SR( I+2 )
  336. SR( I+2 ) = SWAP
  337. *
  338. SWAP = SI( I )
  339. SI( I ) = SI( I+1 )
  340. SI( I+1 ) = SI( I+2 )
  341. SI( I+2 ) = SWAP
  342. END IF
  343. 10 CONTINUE
  344. *
  345. * ==== NSHFTS is supposed to be even, but if it is odd,
  346. * . then simply reduce it by one. The shuffle above
  347. * . ensures that the dropped shift is real and that
  348. * . the remaining shifts are paired. ====
  349. *
  350. NS = NSHFTS - MOD( NSHFTS, 2 )
  351. *
  352. * ==== Machine constants for deflation ====
  353. *
  354. SAFMIN = SLAMCH( 'SAFE MINIMUM' )
  355. SAFMAX = ONE / SAFMIN
  356. CALL SLABAD( SAFMIN, SAFMAX )
  357. ULP = SLAMCH( 'PRECISION' )
  358. SMLNUM = SAFMIN*( REAL( N ) / ULP )
  359. *
  360. * ==== Use accumulated reflections to update far-from-diagonal
  361. * . entries ? ====
  362. *
  363. ACCUM = ( KACC22.EQ.1 ) .OR. ( KACC22.EQ.2 )
  364. *
  365. * ==== clear trash ====
  366. *
  367. IF( KTOP+2.LE.KBOT )
  368. $ H( KTOP+2, KTOP ) = ZERO
  369. *
  370. * ==== NBMPS = number of 2-shift bulges in the chain ====
  371. *
  372. NBMPS = NS / 2
  373. *
  374. * ==== KDU = width of slab ====
  375. *
  376. KDU = 4*NBMPS
  377. *
  378. * ==== Create and chase chains of NBMPS bulges ====
  379. *
  380. DO 180 INCOL = KTOP - 2*NBMPS + 1, KBOT - 2, 2*NBMPS
  381. *
  382. * JTOP = Index from which updates from the right start.
  383. *
  384. IF( ACCUM ) THEN
  385. JTOP = MAX( KTOP, INCOL )
  386. ELSE IF( WANTT ) THEN
  387. JTOP = 1
  388. ELSE
  389. JTOP = KTOP
  390. END IF
  391. *
  392. NDCOL = INCOL + KDU
  393. IF( ACCUM )
  394. $ CALL SLASET( 'ALL', KDU, KDU, ZERO, ONE, U, LDU )
  395. *
  396. * ==== Near-the-diagonal bulge chase. The following loop
  397. * . performs the near-the-diagonal part of a small bulge
  398. * . multi-shift QR sweep. Each 4*NBMPS column diagonal
  399. * . chunk extends from column INCOL to column NDCOL
  400. * . (including both column INCOL and column NDCOL). The
  401. * . following loop chases a 2*NBMPS+1 column long chain of
  402. * . NBMPS bulges 2*NBMPS-1 columns to the right. (INCOL
  403. * . may be less than KTOP and and NDCOL may be greater than
  404. * . KBOT indicating phantom columns from which to chase
  405. * . bulges before they are actually introduced or to which
  406. * . to chase bulges beyond column KBOT.) ====
  407. *
  408. DO 145 KRCOL = INCOL, MIN( INCOL+2*NBMPS-1, KBOT-2 )
  409. *
  410. * ==== Bulges number MTOP to MBOT are active double implicit
  411. * . shift bulges. There may or may not also be small
  412. * . 2-by-2 bulge, if there is room. The inactive bulges
  413. * . (if any) must wait until the active bulges have moved
  414. * . down the diagonal to make room. The phantom matrix
  415. * . paradigm described above helps keep track. ====
  416. *
  417. MTOP = MAX( 1, ( KTOP-KRCOL ) / 2+1 )
  418. MBOT = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 2 )
  419. M22 = MBOT + 1
  420. BMP22 = ( MBOT.LT.NBMPS ) .AND. ( KRCOL+2*( M22-1 ) ).EQ.
  421. $ ( KBOT-2 )
  422. *
  423. * ==== Generate reflections to chase the chain right
  424. * . one column. (The minimum value of K is KTOP-1.) ====
  425. *
  426. IF ( BMP22 ) THEN
  427. *
  428. * ==== Special case: 2-by-2 reflection at bottom treated
  429. * . separately ====
  430. *
  431. K = KRCOL + 2*( M22-1 )
  432. IF( K.EQ.KTOP-1 ) THEN
  433. CALL SLAQR1( 2, H( K+1, K+1 ), LDH, SR( 2*M22-1 ),
  434. $ SI( 2*M22-1 ), SR( 2*M22 ), SI( 2*M22 ),
  435. $ V( 1, M22 ) )
  436. BETA = V( 1, M22 )
  437. CALL SLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
  438. ELSE
  439. BETA = H( K+1, K )
  440. V( 2, M22 ) = H( K+2, K )
  441. CALL SLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
  442. H( K+1, K ) = BETA
  443. H( K+2, K ) = ZERO
  444. END IF
  445. *
  446. * ==== Perform update from right within
  447. * . computational window. ====
  448. *
  449. T1 = V( 1, M22 )
  450. T2 = T1*V( 2, M22 )
  451. DO 30 J = JTOP, MIN( KBOT, K+3 )
  452. REFSUM = H( J, K+1 ) + V( 2, M22 )*H( J, K+2 )
  453. H( J, K+1 ) = H( J, K+1 ) - REFSUM*T1
  454. H( J, K+2 ) = H( J, K+2 ) - REFSUM*T2
  455. 30 CONTINUE
  456. *
  457. * ==== Perform update from left within
  458. * . computational window. ====
  459. *
  460. IF( ACCUM ) THEN
  461. JBOT = MIN( NDCOL, KBOT )
  462. ELSE IF( WANTT ) THEN
  463. JBOT = N
  464. ELSE
  465. JBOT = KBOT
  466. END IF
  467. T1 = V( 1, M22 )
  468. T2 = T1*V( 2, M22 )
  469. DO 40 J = K+1, JBOT
  470. REFSUM = H( K+1, J ) + V( 2, M22 )*H( K+2, J )
  471. H( K+1, J ) = H( K+1, J ) - REFSUM*T1
  472. H( K+2, J ) = H( K+2, J ) - REFSUM*T2
  473. 40 CONTINUE
  474. *
  475. * ==== The following convergence test requires that
  476. * . the tradition small-compared-to-nearby-diagonals
  477. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  478. * . criteria both be satisfied. The latter improves
  479. * . accuracy in some examples. Falling back on an
  480. * . alternate convergence criterion when TST1 or TST2
  481. * . is zero (as done here) is traditional but probably
  482. * . unnecessary. ====
  483. *
  484. IF( K.GE.KTOP ) THEN
  485. IF( H( K+1, K ).NE.ZERO ) THEN
  486. TST1 = ABS( H( K, K ) ) + ABS( H( K+1, K+1 ) )
  487. IF( TST1.EQ.ZERO ) THEN
  488. IF( K.GE.KTOP+1 )
  489. $ TST1 = TST1 + ABS( H( K, K-1 ) )
  490. IF( K.GE.KTOP+2 )
  491. $ TST1 = TST1 + ABS( H( K, K-2 ) )
  492. IF( K.GE.KTOP+3 )
  493. $ TST1 = TST1 + ABS( H( K, K-3 ) )
  494. IF( K.LE.KBOT-2 )
  495. $ TST1 = TST1 + ABS( H( K+2, K+1 ) )
  496. IF( K.LE.KBOT-3 )
  497. $ TST1 = TST1 + ABS( H( K+3, K+1 ) )
  498. IF( K.LE.KBOT-4 )
  499. $ TST1 = TST1 + ABS( H( K+4, K+1 ) )
  500. END IF
  501. IF( ABS( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
  502. $ THEN
  503. H12 = MAX( ABS( H( K+1, K ) ),
  504. $ ABS( H( K, K+1 ) ) )
  505. H21 = MIN( ABS( H( K+1, K ) ),
  506. $ ABS( H( K, K+1 ) ) )
  507. H11 = MAX( ABS( H( K+1, K+1 ) ),
  508. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  509. H22 = MIN( ABS( H( K+1, K+1 ) ),
  510. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  511. SCL = H11 + H12
  512. TST2 = H22*( H11 / SCL )
  513. *
  514. IF( TST2.EQ.ZERO .OR. H21*( H12 / SCL ).LE.
  515. $ MAX( SMLNUM, ULP*TST2 ) ) THEN
  516. H( K+1, K ) = ZERO
  517. END IF
  518. END IF
  519. END IF
  520. END IF
  521. *
  522. * ==== Accumulate orthogonal transformations. ====
  523. *
  524. IF( ACCUM ) THEN
  525. KMS = K - INCOL
  526. T1 = V( 1, M22 )
  527. T2 = T1*V( 2, M22 )
  528. DO 50 J = MAX( 1, KTOP-INCOL ), KDU
  529. REFSUM = U( J, KMS+1 ) + V( 2, M22 )*U( J, KMS+2 )
  530. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM*T1
  531. U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*T2
  532. 50 CONTINUE
  533. ELSE IF( WANTZ ) THEN
  534. T1 = V( 1, M22 )
  535. T2 = T1*V( 2, M22 )
  536. DO 60 J = ILOZ, IHIZ
  537. REFSUM = Z( J, K+1 )+V( 2, M22 )*Z( J, K+2 )
  538. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM*T1
  539. Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*T2
  540. 60 CONTINUE
  541. END IF
  542. END IF
  543. *
  544. * ==== Normal case: Chain of 3-by-3 reflections ====
  545. *
  546. DO 80 M = MBOT, MTOP, -1
  547. K = KRCOL + 2*( M-1 )
  548. IF( K.EQ.KTOP-1 ) THEN
  549. CALL SLAQR1( 3, H( KTOP, KTOP ), LDH, SR( 2*M-1 ),
  550. $ SI( 2*M-1 ), SR( 2*M ), SI( 2*M ),
  551. $ V( 1, M ) )
  552. ALPHA = V( 1, M )
  553. CALL SLARFG( 3, ALPHA, V( 2, M ), 1, V( 1, M ) )
  554. ELSE
  555. *
  556. * ==== Perform delayed transformation of row below
  557. * . Mth bulge. Exploit fact that first two elements
  558. * . of row are actually zero. ====
  559. *
  560. T1 = V( 1, M )
  561. T2 = T1*V( 2, M )
  562. T3 = T1*V( 3, M )
  563. REFSUM = V( 3, M )*H( K+3, K+2 )
  564. H( K+3, K ) = -REFSUM*T1
  565. H( K+3, K+1 ) = -REFSUM*T2
  566. H( K+3, K+2 ) = H( K+3, K+2 ) - REFSUM*T3
  567. *
  568. * ==== Calculate reflection to move
  569. * . Mth bulge one step. ====
  570. *
  571. BETA = H( K+1, K )
  572. V( 2, M ) = H( K+2, K )
  573. V( 3, M ) = H( K+3, K )
  574. CALL SLARFG( 3, BETA, V( 2, M ), 1, V( 1, M ) )
  575. *
  576. * ==== A Bulge may collapse because of vigilant
  577. * . deflation or destructive underflow. In the
  578. * . underflow case, try the two-small-subdiagonals
  579. * . trick to try to reinflate the bulge. ====
  580. *
  581. IF( H( K+3, K ).NE.ZERO .OR. H( K+3, K+1 ).NE.
  582. $ ZERO .OR. H( K+3, K+2 ).EQ.ZERO ) THEN
  583. *
  584. * ==== Typical case: not collapsed (yet). ====
  585. *
  586. H( K+1, K ) = BETA
  587. H( K+2, K ) = ZERO
  588. H( K+3, K ) = ZERO
  589. ELSE
  590. *
  591. * ==== Atypical case: collapsed. Attempt to
  592. * . reintroduce ignoring H(K+1,K) and H(K+2,K).
  593. * . If the fill resulting from the new
  594. * . reflector is too large, then abandon it.
  595. * . Otherwise, use the new one. ====
  596. *
  597. CALL SLAQR1( 3, H( K+1, K+1 ), LDH, SR( 2*M-1 ),
  598. $ SI( 2*M-1 ), SR( 2*M ), SI( 2*M ),
  599. $ VT )
  600. ALPHA = VT( 1 )
  601. CALL SLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
  602. T1 = VT( 1 )
  603. T2 = T1*VT( 2 )
  604. T3 = T2*VT( 3 )
  605. REFSUM = H( K+1, K )+VT( 2 )*H( K+2, K )
  606. *
  607. IF( ABS( H( K+2, K )-REFSUM*T2 )+
  608. $ ABS( REFSUM*T3 ).GT.ULP*
  609. $ ( ABS( H( K, K ) )+ABS( H( K+1,
  610. $ K+1 ) )+ABS( H( K+2, K+2 ) ) ) ) THEN
  611. *
  612. * ==== Starting a new bulge here would
  613. * . create non-negligible fill. Use
  614. * . the old one with trepidation. ====
  615. *
  616. H( K+1, K ) = BETA
  617. H( K+2, K ) = ZERO
  618. H( K+3, K ) = ZERO
  619. ELSE
  620. *
  621. * ==== Starting a new bulge here would
  622. * . create only negligible fill.
  623. * . Replace the old reflector with
  624. * . the new one. ====
  625. *
  626. H( K+1, K ) = H( K+1, K ) - REFSUM*T1
  627. H( K+2, K ) = ZERO
  628. H( K+3, K ) = ZERO
  629. V( 1, M ) = VT( 1 )
  630. V( 2, M ) = VT( 2 )
  631. V( 3, M ) = VT( 3 )
  632. END IF
  633. END IF
  634. END IF
  635. *
  636. * ==== Apply reflection from the right and
  637. * . the first column of update from the left.
  638. * . These updates are required for the vigilant
  639. * . deflation check. We still delay most of the
  640. * . updates from the left for efficiency. ====
  641. *
  642. T1 = V( 1, M )
  643. T2 = T1*V( 2, M )
  644. T3 = T1*V( 3, M )
  645. DO 70 J = JTOP, MIN( KBOT, K+3 )
  646. REFSUM = H( J, K+1 ) + V( 2, M )*H( J, K+2 )
  647. $ + V( 3, M )*H( J, K+3 )
  648. H( J, K+1 ) = H( J, K+1 ) - REFSUM*T1
  649. H( J, K+2 ) = H( J, K+2 ) - REFSUM*T2
  650. H( J, K+3 ) = H( J, K+3 ) - REFSUM*T3
  651. 70 CONTINUE
  652. *
  653. * ==== Perform update from left for subsequent
  654. * . column. ====
  655. *
  656. REFSUM = H( K+1, K+1 ) + V( 2, M )*H( K+2, K+1 )
  657. $ + V( 3, M )*H( K+3, K+1 )
  658. H( K+1, K+1 ) = H( K+1, K+1 ) - REFSUM*T1
  659. H( K+2, K+1 ) = H( K+2, K+1 ) - REFSUM*T2
  660. H( K+3, K+1 ) = H( K+3, K+1 ) - REFSUM*T3
  661. *
  662. * ==== The following convergence test requires that
  663. * . the tradition small-compared-to-nearby-diagonals
  664. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  665. * . criteria both be satisfied. The latter improves
  666. * . accuracy in some examples. Falling back on an
  667. * . alternate convergence criterion when TST1 or TST2
  668. * . is zero (as done here) is traditional but probably
  669. * . unnecessary. ====
  670. *
  671. IF( K.LT.KTOP)
  672. $ CYCLE
  673. IF( H( K+1, K ).NE.ZERO ) THEN
  674. TST1 = ABS( H( K, K ) ) + ABS( H( K+1, K+1 ) )
  675. IF( TST1.EQ.ZERO ) THEN
  676. IF( K.GE.KTOP+1 )
  677. $ TST1 = TST1 + ABS( H( K, K-1 ) )
  678. IF( K.GE.KTOP+2 )
  679. $ TST1 = TST1 + ABS( H( K, K-2 ) )
  680. IF( K.GE.KTOP+3 )
  681. $ TST1 = TST1 + ABS( H( K, K-3 ) )
  682. IF( K.LE.KBOT-2 )
  683. $ TST1 = TST1 + ABS( H( K+2, K+1 ) )
  684. IF( K.LE.KBOT-3 )
  685. $ TST1 = TST1 + ABS( H( K+3, K+1 ) )
  686. IF( K.LE.KBOT-4 )
  687. $ TST1 = TST1 + ABS( H( K+4, K+1 ) )
  688. END IF
  689. IF( ABS( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
  690. $ THEN
  691. H12 = MAX( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
  692. H21 = MIN( ABS( H( K+1, K ) ), ABS( H( K, K+1 ) ) )
  693. H11 = MAX( ABS( H( K+1, K+1 ) ),
  694. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  695. H22 = MIN( ABS( H( K+1, K+1 ) ),
  696. $ ABS( H( K, K )-H( K+1, K+1 ) ) )
  697. SCL = H11 + H12
  698. TST2 = H22*( H11 / SCL )
  699. *
  700. IF( TST2.EQ.ZERO .OR. H21*( H12 / SCL ).LE.
  701. $ MAX( SMLNUM, ULP*TST2 ) ) THEN
  702. H( K+1, K ) = ZERO
  703. END IF
  704. END IF
  705. END IF
  706. 80 CONTINUE
  707. *
  708. * ==== Multiply H by reflections from the left ====
  709. *
  710. IF( ACCUM ) THEN
  711. JBOT = MIN( NDCOL, KBOT )
  712. ELSE IF( WANTT ) THEN
  713. JBOT = N
  714. ELSE
  715. JBOT = KBOT
  716. END IF
  717. *
  718. DO 100 M = MBOT, MTOP, -1
  719. K = KRCOL + 2*( M-1 )
  720. T1 = V( 1, M )
  721. T2 = T1*V( 2, M )
  722. T3 = T1*V( 3, M )
  723. DO 90 J = MAX( KTOP, KRCOL + 2*M ), JBOT
  724. REFSUM = H( K+1, J ) + V( 2, M )*H( K+2, J )
  725. $ + V( 3, M )*H( K+3, J )
  726. H( K+1, J ) = H( K+1, J ) - REFSUM*T1
  727. H( K+2, J ) = H( K+2, J ) - REFSUM*T2
  728. H( K+3, J ) = H( K+3, J ) - REFSUM*T3
  729. 90 CONTINUE
  730. 100 CONTINUE
  731. *
  732. * ==== Accumulate orthogonal transformations. ====
  733. *
  734. IF( ACCUM ) THEN
  735. *
  736. * ==== Accumulate U. (If needed, update Z later
  737. * . with an efficient matrix-matrix
  738. * . multiply.) ====
  739. *
  740. DO 120 M = MBOT, MTOP, -1
  741. K = KRCOL + 2*( M-1 )
  742. KMS = K - INCOL
  743. I2 = MAX( 1, KTOP-INCOL )
  744. I2 = MAX( I2, KMS-(KRCOL-INCOL)+1 )
  745. I4 = MIN( KDU, KRCOL + 2*( MBOT-1 ) - INCOL + 5 )
  746. T1 = V( 1, M )
  747. T2 = T1*V( 2, M )
  748. T3 = T1*V( 3, M )
  749. DO 110 J = I2, I4
  750. REFSUM = U( J, KMS+1 ) + V( 2, M )*U( J, KMS+2 )
  751. $ + V( 3, M )*U( J, KMS+3 )
  752. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM*T1
  753. U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*T2
  754. U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*T3
  755. 110 CONTINUE
  756. 120 CONTINUE
  757. ELSE IF( WANTZ ) THEN
  758. *
  759. * ==== U is not accumulated, so update Z
  760. * . now by multiplying by reflections
  761. * . from the right. ====
  762. *
  763. DO 140 M = MBOT, MTOP, -1
  764. K = KRCOL + 2*( M-1 )
  765. T1 = V( 1, M )
  766. T2 = T1*V( 2, M )
  767. T3 = T1*V( 3, M )
  768. DO 130 J = ILOZ, IHIZ
  769. REFSUM = Z( J, K+1 ) + V( 2, M )*Z( J, K+2 )
  770. $ + V( 3, M )*Z( J, K+3 )
  771. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM*T1
  772. Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*T2
  773. Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*T3
  774. 130 CONTINUE
  775. 140 CONTINUE
  776. END IF
  777. *
  778. * ==== End of near-the-diagonal bulge chase. ====
  779. *
  780. 145 CONTINUE
  781. *
  782. * ==== Use U (if accumulated) to update far-from-diagonal
  783. * . entries in H. If required, use U to update Z as
  784. * . well. ====
  785. *
  786. IF( ACCUM ) THEN
  787. IF( WANTT ) THEN
  788. JTOP = 1
  789. JBOT = N
  790. ELSE
  791. JTOP = KTOP
  792. JBOT = KBOT
  793. END IF
  794. K1 = MAX( 1, KTOP-INCOL )
  795. NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
  796. *
  797. * ==== Horizontal Multiply ====
  798. *
  799. DO 150 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
  800. JLEN = MIN( NH, JBOT-JCOL+1 )
  801. CALL SGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
  802. $ LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH,
  803. $ LDWH )
  804. CALL SLACPY( 'ALL', NU, JLEN, WH, LDWH,
  805. $ H( INCOL+K1, JCOL ), LDH )
  806. 150 CONTINUE
  807. *
  808. * ==== Vertical multiply ====
  809. *
  810. DO 160 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
  811. JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
  812. CALL SGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  813. $ H( JROW, INCOL+K1 ), LDH, U( K1, K1 ),
  814. $ LDU, ZERO, WV, LDWV )
  815. CALL SLACPY( 'ALL', JLEN, NU, WV, LDWV,
  816. $ H( JROW, INCOL+K1 ), LDH )
  817. 160 CONTINUE
  818. *
  819. * ==== Z multiply (also vertical) ====
  820. *
  821. IF( WANTZ ) THEN
  822. DO 170 JROW = ILOZ, IHIZ, NV
  823. JLEN = MIN( NV, IHIZ-JROW+1 )
  824. CALL SGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  825. $ Z( JROW, INCOL+K1 ), LDZ, U( K1, K1 ),
  826. $ LDU, ZERO, WV, LDWV )
  827. CALL SLACPY( 'ALL', JLEN, NU, WV, LDWV,
  828. $ Z( JROW, INCOL+K1 ), LDZ )
  829. 170 CONTINUE
  830. END IF
  831. END IF
  832. 180 CONTINUE
  833. *
  834. * ==== End of SLAQR5 ====
  835. *
  836. END