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.

zgghd3.f 32 kB

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