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.

dgghd3.f 32 kB

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