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.

zlaqz2.f 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. *> \brief \b ZLAQZ2
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZLAQZ2 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ZLAQZ2.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ZLAQZ2.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ZLAQZ2.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZLAQZ2( ILSCHUR, ILQ, ILZ, N, ILO, IHI, NW, A, LDA, B,
  22. * $ LDB, Q, LDQ, Z, LDZ, NS, ND, ALPHA, BETA, QC, LDQC, ZC, LDZC,
  23. * $ WORK, LWORK, RWORK, REC, INFO )
  24. * IMPLICIT NONE
  25. *
  26. * Arguments
  27. * LOGICAL, INTENT( IN ) :: ILSCHUR, ILQ, ILZ
  28. * INTEGER, INTENT( IN ) :: N, ILO, IHI, NW, LDA, LDB, LDQ, LDZ,
  29. * $ LDQC, LDZC, LWORK, REC
  30. *
  31. * COMPLEX*16, INTENT( INOUT ) :: A( LDA, * ), B( LDB, * ), Q( LDQ,
  32. * $ * ), Z( LDZ, * ), ALPHA( * ), BETA( * )
  33. * INTEGER, INTENT( OUT ) :: NS, ND, INFO
  34. * COMPLEX*16 :: QC( LDQC, * ), ZC( LDZC, * ), WORK( * )
  35. * DOUBLE PRECISION :: RWORK( * )
  36. * ..
  37. *
  38. *
  39. *> \par Purpose:
  40. * =============
  41. *>
  42. *> \verbatim
  43. *>
  44. *> ZLAQZ2 performs AED
  45. *> \endverbatim
  46. *
  47. * Arguments:
  48. * ==========
  49. *
  50. *> \param[in] ILSCHUR
  51. *> \verbatim
  52. *> ILSCHUR is LOGICAL
  53. *> Determines whether or not to update the full Schur form
  54. *> \endverbatim
  55. *> \param[in] ILQ
  56. *> \verbatim
  57. *> ILQ is LOGICAL
  58. *> Determines whether or not to update the matrix Q
  59. *> \endverbatim
  60. *>
  61. *> \param[in] ILZ
  62. *> \verbatim
  63. *> ILZ is LOGICAL
  64. *> Determines whether or not to update the matrix Z
  65. *> \endverbatim
  66. *>
  67. *> \param[in] N
  68. *> \verbatim
  69. *> N is INTEGER
  70. *> The order of the matrices A, B, Q, and Z. N >= 0.
  71. *> \endverbatim
  72. *>
  73. *> \param[in] ILO
  74. *> \verbatim
  75. *> ILO is INTEGER
  76. *> \endverbatim
  77. *>
  78. *> \param[in] IHI
  79. *> \verbatim
  80. *> IHI is INTEGER
  81. *> ILO and IHI mark the rows and columns of (A,B) which
  82. *> are to be normalized
  83. *> \endverbatim
  84. *>
  85. *> \param[in] NW
  86. *> \verbatim
  87. *> NW is INTEGER
  88. *> The desired size of the deflation window.
  89. *> \endverbatim
  90. *>
  91. *> \param[in,out] A
  92. *> \verbatim
  93. *> A is COMPLEX*16 array, dimension (LDA, N)
  94. *> \endverbatim
  95. *>
  96. *> \param[in] LDA
  97. *> \verbatim
  98. *> LDA is INTEGER
  99. *> The leading dimension of the array A. LDA >= max( 1, N ).
  100. *> \endverbatim
  101. *>
  102. *> \param[in,out] B
  103. *> \verbatim
  104. *> B is COMPLEX*16 array, dimension (LDB, N)
  105. *> \endverbatim
  106. *>
  107. *> \param[in] LDB
  108. *> \verbatim
  109. *> LDB is INTEGER
  110. *> The leading dimension of the array B. LDB >= max( 1, N ).
  111. *> \endverbatim
  112. *>
  113. *> \param[in,out] Q
  114. *> \verbatim
  115. *> Q is COMPLEX*16 array, dimension (LDQ, N)
  116. *> \endverbatim
  117. *>
  118. *> \param[in] LDQ
  119. *> \verbatim
  120. *> LDQ is INTEGER
  121. *> \endverbatim
  122. *>
  123. *> \param[in,out] Z
  124. *> \verbatim
  125. *> Z is COMPLEX*16 array, dimension (LDZ, N)
  126. *> \endverbatim
  127. *>
  128. *> \param[in] LDZ
  129. *> \verbatim
  130. *> LDZ is INTEGER
  131. *> \endverbatim
  132. *>
  133. *> \param[out] NS
  134. *> \verbatim
  135. *> NS is INTEGER
  136. *> The number of unconverged eigenvalues available to
  137. *> use as shifts.
  138. *> \endverbatim
  139. *>
  140. *> \param[out] ND
  141. *> \verbatim
  142. *> ND is INTEGER
  143. *> The number of converged eigenvalues found.
  144. *> \endverbatim
  145. *>
  146. *> \param[out] ALPHA
  147. *> \verbatim
  148. *> ALPHA is COMPLEX*16 array, dimension (N)
  149. *> Each scalar alpha defining an eigenvalue
  150. *> of GNEP.
  151. *> \endverbatim
  152. *>
  153. *> \param[out] BETA
  154. *> \verbatim
  155. *> BETA is COMPLEX*16 array, dimension (N)
  156. *> The scalars beta that define the eigenvalues of GNEP.
  157. *> Together, the quantities alpha = ALPHA(j) and
  158. *> beta = BETA(j) represent the j-th eigenvalue of the matrix
  159. *> pair (A,B), in one of the forms lambda = alpha/beta or
  160. *> mu = beta/alpha. Since either lambda or mu may overflow,
  161. *> they should not, in general, be computed.
  162. *> \endverbatim
  163. *>
  164. *> \param[in,out] QC
  165. *> \verbatim
  166. *> QC is COMPLEX*16 array, dimension (LDQC, NW)
  167. *> \endverbatim
  168. *>
  169. *> \param[in] LDQC
  170. *> \verbatim
  171. *> LDQC is INTEGER
  172. *> \endverbatim
  173. *>
  174. *> \param[in,out] ZC
  175. *> \verbatim
  176. *> ZC is COMPLEX*16 array, dimension (LDZC, NW)
  177. *> \endverbatim
  178. *>
  179. *> \param[in] LDZC
  180. *> \verbatim
  181. *> LDZ is INTEGER
  182. *> \endverbatim
  183. *>
  184. *> \param[out] WORK
  185. *> \verbatim
  186. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  187. *> On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
  188. *> \endverbatim
  189. *>
  190. *> \param[in] LWORK
  191. *> \verbatim
  192. *> LWORK is INTEGER
  193. *> The dimension of the array WORK. LWORK >= max(1,N).
  194. *>
  195. *> If LWORK = -1, then a workspace query is assumed; the routine
  196. *> only calculates the optimal size of the WORK array, returns
  197. *> this value as the first entry of the WORK array, and no error
  198. *> message related to LWORK is issued by XERBLA.
  199. *> \endverbatim
  200. *>
  201. *> \param[out] RWORK
  202. *> \verbatim
  203. *> RWORK is DOUBLE PRECISION array, dimension (N)
  204. *> \endverbatim
  205. *>
  206. *> \param[in] REC
  207. *> \verbatim
  208. *> REC is INTEGER
  209. *> REC indicates the current recursion level. Should be set
  210. *> to 0 on first call.
  211. *> \endverbatim
  212. *>
  213. *> \param[out] INFO
  214. *> \verbatim
  215. *> INFO is INTEGER
  216. *> = 0: successful exit
  217. *> < 0: if INFO = -i, the i-th argument had an illegal value
  218. *> \endverbatim
  219. *
  220. * Authors:
  221. * ========
  222. *
  223. *> \author Thijs Steel, KU Leuven
  224. *
  225. *> \date May 2020
  226. *
  227. *> \ingroup complex16GEcomputational
  228. *>
  229. * =====================================================================
  230. RECURSIVE SUBROUTINE ZLAQZ2( ILSCHUR, ILQ, ILZ, N, ILO, IHI, NW,
  231. $ A, LDA, B, LDB, Q, LDQ, Z, LDZ, NS,
  232. $ ND, ALPHA, BETA, QC, LDQC, ZC, LDZC,
  233. $ WORK, LWORK, RWORK, REC, INFO )
  234. IMPLICIT NONE
  235. * Arguments
  236. LOGICAL, INTENT( IN ) :: ILSCHUR, ILQ, ILZ
  237. INTEGER, INTENT( IN ) :: N, ILO, IHI, NW, LDA, LDB, LDQ, LDZ,
  238. $ LDQC, LDZC, LWORK, REC
  239. COMPLEX*16, INTENT( INOUT ) :: A( LDA, * ), B( LDB, * ), Q( LDQ,
  240. $ * ), Z( LDZ, * ), ALPHA( * ), BETA( * )
  241. INTEGER, INTENT( OUT ) :: NS, ND, INFO
  242. COMPLEX*16 :: QC( LDQC, * ), ZC( LDZC, * ), WORK( * )
  243. DOUBLE PRECISION :: RWORK( * )
  244. * Parameters
  245. COMPLEX*16 CZERO, CONE
  246. PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ), CONE = ( 1.0D+0,
  247. $ 0.0D+0 ) )
  248. DOUBLE PRECISION :: ZERO, ONE, HALF
  249. PARAMETER( ZERO = 0.0D0, ONE = 1.0D0, HALF = 0.5D0 )
  250. * Local Scalars
  251. INTEGER :: JW, KWTOP, KWBOT, ISTOPM, ISTARTM, K, K2, ZTGEXC_INFO,
  252. $ IFST, ILST, LWORKREQ, QZ_SMALL_INFO
  253. DOUBLE PRECISION ::SMLNUM, ULP, SAFMIN, SAFMAX, C1, TEMPR
  254. COMPLEX*16 :: S, S1, TEMP
  255. * External Functions
  256. EXTERNAL :: XERBLA, ZLAQZ0, ZLAQZ1, DLABAD, ZLACPY, ZLASET, ZGEMM,
  257. $ ZTGEXC, ZLARTG, ZROT
  258. DOUBLE PRECISION, EXTERNAL :: DLAMCH
  259. INFO = 0
  260. * Set up deflation window
  261. JW = MIN( NW, IHI-ILO+1 )
  262. KWTOP = IHI-JW+1
  263. IF ( KWTOP .EQ. ILO ) THEN
  264. S = CZERO
  265. ELSE
  266. S = A( KWTOP, KWTOP-1 )
  267. END IF
  268. * Determine required workspace
  269. IFST = 1
  270. ILST = JW
  271. CALL ZLAQZ0( 'S', 'V', 'V', JW, 1, JW, A( KWTOP, KWTOP ), LDA,
  272. $ B( KWTOP, KWTOP ), LDB, ALPHA, BETA, QC, LDQC, ZC,
  273. $ LDZC, WORK, -1, RWORK, REC+1, QZ_SMALL_INFO )
  274. LWORKREQ = INT( WORK( 1 ) )+2*JW**2
  275. LWORKREQ = MAX( LWORKREQ, N*NW, 2*NW**2+N )
  276. IF ( LWORK .EQ.-1 ) THEN
  277. * workspace query, quick return
  278. WORK( 1 ) = LWORKREQ
  279. RETURN
  280. ELSE IF ( LWORK .LT. LWORKREQ ) THEN
  281. INFO = -26
  282. END IF
  283. IF( INFO.NE.0 ) THEN
  284. CALL XERBLA( 'ZLAQZ2', -INFO )
  285. RETURN
  286. END IF
  287. * Get machine constants
  288. SAFMIN = DLAMCH( 'SAFE MINIMUM' )
  289. SAFMAX = ONE/SAFMIN
  290. CALL DLABAD( SAFMIN, SAFMAX )
  291. ULP = DLAMCH( 'PRECISION' )
  292. SMLNUM = SAFMIN*( DBLE( N )/ULP )
  293. IF ( IHI .EQ. KWTOP ) THEN
  294. * 1 by 1 deflation window, just try a regular deflation
  295. ALPHA( KWTOP ) = A( KWTOP, KWTOP )
  296. BETA( KWTOP ) = B( KWTOP, KWTOP )
  297. NS = 1
  298. ND = 0
  299. IF ( ABS( S ) .LE. MAX( SMLNUM, ULP*ABS( A( KWTOP,
  300. $ KWTOP ) ) ) ) THEN
  301. NS = 0
  302. ND = 1
  303. IF ( KWTOP .GT. ILO ) THEN
  304. A( KWTOP, KWTOP-1 ) = CZERO
  305. END IF
  306. END IF
  307. END IF
  308. * Store window in case of convergence failure
  309. CALL ZLACPY( 'ALL', JW, JW, A( KWTOP, KWTOP ), LDA, WORK, JW )
  310. CALL ZLACPY( 'ALL', JW, JW, B( KWTOP, KWTOP ), LDB, WORK( JW**2+
  311. $ 1 ), JW )
  312. * Transform window to real schur form
  313. CALL ZLASET( 'FULL', JW, JW, CZERO, CONE, QC, LDQC )
  314. CALL ZLASET( 'FULL', JW, JW, CZERO, CONE, ZC, LDZC )
  315. CALL ZLAQZ0( 'S', 'V', 'V', JW, 1, JW, A( KWTOP, KWTOP ), LDA,
  316. $ B( KWTOP, KWTOP ), LDB, ALPHA, BETA, QC, LDQC, ZC,
  317. $ LDZC, WORK( 2*JW**2+1 ), LWORK-2*JW**2, RWORK,
  318. $ REC+1, QZ_SMALL_INFO )
  319. IF( QZ_SMALL_INFO .NE. 0 ) THEN
  320. * Convergence failure, restore the window and exit
  321. ND = 0
  322. NS = JW-QZ_SMALL_INFO
  323. CALL ZLACPY( 'ALL', JW, JW, WORK, JW, A( KWTOP, KWTOP ), LDA )
  324. CALL ZLACPY( 'ALL', JW, JW, WORK( JW**2+1 ), JW, B( KWTOP,
  325. $ KWTOP ), LDB )
  326. RETURN
  327. END IF
  328. * Deflation detection loop
  329. IF ( KWTOP .EQ. ILO .OR. S .EQ. CZERO ) THEN
  330. KWBOT = KWTOP-1
  331. ELSE
  332. KWBOT = IHI
  333. K = 1
  334. K2 = 1
  335. DO WHILE ( K .LE. JW )
  336. * Try to deflate eigenvalue
  337. TEMPR = ABS( A( KWBOT, KWBOT ) )
  338. IF( TEMPR .EQ. ZERO ) THEN
  339. TEMPR = ABS( S )
  340. END IF
  341. IF ( ( ABS( S*QC( 1, KWBOT-KWTOP+1 ) ) ) .LE. MAX( ULP*
  342. $ TEMPR, SMLNUM ) ) THEN
  343. * Deflatable
  344. KWBOT = KWBOT-1
  345. ELSE
  346. * Not deflatable, move out of the way
  347. IFST = KWBOT-KWTOP+1
  348. ILST = K2
  349. CALL ZTGEXC( .TRUE., .TRUE., JW, A( KWTOP, KWTOP ),
  350. $ LDA, B( KWTOP, KWTOP ), LDB, QC, LDQC,
  351. $ ZC, LDZC, IFST, ILST, ZTGEXC_INFO )
  352. K2 = K2+1
  353. END IF
  354. K = K+1
  355. END DO
  356. END IF
  357. * Store eigenvalues
  358. ND = IHI-KWBOT
  359. NS = JW-ND
  360. K = KWTOP
  361. DO WHILE ( K .LE. IHI )
  362. ALPHA( K ) = A( K, K )
  363. BETA( K ) = B( K, K )
  364. K = K+1
  365. END DO
  366. IF ( KWTOP .NE. ILO .AND. S .NE. CZERO ) THEN
  367. * Reflect spike back, this will create optimally packed bulges
  368. A( KWTOP:KWBOT, KWTOP-1 ) = A( KWTOP, KWTOP-1 ) *DCONJG( QC( 1,
  369. $ 1:JW-ND ) )
  370. DO K = KWBOT-1, KWTOP, -1
  371. CALL ZLARTG( A( K, KWTOP-1 ), A( K+1, KWTOP-1 ), C1, S1,
  372. $ TEMP )
  373. A( K, KWTOP-1 ) = TEMP
  374. A( K+1, KWTOP-1 ) = CZERO
  375. K2 = MAX( KWTOP, K-1 )
  376. CALL ZROT( IHI-K2+1, A( K, K2 ), LDA, A( K+1, K2 ), LDA, C1,
  377. $ S1 )
  378. CALL ZROT( IHI-( K-1 )+1, B( K, K-1 ), LDB, B( K+1, K-1 ),
  379. $ LDB, C1, S1 )
  380. CALL ZROT( JW, QC( 1, K-KWTOP+1 ), 1, QC( 1, K+1-KWTOP+1 ),
  381. $ 1, C1, DCONJG( S1 ) )
  382. END DO
  383. * Chase bulges down
  384. ISTARTM = KWTOP
  385. ISTOPM = IHI
  386. K = KWBOT-1
  387. DO WHILE ( K .GE. KWTOP )
  388. * Move bulge down and remove it
  389. DO K2 = K, KWBOT-1
  390. CALL ZLAQZ1( .TRUE., .TRUE., K2, KWTOP, KWTOP+JW-1,
  391. $ KWBOT, A, LDA, B, LDB, JW, KWTOP, QC, LDQC,
  392. $ JW, KWTOP, ZC, LDZC )
  393. END DO
  394. K = K-1
  395. END DO
  396. END IF
  397. * Apply Qc and Zc to rest of the matrix
  398. IF ( ILSCHUR ) THEN
  399. ISTARTM = 1
  400. ISTOPM = N
  401. ELSE
  402. ISTARTM = ILO
  403. ISTOPM = IHI
  404. END IF
  405. IF ( ISTOPM-IHI > 0 ) THEN
  406. CALL ZGEMM( 'C', 'N', JW, ISTOPM-IHI, JW, CONE, QC, LDQC,
  407. $ A( KWTOP, IHI+1 ), LDA, CZERO, WORK, JW )
  408. CALL ZLACPY( 'ALL', JW, ISTOPM-IHI, WORK, JW, A( KWTOP,
  409. $ IHI+1 ), LDA )
  410. CALL ZGEMM( 'C', 'N', JW, ISTOPM-IHI, JW, CONE, QC, LDQC,
  411. $ B( KWTOP, IHI+1 ), LDB, CZERO, WORK, JW )
  412. CALL ZLACPY( 'ALL', JW, ISTOPM-IHI, WORK, JW, B( KWTOP,
  413. $ IHI+1 ), LDB )
  414. END IF
  415. IF ( ILQ ) THEN
  416. CALL ZGEMM( 'N', 'N', N, JW, JW, CONE, Q( 1, KWTOP ), LDQ, QC,
  417. $ LDQC, CZERO, WORK, N )
  418. CALL ZLACPY( 'ALL', N, JW, WORK, N, Q( 1, KWTOP ), LDQ )
  419. END IF
  420. IF ( KWTOP-1-ISTARTM+1 > 0 ) THEN
  421. CALL ZGEMM( 'N', 'N', KWTOP-ISTARTM, JW, JW, CONE, A( ISTARTM,
  422. $ KWTOP ), LDA, ZC, LDZC, CZERO, WORK,
  423. $ KWTOP-ISTARTM )
  424. CALL ZLACPY( 'ALL', KWTOP-ISTARTM, JW, WORK, KWTOP-ISTARTM,
  425. $ A( ISTARTM, KWTOP ), LDA )
  426. CALL ZGEMM( 'N', 'N', KWTOP-ISTARTM, JW, JW, CONE, B( ISTARTM,
  427. $ KWTOP ), LDB, ZC, LDZC, CZERO, WORK,
  428. $ KWTOP-ISTARTM )
  429. CALL ZLACPY( 'ALL', KWTOP-ISTARTM, JW, WORK, KWTOP-ISTARTM,
  430. $ B( ISTARTM, KWTOP ), LDB )
  431. END IF
  432. IF ( ILZ ) THEN
  433. CALL ZGEMM( 'N', 'N', N, JW, JW, CONE, Z( 1, KWTOP ), LDZ, ZC,
  434. $ LDZC, CZERO, WORK, N )
  435. CALL ZLACPY( 'ALL', N, JW, WORK, N, Z( 1, KWTOP ), LDZ )
  436. END IF
  437. END SUBROUTINE