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

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