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.

cgghd3.f 32 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. *> \brief \b CGGHD3
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CGGHD3 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgghd3.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgghd3.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgghd3.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q,
  22. * $ LDQ, Z, LDZ, WORK, LWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER COMPQ, COMPZ
  26. * INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK
  27. * ..
  28. * .. Array Arguments ..
  29. * COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  30. * $ Z( LDZ, * ), WORK( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *>
  40. *> CGGHD3 reduces a pair of complex matrices (A,B) to generalized upper
  41. *> Hessenberg form using unitary transformations, where A is a
  42. *> general matrix and B is upper triangular. The form of the
  43. *> generalized eigenvalue problem is
  44. *> A*x = lambda*B*x,
  45. *> and B is typically made upper triangular by computing its QR
  46. *> factorization and moving the unitary matrix Q to the left side
  47. *> of the equation.
  48. *>
  49. *> This subroutine simultaneously reduces A to a Hessenberg matrix H:
  50. *> Q**H*A*Z = H
  51. *> and transforms B to another upper triangular matrix T:
  52. *> Q**H*B*Z = T
  53. *> in order to reduce the problem to its standard form
  54. *> H*y = lambda*T*y
  55. *> where y = Z**H*x.
  56. *>
  57. *> The unitary matrices Q and Z are determined as products of Givens
  58. *> rotations. They may either be formed explicitly, or they may be
  59. *> postmultiplied into input matrices Q1 and Z1, so that
  60. *>
  61. *> Q1 * A * Z1**H = (Q1*Q) * H * (Z1*Z)**H
  62. *>
  63. *> Q1 * B * Z1**H = (Q1*Q) * T * (Z1*Z)**H
  64. *>
  65. *> If Q1 is the unitary matrix from the QR factorization of B in the
  66. *> original equation A*x = lambda*B*x, then CGGHD3 reduces the original
  67. *> problem to generalized Hessenberg form.
  68. *>
  69. *> This is a blocked variant of CGGHRD, using matrix-matrix
  70. *> multiplications for parts of the computation to enhance performance.
  71. *> \endverbatim
  72. *
  73. * Arguments:
  74. * ==========
  75. *
  76. *> \param[in] COMPQ
  77. *> \verbatim
  78. *> COMPQ is CHARACTER*1
  79. *> = 'N': do not compute Q;
  80. *> = 'I': Q is initialized to the unit matrix, and the
  81. *> unitary matrix Q is returned;
  82. *> = 'V': Q must contain a unitary matrix Q1 on entry,
  83. *> and the product Q1*Q is returned.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] COMPZ
  87. *> \verbatim
  88. *> COMPZ is CHARACTER*1
  89. *> = 'N': do not compute Z;
  90. *> = 'I': Z is initialized to the unit matrix, and the
  91. *> unitary matrix Z is returned;
  92. *> = 'V': Z must contain a unitary matrix Z1 on entry,
  93. *> and the product Z1*Z is returned.
  94. *> \endverbatim
  95. *>
  96. *> \param[in] N
  97. *> \verbatim
  98. *> N is INTEGER
  99. *> The order of the matrices A and B. N >= 0.
  100. *> \endverbatim
  101. *>
  102. *> \param[in] ILO
  103. *> \verbatim
  104. *> ILO is INTEGER
  105. *> \endverbatim
  106. *>
  107. *> \param[in] IHI
  108. *> \verbatim
  109. *> IHI is INTEGER
  110. *>
  111. *> ILO and IHI mark the rows and columns of A which are to be
  112. *> reduced. It is assumed that A is already upper triangular
  113. *> in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are
  114. *> normally set by a previous call to CGGBAL; otherwise they
  115. *> should be set to 1 and N respectively.
  116. *> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
  117. *> \endverbatim
  118. *>
  119. *> \param[in,out] A
  120. *> \verbatim
  121. *> A is COMPLEX array, dimension (LDA, N)
  122. *> On entry, the N-by-N general matrix to be reduced.
  123. *> On exit, the upper triangle and the first subdiagonal of A
  124. *> are overwritten with the upper Hessenberg matrix H, and the
  125. *> rest is set to zero.
  126. *> \endverbatim
  127. *>
  128. *> \param[in] LDA
  129. *> \verbatim
  130. *> LDA is INTEGER
  131. *> The leading dimension of the array A. LDA >= max(1,N).
  132. *> \endverbatim
  133. *>
  134. *> \param[in,out] B
  135. *> \verbatim
  136. *> B is COMPLEX array, dimension (LDB, N)
  137. *> On entry, the N-by-N upper triangular matrix B.
  138. *> On exit, the upper triangular matrix T = Q**H B Z. The
  139. *> elements below the diagonal are set to zero.
  140. *> \endverbatim
  141. *>
  142. *> \param[in] LDB
  143. *> \verbatim
  144. *> LDB is INTEGER
  145. *> The leading dimension of the array B. LDB >= max(1,N).
  146. *> \endverbatim
  147. *>
  148. *> \param[in,out] Q
  149. *> \verbatim
  150. *> Q is COMPLEX array, dimension (LDQ, N)
  151. *> On entry, if COMPQ = 'V', the unitary matrix Q1, typically
  152. *> from the QR factorization of B.
  153. *> On exit, if COMPQ='I', the unitary matrix Q, and if
  154. *> COMPQ = 'V', the product Q1*Q.
  155. *> Not referenced if COMPQ='N'.
  156. *> \endverbatim
  157. *>
  158. *> \param[in] LDQ
  159. *> \verbatim
  160. *> LDQ is INTEGER
  161. *> The leading dimension of the array Q.
  162. *> LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise.
  163. *> \endverbatim
  164. *>
  165. *> \param[in,out] Z
  166. *> \verbatim
  167. *> Z is COMPLEX array, dimension (LDZ, N)
  168. *> On entry, if COMPZ = 'V', the unitary matrix Z1.
  169. *> On exit, if COMPZ='I', the unitary matrix Z, and if
  170. *> COMPZ = 'V', the product Z1*Z.
  171. *> Not referenced if COMPZ='N'.
  172. *> \endverbatim
  173. *>
  174. *> \param[in] LDZ
  175. *> \verbatim
  176. *> LDZ is INTEGER
  177. *> The leading dimension of the array Z.
  178. *> LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise.
  179. *> \endverbatim
  180. *>
  181. *> \param[out] WORK
  182. *> \verbatim
  183. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  184. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  185. *> \endverbatim
  186. *>
  187. *> \param[in] LWORK
  188. *> \verbatim
  189. *> LWORK is INTEGER
  190. *> The length of the array WORK. LWORK >= 1.
  191. *> For optimum performance LWORK >= 6*N*NB, where NB is the
  192. *> optimal blocksize.
  193. *>
  194. *> If LWORK = -1, then a workspace query is assumed; the routine
  195. *> only calculates the optimal size of the WORK array, returns
  196. *> this value as the first entry of the WORK array, and no error
  197. *> message related to LWORK is issued by XERBLA.
  198. *> \endverbatim
  199. *>
  200. *> \param[out] INFO
  201. *> \verbatim
  202. *> INFO is INTEGER
  203. *> = 0: successful exit.
  204. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  205. *> \endverbatim
  206. *
  207. * Authors:
  208. * ========
  209. *
  210. *> \author Univ. of Tennessee
  211. *> \author Univ. of California Berkeley
  212. *> \author Univ. of Colorado Denver
  213. *> \author NAG Ltd.
  214. *
  215. *> \ingroup gghd3
  216. *
  217. *> \par Further Details:
  218. * =====================
  219. *>
  220. *> \verbatim
  221. *>
  222. *> This routine reduces A to Hessenberg form and maintains B in triangular form
  223. *> using a blocked variant of Moler and Stewart's original algorithm,
  224. *> as described by Kagstrom, Kressner, Quintana-Orti, and Quintana-Orti
  225. *> (BIT 2008).
  226. *> \endverbatim
  227. *>
  228. * =====================================================================
  229. SUBROUTINE CGGHD3( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q,
  230. $ LDQ, Z, LDZ, WORK, LWORK, INFO )
  231. *
  232. * -- LAPACK computational routine --
  233. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  234. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  235. *
  236. *
  237. IMPLICIT NONE
  238. *
  239. * .. Scalar Arguments ..
  240. CHARACTER COMPQ, COMPZ
  241. INTEGER IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N, LWORK
  242. * ..
  243. * .. Array Arguments ..
  244. COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  245. $ Z( LDZ, * ), WORK( * )
  246. * ..
  247. *
  248. * =====================================================================
  249. *
  250. * .. Parameters ..
  251. COMPLEX CONE, CZERO
  252. PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ),
  253. $ CZERO = ( 0.0E+0, 0.0E+0 ) )
  254. * ..
  255. * .. Local Scalars ..
  256. LOGICAL BLK22, INITQ, INITZ, LQUERY, WANTQ, WANTZ
  257. CHARACTER*1 COMPQ2, COMPZ2
  258. INTEGER COLA, I, IERR, J, J0, JCOL, JJ, JROW, K,
  259. $ KACC22, LEN, LWKOPT, N2NB, NB, NBLST, NBMIN,
  260. $ NH, NNB, NX, PPW, PPWO, PW, TOP, TOPQ
  261. REAL C
  262. COMPLEX C1, C2, CTEMP, S, S1, S2, TEMP, TEMP1, TEMP2,
  263. $ TEMP3
  264. * ..
  265. * .. External Functions ..
  266. LOGICAL LSAME
  267. INTEGER ILAENV
  268. REAL SROUNDUP_LWORK
  269. EXTERNAL ILAENV, LSAME, SROUNDUP_LWORK
  270. * ..
  271. * .. External Subroutines ..
  272. EXTERNAL CGGHRD, CLARTG, CLASET, CUNM22, CROT, CGEMM,
  273. $ CGEMV, CTRMV, CLACPY, XERBLA
  274. * ..
  275. * .. Intrinsic Functions ..
  276. INTRINSIC REAL, CMPLX, CONJG, MAX
  277. * ..
  278. * .. Executable Statements ..
  279. *
  280. * Decode and test the input parameters.
  281. *
  282. INFO = 0
  283. NB = ILAENV( 1, 'CGGHD3', ' ', N, ILO, IHI, -1 )
  284. NH = IHI - ILO + 1
  285. IF( NH.LE.1 ) THEN
  286. LWKOPT = 1
  287. ELSE
  288. LWKOPT = 6*N*NB
  289. END IF
  290. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  291. INITQ = LSAME( COMPQ, 'I' )
  292. WANTQ = INITQ .OR. LSAME( COMPQ, 'V' )
  293. INITZ = LSAME( COMPZ, 'I' )
  294. WANTZ = INITZ .OR. LSAME( COMPZ, 'V' )
  295. LQUERY = ( LWORK.EQ.-1 )
  296. *
  297. IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN
  298. INFO = -1
  299. ELSE IF( .NOT.LSAME( COMPZ, 'N' ) .AND. .NOT.WANTZ ) THEN
  300. INFO = -2
  301. ELSE IF( N.LT.0 ) THEN
  302. INFO = -3
  303. ELSE IF( ILO.LT.1 ) THEN
  304. INFO = -4
  305. ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
  306. INFO = -5
  307. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  308. INFO = -7
  309. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  310. INFO = -9
  311. ELSE IF( ( WANTQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN
  312. INFO = -11
  313. ELSE IF( ( WANTZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN
  314. INFO = -13
  315. ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
  316. INFO = -15
  317. END IF
  318. IF( INFO.NE.0 ) THEN
  319. CALL XERBLA( 'CGGHD3', -INFO )
  320. RETURN
  321. ELSE IF( LQUERY ) THEN
  322. RETURN
  323. END IF
  324. *
  325. * Initialize Q and Z if desired.
  326. *
  327. IF( INITQ )
  328. $ CALL CLASET( 'All', N, N, CZERO, CONE, Q, LDQ )
  329. IF( INITZ )
  330. $ CALL CLASET( 'All', N, N, CZERO, CONE, Z, LDZ )
  331. *
  332. * Zero out lower triangle of B.
  333. *
  334. IF( N.GT.1 )
  335. $ CALL CLASET( 'Lower', N-1, N-1, CZERO, CZERO, B(2, 1), LDB )
  336. *
  337. * Quick return if possible
  338. *
  339. IF( NH.LE.1 ) THEN
  340. WORK( 1 ) = CONE
  341. RETURN
  342. END IF
  343. *
  344. * Determine the blocksize.
  345. *
  346. NBMIN = ILAENV( 2, 'CGGHD3', ' ', N, ILO, IHI, -1 )
  347. IF( NB.GT.1 .AND. NB.LT.NH ) THEN
  348. *
  349. * Determine when to use unblocked instead of blocked code.
  350. *
  351. NX = MAX( NB, ILAENV( 3, 'CGGHD3', ' ', N, ILO, IHI, -1 ) )
  352. IF( NX.LT.NH ) THEN
  353. *
  354. * Determine if workspace is large enough for blocked code.
  355. *
  356. IF( LWORK.LT.LWKOPT ) THEN
  357. *
  358. * Not enough workspace to use optimal NB: determine the
  359. * minimum value of NB, and reduce NB or force use of
  360. * unblocked code.
  361. *
  362. NBMIN = MAX( 2, ILAENV( 2, 'CGGHD3', ' ', N, ILO, IHI,
  363. $ -1 ) )
  364. IF( LWORK.GE.6*N*NBMIN ) THEN
  365. NB = LWORK / ( 6*N )
  366. ELSE
  367. NB = 1
  368. END IF
  369. END IF
  370. END IF
  371. END IF
  372. *
  373. IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN
  374. *
  375. * Use unblocked code below
  376. *
  377. JCOL = ILO
  378. *
  379. ELSE
  380. *
  381. * Use blocked code
  382. *
  383. KACC22 = ILAENV( 16, 'CGGHD3', ' ', N, ILO, IHI, -1 )
  384. BLK22 = KACC22.EQ.2
  385. DO JCOL = ILO, IHI-2, NB
  386. NNB = MIN( NB, IHI-JCOL-1 )
  387. *
  388. * Initialize small unitary factors that will hold the
  389. * accumulated Givens rotations in workspace.
  390. * N2NB denotes the number of 2*NNB-by-2*NNB factors
  391. * NBLST denotes the (possibly smaller) order of the last
  392. * factor.
  393. *
  394. N2NB = ( IHI-JCOL-1 ) / NNB - 1
  395. NBLST = IHI - JCOL - N2NB*NNB
  396. CALL CLASET( 'All', NBLST, NBLST, CZERO, CONE, WORK, NBLST )
  397. PW = NBLST * NBLST + 1
  398. DO I = 1, N2NB
  399. CALL CLASET( 'All', 2*NNB, 2*NNB, CZERO, CONE,
  400. $ WORK( PW ), 2*NNB )
  401. PW = PW + 4*NNB*NNB
  402. END DO
  403. *
  404. * Reduce columns JCOL:JCOL+NNB-1 of A to Hessenberg form.
  405. *
  406. DO J = JCOL, JCOL+NNB-1
  407. *
  408. * Reduce Jth column of A. Store cosines and sines in Jth
  409. * column of A and B, respectively.
  410. *
  411. DO I = IHI, J+2, -1
  412. TEMP = A( I-1, J )
  413. CALL CLARTG( TEMP, A( I, J ), C, S, A( I-1, J ) )
  414. A( I, J ) = CMPLX( C )
  415. B( I, J ) = S
  416. END DO
  417. *
  418. * Accumulate Givens rotations into workspace array.
  419. *
  420. PPW = ( NBLST + 1 )*( NBLST - 2 ) - J + JCOL + 1
  421. LEN = 2 + J - JCOL
  422. JROW = J + N2NB*NNB + 2
  423. DO I = IHI, JROW, -1
  424. CTEMP = A( I, J )
  425. S = B( I, J )
  426. DO JJ = PPW, PPW+LEN-1
  427. TEMP = WORK( JJ + NBLST )
  428. WORK( JJ + NBLST ) = CTEMP*TEMP - S*WORK( JJ )
  429. WORK( JJ ) = CONJG( S )*TEMP + CTEMP*WORK( JJ )
  430. END DO
  431. LEN = LEN + 1
  432. PPW = PPW - NBLST - 1
  433. END DO
  434. *
  435. PPWO = NBLST*NBLST + ( NNB+J-JCOL-1 )*2*NNB + NNB
  436. J0 = JROW - NNB
  437. DO JROW = J0, J+2, -NNB
  438. PPW = PPWO
  439. LEN = 2 + J - JCOL
  440. DO I = JROW+NNB-1, JROW, -1
  441. CTEMP = A( I, J )
  442. S = B( I, J )
  443. DO JJ = PPW, PPW+LEN-1
  444. TEMP = WORK( JJ + 2*NNB )
  445. WORK( JJ + 2*NNB ) = CTEMP*TEMP - S*WORK( JJ )
  446. WORK( JJ ) = CONJG( S )*TEMP + CTEMP*WORK( JJ )
  447. END DO
  448. LEN = LEN + 1
  449. PPW = PPW - 2*NNB - 1
  450. END DO
  451. PPWO = PPWO + 4*NNB*NNB
  452. END DO
  453. *
  454. * TOP denotes the number of top rows in A and B that will
  455. * not be updated during the next steps.
  456. *
  457. IF( JCOL.LE.2 ) THEN
  458. TOP = 0
  459. ELSE
  460. TOP = JCOL
  461. END IF
  462. *
  463. * Propagate transformations through B and replace stored
  464. * left sines/cosines by right sines/cosines.
  465. *
  466. DO JJ = N, J+1, -1
  467. *
  468. * Update JJth column of B.
  469. *
  470. DO I = MIN( JJ+1, IHI ), J+2, -1
  471. CTEMP = A( I, J )
  472. S = B( I, J )
  473. TEMP = B( I, JJ )
  474. B( I, JJ ) = CTEMP*TEMP - CONJG( S )*B( I-1, JJ )
  475. B( I-1, JJ ) = S*TEMP + CTEMP*B( I-1, JJ )
  476. END DO
  477. *
  478. * Annihilate B( JJ+1, JJ ).
  479. *
  480. IF( JJ.LT.IHI ) THEN
  481. TEMP = B( JJ+1, JJ+1 )
  482. CALL CLARTG( TEMP, B( JJ+1, JJ ), C, S,
  483. $ B( JJ+1, JJ+1 ) )
  484. B( JJ+1, JJ ) = CZERO
  485. CALL CROT( JJ-TOP, B( TOP+1, JJ+1 ), 1,
  486. $ B( TOP+1, JJ ), 1, C, S )
  487. A( JJ+1, J ) = CMPLX( C )
  488. B( JJ+1, J ) = -CONJG( S )
  489. END IF
  490. END DO
  491. *
  492. * Update A by transformations from right.
  493. *
  494. JJ = MOD( IHI-J-1, 3 )
  495. DO I = IHI-J-3, JJ+1, -3
  496. CTEMP = A( J+1+I, J )
  497. S = -B( J+1+I, J )
  498. C1 = A( J+2+I, J )
  499. S1 = -B( J+2+I, J )
  500. C2 = A( J+3+I, J )
  501. S2 = -B( J+3+I, J )
  502. *
  503. DO K = TOP+1, IHI
  504. TEMP = A( K, J+I )
  505. TEMP1 = A( K, J+I+1 )
  506. TEMP2 = A( K, J+I+2 )
  507. TEMP3 = A( K, J+I+3 )
  508. A( K, J+I+3 ) = C2*TEMP3 + CONJG( S2 )*TEMP2
  509. TEMP2 = -S2*TEMP3 + C2*TEMP2
  510. A( K, J+I+2 ) = C1*TEMP2 + CONJG( S1 )*TEMP1
  511. TEMP1 = -S1*TEMP2 + C1*TEMP1
  512. A( K, J+I+1 ) = CTEMP*TEMP1 + CONJG( S )*TEMP
  513. A( K, J+I ) = -S*TEMP1 + CTEMP*TEMP
  514. END DO
  515. END DO
  516. *
  517. IF( JJ.GT.0 ) THEN
  518. DO I = JJ, 1, -1
  519. C = REAL( A( J+1+I, J ) )
  520. CALL CROT( IHI-TOP, A( TOP+1, J+I+1 ), 1,
  521. $ A( TOP+1, J+I ), 1, C,
  522. $ -CONJG( B( J+1+I, J ) ) )
  523. END DO
  524. END IF
  525. *
  526. * Update (J+1)th column of A by transformations from left.
  527. *
  528. IF ( J .LT. JCOL + NNB - 1 ) THEN
  529. LEN = 1 + J - JCOL
  530. *
  531. * Multiply with the trailing accumulated unitary
  532. * matrix, which takes the form
  533. *
  534. * [ U11 U12 ]
  535. * U = [ ],
  536. * [ U21 U22 ]
  537. *
  538. * where U21 is a LEN-by-LEN matrix and U12 is lower
  539. * triangular.
  540. *
  541. JROW = IHI - NBLST + 1
  542. CALL CGEMV( 'Conjugate', NBLST, LEN, CONE, WORK,
  543. $ NBLST, A( JROW, J+1 ), 1, CZERO,
  544. $ WORK( PW ), 1 )
  545. PPW = PW + LEN
  546. DO I = JROW, JROW+NBLST-LEN-1
  547. WORK( PPW ) = A( I, J+1 )
  548. PPW = PPW + 1
  549. END DO
  550. CALL CTRMV( 'Lower', 'Conjugate', 'Non-unit',
  551. $ NBLST-LEN, WORK( LEN*NBLST + 1 ), NBLST,
  552. $ WORK( PW+LEN ), 1 )
  553. CALL CGEMV( 'Conjugate', LEN, NBLST-LEN, CONE,
  554. $ WORK( (LEN+1)*NBLST - LEN + 1 ), NBLST,
  555. $ A( JROW+NBLST-LEN, J+1 ), 1, CONE,
  556. $ WORK( PW+LEN ), 1 )
  557. PPW = PW
  558. DO I = JROW, JROW+NBLST-1
  559. A( I, J+1 ) = WORK( PPW )
  560. PPW = PPW + 1
  561. END DO
  562. *
  563. * Multiply with the other accumulated unitary
  564. * matrices, which take the form
  565. *
  566. * [ U11 U12 0 ]
  567. * [ ]
  568. * U = [ U21 U22 0 ],
  569. * [ ]
  570. * [ 0 0 I ]
  571. *
  572. * where I denotes the (NNB-LEN)-by-(NNB-LEN) identity
  573. * matrix, U21 is a LEN-by-LEN upper triangular matrix
  574. * and U12 is an NNB-by-NNB lower triangular matrix.
  575. *
  576. PPWO = 1 + NBLST*NBLST
  577. J0 = JROW - NNB
  578. DO JROW = J0, JCOL+1, -NNB
  579. PPW = PW + LEN
  580. DO I = JROW, JROW+NNB-1
  581. WORK( PPW ) = A( I, J+1 )
  582. PPW = PPW + 1
  583. END DO
  584. PPW = PW
  585. DO I = JROW+NNB, JROW+NNB+LEN-1
  586. WORK( PPW ) = A( I, J+1 )
  587. PPW = PPW + 1
  588. END DO
  589. CALL CTRMV( 'Upper', 'Conjugate', 'Non-unit', LEN,
  590. $ WORK( PPWO + NNB ), 2*NNB, WORK( PW ),
  591. $ 1 )
  592. CALL CTRMV( 'Lower', 'Conjugate', 'Non-unit', NNB,
  593. $ WORK( PPWO + 2*LEN*NNB ),
  594. $ 2*NNB, WORK( PW + LEN ), 1 )
  595. CALL CGEMV( 'Conjugate', NNB, LEN, CONE,
  596. $ WORK( PPWO ), 2*NNB, A( JROW, J+1 ), 1,
  597. $ CONE, WORK( PW ), 1 )
  598. CALL CGEMV( 'Conjugate', LEN, NNB, CONE,
  599. $ WORK( PPWO + 2*LEN*NNB + NNB ), 2*NNB,
  600. $ A( JROW+NNB, J+1 ), 1, CONE,
  601. $ WORK( PW+LEN ), 1 )
  602. PPW = PW
  603. DO I = JROW, JROW+LEN+NNB-1
  604. A( I, J+1 ) = WORK( PPW )
  605. PPW = PPW + 1
  606. END DO
  607. PPWO = PPWO + 4*NNB*NNB
  608. END DO
  609. END IF
  610. END DO
  611. *
  612. * Apply accumulated unitary matrices to A.
  613. *
  614. COLA = N - JCOL - NNB + 1
  615. J = IHI - NBLST + 1
  616. CALL CGEMM( 'Conjugate', 'No Transpose', NBLST,
  617. $ COLA, NBLST, CONE, WORK, NBLST,
  618. $ A( J, JCOL+NNB ), LDA, CZERO, WORK( PW ),
  619. $ NBLST )
  620. CALL CLACPY( 'All', NBLST, COLA, WORK( PW ), NBLST,
  621. $ A( J, JCOL+NNB ), LDA )
  622. PPWO = NBLST*NBLST + 1
  623. J0 = J - NNB
  624. DO J = J0, JCOL+1, -NNB
  625. IF ( BLK22 ) THEN
  626. *
  627. * Exploit the structure of
  628. *
  629. * [ U11 U12 ]
  630. * U = [ ]
  631. * [ U21 U22 ],
  632. *
  633. * where all blocks are NNB-by-NNB, U21 is upper
  634. * triangular and U12 is lower triangular.
  635. *
  636. CALL CUNM22( 'Left', 'Conjugate', 2*NNB, COLA, NNB,
  637. $ NNB, WORK( PPWO ), 2*NNB,
  638. $ A( J, JCOL+NNB ), LDA, WORK( PW ),
  639. $ LWORK-PW+1, IERR )
  640. ELSE
  641. *
  642. * Ignore the structure of U.
  643. *
  644. CALL CGEMM( 'Conjugate', 'No Transpose', 2*NNB,
  645. $ COLA, 2*NNB, CONE, WORK( PPWO ), 2*NNB,
  646. $ A( J, JCOL+NNB ), LDA, CZERO, WORK( PW ),
  647. $ 2*NNB )
  648. CALL CLACPY( 'All', 2*NNB, COLA, WORK( PW ), 2*NNB,
  649. $ A( J, JCOL+NNB ), LDA )
  650. END IF
  651. PPWO = PPWO + 4*NNB*NNB
  652. END DO
  653. *
  654. * Apply accumulated unitary matrices to Q.
  655. *
  656. IF( WANTQ ) THEN
  657. J = IHI - NBLST + 1
  658. IF ( INITQ ) THEN
  659. TOPQ = MAX( 2, J - JCOL + 1 )
  660. NH = IHI - TOPQ + 1
  661. ELSE
  662. TOPQ = 1
  663. NH = N
  664. END IF
  665. CALL CGEMM( 'No Transpose', 'No Transpose', NH,
  666. $ NBLST, NBLST, CONE, Q( TOPQ, J ), LDQ,
  667. $ WORK, NBLST, CZERO, WORK( PW ), NH )
  668. CALL CLACPY( 'All', NH, NBLST, WORK( PW ), NH,
  669. $ Q( TOPQ, J ), LDQ )
  670. PPWO = NBLST*NBLST + 1
  671. J0 = J - NNB
  672. DO J = J0, JCOL+1, -NNB
  673. IF ( INITQ ) THEN
  674. TOPQ = MAX( 2, J - JCOL + 1 )
  675. NH = IHI - TOPQ + 1
  676. END IF
  677. IF ( BLK22 ) THEN
  678. *
  679. * Exploit the structure of U.
  680. *
  681. CALL CUNM22( 'Right', 'No Transpose', NH, 2*NNB,
  682. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  683. $ Q( TOPQ, J ), LDQ, WORK( PW ),
  684. $ LWORK-PW+1, IERR )
  685. ELSE
  686. *
  687. * Ignore the structure of U.
  688. *
  689. CALL CGEMM( 'No Transpose', 'No Transpose', NH,
  690. $ 2*NNB, 2*NNB, CONE, Q( TOPQ, J ), LDQ,
  691. $ WORK( PPWO ), 2*NNB, CZERO, WORK( PW ),
  692. $ NH )
  693. CALL CLACPY( 'All', NH, 2*NNB, WORK( PW ), NH,
  694. $ Q( TOPQ, J ), LDQ )
  695. END IF
  696. PPWO = PPWO + 4*NNB*NNB
  697. END DO
  698. END IF
  699. *
  700. * Accumulate right Givens rotations if required.
  701. *
  702. IF ( WANTZ .OR. TOP.GT.0 ) THEN
  703. *
  704. * Initialize small unitary factors that will hold the
  705. * accumulated Givens rotations in workspace.
  706. *
  707. CALL CLASET( 'All', NBLST, NBLST, CZERO, CONE, WORK,
  708. $ NBLST )
  709. PW = NBLST * NBLST + 1
  710. DO I = 1, N2NB
  711. CALL CLASET( 'All', 2*NNB, 2*NNB, CZERO, CONE,
  712. $ WORK( PW ), 2*NNB )
  713. PW = PW + 4*NNB*NNB
  714. END DO
  715. *
  716. * Accumulate Givens rotations into workspace array.
  717. *
  718. DO J = JCOL, JCOL+NNB-1
  719. PPW = ( NBLST + 1 )*( NBLST - 2 ) - J + JCOL + 1
  720. LEN = 2 + J - JCOL
  721. JROW = J + N2NB*NNB + 2
  722. DO I = IHI, JROW, -1
  723. CTEMP = A( I, J )
  724. A( I, J ) = CZERO
  725. S = B( I, J )
  726. B( I, J ) = CZERO
  727. DO JJ = PPW, PPW+LEN-1
  728. TEMP = WORK( JJ + NBLST )
  729. WORK( JJ + NBLST ) = CTEMP*TEMP -
  730. $ CONJG( S )*WORK( JJ )
  731. WORK( JJ ) = S*TEMP + CTEMP*WORK( JJ )
  732. END DO
  733. LEN = LEN + 1
  734. PPW = PPW - NBLST - 1
  735. END DO
  736. *
  737. PPWO = NBLST*NBLST + ( NNB+J-JCOL-1 )*2*NNB + NNB
  738. J0 = JROW - NNB
  739. DO JROW = J0, J+2, -NNB
  740. PPW = PPWO
  741. LEN = 2 + J - JCOL
  742. DO I = JROW+NNB-1, JROW, -1
  743. CTEMP = A( I, J )
  744. A( I, J ) = CZERO
  745. S = B( I, J )
  746. B( I, J ) = CZERO
  747. DO JJ = PPW, PPW+LEN-1
  748. TEMP = WORK( JJ + 2*NNB )
  749. WORK( JJ + 2*NNB ) = CTEMP*TEMP -
  750. $ CONJG( S )*WORK( JJ )
  751. WORK( JJ ) = S*TEMP + CTEMP*WORK( JJ )
  752. END DO
  753. LEN = LEN + 1
  754. PPW = PPW - 2*NNB - 1
  755. END DO
  756. PPWO = PPWO + 4*NNB*NNB
  757. END DO
  758. END DO
  759. ELSE
  760. *
  761. CALL CLASET( 'Lower', IHI - JCOL - 1, NNB, CZERO, CZERO,
  762. $ A( JCOL + 2, JCOL ), LDA )
  763. CALL CLASET( 'Lower', IHI - JCOL - 1, NNB, CZERO, CZERO,
  764. $ B( JCOL + 2, JCOL ), LDB )
  765. END IF
  766. *
  767. * Apply accumulated unitary matrices to A and B.
  768. *
  769. IF ( TOP.GT.0 ) THEN
  770. J = IHI - NBLST + 1
  771. CALL CGEMM( 'No Transpose', 'No Transpose', TOP,
  772. $ NBLST, NBLST, CONE, A( 1, J ), LDA,
  773. $ WORK, NBLST, CZERO, WORK( PW ), TOP )
  774. CALL CLACPY( 'All', TOP, NBLST, WORK( PW ), TOP,
  775. $ A( 1, J ), LDA )
  776. PPWO = NBLST*NBLST + 1
  777. J0 = J - NNB
  778. DO J = J0, JCOL+1, -NNB
  779. IF ( BLK22 ) THEN
  780. *
  781. * Exploit the structure of U.
  782. *
  783. CALL CUNM22( 'Right', 'No Transpose', TOP, 2*NNB,
  784. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  785. $ A( 1, J ), LDA, WORK( PW ),
  786. $ LWORK-PW+1, IERR )
  787. ELSE
  788. *
  789. * Ignore the structure of U.
  790. *
  791. CALL CGEMM( 'No Transpose', 'No Transpose', TOP,
  792. $ 2*NNB, 2*NNB, CONE, A( 1, J ), LDA,
  793. $ WORK( PPWO ), 2*NNB, CZERO,
  794. $ WORK( PW ), TOP )
  795. CALL CLACPY( 'All', TOP, 2*NNB, WORK( PW ), TOP,
  796. $ A( 1, J ), LDA )
  797. END IF
  798. PPWO = PPWO + 4*NNB*NNB
  799. END DO
  800. *
  801. J = IHI - NBLST + 1
  802. CALL CGEMM( 'No Transpose', 'No Transpose', TOP,
  803. $ NBLST, NBLST, CONE, B( 1, J ), LDB,
  804. $ WORK, NBLST, CZERO, WORK( PW ), TOP )
  805. CALL CLACPY( 'All', TOP, NBLST, WORK( PW ), TOP,
  806. $ B( 1, J ), LDB )
  807. PPWO = NBLST*NBLST + 1
  808. J0 = J - NNB
  809. DO J = J0, JCOL+1, -NNB
  810. IF ( BLK22 ) THEN
  811. *
  812. * Exploit the structure of U.
  813. *
  814. CALL CUNM22( 'Right', 'No Transpose', TOP, 2*NNB,
  815. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  816. $ B( 1, J ), LDB, WORK( PW ),
  817. $ LWORK-PW+1, IERR )
  818. ELSE
  819. *
  820. * Ignore the structure of U.
  821. *
  822. CALL CGEMM( 'No Transpose', 'No Transpose', TOP,
  823. $ 2*NNB, 2*NNB, CONE, B( 1, J ), LDB,
  824. $ WORK( PPWO ), 2*NNB, CZERO,
  825. $ WORK( PW ), TOP )
  826. CALL CLACPY( 'All', TOP, 2*NNB, WORK( PW ), TOP,
  827. $ B( 1, J ), LDB )
  828. END IF
  829. PPWO = PPWO + 4*NNB*NNB
  830. END DO
  831. END IF
  832. *
  833. * Apply accumulated unitary matrices to Z.
  834. *
  835. IF( WANTZ ) THEN
  836. J = IHI - NBLST + 1
  837. IF ( INITQ ) THEN
  838. TOPQ = MAX( 2, J - JCOL + 1 )
  839. NH = IHI - TOPQ + 1
  840. ELSE
  841. TOPQ = 1
  842. NH = N
  843. END IF
  844. CALL CGEMM( 'No Transpose', 'No Transpose', NH,
  845. $ NBLST, NBLST, CONE, Z( TOPQ, J ), LDZ,
  846. $ WORK, NBLST, CZERO, WORK( PW ), NH )
  847. CALL CLACPY( 'All', NH, NBLST, WORK( PW ), NH,
  848. $ Z( TOPQ, J ), LDZ )
  849. PPWO = NBLST*NBLST + 1
  850. J0 = J - NNB
  851. DO J = J0, JCOL+1, -NNB
  852. IF ( INITQ ) THEN
  853. TOPQ = MAX( 2, J - JCOL + 1 )
  854. NH = IHI - TOPQ + 1
  855. END IF
  856. IF ( BLK22 ) THEN
  857. *
  858. * Exploit the structure of U.
  859. *
  860. CALL CUNM22( 'Right', 'No Transpose', NH, 2*NNB,
  861. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  862. $ Z( TOPQ, J ), LDZ, WORK( PW ),
  863. $ LWORK-PW+1, IERR )
  864. ELSE
  865. *
  866. * Ignore the structure of U.
  867. *
  868. CALL CGEMM( 'No Transpose', 'No Transpose', NH,
  869. $ 2*NNB, 2*NNB, CONE, Z( TOPQ, J ), LDZ,
  870. $ WORK( PPWO ), 2*NNB, CZERO, WORK( PW ),
  871. $ NH )
  872. CALL CLACPY( 'All', NH, 2*NNB, WORK( PW ), NH,
  873. $ Z( TOPQ, J ), LDZ )
  874. END IF
  875. PPWO = PPWO + 4*NNB*NNB
  876. END DO
  877. END IF
  878. END DO
  879. END IF
  880. *
  881. * Use unblocked code to reduce the rest of the matrix
  882. * Avoid re-initialization of modified Q and Z.
  883. *
  884. COMPQ2 = COMPQ
  885. COMPZ2 = COMPZ
  886. IF ( JCOL.NE.ILO ) THEN
  887. IF ( WANTQ )
  888. $ COMPQ2 = 'V'
  889. IF ( WANTZ )
  890. $ COMPZ2 = 'V'
  891. END IF
  892. *
  893. IF ( JCOL.LT.IHI )
  894. $ CALL CGGHRD( COMPQ2, COMPZ2, N, JCOL, IHI, A, LDA, B, LDB, Q,
  895. $ LDQ, Z, LDZ, IERR )
  896. *
  897. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  898. *
  899. RETURN
  900. *
  901. * End of CGGHD3
  902. *
  903. END