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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  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, T1, T2, T3
  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. T1 = V( 1, M22 )
  427. T2 = T1*CONJG( V( 2, M22 ) )
  428. DO 30 J = JTOP, MIN( KBOT, K+3 )
  429. REFSUM = H( J, K+1 ) + V( 2, M22 )*H( J, K+2 )
  430. H( J, K+1 ) = H( J, K+1 ) - REFSUM*T1
  431. H( J, K+2 ) = H( J, K+2 ) - REFSUM*T2
  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. T1 = CONJG( V( 1, M22 ) )
  445. T2 = T1*V( 2, M22 )
  446. DO 40 J = K+1, JBOT
  447. REFSUM = H( K+1, J ) +
  448. $ CONJG( V( 2, M22 ) )*H( K+2, J )
  449. H( K+1, J ) = H( K+1, J ) - REFSUM*T1
  450. H( K+2, J ) = H( K+2, J ) - REFSUM*T2
  451. 40 CONTINUE
  452. *
  453. * ==== The following convergence test requires that
  454. * . the tradition small-compared-to-nearby-diagonals
  455. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  456. * . criteria both be satisfied. The latter improves
  457. * . accuracy in some examples. Falling back on an
  458. * . alternate convergence criterion when TST1 or TST2
  459. * . is zero (as done here) is traditional but probably
  460. * . unnecessary. ====
  461. *
  462. IF( K.GE.KTOP) THEN
  463. IF( H( K+1, K ).NE.ZERO ) THEN
  464. TST1 = CABS1( H( K, K ) ) + CABS1( H( K+1, K+1 ) )
  465. IF( TST1.EQ.RZERO ) THEN
  466. IF( K.GE.KTOP+1 )
  467. $ TST1 = TST1 + CABS1( H( K, K-1 ) )
  468. IF( K.GE.KTOP+2 )
  469. $ TST1 = TST1 + CABS1( H( K, K-2 ) )
  470. IF( K.GE.KTOP+3 )
  471. $ TST1 = TST1 + CABS1( H( K, K-3 ) )
  472. IF( K.LE.KBOT-2 )
  473. $ TST1 = TST1 + CABS1( H( K+2, K+1 ) )
  474. IF( K.LE.KBOT-3 )
  475. $ TST1 = TST1 + CABS1( H( K+3, K+1 ) )
  476. IF( K.LE.KBOT-4 )
  477. $ TST1 = TST1 + CABS1( H( K+4, K+1 ) )
  478. END IF
  479. IF( CABS1( H( K+1, K ) )
  480. $ .LE.MAX( SMLNUM, ULP*TST1 ) ) THEN
  481. H12 = MAX( CABS1( H( K+1, K ) ),
  482. $ CABS1( H( K, K+1 ) ) )
  483. H21 = MIN( CABS1( H( K+1, K ) ),
  484. $ CABS1( H( K, K+1 ) ) )
  485. H11 = MAX( CABS1( H( K+1, K+1 ) ),
  486. $ CABS1( H( K, K )-H( K+1, K+1 ) ) )
  487. H22 = MIN( CABS1( H( K+1, K+1 ) ),
  488. $ CABS1( H( K, K )-H( K+1, K+1 ) ) )
  489. SCL = H11 + H12
  490. TST2 = H22*( H11 / SCL )
  491. *
  492. IF( TST2.EQ.RZERO .OR. H21*( H12 / SCL ).LE.
  493. $ MAX( SMLNUM, ULP*TST2 ) )H( K+1, K ) = ZERO
  494. END IF
  495. END IF
  496. END IF
  497. *
  498. * ==== Accumulate orthogonal transformations. ====
  499. *
  500. IF( ACCUM ) THEN
  501. KMS = K - INCOL
  502. DO 50 J = MAX( 1, KTOP-INCOL ), KDU
  503. REFSUM = V( 1, M22 )*( U( J, KMS+1 )+
  504. $ V( 2, M22 )*U( J, KMS+2 ) )
  505. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
  506. U( J, KMS+2 ) = U( J, KMS+2 ) -
  507. $ REFSUM*CONJG( V( 2, M22 ) )
  508. 50 CONTINUE
  509. ELSE IF( WANTZ ) THEN
  510. DO 60 J = ILOZ, IHIZ
  511. REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )*
  512. $ Z( J, K+2 ) )
  513. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
  514. Z( J, K+2 ) = Z( J, K+2 ) -
  515. $ REFSUM*CONJG( V( 2, M22 ) )
  516. 60 CONTINUE
  517. END IF
  518. END IF
  519. *
  520. * ==== Normal case: Chain of 3-by-3 reflections ====
  521. *
  522. DO 80 M = MBOT, MTOP, -1
  523. K = KRCOL + 2*( M-1 )
  524. IF( K.EQ.KTOP-1 ) THEN
  525. CALL CLAQR1( 3, H( KTOP, KTOP ), LDH, S( 2*M-1 ),
  526. $ S( 2*M ), V( 1, M ) )
  527. ALPHA = V( 1, M )
  528. CALL CLARFG( 3, ALPHA, V( 2, M ), 1, V( 1, M ) )
  529. ELSE
  530. *
  531. * ==== Perform delayed transformation of row below
  532. * . Mth bulge. Exploit fact that first two elements
  533. * . of row are actually zero. ====
  534. *
  535. T1 = V( 1, M )
  536. T2 = T1*CONJG( V( 2, M ) )
  537. T3 = T1*CONJG( V( 3, M ) )
  538. REFSUM = V( 3, M )*H( K+3, K+2 )
  539. H( K+3, K ) = -REFSUM*T1
  540. H( K+3, K+1 ) = -REFSUM*T2
  541. H( K+3, K+2 ) = H( K+3, K+2 ) - REFSUM*T3
  542. *
  543. * ==== Calculate reflection to move
  544. * . Mth bulge one step. ====
  545. *
  546. BETA = H( K+1, K )
  547. V( 2, M ) = H( K+2, K )
  548. V( 3, M ) = H( K+3, K )
  549. CALL CLARFG( 3, BETA, V( 2, M ), 1, V( 1, M ) )
  550. *
  551. * ==== A Bulge may collapse because of vigilant
  552. * . deflation or destructive underflow. In the
  553. * . underflow case, try the two-small-subdiagonals
  554. * . trick to try to reinflate the bulge. ====
  555. *
  556. IF( H( K+3, K ).NE.ZERO .OR. H( K+3, K+1 ).NE.
  557. $ ZERO .OR. H( K+3, K+2 ).EQ.ZERO ) THEN
  558. *
  559. * ==== Typical case: not collapsed (yet). ====
  560. *
  561. H( K+1, K ) = BETA
  562. H( K+2, K ) = ZERO
  563. H( K+3, K ) = ZERO
  564. ELSE
  565. *
  566. * ==== Atypical case: collapsed. Attempt to
  567. * . reintroduce ignoring H(K+1,K) and H(K+2,K).
  568. * . If the fill resulting from the new
  569. * . reflector is too large, then abandon it.
  570. * . Otherwise, use the new one. ====
  571. *
  572. CALL CLAQR1( 3, H( K+1, K+1 ), LDH, S( 2*M-1 ),
  573. $ S( 2*M ), VT )
  574. ALPHA = VT( 1 )
  575. CALL CLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
  576. T1 = CONJG( VT( 1 ) )
  577. T2 = T1*VT( 2 )
  578. T3 = T1*VT( 3 )
  579. REFSUM = H( K+1, K )+CONJG( VT( 2 ) )*H( K+2, K )
  580. *
  581. IF( CABS1( H( K+2, K )-REFSUM*T2 )+
  582. $ CABS1( REFSUM*T3 ).GT.ULP*
  583. $ ( CABS1( H( K, K ) )+CABS1( H( K+1,
  584. $ K+1 ) )+CABS1( H( K+2, K+2 ) ) ) ) THEN
  585. *
  586. * ==== Starting a new bulge here would
  587. * . create non-negligible fill. Use
  588. * . the old one with trepidation. ====
  589. *
  590. H( K+1, K ) = BETA
  591. H( K+2, K ) = ZERO
  592. H( K+3, K ) = ZERO
  593. ELSE
  594. *
  595. * ==== Starting a new bulge here would
  596. * . create only negligible fill.
  597. * . Replace the old reflector with
  598. * . the new one. ====
  599. *
  600. H( K+1, K ) = H( K+1, K ) - REFSUM*T1
  601. H( K+2, K ) = ZERO
  602. H( K+3, K ) = ZERO
  603. V( 1, M ) = VT( 1 )
  604. V( 2, M ) = VT( 2 )
  605. V( 3, M ) = VT( 3 )
  606. END IF
  607. END IF
  608. END IF
  609. *
  610. * ==== Apply reflection from the right and
  611. * . the first column of update from the left.
  612. * . These updates are required for the vigilant
  613. * . deflation check. We still delay most of the
  614. * . updates from the left for efficiency. ====
  615. *
  616. T1 = V( 1, M )
  617. T2 = T1*CONJG( V( 2, M ) )
  618. T3 = T1*CONJG( V( 3, M ) )
  619. DO 70 J = JTOP, MIN( KBOT, K+3 )
  620. REFSUM = H( J, K+1 ) + V( 2, M )*H( J, K+2 )
  621. $ + V( 3, M )*H( J, K+3 )
  622. H( J, K+1 ) = H( J, K+1 ) - REFSUM*T1
  623. H( J, K+2 ) = H( J, K+2 ) - REFSUM*T2
  624. H( J, K+3 ) = H( J, K+3 ) - REFSUM*T3
  625. 70 CONTINUE
  626. *
  627. * ==== Perform update from left for subsequent
  628. * . column. ====
  629. *
  630. T1 = CONJG( V( 1, M ) )
  631. T2 = T1*V( 2, M )
  632. T3 = T1*V( 3, M )
  633. REFSUM = H( K+1, K+1 ) + CONJG( V( 2, M ) )*H( K+2, K+1 )
  634. $ + CONJG( V( 3, M ) )*H( K+3, K+1 )
  635. H( K+1, K+1 ) = H( K+1, K+1 ) - REFSUM*T1
  636. H( K+2, K+1 ) = H( K+2, K+1 ) - REFSUM*T2
  637. H( K+3, K+1 ) = H( K+3, K+1 ) - REFSUM*T3
  638. *
  639. * ==== The following convergence test requires that
  640. * . the tradition small-compared-to-nearby-diagonals
  641. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  642. * . criteria both be satisfied. The latter improves
  643. * . accuracy in some examples. Falling back on an
  644. * . alternate convergence criterion when TST1 or TST2
  645. * . is zero (as done here) is traditional but probably
  646. * . unnecessary. ====
  647. *
  648. IF( K.LT.KTOP)
  649. $ CYCLE
  650. IF( H( K+1, K ).NE.ZERO ) THEN
  651. TST1 = CABS1( H( K, K ) ) + CABS1( H( K+1, K+1 ) )
  652. IF( TST1.EQ.RZERO ) THEN
  653. IF( K.GE.KTOP+1 )
  654. $ TST1 = TST1 + CABS1( H( K, K-1 ) )
  655. IF( K.GE.KTOP+2 )
  656. $ TST1 = TST1 + CABS1( H( K, K-2 ) )
  657. IF( K.GE.KTOP+3 )
  658. $ TST1 = TST1 + CABS1( H( K, K-3 ) )
  659. IF( K.LE.KBOT-2 )
  660. $ TST1 = TST1 + CABS1( H( K+2, K+1 ) )
  661. IF( K.LE.KBOT-3 )
  662. $ TST1 = TST1 + CABS1( H( K+3, K+1 ) )
  663. IF( K.LE.KBOT-4 )
  664. $ TST1 = TST1 + CABS1( H( K+4, K+1 ) )
  665. END IF
  666. IF( CABS1( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
  667. $ THEN
  668. H12 = MAX( CABS1( H( K+1, K ) ),
  669. $ CABS1( H( K, K+1 ) ) )
  670. H21 = MIN( CABS1( H( K+1, K ) ),
  671. $ CABS1( H( K, K+1 ) ) )
  672. H11 = MAX( CABS1( H( K+1, K+1 ) ),
  673. $ CABS1( H( K, K )-H( K+1, K+1 ) ) )
  674. H22 = MIN( CABS1( H( K+1, K+1 ) ),
  675. $ CABS1( H( K, K )-H( K+1, K+1 ) ) )
  676. SCL = H11 + H12
  677. TST2 = H22*( H11 / SCL )
  678. *
  679. IF( TST2.EQ.RZERO .OR. H21*( H12 / SCL ).LE.
  680. $ MAX( SMLNUM, ULP*TST2 ) )H( K+1, K ) = ZERO
  681. END IF
  682. END IF
  683. 80 CONTINUE
  684. *
  685. * ==== Multiply H by reflections from the left ====
  686. *
  687. IF( ACCUM ) THEN
  688. JBOT = MIN( NDCOL, KBOT )
  689. ELSE IF( WANTT ) THEN
  690. JBOT = N
  691. ELSE
  692. JBOT = KBOT
  693. END IF
  694. *
  695. DO 100 M = MBOT, MTOP, -1
  696. K = KRCOL + 2*( M-1 )
  697. T1 = CONJG( V( 1, M ) )
  698. T2 = T1*V( 2, M )
  699. T3 = T1*V( 3, M )
  700. DO 90 J = MAX( KTOP, KRCOL + 2*M ), JBOT
  701. REFSUM = H( K+1, J ) + CONJG( V( 2, M ) )*
  702. $ H( K+2, J ) + CONJG( V( 3, M ) )*H( K+3, J )
  703. H( K+1, J ) = H( K+1, J ) - REFSUM*T1
  704. H( K+2, J ) = H( K+2, J ) - REFSUM*T2
  705. H( K+3, J ) = H( K+3, J ) - REFSUM*T3
  706. 90 CONTINUE
  707. 100 CONTINUE
  708. *
  709. * ==== Accumulate orthogonal transformations. ====
  710. *
  711. IF( ACCUM ) THEN
  712. *
  713. * ==== Accumulate U. (If needed, update Z later
  714. * . with an efficient matrix-matrix
  715. * . multiply.) ====
  716. *
  717. DO 120 M = MBOT, MTOP, -1
  718. K = KRCOL + 2*( M-1 )
  719. KMS = K - INCOL
  720. I2 = MAX( 1, KTOP-INCOL )
  721. I2 = MAX( I2, KMS-(KRCOL-INCOL)+1 )
  722. I4 = MIN( KDU, KRCOL + 2*( MBOT-1 ) - INCOL + 5 )
  723. T1 = V( 1, M )
  724. T2 = T1*CONJG( V( 2, M ) )
  725. T3 = T1*CONJG( V( 3, M ) )
  726. DO 110 J = I2, I4
  727. REFSUM = U( J, KMS+1 ) + V( 2, M )*U( J, KMS+2 )
  728. $ + V( 3, M )*U( J, KMS+3 )
  729. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM*T1
  730. U( J, KMS+2 ) = U( J, KMS+2 ) - REFSUM*T2
  731. U( J, KMS+3 ) = U( J, KMS+3 ) - REFSUM*T3
  732. 110 CONTINUE
  733. 120 CONTINUE
  734. ELSE IF( WANTZ ) THEN
  735. *
  736. * ==== U is not accumulated, so update Z
  737. * . now by multiplying by reflections
  738. * . from the right. ====
  739. *
  740. DO 140 M = MBOT, MTOP, -1
  741. K = KRCOL + 2*( M-1 )
  742. T1 = V( 1, M )
  743. T2 = T1*CONJG( V( 2, M ) )
  744. T3 = T1*CONJG( V( 3, M ) )
  745. DO 130 J = ILOZ, IHIZ
  746. REFSUM = Z( J, K+1 ) + V( 2, M )*Z( J, K+2 )
  747. $ + V( 3, M )*Z( J, K+3 )
  748. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM*T1
  749. Z( J, K+2 ) = Z( J, K+2 ) - REFSUM*T2
  750. Z( J, K+3 ) = Z( J, K+3 ) - REFSUM*T3
  751. 130 CONTINUE
  752. 140 CONTINUE
  753. END IF
  754. *
  755. * ==== End of near-the-diagonal bulge chase. ====
  756. *
  757. 145 CONTINUE
  758. *
  759. * ==== Use U (if accumulated) to update far-from-diagonal
  760. * . entries in H. If required, use U to update Z as
  761. * . well. ====
  762. *
  763. IF( ACCUM ) THEN
  764. IF( WANTT ) THEN
  765. JTOP = 1
  766. JBOT = N
  767. ELSE
  768. JTOP = KTOP
  769. JBOT = KBOT
  770. END IF
  771. K1 = MAX( 1, KTOP-INCOL )
  772. NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
  773. *
  774. * ==== Horizontal Multiply ====
  775. *
  776. DO 150 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
  777. JLEN = MIN( NH, JBOT-JCOL+1 )
  778. CALL CGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
  779. $ LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH,
  780. $ LDWH )
  781. CALL CLACPY( 'ALL', NU, JLEN, WH, LDWH,
  782. $ H( INCOL+K1, JCOL ), LDH )
  783. 150 CONTINUE
  784. *
  785. * ==== Vertical multiply ====
  786. *
  787. DO 160 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
  788. JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
  789. CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  790. $ H( JROW, INCOL+K1 ), LDH, U( K1, K1 ),
  791. $ LDU, ZERO, WV, LDWV )
  792. CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV,
  793. $ H( JROW, INCOL+K1 ), LDH )
  794. 160 CONTINUE
  795. *
  796. * ==== Z multiply (also vertical) ====
  797. *
  798. IF( WANTZ ) THEN
  799. DO 170 JROW = ILOZ, IHIZ, NV
  800. JLEN = MIN( NV, IHIZ-JROW+1 )
  801. CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  802. $ Z( JROW, INCOL+K1 ), LDZ, U( K1, K1 ),
  803. $ LDU, ZERO, WV, LDWV )
  804. CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV,
  805. $ Z( JROW, INCOL+K1 ), LDZ )
  806. 170 CONTINUE
  807. END IF
  808. END IF
  809. 180 CONTINUE
  810. *
  811. * ==== End of CLAQR5 ====
  812. *
  813. END