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.

sgghd3.f 32 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. *> \brief \b SGGHD3
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGGHD3 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgghd3.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgghd3.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgghd3.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGGHD3( 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. * REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  30. * $ Z( LDZ, * ), WORK( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> SGGHD3 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 SGGHD3 reduces the original
  66. *> problem to generalized Hessenberg form.
  67. *>
  68. *> This is a blocked variant of SGGHRD, 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 SGGBAL; 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL array, dimension (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 SGGHD3( 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. REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  243. $ Z( LDZ, * ), WORK( * )
  244. * ..
  245. *
  246. * =====================================================================
  247. *
  248. * .. Parameters ..
  249. REAL ZERO, ONE
  250. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+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. REAL C, C1, C2, S, S1, S2, TEMP, TEMP1, TEMP2, TEMP3
  259. * ..
  260. * .. External Functions ..
  261. LOGICAL LSAME
  262. INTEGER ILAENV
  263. REAL SROUNDUP_LWORK
  264. EXTERNAL ILAENV, LSAME, SROUNDUP_LWORK
  265. * ..
  266. * .. External Subroutines ..
  267. EXTERNAL SGGHRD, SLARTG, SLASET, SORM22, SROT, SGEMM,
  268. $ SGEMV, STRMV, SLACPY, XERBLA
  269. * ..
  270. * .. Intrinsic Functions ..
  271. INTRINSIC MAX
  272. * ..
  273. * .. Executable Statements ..
  274. *
  275. * Decode and test the input parameters.
  276. *
  277. INFO = 0
  278. NB = ILAENV( 1, 'SGGHD3', ' ', N, ILO, IHI, -1 )
  279. LWKOPT = MAX( 6*N*NB, 1 )
  280. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  281. INITQ = LSAME( COMPQ, 'I' )
  282. WANTQ = INITQ .OR. LSAME( COMPQ, 'V' )
  283. INITZ = LSAME( COMPZ, 'I' )
  284. WANTZ = INITZ .OR. LSAME( COMPZ, 'V' )
  285. LQUERY = ( LWORK.EQ.-1 )
  286. *
  287. IF( .NOT.LSAME( COMPQ, 'N' ) .AND. .NOT.WANTQ ) THEN
  288. INFO = -1
  289. ELSE IF( .NOT.LSAME( COMPZ, 'N' ) .AND. .NOT.WANTZ ) THEN
  290. INFO = -2
  291. ELSE IF( N.LT.0 ) THEN
  292. INFO = -3
  293. ELSE IF( ILO.LT.1 ) THEN
  294. INFO = -4
  295. ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
  296. INFO = -5
  297. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  298. INFO = -7
  299. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  300. INFO = -9
  301. ELSE IF( ( WANTQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN
  302. INFO = -11
  303. ELSE IF( ( WANTZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN
  304. INFO = -13
  305. ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
  306. INFO = -15
  307. END IF
  308. IF( INFO.NE.0 ) THEN
  309. CALL XERBLA( 'SGGHD3', -INFO )
  310. RETURN
  311. ELSE IF( LQUERY ) THEN
  312. RETURN
  313. END IF
  314. *
  315. * Initialize Q and Z if desired.
  316. *
  317. IF( INITQ )
  318. $ CALL SLASET( 'All', N, N, ZERO, ONE, Q, LDQ )
  319. IF( INITZ )
  320. $ CALL SLASET( 'All', N, N, ZERO, ONE, Z, LDZ )
  321. *
  322. * Zero out lower triangle of B.
  323. *
  324. IF( N.GT.1 )
  325. $ CALL SLASET( 'Lower', N-1, N-1, ZERO, ZERO, B(2, 1), LDB )
  326. *
  327. * Quick return if possible
  328. *
  329. NH = IHI - ILO + 1
  330. IF( NH.LE.1 ) THEN
  331. WORK( 1 ) = ONE
  332. RETURN
  333. END IF
  334. *
  335. * Determine the blocksize.
  336. *
  337. NBMIN = ILAENV( 2, 'SGGHD3', ' ', N, ILO, IHI, -1 )
  338. IF( NB.GT.1 .AND. NB.LT.NH ) THEN
  339. *
  340. * Determine when to use unblocked instead of blocked code.
  341. *
  342. NX = MAX( NB, ILAENV( 3, 'SGGHD3', ' ', N, ILO, IHI, -1 ) )
  343. IF( NX.LT.NH ) THEN
  344. *
  345. * Determine if workspace is large enough for blocked code.
  346. *
  347. IF( LWORK.LT.LWKOPT ) THEN
  348. *
  349. * Not enough workspace to use optimal NB: determine the
  350. * minimum value of NB, and reduce NB or force use of
  351. * unblocked code.
  352. *
  353. NBMIN = MAX( 2, ILAENV( 2, 'SGGHD3', ' ', N, ILO, IHI,
  354. $ -1 ) )
  355. IF( LWORK.GE.6*N*NBMIN ) THEN
  356. NB = LWORK / ( 6*N )
  357. ELSE
  358. NB = 1
  359. END IF
  360. END IF
  361. END IF
  362. END IF
  363. *
  364. IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN
  365. *
  366. * Use unblocked code below
  367. *
  368. JCOL = ILO
  369. *
  370. ELSE
  371. *
  372. * Use blocked code
  373. *
  374. KACC22 = ILAENV( 16, 'SGGHD3', ' ', N, ILO, IHI, -1 )
  375. BLK22 = KACC22.EQ.2
  376. DO JCOL = ILO, IHI-2, NB
  377. NNB = MIN( NB, IHI-JCOL-1 )
  378. *
  379. * Initialize small orthogonal factors that will hold the
  380. * accumulated Givens rotations in workspace.
  381. * N2NB denotes the number of 2*NNB-by-2*NNB factors
  382. * NBLST denotes the (possibly smaller) order of the last
  383. * factor.
  384. *
  385. N2NB = ( IHI-JCOL-1 ) / NNB - 1
  386. NBLST = IHI - JCOL - N2NB*NNB
  387. CALL SLASET( 'All', NBLST, NBLST, ZERO, ONE, WORK, NBLST )
  388. PW = NBLST * NBLST + 1
  389. DO I = 1, N2NB
  390. CALL SLASET( 'All', 2*NNB, 2*NNB, ZERO, ONE,
  391. $ WORK( PW ), 2*NNB )
  392. PW = PW + 4*NNB*NNB
  393. END DO
  394. *
  395. * Reduce columns JCOL:JCOL+NNB-1 of A to Hessenberg form.
  396. *
  397. DO J = JCOL, JCOL+NNB-1
  398. *
  399. * Reduce Jth column of A. Store cosines and sines in Jth
  400. * column of A and B, respectively.
  401. *
  402. DO I = IHI, J+2, -1
  403. TEMP = A( I-1, J )
  404. CALL SLARTG( TEMP, A( I, J ), C, S, A( I-1, J ) )
  405. A( I, J ) = C
  406. B( I, J ) = S
  407. END DO
  408. *
  409. * Accumulate Givens rotations into workspace array.
  410. *
  411. PPW = ( NBLST + 1 )*( NBLST - 2 ) - J + JCOL + 1
  412. LEN = 2 + J - JCOL
  413. JROW = J + N2NB*NNB + 2
  414. DO I = IHI, JROW, -1
  415. C = A( I, J )
  416. S = B( I, J )
  417. DO JJ = PPW, PPW+LEN-1
  418. TEMP = WORK( JJ + NBLST )
  419. WORK( JJ + NBLST ) = C*TEMP - S*WORK( JJ )
  420. WORK( JJ ) = S*TEMP + C*WORK( JJ )
  421. END DO
  422. LEN = LEN + 1
  423. PPW = PPW - NBLST - 1
  424. END DO
  425. *
  426. PPWO = NBLST*NBLST + ( NNB+J-JCOL-1 )*2*NNB + NNB
  427. J0 = JROW - NNB
  428. DO JROW = J0, J+2, -NNB
  429. PPW = PPWO
  430. LEN = 2 + J - JCOL
  431. DO I = JROW+NNB-1, JROW, -1
  432. C = A( I, J )
  433. S = B( I, J )
  434. DO JJ = PPW, PPW+LEN-1
  435. TEMP = WORK( JJ + 2*NNB )
  436. WORK( JJ + 2*NNB ) = C*TEMP - S*WORK( JJ )
  437. WORK( JJ ) = S*TEMP + C*WORK( JJ )
  438. END DO
  439. LEN = LEN + 1
  440. PPW = PPW - 2*NNB - 1
  441. END DO
  442. PPWO = PPWO + 4*NNB*NNB
  443. END DO
  444. *
  445. * TOP denotes the number of top rows in A and B that will
  446. * not be updated during the next steps.
  447. *
  448. IF( JCOL.LE.2 ) THEN
  449. TOP = 0
  450. ELSE
  451. TOP = JCOL
  452. END IF
  453. *
  454. * Propagate transformations through B and replace stored
  455. * left sines/cosines by right sines/cosines.
  456. *
  457. DO JJ = N, J+1, -1
  458. *
  459. * Update JJth column of B.
  460. *
  461. DO I = MIN( JJ+1, IHI ), J+2, -1
  462. C = A( I, J )
  463. S = B( I, J )
  464. TEMP = B( I, JJ )
  465. B( I, JJ ) = C*TEMP - S*B( I-1, JJ )
  466. B( I-1, JJ ) = S*TEMP + C*B( I-1, JJ )
  467. END DO
  468. *
  469. * Annihilate B( JJ+1, JJ ).
  470. *
  471. IF( JJ.LT.IHI ) THEN
  472. TEMP = B( JJ+1, JJ+1 )
  473. CALL SLARTG( TEMP, B( JJ+1, JJ ), C, S,
  474. $ B( JJ+1, JJ+1 ) )
  475. B( JJ+1, JJ ) = ZERO
  476. CALL SROT( JJ-TOP, B( TOP+1, JJ+1 ), 1,
  477. $ B( TOP+1, JJ ), 1, C, S )
  478. A( JJ+1, J ) = C
  479. B( JJ+1, J ) = -S
  480. END IF
  481. END DO
  482. *
  483. * Update A by transformations from right.
  484. * Explicit loop unrolling provides better performance
  485. * compared to SLASR.
  486. * CALL SLASR( 'Right', 'Variable', 'Backward', IHI-TOP,
  487. * $ IHI-J, A( J+2, J ), B( J+2, J ),
  488. * $ A( TOP+1, J+1 ), LDA )
  489. *
  490. JJ = MOD( IHI-J-1, 3 )
  491. DO I = IHI-J-3, JJ+1, -3
  492. C = A( J+1+I, J )
  493. S = -B( J+1+I, J )
  494. C1 = A( J+2+I, J )
  495. S1 = -B( J+2+I, J )
  496. C2 = A( J+3+I, J )
  497. S2 = -B( J+3+I, J )
  498. *
  499. DO K = TOP+1, IHI
  500. TEMP = A( K, J+I )
  501. TEMP1 = A( K, J+I+1 )
  502. TEMP2 = A( K, J+I+2 )
  503. TEMP3 = A( K, J+I+3 )
  504. A( K, J+I+3 ) = C2*TEMP3 + S2*TEMP2
  505. TEMP2 = -S2*TEMP3 + C2*TEMP2
  506. A( K, J+I+2 ) = C1*TEMP2 + S1*TEMP1
  507. TEMP1 = -S1*TEMP2 + C1*TEMP1
  508. A( K, J+I+1 ) = C*TEMP1 + S*TEMP
  509. A( K, J+I ) = -S*TEMP1 + C*TEMP
  510. END DO
  511. END DO
  512. *
  513. IF( JJ.GT.0 ) THEN
  514. DO I = JJ, 1, -1
  515. CALL SROT( IHI-TOP, A( TOP+1, J+I+1 ), 1,
  516. $ A( TOP+1, J+I ), 1, A( J+1+I, J ),
  517. $ -B( J+1+I, J ) )
  518. END DO
  519. END IF
  520. *
  521. * Update (J+1)th column of A by transformations from left.
  522. *
  523. IF ( J .LT. JCOL + NNB - 1 ) THEN
  524. LEN = 1 + J - JCOL
  525. *
  526. * Multiply with the trailing accumulated orthogonal
  527. * matrix, which takes the form
  528. *
  529. * [ U11 U12 ]
  530. * U = [ ],
  531. * [ U21 U22 ]
  532. *
  533. * where U21 is a LEN-by-LEN matrix and U12 is lower
  534. * triangular.
  535. *
  536. JROW = IHI - NBLST + 1
  537. CALL SGEMV( 'Transpose', NBLST, LEN, ONE, WORK,
  538. $ NBLST, A( JROW, J+1 ), 1, ZERO,
  539. $ WORK( PW ), 1 )
  540. PPW = PW + LEN
  541. DO I = JROW, JROW+NBLST-LEN-1
  542. WORK( PPW ) = A( I, J+1 )
  543. PPW = PPW + 1
  544. END DO
  545. CALL STRMV( 'Lower', 'Transpose', 'Non-unit',
  546. $ NBLST-LEN, WORK( LEN*NBLST + 1 ), NBLST,
  547. $ WORK( PW+LEN ), 1 )
  548. CALL SGEMV( 'Transpose', LEN, NBLST-LEN, ONE,
  549. $ WORK( (LEN+1)*NBLST - LEN + 1 ), NBLST,
  550. $ A( JROW+NBLST-LEN, J+1 ), 1, ONE,
  551. $ WORK( PW+LEN ), 1 )
  552. PPW = PW
  553. DO I = JROW, JROW+NBLST-1
  554. A( I, J+1 ) = WORK( PPW )
  555. PPW = PPW + 1
  556. END DO
  557. *
  558. * Multiply with the other accumulated orthogonal
  559. * matrices, which take the form
  560. *
  561. * [ U11 U12 0 ]
  562. * [ ]
  563. * U = [ U21 U22 0 ],
  564. * [ ]
  565. * [ 0 0 I ]
  566. *
  567. * where I denotes the (NNB-LEN)-by-(NNB-LEN) identity
  568. * matrix, U21 is a LEN-by-LEN upper triangular matrix
  569. * and U12 is an NNB-by-NNB lower triangular matrix.
  570. *
  571. PPWO = 1 + NBLST*NBLST
  572. J0 = JROW - NNB
  573. DO JROW = J0, JCOL+1, -NNB
  574. PPW = PW + LEN
  575. DO I = JROW, JROW+NNB-1
  576. WORK( PPW ) = A( I, J+1 )
  577. PPW = PPW + 1
  578. END DO
  579. PPW = PW
  580. DO I = JROW+NNB, JROW+NNB+LEN-1
  581. WORK( PPW ) = A( I, J+1 )
  582. PPW = PPW + 1
  583. END DO
  584. CALL STRMV( 'Upper', 'Transpose', 'Non-unit', LEN,
  585. $ WORK( PPWO + NNB ), 2*NNB, WORK( PW ),
  586. $ 1 )
  587. CALL STRMV( 'Lower', 'Transpose', 'Non-unit', NNB,
  588. $ WORK( PPWO + 2*LEN*NNB ),
  589. $ 2*NNB, WORK( PW + LEN ), 1 )
  590. CALL SGEMV( 'Transpose', NNB, LEN, ONE,
  591. $ WORK( PPWO ), 2*NNB, A( JROW, J+1 ), 1,
  592. $ ONE, WORK( PW ), 1 )
  593. CALL SGEMV( 'Transpose', LEN, NNB, ONE,
  594. $ WORK( PPWO + 2*LEN*NNB + NNB ), 2*NNB,
  595. $ A( JROW+NNB, J+1 ), 1, ONE,
  596. $ WORK( PW+LEN ), 1 )
  597. PPW = PW
  598. DO I = JROW, JROW+LEN+NNB-1
  599. A( I, J+1 ) = WORK( PPW )
  600. PPW = PPW + 1
  601. END DO
  602. PPWO = PPWO + 4*NNB*NNB
  603. END DO
  604. END IF
  605. END DO
  606. *
  607. * Apply accumulated orthogonal matrices to A.
  608. *
  609. COLA = N - JCOL - NNB + 1
  610. J = IHI - NBLST + 1
  611. CALL SGEMM( 'Transpose', 'No Transpose', NBLST,
  612. $ COLA, NBLST, ONE, WORK, NBLST,
  613. $ A( J, JCOL+NNB ), LDA, ZERO, WORK( PW ),
  614. $ NBLST )
  615. CALL SLACPY( 'All', NBLST, COLA, WORK( PW ), NBLST,
  616. $ A( J, JCOL+NNB ), LDA )
  617. PPWO = NBLST*NBLST + 1
  618. J0 = J - NNB
  619. DO J = J0, JCOL+1, -NNB
  620. IF ( BLK22 ) THEN
  621. *
  622. * Exploit the structure of
  623. *
  624. * [ U11 U12 ]
  625. * U = [ ]
  626. * [ U21 U22 ],
  627. *
  628. * where all blocks are NNB-by-NNB, U21 is upper
  629. * triangular and U12 is lower triangular.
  630. *
  631. CALL SORM22( 'Left', 'Transpose', 2*NNB, COLA, NNB,
  632. $ NNB, WORK( PPWO ), 2*NNB,
  633. $ A( J, JCOL+NNB ), LDA, WORK( PW ),
  634. $ LWORK-PW+1, IERR )
  635. ELSE
  636. *
  637. * Ignore the structure of U.
  638. *
  639. CALL SGEMM( 'Transpose', 'No Transpose', 2*NNB,
  640. $ COLA, 2*NNB, ONE, WORK( PPWO ), 2*NNB,
  641. $ A( J, JCOL+NNB ), LDA, ZERO, WORK( PW ),
  642. $ 2*NNB )
  643. CALL SLACPY( 'All', 2*NNB, COLA, WORK( PW ), 2*NNB,
  644. $ A( J, JCOL+NNB ), LDA )
  645. END IF
  646. PPWO = PPWO + 4*NNB*NNB
  647. END DO
  648. *
  649. * Apply accumulated orthogonal matrices to Q.
  650. *
  651. IF( WANTQ ) THEN
  652. J = IHI - NBLST + 1
  653. IF ( INITQ ) THEN
  654. TOPQ = MAX( 2, J - JCOL + 1 )
  655. NH = IHI - TOPQ + 1
  656. ELSE
  657. TOPQ = 1
  658. NH = N
  659. END IF
  660. CALL SGEMM( 'No Transpose', 'No Transpose', NH,
  661. $ NBLST, NBLST, ONE, Q( TOPQ, J ), LDQ,
  662. $ WORK, NBLST, ZERO, WORK( PW ), NH )
  663. CALL SLACPY( 'All', NH, NBLST, WORK( PW ), NH,
  664. $ Q( TOPQ, J ), LDQ )
  665. PPWO = NBLST*NBLST + 1
  666. J0 = J - NNB
  667. DO J = J0, JCOL+1, -NNB
  668. IF ( INITQ ) THEN
  669. TOPQ = MAX( 2, J - JCOL + 1 )
  670. NH = IHI - TOPQ + 1
  671. END IF
  672. IF ( BLK22 ) THEN
  673. *
  674. * Exploit the structure of U.
  675. *
  676. CALL SORM22( 'Right', 'No Transpose', NH, 2*NNB,
  677. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  678. $ Q( TOPQ, J ), LDQ, WORK( PW ),
  679. $ LWORK-PW+1, IERR )
  680. ELSE
  681. *
  682. * Ignore the structure of U.
  683. *
  684. CALL SGEMM( 'No Transpose', 'No Transpose', NH,
  685. $ 2*NNB, 2*NNB, ONE, Q( TOPQ, J ), LDQ,
  686. $ WORK( PPWO ), 2*NNB, ZERO, WORK( PW ),
  687. $ NH )
  688. CALL SLACPY( 'All', NH, 2*NNB, WORK( PW ), NH,
  689. $ Q( TOPQ, J ), LDQ )
  690. END IF
  691. PPWO = PPWO + 4*NNB*NNB
  692. END DO
  693. END IF
  694. *
  695. * Accumulate right Givens rotations if required.
  696. *
  697. IF ( WANTZ .OR. TOP.GT.0 ) THEN
  698. *
  699. * Initialize small orthogonal factors that will hold the
  700. * accumulated Givens rotations in workspace.
  701. *
  702. CALL SLASET( 'All', NBLST, NBLST, ZERO, ONE, WORK,
  703. $ NBLST )
  704. PW = NBLST * NBLST + 1
  705. DO I = 1, N2NB
  706. CALL SLASET( 'All', 2*NNB, 2*NNB, ZERO, ONE,
  707. $ WORK( PW ), 2*NNB )
  708. PW = PW + 4*NNB*NNB
  709. END DO
  710. *
  711. * Accumulate Givens rotations into workspace array.
  712. *
  713. DO J = JCOL, JCOL+NNB-1
  714. PPW = ( NBLST + 1 )*( NBLST - 2 ) - J + JCOL + 1
  715. LEN = 2 + J - JCOL
  716. JROW = J + N2NB*NNB + 2
  717. DO I = IHI, JROW, -1
  718. C = A( I, J )
  719. A( I, J ) = ZERO
  720. S = B( I, J )
  721. B( I, J ) = ZERO
  722. DO JJ = PPW, PPW+LEN-1
  723. TEMP = WORK( JJ + NBLST )
  724. WORK( JJ + NBLST ) = C*TEMP - S*WORK( JJ )
  725. WORK( JJ ) = S*TEMP + C*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. C = A( I, J )
  738. A( I, J ) = ZERO
  739. S = B( I, J )
  740. B( I, J ) = ZERO
  741. DO JJ = PPW, PPW+LEN-1
  742. TEMP = WORK( JJ + 2*NNB )
  743. WORK( JJ + 2*NNB ) = C*TEMP - S*WORK( JJ )
  744. WORK( JJ ) = S*TEMP + C*WORK( JJ )
  745. END DO
  746. LEN = LEN + 1
  747. PPW = PPW - 2*NNB - 1
  748. END DO
  749. PPWO = PPWO + 4*NNB*NNB
  750. END DO
  751. END DO
  752. ELSE
  753. *
  754. CALL SLASET( 'Lower', IHI - JCOL - 1, NNB, ZERO, ZERO,
  755. $ A( JCOL + 2, JCOL ), LDA )
  756. CALL SLASET( 'Lower', IHI - JCOL - 1, NNB, ZERO, ZERO,
  757. $ B( JCOL + 2, JCOL ), LDB )
  758. END IF
  759. *
  760. * Apply accumulated orthogonal matrices to A and B.
  761. *
  762. IF ( TOP.GT.0 ) THEN
  763. J = IHI - NBLST + 1
  764. CALL SGEMM( 'No Transpose', 'No Transpose', TOP,
  765. $ NBLST, NBLST, ONE, A( 1, J ), LDA,
  766. $ WORK, NBLST, ZERO, WORK( PW ), TOP )
  767. CALL SLACPY( 'All', TOP, NBLST, WORK( PW ), TOP,
  768. $ A( 1, J ), LDA )
  769. PPWO = NBLST*NBLST + 1
  770. J0 = J - NNB
  771. DO J = J0, JCOL+1, -NNB
  772. IF ( BLK22 ) THEN
  773. *
  774. * Exploit the structure of U.
  775. *
  776. CALL SORM22( 'Right', 'No Transpose', TOP, 2*NNB,
  777. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  778. $ A( 1, J ), LDA, WORK( PW ),
  779. $ LWORK-PW+1, IERR )
  780. ELSE
  781. *
  782. * Ignore the structure of U.
  783. *
  784. CALL SGEMM( 'No Transpose', 'No Transpose', TOP,
  785. $ 2*NNB, 2*NNB, ONE, A( 1, J ), LDA,
  786. $ WORK( PPWO ), 2*NNB, ZERO,
  787. $ WORK( PW ), TOP )
  788. CALL SLACPY( 'All', TOP, 2*NNB, WORK( PW ), TOP,
  789. $ A( 1, J ), LDA )
  790. END IF
  791. PPWO = PPWO + 4*NNB*NNB
  792. END DO
  793. *
  794. J = IHI - NBLST + 1
  795. CALL SGEMM( 'No Transpose', 'No Transpose', TOP,
  796. $ NBLST, NBLST, ONE, B( 1, J ), LDB,
  797. $ WORK, NBLST, ZERO, WORK( PW ), TOP )
  798. CALL SLACPY( 'All', TOP, NBLST, WORK( PW ), TOP,
  799. $ B( 1, J ), LDB )
  800. PPWO = NBLST*NBLST + 1
  801. J0 = J - NNB
  802. DO J = J0, JCOL+1, -NNB
  803. IF ( BLK22 ) THEN
  804. *
  805. * Exploit the structure of U.
  806. *
  807. CALL SORM22( 'Right', 'No Transpose', TOP, 2*NNB,
  808. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  809. $ B( 1, J ), LDB, WORK( PW ),
  810. $ LWORK-PW+1, IERR )
  811. ELSE
  812. *
  813. * Ignore the structure of U.
  814. *
  815. CALL SGEMM( 'No Transpose', 'No Transpose', TOP,
  816. $ 2*NNB, 2*NNB, ONE, B( 1, J ), LDB,
  817. $ WORK( PPWO ), 2*NNB, ZERO,
  818. $ WORK( PW ), TOP )
  819. CALL SLACPY( 'All', TOP, 2*NNB, WORK( PW ), TOP,
  820. $ B( 1, J ), LDB )
  821. END IF
  822. PPWO = PPWO + 4*NNB*NNB
  823. END DO
  824. END IF
  825. *
  826. * Apply accumulated orthogonal matrices to Z.
  827. *
  828. IF( WANTZ ) THEN
  829. J = IHI - NBLST + 1
  830. IF ( INITQ ) THEN
  831. TOPQ = MAX( 2, J - JCOL + 1 )
  832. NH = IHI - TOPQ + 1
  833. ELSE
  834. TOPQ = 1
  835. NH = N
  836. END IF
  837. CALL SGEMM( 'No Transpose', 'No Transpose', NH,
  838. $ NBLST, NBLST, ONE, Z( TOPQ, J ), LDZ,
  839. $ WORK, NBLST, ZERO, WORK( PW ), NH )
  840. CALL SLACPY( 'All', NH, NBLST, WORK( PW ), NH,
  841. $ Z( TOPQ, J ), LDZ )
  842. PPWO = NBLST*NBLST + 1
  843. J0 = J - NNB
  844. DO J = J0, JCOL+1, -NNB
  845. IF ( INITQ ) THEN
  846. TOPQ = MAX( 2, J - JCOL + 1 )
  847. NH = IHI - TOPQ + 1
  848. END IF
  849. IF ( BLK22 ) THEN
  850. *
  851. * Exploit the structure of U.
  852. *
  853. CALL SORM22( 'Right', 'No Transpose', NH, 2*NNB,
  854. $ NNB, NNB, WORK( PPWO ), 2*NNB,
  855. $ Z( TOPQ, J ), LDZ, WORK( PW ),
  856. $ LWORK-PW+1, IERR )
  857. ELSE
  858. *
  859. * Ignore the structure of U.
  860. *
  861. CALL SGEMM( 'No Transpose', 'No Transpose', NH,
  862. $ 2*NNB, 2*NNB, ONE, Z( TOPQ, J ), LDZ,
  863. $ WORK( PPWO ), 2*NNB, ZERO, WORK( PW ),
  864. $ NH )
  865. CALL SLACPY( 'All', NH, 2*NNB, WORK( PW ), NH,
  866. $ Z( TOPQ, J ), LDZ )
  867. END IF
  868. PPWO = PPWO + 4*NNB*NNB
  869. END DO
  870. END IF
  871. END DO
  872. END IF
  873. *
  874. * Use unblocked code to reduce the rest of the matrix
  875. * Avoid re-initialization of modified Q and Z.
  876. *
  877. COMPQ2 = COMPQ
  878. COMPZ2 = COMPZ
  879. IF ( JCOL.NE.ILO ) THEN
  880. IF ( WANTQ )
  881. $ COMPQ2 = 'V'
  882. IF ( WANTZ )
  883. $ COMPZ2 = 'V'
  884. END IF
  885. *
  886. IF ( JCOL.LT.IHI )
  887. $ CALL SGGHRD( COMPQ2, COMPZ2, N, JCOL, IHI, A, LDA, B, LDB, Q,
  888. $ LDQ, Z, LDZ, IERR )
  889. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  890. *
  891. RETURN
  892. *
  893. * End of SGGHD3
  894. *
  895. END