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 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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: CLAQR5 accumulates reflections, uses matrix-matrix
  73. *> multiply to update the far-from-diagonal matrix entries,
  74. *> and takes advantage of 2-by-2 block structure during
  75. *> matrix multiplies.
  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] S
  109. *> \verbatim
  110. *> S is COMPLEX array, dimension (NSHFTS)
  111. *> S contains the shifts of origin that define the multi-
  112. *> shift QR sweep. On output S may be reordered.
  113. *> \endverbatim
  114. *>
  115. *> \param[in,out] H
  116. *> \verbatim
  117. *> H is COMPLEX array, dimension (LDH,N)
  118. *> On input H contains a Hessenberg matrix. On output a
  119. *> multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied
  120. *> to the isolated diagonal block in rows and columns KTOP
  121. *> through KBOT.
  122. *> \endverbatim
  123. *>
  124. *> \param[in] LDH
  125. *> \verbatim
  126. *> LDH is INTEGER
  127. *> LDH is the leading dimension of H just as declared in the
  128. *> calling procedure. LDH.GE.MAX(1,N).
  129. *> \endverbatim
  130. *>
  131. *> \param[in] ILOZ
  132. *> \verbatim
  133. *> ILOZ is INTEGER
  134. *> \endverbatim
  135. *>
  136. *> \param[in] IHIZ
  137. *> \verbatim
  138. *> IHIZ is INTEGER
  139. *> Specify the rows of Z to which transformations must be
  140. *> applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N
  141. *> \endverbatim
  142. *>
  143. *> \param[in,out] Z
  144. *> \verbatim
  145. *> Z is COMPLEX array, dimension (LDZ,IHIZ)
  146. *> If WANTZ = .TRUE., then the QR Sweep unitary
  147. *> similarity transformation is accumulated into
  148. *> Z(ILOZ:IHIZ,ILOZ:IHIZ) from the right.
  149. *> If WANTZ = .FALSE., then Z is unreferenced.
  150. *> \endverbatim
  151. *>
  152. *> \param[in] LDZ
  153. *> \verbatim
  154. *> LDZ is INTEGER
  155. *> LDA is the leading dimension of Z just as declared in
  156. *> the calling procedure. LDZ.GE.N.
  157. *> \endverbatim
  158. *>
  159. *> \param[out] V
  160. *> \verbatim
  161. *> V is COMPLEX array, dimension (LDV,NSHFTS/2)
  162. *> \endverbatim
  163. *>
  164. *> \param[in] LDV
  165. *> \verbatim
  166. *> LDV is INTEGER
  167. *> LDV is the leading dimension of V as declared in the
  168. *> calling procedure. LDV.GE.3.
  169. *> \endverbatim
  170. *>
  171. *> \param[out] U
  172. *> \verbatim
  173. *> U is COMPLEX array, dimension (LDU,3*NSHFTS-3)
  174. *> \endverbatim
  175. *>
  176. *> \param[in] LDU
  177. *> \verbatim
  178. *> LDU is INTEGER
  179. *> LDU is the leading dimension of U just as declared in the
  180. *> in the calling subroutine. LDU.GE.3*NSHFTS-3.
  181. *> \endverbatim
  182. *>
  183. *> \param[in] NH
  184. *> \verbatim
  185. *> NH is INTEGER
  186. *> NH is the number of columns in array WH available for
  187. *> workspace. NH.GE.1.
  188. *> \endverbatim
  189. *>
  190. *> \param[out] WH
  191. *> \verbatim
  192. *> WH is COMPLEX array, dimension (LDWH,NH)
  193. *> \endverbatim
  194. *>
  195. *> \param[in] LDWH
  196. *> \verbatim
  197. *> LDWH is INTEGER
  198. *> Leading dimension of WH just as declared in the
  199. *> calling procedure. LDWH.GE.3*NSHFTS-3.
  200. *> \endverbatim
  201. *>
  202. *> \param[in] NV
  203. *> \verbatim
  204. *> NV is INTEGER
  205. *> NV is the number of rows in WV agailable for workspace.
  206. *> NV.GE.1.
  207. *> \endverbatim
  208. *>
  209. *> \param[out] WV
  210. *> \verbatim
  211. *> WV is COMPLEX array, dimension (LDWV,3*NSHFTS-3)
  212. *> \endverbatim
  213. *>
  214. *> \param[in] LDWV
  215. *> \verbatim
  216. *> LDWV is INTEGER
  217. *> LDWV is the leading dimension of WV as declared in the
  218. *> in the calling subroutine. LDWV.GE.NV.
  219. *> \endverbatim
  220. *
  221. * Authors:
  222. * ========
  223. *
  224. *> \author Univ. of Tennessee
  225. *> \author Univ. of California Berkeley
  226. *> \author Univ. of Colorado Denver
  227. *> \author NAG Ltd.
  228. *
  229. *> \date June 2016
  230. *
  231. *> \ingroup complexOTHERauxiliary
  232. *
  233. *> \par Contributors:
  234. * ==================
  235. *>
  236. *> Karen Braman and Ralph Byers, Department of Mathematics,
  237. *> University of Kansas, USA
  238. *
  239. *> \par References:
  240. * ================
  241. *>
  242. *> K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
  243. *> Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
  244. *> Performance, SIAM Journal of Matrix Analysis, volume 23, pages
  245. *> 929--947, 2002.
  246. *>
  247. * =====================================================================
  248. SUBROUTINE CLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS, S,
  249. $ H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U, LDU, NV,
  250. $ WV, LDWV, NH, WH, LDWH )
  251. *
  252. * -- LAPACK auxiliary routine (version 3.7.1) --
  253. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  254. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  255. * June 2016
  256. *
  257. * .. Scalar Arguments ..
  258. INTEGER IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV,
  259. $ LDWH, LDWV, LDZ, N, NH, NSHFTS, NV
  260. LOGICAL WANTT, WANTZ
  261. * ..
  262. * .. Array Arguments ..
  263. COMPLEX H( LDH, * ), S( * ), U( LDU, * ), V( LDV, * ),
  264. $ WH( LDWH, * ), WV( LDWV, * ), Z( LDZ, * )
  265. * ..
  266. *
  267. * ================================================================
  268. * .. Parameters ..
  269. COMPLEX ZERO, ONE
  270. PARAMETER ( ZERO = ( 0.0e0, 0.0e0 ),
  271. $ ONE = ( 1.0e0, 0.0e0 ) )
  272. REAL RZERO, RONE
  273. PARAMETER ( RZERO = 0.0e0, RONE = 1.0e0 )
  274. * ..
  275. * .. Local Scalars ..
  276. COMPLEX ALPHA, BETA, CDUM, REFSUM
  277. REAL H11, H12, H21, H22, SAFMAX, SAFMIN, SCL,
  278. $ SMLNUM, TST1, TST2, ULP
  279. INTEGER I2, I4, INCOL, J, J2, J4, JBOT, JCOL, JLEN,
  280. $ JROW, JTOP, K, K1, KDU, KMS, KNZ, KRCOL, KZS,
  281. $ M, M22, MBOT, MEND, MSTART, MTOP, NBMPS, NDCOL,
  282. $ NS, NU
  283. LOGICAL ACCUM, BLK22, BMP22
  284. * ..
  285. * .. External Functions ..
  286. REAL SLAMCH
  287. EXTERNAL SLAMCH
  288. * ..
  289. * .. Intrinsic Functions ..
  290. *
  291. INTRINSIC ABS, AIMAG, CONJG, MAX, MIN, MOD, REAL
  292. * ..
  293. * .. Local Arrays ..
  294. COMPLEX VT( 3 )
  295. * ..
  296. * .. External Subroutines ..
  297. EXTERNAL CGEMM, CLACPY, CLAQR1, CLARFG, CLASET, CTRMM,
  298. $ SLABAD
  299. * ..
  300. * .. Statement Functions ..
  301. REAL CABS1
  302. * ..
  303. * .. Statement Function definitions ..
  304. CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) )
  305. * ..
  306. * .. Executable Statements ..
  307. *
  308. * ==== If there are no shifts, then there is nothing to do. ====
  309. *
  310. IF( NSHFTS.LT.2 )
  311. $ RETURN
  312. *
  313. * ==== If the active block is empty or 1-by-1, then there
  314. * . is nothing to do. ====
  315. *
  316. IF( KTOP.GE.KBOT )
  317. $ RETURN
  318. *
  319. * ==== NSHFTS is supposed to be even, but if it is odd,
  320. * . then simply reduce it by one. ====
  321. *
  322. NS = NSHFTS - MOD( NSHFTS, 2 )
  323. *
  324. * ==== Machine constants for deflation ====
  325. *
  326. SAFMIN = SLAMCH( 'SAFE MINIMUM' )
  327. SAFMAX = RONE / SAFMIN
  328. CALL SLABAD( SAFMIN, SAFMAX )
  329. ULP = SLAMCH( 'PRECISION' )
  330. SMLNUM = SAFMIN*( REAL( N ) / ULP )
  331. *
  332. * ==== Use accumulated reflections to update far-from-diagonal
  333. * . entries ? ====
  334. *
  335. ACCUM = ( KACC22.EQ.1 ) .OR. ( KACC22.EQ.2 )
  336. *
  337. * ==== If so, exploit the 2-by-2 block structure? ====
  338. *
  339. BLK22 = ( NS.GT.2 ) .AND. ( KACC22.EQ.2 )
  340. *
  341. * ==== clear trash ====
  342. *
  343. IF( KTOP+2.LE.KBOT )
  344. $ H( KTOP+2, KTOP ) = ZERO
  345. *
  346. * ==== NBMPS = number of 2-shift bulges in the chain ====
  347. *
  348. NBMPS = NS / 2
  349. *
  350. * ==== KDU = width of slab ====
  351. *
  352. KDU = 6*NBMPS - 3
  353. *
  354. * ==== Create and chase chains of NBMPS bulges ====
  355. *
  356. DO 210 INCOL = 3*( 1-NBMPS ) + KTOP - 1, KBOT - 2, 3*NBMPS - 2
  357. NDCOL = INCOL + KDU
  358. IF( ACCUM )
  359. $ CALL CLASET( 'ALL', KDU, KDU, ZERO, ONE, U, LDU )
  360. *
  361. * ==== Near-the-diagonal bulge chase. The following loop
  362. * . performs the near-the-diagonal part of a small bulge
  363. * . multi-shift QR sweep. Each 6*NBMPS-2 column diagonal
  364. * . chunk extends from column INCOL to column NDCOL
  365. * . (including both column INCOL and column NDCOL). The
  366. * . following loop chases a 3*NBMPS column long chain of
  367. * . NBMPS bulges 3*NBMPS-2 columns to the right. (INCOL
  368. * . may be less than KTOP and and NDCOL may be greater than
  369. * . KBOT indicating phantom columns from which to chase
  370. * . bulges before they are actually introduced or to which
  371. * . to chase bulges beyond column KBOT.) ====
  372. *
  373. DO 140 KRCOL = INCOL, MIN( INCOL+3*NBMPS-3, KBOT-2 )
  374. *
  375. * ==== Bulges number MTOP to MBOT are active double implicit
  376. * . shift bulges. There may or may not also be small
  377. * . 2-by-2 bulge, if there is room. The inactive bulges
  378. * . (if any) must wait until the active bulges have moved
  379. * . down the diagonal to make room. The phantom matrix
  380. * . paradigm described above helps keep track. ====
  381. *
  382. MTOP = MAX( 1, ( ( KTOP-1 )-KRCOL+2 ) / 3+1 )
  383. MBOT = MIN( NBMPS, ( KBOT-KRCOL ) / 3 )
  384. M22 = MBOT + 1
  385. BMP22 = ( MBOT.LT.NBMPS ) .AND. ( KRCOL+3*( M22-1 ) ).EQ.
  386. $ ( KBOT-2 )
  387. *
  388. * ==== Generate reflections to chase the chain right
  389. * . one column. (The minimum value of K is KTOP-1.) ====
  390. *
  391. DO 10 M = MTOP, MBOT
  392. K = KRCOL + 3*( M-1 )
  393. IF( K.EQ.KTOP-1 ) THEN
  394. CALL CLAQR1( 3, H( KTOP, KTOP ), LDH, S( 2*M-1 ),
  395. $ S( 2*M ), V( 1, M ) )
  396. ALPHA = V( 1, M )
  397. CALL CLARFG( 3, ALPHA, V( 2, M ), 1, V( 1, M ) )
  398. ELSE
  399. BETA = H( K+1, K )
  400. V( 2, M ) = H( K+2, K )
  401. V( 3, M ) = H( K+3, K )
  402. CALL CLARFG( 3, BETA, V( 2, M ), 1, V( 1, M ) )
  403. *
  404. * ==== A Bulge may collapse because of vigilant
  405. * . deflation or destructive underflow. In the
  406. * . underflow case, try the two-small-subdiagonals
  407. * . trick to try to reinflate the bulge. ====
  408. *
  409. IF( H( K+3, K ).NE.ZERO .OR. H( K+3, K+1 ).NE.
  410. $ ZERO .OR. H( K+3, K+2 ).EQ.ZERO ) THEN
  411. *
  412. * ==== Typical case: not collapsed (yet). ====
  413. *
  414. H( K+1, K ) = BETA
  415. H( K+2, K ) = ZERO
  416. H( K+3, K ) = ZERO
  417. ELSE
  418. *
  419. * ==== Atypical case: collapsed. Attempt to
  420. * . reintroduce ignoring H(K+1,K) and H(K+2,K).
  421. * . If the fill resulting from the new
  422. * . reflector is too large, then abandon it.
  423. * . Otherwise, use the new one. ====
  424. *
  425. CALL CLAQR1( 3, H( K+1, K+1 ), LDH, S( 2*M-1 ),
  426. $ S( 2*M ), VT )
  427. ALPHA = VT( 1 )
  428. CALL CLARFG( 3, ALPHA, VT( 2 ), 1, VT( 1 ) )
  429. REFSUM = CONJG( VT( 1 ) )*
  430. $ ( H( K+1, K )+CONJG( VT( 2 ) )*
  431. $ H( K+2, K ) )
  432. *
  433. IF( CABS1( H( K+2, K )-REFSUM*VT( 2 ) )+
  434. $ CABS1( REFSUM*VT( 3 ) ).GT.ULP*
  435. $ ( CABS1( H( K, K ) )+CABS1( H( K+1,
  436. $ K+1 ) )+CABS1( H( K+2, K+2 ) ) ) ) THEN
  437. *
  438. * ==== Starting a new bulge here would
  439. * . create non-negligible fill. Use
  440. * . the old one with trepidation. ====
  441. *
  442. H( K+1, K ) = BETA
  443. H( K+2, K ) = ZERO
  444. H( K+3, K ) = ZERO
  445. ELSE
  446. *
  447. * ==== Stating a new bulge here would
  448. * . create only negligible fill.
  449. * . Replace the old reflector with
  450. * . the new one. ====
  451. *
  452. H( K+1, K ) = H( K+1, K ) - REFSUM
  453. H( K+2, K ) = ZERO
  454. H( K+3, K ) = ZERO
  455. V( 1, M ) = VT( 1 )
  456. V( 2, M ) = VT( 2 )
  457. V( 3, M ) = VT( 3 )
  458. END IF
  459. END IF
  460. END IF
  461. 10 CONTINUE
  462. *
  463. * ==== Generate a 2-by-2 reflection, if needed. ====
  464. *
  465. K = KRCOL + 3*( M22-1 )
  466. IF( BMP22 ) THEN
  467. IF( K.EQ.KTOP-1 ) THEN
  468. CALL CLAQR1( 2, H( K+1, K+1 ), LDH, S( 2*M22-1 ),
  469. $ S( 2*M22 ), V( 1, M22 ) )
  470. BETA = V( 1, M22 )
  471. CALL CLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
  472. ELSE
  473. BETA = H( K+1, K )
  474. V( 2, M22 ) = H( K+2, K )
  475. CALL CLARFG( 2, BETA, V( 2, M22 ), 1, V( 1, M22 ) )
  476. H( K+1, K ) = BETA
  477. H( K+2, K ) = ZERO
  478. END IF
  479. END IF
  480. *
  481. * ==== Multiply H by reflections from the left ====
  482. *
  483. IF( ACCUM ) THEN
  484. JBOT = MIN( NDCOL, KBOT )
  485. ELSE IF( WANTT ) THEN
  486. JBOT = N
  487. ELSE
  488. JBOT = KBOT
  489. END IF
  490. DO 30 J = MAX( KTOP, KRCOL ), JBOT
  491. MEND = MIN( MBOT, ( J-KRCOL+2 ) / 3 )
  492. DO 20 M = MTOP, MEND
  493. K = KRCOL + 3*( M-1 )
  494. REFSUM = CONJG( V( 1, M ) )*
  495. $ ( H( K+1, J )+CONJG( V( 2, M ) )*H( K+2, J )+
  496. $ CONJG( V( 3, M ) )*H( K+3, J ) )
  497. H( K+1, J ) = H( K+1, J ) - REFSUM
  498. H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M )
  499. H( K+3, J ) = H( K+3, J ) - REFSUM*V( 3, M )
  500. 20 CONTINUE
  501. 30 CONTINUE
  502. IF( BMP22 ) THEN
  503. K = KRCOL + 3*( M22-1 )
  504. DO 40 J = MAX( K+1, KTOP ), JBOT
  505. REFSUM = CONJG( V( 1, M22 ) )*
  506. $ ( H( K+1, J )+CONJG( V( 2, M22 ) )*
  507. $ H( K+2, J ) )
  508. H( K+1, J ) = H( K+1, J ) - REFSUM
  509. H( K+2, J ) = H( K+2, J ) - REFSUM*V( 2, M22 )
  510. 40 CONTINUE
  511. END IF
  512. *
  513. * ==== Multiply H by reflections from the right.
  514. * . Delay filling in the last row until the
  515. * . vigilant deflation check is complete. ====
  516. *
  517. IF( ACCUM ) THEN
  518. JTOP = MAX( KTOP, INCOL )
  519. ELSE IF( WANTT ) THEN
  520. JTOP = 1
  521. ELSE
  522. JTOP = KTOP
  523. END IF
  524. DO 80 M = MTOP, MBOT
  525. IF( V( 1, M ).NE.ZERO ) THEN
  526. K = KRCOL + 3*( M-1 )
  527. DO 50 J = JTOP, MIN( KBOT, K+3 )
  528. REFSUM = V( 1, M )*( H( J, K+1 )+V( 2, M )*
  529. $ H( J, K+2 )+V( 3, M )*H( J, K+3 ) )
  530. H( J, K+1 ) = H( J, K+1 ) - REFSUM
  531. H( J, K+2 ) = H( J, K+2 ) -
  532. $ REFSUM*CONJG( V( 2, M ) )
  533. H( J, K+3 ) = H( J, K+3 ) -
  534. $ REFSUM*CONJG( V( 3, M ) )
  535. 50 CONTINUE
  536. *
  537. IF( ACCUM ) THEN
  538. *
  539. * ==== Accumulate U. (If necessary, update Z later
  540. * . with with an efficient matrix-matrix
  541. * . multiply.) ====
  542. *
  543. KMS = K - INCOL
  544. DO 60 J = MAX( 1, KTOP-INCOL ), KDU
  545. REFSUM = V( 1, M )*( U( J, KMS+1 )+V( 2, M )*
  546. $ U( J, KMS+2 )+V( 3, M )*U( J, KMS+3 ) )
  547. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
  548. U( J, KMS+2 ) = U( J, KMS+2 ) -
  549. $ REFSUM*CONJG( V( 2, M ) )
  550. U( J, KMS+3 ) = U( J, KMS+3 ) -
  551. $ REFSUM*CONJG( V( 3, M ) )
  552. 60 CONTINUE
  553. ELSE IF( WANTZ ) THEN
  554. *
  555. * ==== U is not accumulated, so update Z
  556. * . now by multiplying by reflections
  557. * . from the right. ====
  558. *
  559. DO 70 J = ILOZ, IHIZ
  560. REFSUM = V( 1, M )*( Z( J, K+1 )+V( 2, M )*
  561. $ Z( J, K+2 )+V( 3, M )*Z( J, K+3 ) )
  562. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
  563. Z( J, K+2 ) = Z( J, K+2 ) -
  564. $ REFSUM*CONJG( V( 2, M ) )
  565. Z( J, K+3 ) = Z( J, K+3 ) -
  566. $ REFSUM*CONJG( V( 3, M ) )
  567. 70 CONTINUE
  568. END IF
  569. END IF
  570. 80 CONTINUE
  571. *
  572. * ==== Special case: 2-by-2 reflection (if needed) ====
  573. *
  574. K = KRCOL + 3*( M22-1 )
  575. IF( BMP22 ) THEN
  576. IF ( V( 1, M22 ).NE.ZERO ) THEN
  577. DO 90 J = JTOP, MIN( KBOT, K+3 )
  578. REFSUM = V( 1, M22 )*( H( J, K+1 )+V( 2, M22 )*
  579. $ H( J, K+2 ) )
  580. H( J, K+1 ) = H( J, K+1 ) - REFSUM
  581. H( J, K+2 ) = H( J, K+2 ) -
  582. $ REFSUM*CONJG( V( 2, M22 ) )
  583. 90 CONTINUE
  584. *
  585. IF( ACCUM ) THEN
  586. KMS = K - INCOL
  587. DO 100 J = MAX( 1, KTOP-INCOL ), KDU
  588. REFSUM = V( 1, M22 )*( U( J, KMS+1 )+
  589. $ V( 2, M22 )*U( J, KMS+2 ) )
  590. U( J, KMS+1 ) = U( J, KMS+1 ) - REFSUM
  591. U( J, KMS+2 ) = U( J, KMS+2 ) -
  592. $ REFSUM*CONJG( V( 2, M22 ) )
  593. 100 CONTINUE
  594. ELSE IF( WANTZ ) THEN
  595. DO 110 J = ILOZ, IHIZ
  596. REFSUM = V( 1, M22 )*( Z( J, K+1 )+V( 2, M22 )*
  597. $ Z( J, K+2 ) )
  598. Z( J, K+1 ) = Z( J, K+1 ) - REFSUM
  599. Z( J, K+2 ) = Z( J, K+2 ) -
  600. $ REFSUM*CONJG( V( 2, M22 ) )
  601. 110 CONTINUE
  602. END IF
  603. END IF
  604. END IF
  605. *
  606. * ==== Vigilant deflation check ====
  607. *
  608. MSTART = MTOP
  609. IF( KRCOL+3*( MSTART-1 ).LT.KTOP )
  610. $ MSTART = MSTART + 1
  611. MEND = MBOT
  612. IF( BMP22 )
  613. $ MEND = MEND + 1
  614. IF( KRCOL.EQ.KBOT-2 )
  615. $ MEND = MEND + 1
  616. DO 120 M = MSTART, MEND
  617. K = MIN( KBOT-1, KRCOL+3*( M-1 ) )
  618. *
  619. * ==== The following convergence test requires that
  620. * . the tradition small-compared-to-nearby-diagonals
  621. * . criterion and the Ahues & Tisseur (LAWN 122, 1997)
  622. * . criteria both be satisfied. The latter improves
  623. * . accuracy in some examples. Falling back on an
  624. * . alternate convergence criterion when TST1 or TST2
  625. * . is zero (as done here) is traditional but probably
  626. * . unnecessary. ====
  627. *
  628. IF( H( K+1, K ).NE.ZERO ) THEN
  629. TST1 = CABS1( H( K, K ) ) + CABS1( H( K+1, K+1 ) )
  630. IF( TST1.EQ.RZERO ) THEN
  631. IF( K.GE.KTOP+1 )
  632. $ TST1 = TST1 + CABS1( H( K, K-1 ) )
  633. IF( K.GE.KTOP+2 )
  634. $ TST1 = TST1 + CABS1( H( K, K-2 ) )
  635. IF( K.GE.KTOP+3 )
  636. $ TST1 = TST1 + CABS1( H( K, K-3 ) )
  637. IF( K.LE.KBOT-2 )
  638. $ TST1 = TST1 + CABS1( H( K+2, K+1 ) )
  639. IF( K.LE.KBOT-3 )
  640. $ TST1 = TST1 + CABS1( H( K+3, K+1 ) )
  641. IF( K.LE.KBOT-4 )
  642. $ TST1 = TST1 + CABS1( H( K+4, K+1 ) )
  643. END IF
  644. IF( CABS1( H( K+1, K ) ).LE.MAX( SMLNUM, ULP*TST1 ) )
  645. $ THEN
  646. H12 = MAX( CABS1( H( K+1, K ) ),
  647. $ CABS1( H( K, K+1 ) ) )
  648. H21 = MIN( CABS1( H( K+1, K ) ),
  649. $ CABS1( H( K, K+1 ) ) )
  650. H11 = MAX( CABS1( H( K+1, K+1 ) ),
  651. $ CABS1( H( K, K )-H( K+1, K+1 ) ) )
  652. H22 = MIN( CABS1( H( K+1, K+1 ) ),
  653. $ CABS1( H( K, K )-H( K+1, K+1 ) ) )
  654. SCL = H11 + H12
  655. TST2 = H22*( H11 / SCL )
  656. *
  657. IF( TST2.EQ.RZERO .OR. H21*( H12 / SCL ).LE.
  658. $ MAX( SMLNUM, ULP*TST2 ) )H( K+1, K ) = ZERO
  659. END IF
  660. END IF
  661. 120 CONTINUE
  662. *
  663. * ==== Fill in the last row of each bulge. ====
  664. *
  665. MEND = MIN( NBMPS, ( KBOT-KRCOL-1 ) / 3 )
  666. DO 130 M = MTOP, MEND
  667. K = KRCOL + 3*( M-1 )
  668. REFSUM = V( 1, M )*V( 3, M )*H( K+4, K+3 )
  669. H( K+4, K+1 ) = -REFSUM
  670. H( K+4, K+2 ) = -REFSUM*CONJG( V( 2, M ) )
  671. H( K+4, K+3 ) = H( K+4, K+3 ) - REFSUM*CONJG( V( 3, M ) )
  672. 130 CONTINUE
  673. *
  674. * ==== End of near-the-diagonal bulge chase. ====
  675. *
  676. 140 CONTINUE
  677. *
  678. * ==== Use U (if accumulated) to update far-from-diagonal
  679. * . entries in H. If required, use U to update Z as
  680. * . well. ====
  681. *
  682. IF( ACCUM ) THEN
  683. IF( WANTT ) THEN
  684. JTOP = 1
  685. JBOT = N
  686. ELSE
  687. JTOP = KTOP
  688. JBOT = KBOT
  689. END IF
  690. IF( ( .NOT.BLK22 ) .OR. ( INCOL.LT.KTOP ) .OR.
  691. $ ( NDCOL.GT.KBOT ) .OR. ( NS.LE.2 ) ) THEN
  692. *
  693. * ==== Updates not exploiting the 2-by-2 block
  694. * . structure of U. K1 and NU keep track of
  695. * . the location and size of U in the special
  696. * . cases of introducing bulges and chasing
  697. * . bulges off the bottom. In these special
  698. * . cases and in case the number of shifts
  699. * . is NS = 2, there is no 2-by-2 block
  700. * . structure to exploit. ====
  701. *
  702. K1 = MAX( 1, KTOP-INCOL )
  703. NU = ( KDU-MAX( 0, NDCOL-KBOT ) ) - K1 + 1
  704. *
  705. * ==== Horizontal Multiply ====
  706. *
  707. DO 150 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
  708. JLEN = MIN( NH, JBOT-JCOL+1 )
  709. CALL CGEMM( 'C', 'N', NU, JLEN, NU, ONE, U( K1, K1 ),
  710. $ LDU, H( INCOL+K1, JCOL ), LDH, ZERO, WH,
  711. $ LDWH )
  712. CALL CLACPY( 'ALL', NU, JLEN, WH, LDWH,
  713. $ H( INCOL+K1, JCOL ), LDH )
  714. 150 CONTINUE
  715. *
  716. * ==== Vertical multiply ====
  717. *
  718. DO 160 JROW = JTOP, MAX( KTOP, INCOL ) - 1, NV
  719. JLEN = MIN( NV, MAX( KTOP, INCOL )-JROW )
  720. CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  721. $ H( JROW, INCOL+K1 ), LDH, U( K1, K1 ),
  722. $ LDU, ZERO, WV, LDWV )
  723. CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV,
  724. $ H( JROW, INCOL+K1 ), LDH )
  725. 160 CONTINUE
  726. *
  727. * ==== Z multiply (also vertical) ====
  728. *
  729. IF( WANTZ ) THEN
  730. DO 170 JROW = ILOZ, IHIZ, NV
  731. JLEN = MIN( NV, IHIZ-JROW+1 )
  732. CALL CGEMM( 'N', 'N', JLEN, NU, NU, ONE,
  733. $ Z( JROW, INCOL+K1 ), LDZ, U( K1, K1 ),
  734. $ LDU, ZERO, WV, LDWV )
  735. CALL CLACPY( 'ALL', JLEN, NU, WV, LDWV,
  736. $ Z( JROW, INCOL+K1 ), LDZ )
  737. 170 CONTINUE
  738. END IF
  739. ELSE
  740. *
  741. * ==== Updates exploiting U's 2-by-2 block structure.
  742. * . (I2, I4, J2, J4 are the last rows and columns
  743. * . of the blocks.) ====
  744. *
  745. I2 = ( KDU+1 ) / 2
  746. I4 = KDU
  747. J2 = I4 - I2
  748. J4 = KDU
  749. *
  750. * ==== KZS and KNZ deal with the band of zeros
  751. * . along the diagonal of one of the triangular
  752. * . blocks. ====
  753. *
  754. KZS = ( J4-J2 ) - ( NS+1 )
  755. KNZ = NS + 1
  756. *
  757. * ==== Horizontal multiply ====
  758. *
  759. DO 180 JCOL = MIN( NDCOL, KBOT ) + 1, JBOT, NH
  760. JLEN = MIN( NH, JBOT-JCOL+1 )
  761. *
  762. * ==== Copy bottom of H to top+KZS of scratch ====
  763. * (The first KZS rows get multiplied by zero.) ====
  764. *
  765. CALL CLACPY( 'ALL', KNZ, JLEN, H( INCOL+1+J2, JCOL ),
  766. $ LDH, WH( KZS+1, 1 ), LDWH )
  767. *
  768. * ==== Multiply by U21**H ====
  769. *
  770. CALL CLASET( 'ALL', KZS, JLEN, ZERO, ZERO, WH, LDWH )
  771. CALL CTRMM( 'L', 'U', 'C', 'N', KNZ, JLEN, ONE,
  772. $ U( J2+1, 1+KZS ), LDU, WH( KZS+1, 1 ),
  773. $ LDWH )
  774. *
  775. * ==== Multiply top of H by U11**H ====
  776. *
  777. CALL CGEMM( 'C', 'N', I2, JLEN, J2, ONE, U, LDU,
  778. $ H( INCOL+1, JCOL ), LDH, ONE, WH, LDWH )
  779. *
  780. * ==== Copy top of H to bottom of WH ====
  781. *
  782. CALL CLACPY( 'ALL', J2, JLEN, H( INCOL+1, JCOL ), LDH,
  783. $ WH( I2+1, 1 ), LDWH )
  784. *
  785. * ==== Multiply by U21**H ====
  786. *
  787. CALL CTRMM( 'L', 'L', 'C', 'N', J2, JLEN, ONE,
  788. $ U( 1, I2+1 ), LDU, WH( I2+1, 1 ), LDWH )
  789. *
  790. * ==== Multiply by U22 ====
  791. *
  792. CALL CGEMM( 'C', 'N', I4-I2, JLEN, J4-J2, ONE,
  793. $ U( J2+1, I2+1 ), LDU,
  794. $ H( INCOL+1+J2, JCOL ), LDH, ONE,
  795. $ WH( I2+1, 1 ), LDWH )
  796. *
  797. * ==== Copy it back ====
  798. *
  799. CALL CLACPY( 'ALL', KDU, JLEN, WH, LDWH,
  800. $ H( INCOL+1, JCOL ), LDH )
  801. 180 CONTINUE
  802. *
  803. * ==== Vertical multiply ====
  804. *
  805. DO 190 JROW = JTOP, MAX( INCOL, KTOP ) - 1, NV
  806. JLEN = MIN( NV, MAX( INCOL, KTOP )-JROW )
  807. *
  808. * ==== Copy right of H to scratch (the first KZS
  809. * . columns get multiplied by zero) ====
  810. *
  811. CALL CLACPY( 'ALL', JLEN, KNZ, H( JROW, INCOL+1+J2 ),
  812. $ LDH, WV( 1, 1+KZS ), LDWV )
  813. *
  814. * ==== Multiply by U21 ====
  815. *
  816. CALL CLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV, LDWV )
  817. CALL CTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE,
  818. $ U( J2+1, 1+KZS ), LDU, WV( 1, 1+KZS ),
  819. $ LDWV )
  820. *
  821. * ==== Multiply by U11 ====
  822. *
  823. CALL CGEMM( 'N', 'N', JLEN, I2, J2, ONE,
  824. $ H( JROW, INCOL+1 ), LDH, U, LDU, ONE, WV,
  825. $ LDWV )
  826. *
  827. * ==== Copy left of H to right of scratch ====
  828. *
  829. CALL CLACPY( 'ALL', JLEN, J2, H( JROW, INCOL+1 ), LDH,
  830. $ WV( 1, 1+I2 ), LDWV )
  831. *
  832. * ==== Multiply by U21 ====
  833. *
  834. CALL CTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE,
  835. $ U( 1, I2+1 ), LDU, WV( 1, 1+I2 ), LDWV )
  836. *
  837. * ==== Multiply by U22 ====
  838. *
  839. CALL CGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE,
  840. $ H( JROW, INCOL+1+J2 ), LDH,
  841. $ U( J2+1, I2+1 ), LDU, ONE, WV( 1, 1+I2 ),
  842. $ LDWV )
  843. *
  844. * ==== Copy it back ====
  845. *
  846. CALL CLACPY( 'ALL', JLEN, KDU, WV, LDWV,
  847. $ H( JROW, INCOL+1 ), LDH )
  848. 190 CONTINUE
  849. *
  850. * ==== Multiply Z (also vertical) ====
  851. *
  852. IF( WANTZ ) THEN
  853. DO 200 JROW = ILOZ, IHIZ, NV
  854. JLEN = MIN( NV, IHIZ-JROW+1 )
  855. *
  856. * ==== Copy right of Z to left of scratch (first
  857. * . KZS columns get multiplied by zero) ====
  858. *
  859. CALL CLACPY( 'ALL', JLEN, KNZ,
  860. $ Z( JROW, INCOL+1+J2 ), LDZ,
  861. $ WV( 1, 1+KZS ), LDWV )
  862. *
  863. * ==== Multiply by U12 ====
  864. *
  865. CALL CLASET( 'ALL', JLEN, KZS, ZERO, ZERO, WV,
  866. $ LDWV )
  867. CALL CTRMM( 'R', 'U', 'N', 'N', JLEN, KNZ, ONE,
  868. $ U( J2+1, 1+KZS ), LDU, WV( 1, 1+KZS ),
  869. $ LDWV )
  870. *
  871. * ==== Multiply by U11 ====
  872. *
  873. CALL CGEMM( 'N', 'N', JLEN, I2, J2, ONE,
  874. $ Z( JROW, INCOL+1 ), LDZ, U, LDU, ONE,
  875. $ WV, LDWV )
  876. *
  877. * ==== Copy left of Z to right of scratch ====
  878. *
  879. CALL CLACPY( 'ALL', JLEN, J2, Z( JROW, INCOL+1 ),
  880. $ LDZ, WV( 1, 1+I2 ), LDWV )
  881. *
  882. * ==== Multiply by U21 ====
  883. *
  884. CALL CTRMM( 'R', 'L', 'N', 'N', JLEN, I4-I2, ONE,
  885. $ U( 1, I2+1 ), LDU, WV( 1, 1+I2 ),
  886. $ LDWV )
  887. *
  888. * ==== Multiply by U22 ====
  889. *
  890. CALL CGEMM( 'N', 'N', JLEN, I4-I2, J4-J2, ONE,
  891. $ Z( JROW, INCOL+1+J2 ), LDZ,
  892. $ U( J2+1, I2+1 ), LDU, ONE,
  893. $ WV( 1, 1+I2 ), LDWV )
  894. *
  895. * ==== Copy the result back to Z ====
  896. *
  897. CALL CLACPY( 'ALL', JLEN, KDU, WV, LDWV,
  898. $ Z( JROW, INCOL+1 ), LDZ )
  899. 200 CONTINUE
  900. END IF
  901. END IF
  902. END IF
  903. 210 CONTINUE
  904. *
  905. * ==== End of CLAQR5 ====
  906. *
  907. END