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.

claqz0.f 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. *> \brief \b CLAQZ0
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CLAQZ0 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/CLAQZ0.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/CLAQZ0.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/CLAQZ0.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CLAQZ0( WANTS, WANTQ, WANTZ, N, ILO, IHI, A, LDA, B,
  22. * $ LDB, ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK, RWORK, REC,
  23. * $ INFO )
  24. * IMPLICIT NONE
  25. *
  26. * Arguments
  27. * CHARACTER, INTENT( IN ) :: WANTS, WANTQ, WANTZ
  28. * INTEGER, INTENT( IN ) :: N, ILO, IHI, LDA, LDB, LDQ, LDZ, LWORK,
  29. * $ REC
  30. * INTEGER, INTENT( OUT ) :: INFO
  31. * COMPLEX, INTENT( INOUT ) :: A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  32. * $ Z( LDZ, * ), ALPHA( * ), BETA( * ), WORK( * )
  33. * REAL, INTENT( OUT ) :: RWORK( * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> CLAQZ0 computes the eigenvalues of a matrix pair (H,T),
  43. *> where H is an upper Hessenberg matrix and T is upper triangular,
  44. *> using the double-shift QZ method.
  45. *> Matrix pairs of this type are produced by the reduction to
  46. *> generalized upper Hessenberg form of a matrix pair (A,B):
  47. *>
  48. *> A = Q1*H*Z1**H, B = Q1*T*Z1**H,
  49. *>
  50. *> as computed by CGGHRD.
  51. *>
  52. *> If JOB='S', then the Hessenberg-triangular pair (H,T) is
  53. *> also reduced to generalized Schur form,
  54. *>
  55. *> H = Q*S*Z**H, T = Q*P*Z**H,
  56. *>
  57. *> where Q and Z are unitary matrices, P and S are an upper triangular
  58. *> matrices.
  59. *>
  60. *> Optionally, the unitary matrix Q from the generalized Schur
  61. *> factorization may be postmultiplied into an input matrix Q1, and the
  62. *> unitary matrix Z may be postmultiplied into an input matrix Z1.
  63. *> If Q1 and Z1 are the unitary matrices from CGGHRD that reduced
  64. *> the matrix pair (A,B) to generalized upper Hessenberg form, then the
  65. *> output matrices Q1*Q and Z1*Z are the unitary factors from the
  66. *> generalized Schur factorization of (A,B):
  67. *>
  68. *> A = (Q1*Q)*S*(Z1*Z)**H, B = (Q1*Q)*P*(Z1*Z)**H.
  69. *>
  70. *> To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently,
  71. *> of (A,B)) are computed as a pair of values (alpha,beta), where alpha is
  72. *> complex and beta real.
  73. *> If beta is nonzero, lambda = alpha / beta is an eigenvalue of the
  74. *> generalized nonsymmetric eigenvalue problem (GNEP)
  75. *> A*x = lambda*B*x
  76. *> and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
  77. *> alternate form of the GNEP
  78. *> mu*A*y = B*y.
  79. *> Eigenvalues can be read directly from the generalized Schur
  80. *> form:
  81. *> alpha = S(i,i), beta = P(i,i).
  82. *>
  83. *> Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
  84. *> Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
  85. *> pp. 241--256.
  86. *>
  87. *> Ref: B. Kagstrom, D. Kressner, "Multishift Variants of the QZ
  88. *> Algorithm with Aggressive Early Deflation", SIAM J. Numer.
  89. *> Anal., 29(2006), pp. 199--227.
  90. *>
  91. *> Ref: T. Steel, D. Camps, K. Meerbergen, R. Vandebril "A multishift,
  92. *> multipole rational QZ method with aggressive early deflation"
  93. *> \endverbatim
  94. *
  95. * Arguments:
  96. * ==========
  97. *
  98. *> \param[in] WANTS
  99. *> \verbatim
  100. *> WANTS is CHARACTER*1
  101. *> = 'E': Compute eigenvalues only;
  102. *> = 'S': Compute eigenvalues and the Schur form.
  103. *> \endverbatim
  104. *>
  105. *> \param[in] WANTQ
  106. *> \verbatim
  107. *> WANTQ is CHARACTER*1
  108. *> = 'N': Left Schur vectors (Q) are not computed;
  109. *> = 'I': Q is initialized to the unit matrix and the matrix Q
  110. *> of left Schur vectors of (A,B) is returned;
  111. *> = 'V': Q must contain an unitary matrix Q1 on entry and
  112. *> the product Q1*Q is returned.
  113. *> \endverbatim
  114. *>
  115. *> \param[in] WANTZ
  116. *> \verbatim
  117. *> WANTZ is CHARACTER*1
  118. *> = 'N': Right Schur vectors (Z) are not computed;
  119. *> = 'I': Z is initialized to the unit matrix and the matrix Z
  120. *> of right Schur vectors of (A,B) is returned;
  121. *> = 'V': Z must contain an unitary matrix Z1 on entry and
  122. *> the product Z1*Z is returned.
  123. *> \endverbatim
  124. *>
  125. *> \param[in] N
  126. *> \verbatim
  127. *> N is INTEGER
  128. *> The order of the matrices A, B, Q, and Z. N >= 0.
  129. *> \endverbatim
  130. *>
  131. *> \param[in] ILO
  132. *> \verbatim
  133. *> ILO is INTEGER
  134. *> \endverbatim
  135. *>
  136. *> \param[in] IHI
  137. *> \verbatim
  138. *> IHI is INTEGER
  139. *> ILO and IHI mark the rows and columns of A which are in
  140. *> Hessenberg form. It is assumed that A is already upper
  141. *> triangular in rows and columns 1:ILO-1 and IHI+1:N.
  142. *> If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0.
  143. *> \endverbatim
  144. *>
  145. *> \param[in,out] A
  146. *> \verbatim
  147. *> A is COMPLEX array, dimension (LDA, N)
  148. *> On entry, the N-by-N upper Hessenberg matrix A.
  149. *> On exit, if JOB = 'S', A contains the upper triangular
  150. *> matrix S from the generalized Schur factorization.
  151. *> If JOB = 'E', the diagonal of A matches that of S, but
  152. *> the rest of A is unspecified.
  153. *> \endverbatim
  154. *>
  155. *> \param[in] LDA
  156. *> \verbatim
  157. *> LDA is INTEGER
  158. *> The leading dimension of the array A. LDA >= max( 1, N ).
  159. *> \endverbatim
  160. *>
  161. *> \param[in,out] B
  162. *> \verbatim
  163. *> B is COMPLEX array, dimension (LDB, N)
  164. *> On entry, the N-by-N upper triangular matrix B.
  165. *> On exit, if JOB = 'S', B contains the upper triangular
  166. *> matrix P from the generalized Schur factorization.
  167. *> If JOB = 'E', the diagonal of B matches that of P, but
  168. *> the rest of B is unspecified.
  169. *> \endverbatim
  170. *>
  171. *> \param[in] LDB
  172. *> \verbatim
  173. *> LDB is INTEGER
  174. *> The leading dimension of the array B. LDB >= max( 1, N ).
  175. *> \endverbatim
  176. *>
  177. *> \param[out] ALPHA
  178. *> \verbatim
  179. *> ALPHA is COMPLEX array, dimension (N)
  180. *> Each scalar alpha defining an eigenvalue
  181. *> of GNEP.
  182. *> \endverbatim
  183. *>
  184. *> \param[out] BETA
  185. *> \verbatim
  186. *> BETA is COMPLEX array, dimension (N)
  187. *> The scalars beta that define the eigenvalues of GNEP.
  188. *> Together, the quantities alpha = ALPHA(j) and
  189. *> beta = BETA(j) represent the j-th eigenvalue of the matrix
  190. *> pair (A,B), in one of the forms lambda = alpha/beta or
  191. *> mu = beta/alpha. Since either lambda or mu may overflow,
  192. *> they should not, in general, be computed.
  193. *> \endverbatim
  194. *>
  195. *> \param[in,out] Q
  196. *> \verbatim
  197. *> Q is COMPLEX array, dimension (LDQ, N)
  198. *> On entry, if COMPQ = 'V', the unitary matrix Q1 used in
  199. *> the reduction of (A,B) to generalized Hessenberg form.
  200. *> On exit, if COMPQ = 'I', the unitary matrix of left Schur
  201. *> vectors of (A,B), and if COMPQ = 'V', the unitary matrix
  202. *> of left Schur vectors of (A,B).
  203. *> Not referenced if COMPQ = 'N'.
  204. *> \endverbatim
  205. *>
  206. *> \param[in] LDQ
  207. *> \verbatim
  208. *> LDQ is INTEGER
  209. *> The leading dimension of the array Q. LDQ >= 1.
  210. *> If COMPQ='V' or 'I', then LDQ >= N.
  211. *> \endverbatim
  212. *>
  213. *> \param[in,out] Z
  214. *> \verbatim
  215. *> Z is COMPLEX array, dimension (LDZ, N)
  216. *> On entry, if COMPZ = 'V', the unitary matrix Z1 used in
  217. *> the reduction of (A,B) to generalized Hessenberg form.
  218. *> On exit, if COMPZ = 'I', the unitary matrix of
  219. *> right Schur vectors of (H,T), and if COMPZ = 'V', the
  220. *> unitary matrix of right Schur vectors of (A,B).
  221. *> Not referenced if COMPZ = 'N'.
  222. *> \endverbatim
  223. *>
  224. *> \param[in] LDZ
  225. *> \verbatim
  226. *> LDZ is INTEGER
  227. *> The leading dimension of the array Z. LDZ >= 1.
  228. *> If COMPZ='V' or 'I', then LDZ >= N.
  229. *> \endverbatim
  230. *>
  231. *> \param[out] WORK
  232. *> \verbatim
  233. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  234. *> On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
  235. *> \endverbatim
  236. *>
  237. *> \param[in] LWORK
  238. *> \verbatim
  239. *> LWORK is INTEGER
  240. *> The dimension of the array WORK. LWORK >= max(1,N).
  241. *>
  242. *> If LWORK = -1, then a workspace query is assumed; the routine
  243. *> only calculates the optimal size of the WORK array, returns
  244. *> this value as the first entry of the WORK array, and no error
  245. *> message related to LWORK is issued by XERBLA.
  246. *> \endverbatim
  247. *>
  248. *> \param[out] RWORK
  249. *> \verbatim
  250. *> RWORK is REAL array, dimension (N)
  251. *> \endverbatim
  252. *>
  253. *> \param[in] REC
  254. *> \verbatim
  255. *> REC is INTEGER
  256. *> REC indicates the current recursion level. Should be set
  257. *> to 0 on first call.
  258. *> \endverbatim
  259. *>
  260. *> \param[out] INFO
  261. *> \verbatim
  262. *> INFO is INTEGER
  263. *> = 0: successful exit
  264. *> < 0: if INFO = -i, the i-th argument had an illegal value
  265. *> = 1,...,N: the QZ iteration did not converge. (A,B) is not
  266. *> in Schur form, but ALPHA(i) and
  267. *> BETA(i), i=INFO+1,...,N should be correct.
  268. *> \endverbatim
  269. *
  270. * Authors:
  271. * ========
  272. *
  273. *> \author Thijs Steel, KU Leuven
  274. *
  275. *> \date May 2020
  276. *
  277. *> \ingroup complexGEcomputational
  278. *>
  279. * =====================================================================
  280. RECURSIVE SUBROUTINE CLAQZ0( WANTS, WANTQ, WANTZ, N, ILO, IHI, A,
  281. $ LDA, B, LDB, ALPHA, BETA, Q, LDQ, Z,
  282. $ LDZ, WORK, LWORK, RWORK, REC,
  283. $ INFO )
  284. IMPLICIT NONE
  285. * Arguments
  286. CHARACTER, INTENT( IN ) :: WANTS, WANTQ, WANTZ
  287. INTEGER, INTENT( IN ) :: N, ILO, IHI, LDA, LDB, LDQ, LDZ, LWORK,
  288. $ REC
  289. INTEGER, INTENT( OUT ) :: INFO
  290. COMPLEX, INTENT( INOUT ) :: A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
  291. $ Z( LDZ, * ), ALPHA( * ), BETA( * ), WORK( * )
  292. REAL, INTENT( OUT ) :: RWORK( * )
  293. * Parameters
  294. COMPLEX CZERO, CONE
  295. PARAMETER ( CZERO = ( 0.0, 0.0 ), CONE = ( 1.0, 0.0 ) )
  296. REAL :: ZERO, ONE, HALF
  297. PARAMETER( ZERO = 0.0, ONE = 1.0, HALF = 0.5 )
  298. * Local scalars
  299. REAL :: SMLNUM, ULP, SAFMIN, SAFMAX, C1, TEMPR, BNORM, BTOL
  300. COMPLEX :: ESHIFT, S1, TEMP
  301. INTEGER :: ISTART, ISTOP, IITER, MAXIT, ISTART2, K, LD, NSHIFTS,
  302. $ NBLOCK, NW, NMIN, NIBBLE, N_UNDEFLATED, N_DEFLATED,
  303. $ NS, SWEEP_INFO, SHIFTPOS, LWORKREQ, K2, ISTARTM,
  304. $ ISTOPM, IWANTS, IWANTQ, IWANTZ, NORM_INFO, AED_INFO,
  305. $ NWR, NBR, NSR, ITEMP1, ITEMP2, RCOST
  306. LOGICAL :: ILSCHUR, ILQ, ILZ
  307. CHARACTER :: JBCMPZ*3
  308. * External Functions
  309. EXTERNAL :: XERBLA, CHGEQZ, CLAQZ2, CLAQZ3, CLASET,
  310. $ CLARTG, CROT
  311. REAL, EXTERNAL :: SLAMCH, CLANHS
  312. LOGICAL, EXTERNAL :: LSAME
  313. INTEGER, EXTERNAL :: ILAENV
  314. *
  315. * Decode wantS,wantQ,wantZ
  316. *
  317. IF( LSAME( WANTS, 'E' ) ) THEN
  318. ILSCHUR = .FALSE.
  319. IWANTS = 1
  320. ELSE IF( LSAME( WANTS, 'S' ) ) THEN
  321. ILSCHUR = .TRUE.
  322. IWANTS = 2
  323. ELSE
  324. IWANTS = 0
  325. END IF
  326. IF( LSAME( WANTQ, 'N' ) ) THEN
  327. ILQ = .FALSE.
  328. IWANTQ = 1
  329. ELSE IF( LSAME( WANTQ, 'V' ) ) THEN
  330. ILQ = .TRUE.
  331. IWANTQ = 2
  332. ELSE IF( LSAME( WANTQ, 'I' ) ) THEN
  333. ILQ = .TRUE.
  334. IWANTQ = 3
  335. ELSE
  336. IWANTQ = 0
  337. END IF
  338. IF( LSAME( WANTZ, 'N' ) ) THEN
  339. ILZ = .FALSE.
  340. IWANTZ = 1
  341. ELSE IF( LSAME( WANTZ, 'V' ) ) THEN
  342. ILZ = .TRUE.
  343. IWANTZ = 2
  344. ELSE IF( LSAME( WANTZ, 'I' ) ) THEN
  345. ILZ = .TRUE.
  346. IWANTZ = 3
  347. ELSE
  348. IWANTZ = 0
  349. END IF
  350. *
  351. * Check Argument Values
  352. *
  353. INFO = 0
  354. IF( IWANTS.EQ.0 ) THEN
  355. INFO = -1
  356. ELSE IF( IWANTQ.EQ.0 ) THEN
  357. INFO = -2
  358. ELSE IF( IWANTZ.EQ.0 ) THEN
  359. INFO = -3
  360. ELSE IF( N.LT.0 ) THEN
  361. INFO = -4
  362. ELSE IF( ILO.LT.1 ) THEN
  363. INFO = -5
  364. ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
  365. INFO = -6
  366. ELSE IF( LDA.LT.N ) THEN
  367. INFO = -8
  368. ELSE IF( LDB.LT.N ) THEN
  369. INFO = -10
  370. ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
  371. INFO = -15
  372. ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
  373. INFO = -17
  374. END IF
  375. IF( INFO.NE.0 ) THEN
  376. CALL XERBLA( 'CLAQZ0', -INFO )
  377. RETURN
  378. END IF
  379. *
  380. * Quick return if possible
  381. *
  382. IF( N.LE.0 ) THEN
  383. WORK( 1 ) = REAL( 1 )
  384. RETURN
  385. END IF
  386. *
  387. * Get the parameters
  388. *
  389. JBCMPZ( 1:1 ) = WANTS
  390. JBCMPZ( 2:2 ) = WANTQ
  391. JBCMPZ( 3:3 ) = WANTZ
  392. NMIN = ILAENV( 12, 'CLAQZ0', JBCMPZ, N, ILO, IHI, LWORK )
  393. NWR = ILAENV( 13, 'CLAQZ0', JBCMPZ, N, ILO, IHI, LWORK )
  394. NWR = MAX( 2, NWR )
  395. NWR = MIN( IHI-ILO+1, ( N-1 ) / 3, NWR )
  396. NIBBLE = ILAENV( 14, 'CLAQZ0', JBCMPZ, N, ILO, IHI, LWORK )
  397. NSR = ILAENV( 15, 'CLAQZ0', JBCMPZ, N, ILO, IHI, LWORK )
  398. NSR = MIN( NSR, ( N+6 ) / 9, IHI-ILO )
  399. NSR = MAX( 2, NSR-MOD( NSR, 2 ) )
  400. RCOST = ILAENV( 17, 'CLAQZ0', JBCMPZ, N, ILO, IHI, LWORK )
  401. ITEMP1 = INT( NSR/SQRT( 1+2*NSR/( REAL( RCOST )/100*N ) ) )
  402. ITEMP1 = ( ( ITEMP1-1 )/4 )*4+4
  403. NBR = NSR+ITEMP1
  404. IF( N .LT. NMIN .OR. REC .GE. 2 ) THEN
  405. CALL CHGEQZ( WANTS, WANTQ, WANTZ, N, ILO, IHI, A, LDA, B, LDB,
  406. $ ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK, RWORK,
  407. $ INFO )
  408. RETURN
  409. END IF
  410. *
  411. * Find out required workspace
  412. *
  413. * Workspace query to CLAQZ2
  414. NW = MAX( NWR, NMIN )
  415. CALL CLAQZ2( ILSCHUR, ILQ, ILZ, N, ILO, IHI, NW, A, LDA, B, LDB,
  416. $ Q, LDQ, Z, LDZ, N_UNDEFLATED, N_DEFLATED, ALPHA,
  417. $ BETA, WORK, NW, WORK, NW, WORK, -1, RWORK, REC,
  418. $ AED_INFO )
  419. ITEMP1 = INT( WORK( 1 ) )
  420. * Workspace query to CLAQZ3
  421. CALL CLAQZ3( ILSCHUR, ILQ, ILZ, N, ILO, IHI, NSR, NBR, ALPHA,
  422. $ BETA, A, LDA, B, LDB, Q, LDQ, Z, LDZ, WORK, NBR,
  423. $ WORK, NBR, WORK, -1, SWEEP_INFO )
  424. ITEMP2 = INT( WORK( 1 ) )
  425. LWORKREQ = MAX( ITEMP1+2*NW**2, ITEMP2+2*NBR**2 )
  426. IF ( LWORK .EQ.-1 ) THEN
  427. WORK( 1 ) = REAL( LWORKREQ )
  428. RETURN
  429. ELSE IF ( LWORK .LT. LWORKREQ ) THEN
  430. INFO = -19
  431. END IF
  432. IF( INFO.NE.0 ) THEN
  433. CALL XERBLA( 'CLAQZ0', INFO )
  434. RETURN
  435. END IF
  436. *
  437. * Initialize Q and Z
  438. *
  439. IF( IWANTQ.EQ.3 ) CALL CLASET( 'FULL', N, N, CZERO, CONE, Q,
  440. $ LDQ )
  441. IF( IWANTZ.EQ.3 ) CALL CLASET( 'FULL', N, N, CZERO, CONE, Z,
  442. $ LDZ )
  443. * Get machine constants
  444. SAFMIN = SLAMCH( 'SAFE MINIMUM' )
  445. SAFMAX = ONE/SAFMIN
  446. ULP = SLAMCH( 'PRECISION' )
  447. SMLNUM = SAFMIN*( REAL( N )/ULP )
  448. BNORM = CLANHS( 'F', IHI-ILO+1, B( ILO, ILO ), LDB, RWORK )
  449. BTOL = MAX( SAFMIN, ULP*BNORM )
  450. ISTART = ILO
  451. ISTOP = IHI
  452. MAXIT = 30*( IHI-ILO+1 )
  453. LD = 0
  454. DO IITER = 1, MAXIT
  455. IF( IITER .GE. MAXIT ) THEN
  456. INFO = ISTOP+1
  457. GOTO 80
  458. END IF
  459. IF ( ISTART+1 .GE. ISTOP ) THEN
  460. ISTOP = ISTART
  461. EXIT
  462. END IF
  463. * Check deflations at the end
  464. IF ( ABS( A( ISTOP, ISTOP-1 ) ) .LE. MAX( SMLNUM,
  465. $ ULP*( ABS( A( ISTOP, ISTOP ) )+ABS( A( ISTOP-1,
  466. $ ISTOP-1 ) ) ) ) ) THEN
  467. A( ISTOP, ISTOP-1 ) = CZERO
  468. ISTOP = ISTOP-1
  469. LD = 0
  470. ESHIFT = CZERO
  471. END IF
  472. * Check deflations at the start
  473. IF ( ABS( A( ISTART+1, ISTART ) ) .LE. MAX( SMLNUM,
  474. $ ULP*( ABS( A( ISTART, ISTART ) )+ABS( A( ISTART+1,
  475. $ ISTART+1 ) ) ) ) ) THEN
  476. A( ISTART+1, ISTART ) = CZERO
  477. ISTART = ISTART+1
  478. LD = 0
  479. ESHIFT = CZERO
  480. END IF
  481. IF ( ISTART+1 .GE. ISTOP ) THEN
  482. EXIT
  483. END IF
  484. * Check interior deflations
  485. ISTART2 = ISTART
  486. DO K = ISTOP, ISTART+1, -1
  487. IF ( ABS( A( K, K-1 ) ) .LE. MAX( SMLNUM, ULP*( ABS( A( K,
  488. $ K ) )+ABS( A( K-1, K-1 ) ) ) ) ) THEN
  489. A( K, K-1 ) = CZERO
  490. ISTART2 = K
  491. EXIT
  492. END IF
  493. END DO
  494. * Get range to apply rotations to
  495. IF ( ILSCHUR ) THEN
  496. ISTARTM = 1
  497. ISTOPM = N
  498. ELSE
  499. ISTARTM = ISTART2
  500. ISTOPM = ISTOP
  501. END IF
  502. * Check infinite eigenvalues, this is done without blocking so might
  503. * slow down the method when many infinite eigenvalues are present
  504. K = ISTOP
  505. DO WHILE ( K.GE.ISTART2 )
  506. IF( ABS( B( K, K ) ) .LT. BTOL ) THEN
  507. * A diagonal element of B is negligible, move it
  508. * to the top and deflate it
  509. DO K2 = K, ISTART2+1, -1
  510. CALL CLARTG( B( K2-1, K2 ), B( K2-1, K2-1 ), C1, S1,
  511. $ TEMP )
  512. B( K2-1, K2 ) = TEMP
  513. B( K2-1, K2-1 ) = CZERO
  514. CALL CROT( K2-2-ISTARTM+1, B( ISTARTM, K2 ), 1,
  515. $ B( ISTARTM, K2-1 ), 1, C1, S1 )
  516. CALL CROT( MIN( K2+1, ISTOP )-ISTARTM+1, A( ISTARTM,
  517. $ K2 ), 1, A( ISTARTM, K2-1 ), 1, C1, S1 )
  518. IF ( ILZ ) THEN
  519. CALL CROT( N, Z( 1, K2 ), 1, Z( 1, K2-1 ), 1, C1,
  520. $ S1 )
  521. END IF
  522. IF( K2.LT.ISTOP ) THEN
  523. CALL CLARTG( A( K2, K2-1 ), A( K2+1, K2-1 ), C1,
  524. $ S1, TEMP )
  525. A( K2, K2-1 ) = TEMP
  526. A( K2+1, K2-1 ) = CZERO
  527. CALL CROT( ISTOPM-K2+1, A( K2, K2 ), LDA, A( K2+1,
  528. $ K2 ), LDA, C1, S1 )
  529. CALL CROT( ISTOPM-K2+1, B( K2, K2 ), LDB, B( K2+1,
  530. $ K2 ), LDB, C1, S1 )
  531. IF( ILQ ) THEN
  532. CALL CROT( N, Q( 1, K2 ), 1, Q( 1, K2+1 ), 1,
  533. $ C1, CONJG( S1 ) )
  534. END IF
  535. END IF
  536. END DO
  537. IF( ISTART2.LT.ISTOP )THEN
  538. CALL CLARTG( A( ISTART2, ISTART2 ), A( ISTART2+1,
  539. $ ISTART2 ), C1, S1, TEMP )
  540. A( ISTART2, ISTART2 ) = TEMP
  541. A( ISTART2+1, ISTART2 ) = CZERO
  542. CALL CROT( ISTOPM-( ISTART2+1 )+1, A( ISTART2,
  543. $ ISTART2+1 ), LDA, A( ISTART2+1,
  544. $ ISTART2+1 ), LDA, C1, S1 )
  545. CALL CROT( ISTOPM-( ISTART2+1 )+1, B( ISTART2,
  546. $ ISTART2+1 ), LDB, B( ISTART2+1,
  547. $ ISTART2+1 ), LDB, C1, S1 )
  548. IF( ILQ ) THEN
  549. CALL CROT( N, Q( 1, ISTART2 ), 1, Q( 1,
  550. $ ISTART2+1 ), 1, C1, CONJG( S1 ) )
  551. END IF
  552. END IF
  553. ISTART2 = ISTART2+1
  554. END IF
  555. K = K-1
  556. END DO
  557. * istart2 now points to the top of the bottom right
  558. * unreduced Hessenberg block
  559. IF ( ISTART2 .GE. ISTOP ) THEN
  560. ISTOP = ISTART2-1
  561. LD = 0
  562. ESHIFT = CZERO
  563. CYCLE
  564. END IF
  565. NW = NWR
  566. NSHIFTS = NSR
  567. NBLOCK = NBR
  568. IF ( ISTOP-ISTART2+1 .LT. NMIN ) THEN
  569. * Setting nw to the size of the subblock will make AED deflate
  570. * all the eigenvalues. This is slightly more efficient than just
  571. * using CHGEQZ because the off diagonal part gets updated via BLAS.
  572. IF ( ISTOP-ISTART+1 .LT. NMIN ) THEN
  573. NW = ISTOP-ISTART+1
  574. ISTART2 = ISTART
  575. ELSE
  576. NW = ISTOP-ISTART2+1
  577. END IF
  578. END IF
  579. *
  580. * Time for AED
  581. *
  582. CALL CLAQZ2( ILSCHUR, ILQ, ILZ, N, ISTART2, ISTOP, NW, A, LDA,
  583. $ B, LDB, Q, LDQ, Z, LDZ, N_UNDEFLATED, N_DEFLATED,
  584. $ ALPHA, BETA, WORK, NW, WORK( NW**2+1 ), NW,
  585. $ WORK( 2*NW**2+1 ), LWORK-2*NW**2, RWORK, REC,
  586. $ AED_INFO )
  587. IF ( N_DEFLATED > 0 ) THEN
  588. ISTOP = ISTOP-N_DEFLATED
  589. LD = 0
  590. ESHIFT = CZERO
  591. END IF
  592. IF ( 100*N_DEFLATED > NIBBLE*( N_DEFLATED+N_UNDEFLATED ) .OR.
  593. $ ISTOP-ISTART2+1 .LT. NMIN ) THEN
  594. * AED has uncovered many eigenvalues. Skip a QZ sweep and run
  595. * AED again.
  596. CYCLE
  597. END IF
  598. LD = LD+1
  599. NS = MIN( NSHIFTS, ISTOP-ISTART2 )
  600. NS = MIN( NS, N_UNDEFLATED )
  601. SHIFTPOS = ISTOP-N_UNDEFLATED+1
  602. IF ( MOD( LD, 6 ) .EQ. 0 ) THEN
  603. *
  604. * Exceptional shift. Chosen for no particularly good reason.
  605. *
  606. IF( ( REAL( MAXIT )*SAFMIN )*ABS( A( ISTOP,
  607. $ ISTOP-1 ) ).LT.ABS( A( ISTOP-1, ISTOP-1 ) ) ) THEN
  608. ESHIFT = A( ISTOP, ISTOP-1 )/B( ISTOP-1, ISTOP-1 )
  609. ELSE
  610. ESHIFT = ESHIFT+CONE/( SAFMIN*REAL( MAXIT ) )
  611. END IF
  612. ALPHA( SHIFTPOS ) = CONE
  613. BETA( SHIFTPOS ) = ESHIFT
  614. NS = 1
  615. END IF
  616. *
  617. * Time for a QZ sweep
  618. *
  619. CALL CLAQZ3( ILSCHUR, ILQ, ILZ, N, ISTART2, ISTOP, NS, NBLOCK,
  620. $ ALPHA( SHIFTPOS ), BETA( SHIFTPOS ), A, LDA, B,
  621. $ LDB, Q, LDQ, Z, LDZ, WORK, NBLOCK, WORK( NBLOCK**
  622. $ 2+1 ), NBLOCK, WORK( 2*NBLOCK**2+1 ),
  623. $ LWORK-2*NBLOCK**2, SWEEP_INFO )
  624. END DO
  625. *
  626. * Call CHGEQZ to normalize the eigenvalue blocks and set the eigenvalues
  627. * If all the eigenvalues have been found, CHGEQZ will not do any iterations
  628. * and only normalize the blocks. In case of a rare convergence failure,
  629. * the single shift might perform better.
  630. *
  631. 80 CALL CHGEQZ( WANTS, WANTQ, WANTZ, N, ILO, IHI, A, LDA, B, LDB,
  632. $ ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK, RWORK,
  633. $ NORM_INFO )
  634. INFO = NORM_INFO
  635. END SUBROUTINE