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.

claqr5.f 30 kB

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