dlaqr4.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /* dlaqr4.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__13 = 13;
  15. static integer c__15 = 15;
  16. static integer c_n1 = -1;
  17. static integer c__12 = 12;
  18. static integer c__14 = 14;
  19. static integer c__16 = 16;
  20. static logical c_false = FALSE_;
  21. static integer c__1 = 1;
  22. static integer c__3 = 3;
  23. /* Subroutine */ int _starpu_dlaqr4_(logical *wantt, logical *wantz, integer *n,
  24. integer *ilo, integer *ihi, doublereal *h__, integer *ldh, doublereal
  25. *wr, doublereal *wi, integer *iloz, integer *ihiz, doublereal *z__,
  26. integer *ldz, doublereal *work, integer *lwork, integer *info)
  27. {
  28. /* System generated locals */
  29. integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  30. doublereal d__1, d__2, d__3, d__4;
  31. /* Local variables */
  32. integer i__, k;
  33. doublereal aa, bb, cc, dd;
  34. integer ld;
  35. doublereal cs;
  36. integer nh, it, ks, kt;
  37. doublereal sn;
  38. integer ku, kv, ls, ns;
  39. doublereal ss;
  40. integer nw, inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl, kbot,
  41. nmin;
  42. doublereal swap;
  43. integer ktop;
  44. doublereal zdum[1] /* was [1][1] */;
  45. integer kacc22, itmax, nsmax, nwmax, kwtop;
  46. extern /* Subroutine */ int _starpu_dlaqr2_(logical *, logical *, integer *,
  47. integer *, integer *, integer *, doublereal *, integer *, integer
  48. *, integer *, doublereal *, integer *, integer *, integer *,
  49. doublereal *, doublereal *, doublereal *, integer *, integer *,
  50. doublereal *, integer *, integer *, doublereal *, integer *,
  51. doublereal *, integer *), _starpu_dlanv2_(doublereal *, doublereal *,
  52. doublereal *, doublereal *, doublereal *, doublereal *,
  53. doublereal *, doublereal *, doublereal *, doublereal *), _starpu_dlaqr5_(
  54. logical *, logical *, integer *, integer *, integer *, integer *,
  55. integer *, doublereal *, doublereal *, doublereal *, integer *,
  56. integer *, integer *, doublereal *, integer *, doublereal *,
  57. integer *, doublereal *, integer *, integer *, doublereal *,
  58. integer *, integer *, doublereal *, integer *);
  59. integer nibble;
  60. extern /* Subroutine */ int _starpu_dlahqr_(logical *, logical *, integer *,
  61. integer *, integer *, doublereal *, integer *, doublereal *,
  62. doublereal *, integer *, integer *, doublereal *, integer *,
  63. integer *), _starpu_dlacpy_(char *, integer *, integer *, doublereal *,
  64. integer *, doublereal *, integer *);
  65. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  66. integer *, integer *);
  67. char jbcmpz[1];
  68. integer nwupbd;
  69. logical sorted;
  70. integer lwkopt;
  71. /* -- LAPACK auxiliary routine (version 3.2) -- */
  72. /* Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */
  73. /* November 2006 */
  74. /* .. Scalar Arguments .. */
  75. /* .. */
  76. /* .. Array Arguments .. */
  77. /* .. */
  78. /* This subroutine implements one level of recursion for DLAQR0. */
  79. /* It is a complete implementation of the small bulge multi-shift */
  80. /* QR algorithm. It may be called by DLAQR0 and, for large enough */
  81. /* deflation window size, it may be called by DLAQR3. This */
  82. /* subroutine is identical to DLAQR0 except that it calls DLAQR2 */
  83. /* instead of DLAQR3. */
  84. /* Purpose */
  85. /* ======= */
  86. /* DLAQR4 computes the eigenvalues of a Hessenberg matrix H */
  87. /* and, optionally, the matrices T and Z from the Schur decomposition */
  88. /* H = Z T Z**T, where T is an upper quasi-triangular matrix (the */
  89. /* Schur form), and Z is the orthogonal matrix of Schur vectors. */
  90. /* Optionally Z may be postmultiplied into an input orthogonal */
  91. /* matrix Q so that this routine can give the Schur factorization */
  92. /* of a matrix A which has been reduced to the Hessenberg form H */
  93. /* by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T. */
  94. /* Arguments */
  95. /* ========= */
  96. /* WANTT (input) LOGICAL */
  97. /* = .TRUE. : the full Schur form T is required; */
  98. /* = .FALSE.: only eigenvalues are required. */
  99. /* WANTZ (input) LOGICAL */
  100. /* = .TRUE. : the matrix of Schur vectors Z is required; */
  101. /* = .FALSE.: Schur vectors are not required. */
  102. /* N (input) INTEGER */
  103. /* The order of the matrix H. N .GE. 0. */
  104. /* ILO (input) INTEGER */
  105. /* IHI (input) INTEGER */
  106. /* It is assumed that H is already upper triangular in rows */
  107. /* and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1, */
  108. /* H(ILO,ILO-1) is zero. ILO and IHI are normally set by a */
  109. /* previous call to DGEBAL, and then passed to DGEHRD when the */
  110. /* matrix output by DGEBAL is reduced to Hessenberg form. */
  111. /* Otherwise, ILO and IHI should be set to 1 and N, */
  112. /* respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N. */
  113. /* If N = 0, then ILO = 1 and IHI = 0. */
  114. /* H (input/output) DOUBLE PRECISION array, dimension (LDH,N) */
  115. /* On entry, the upper Hessenberg matrix H. */
  116. /* On exit, if INFO = 0 and WANTT is .TRUE., then H contains */
  117. /* the upper quasi-triangular matrix T from the Schur */
  118. /* decomposition (the Schur form); 2-by-2 diagonal blocks */
  119. /* (corresponding to complex conjugate pairs of eigenvalues) */
  120. /* are returned in standard form, with H(i,i) = H(i+1,i+1) */
  121. /* and H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and WANTT is */
  122. /* .FALSE., then the contents of H are unspecified on exit. */
  123. /* (The output value of H when INFO.GT.0 is given under the */
  124. /* description of INFO below.) */
  125. /* This subroutine may explicitly set H(i,j) = 0 for i.GT.j and */
  126. /* j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N. */
  127. /* LDH (input) INTEGER */
  128. /* The leading dimension of the array H. LDH .GE. max(1,N). */
  129. /* WR (output) DOUBLE PRECISION array, dimension (IHI) */
  130. /* WI (output) DOUBLE PRECISION array, dimension (IHI) */
  131. /* The real and imaginary parts, respectively, of the computed */
  132. /* eigenvalues of H(ILO:IHI,ILO:IHI) are stored in WR(ILO:IHI) */
  133. /* and WI(ILO:IHI). If two eigenvalues are computed as a */
  134. /* complex conjugate pair, they are stored in consecutive */
  135. /* elements of WR and WI, say the i-th and (i+1)th, with */
  136. /* WI(i) .GT. 0 and WI(i+1) .LT. 0. If WANTT is .TRUE., then */
  137. /* the eigenvalues are stored in the same order as on the */
  138. /* diagonal of the Schur form returned in H, with */
  139. /* WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 diagonal */
  140. /* block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and */
  141. /* WI(i+1) = -WI(i). */
  142. /* ILOZ (input) INTEGER */
  143. /* IHIZ (input) INTEGER */
  144. /* Specify the rows of Z to which transformations must be */
  145. /* applied if WANTZ is .TRUE.. */
  146. /* 1 .LE. ILOZ .LE. ILO; IHI .LE. IHIZ .LE. N. */
  147. /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ,IHI) */
  148. /* If WANTZ is .FALSE., then Z is not referenced. */
  149. /* If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is */
  150. /* replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the */
  151. /* orthogonal Schur factor of H(ILO:IHI,ILO:IHI). */
  152. /* (The output value of Z when INFO.GT.0 is given under */
  153. /* the description of INFO below.) */
  154. /* LDZ (input) INTEGER */
  155. /* The leading dimension of the array Z. if WANTZ is .TRUE. */
  156. /* then LDZ.GE.MAX(1,IHIZ). Otherwize, LDZ.GE.1. */
  157. /* WORK (workspace/output) DOUBLE PRECISION array, dimension LWORK */
  158. /* On exit, if LWORK = -1, WORK(1) returns an estimate of */
  159. /* the optimal value for LWORK. */
  160. /* LWORK (input) INTEGER */
  161. /* The dimension of the array WORK. LWORK .GE. max(1,N) */
  162. /* is sufficient, but LWORK typically as large as 6*N may */
  163. /* be required for optimal performance. A workspace query */
  164. /* to determine the optimal workspace size is recommended. */
  165. /* If LWORK = -1, then DLAQR4 does a workspace query. */
  166. /* In this case, DLAQR4 checks the input parameters and */
  167. /* estimates the optimal workspace size for the given */
  168. /* values of N, ILO and IHI. The estimate is returned */
  169. /* in WORK(1). No error message related to LWORK is */
  170. /* issued by XERBLA. Neither H nor Z are accessed. */
  171. /* INFO (output) INTEGER */
  172. /* = 0: successful exit */
  173. /* .GT. 0: if INFO = i, DLAQR4 failed to compute all of */
  174. /* the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */
  175. /* and WI contain those eigenvalues which have been */
  176. /* successfully computed. (Failures are rare.) */
  177. /* If INFO .GT. 0 and WANT is .FALSE., then on exit, */
  178. /* the remaining unconverged eigenvalues are the eigen- */
  179. /* values of the upper Hessenberg matrix rows and */
  180. /* columns ILO through INFO of the final, output */
  181. /* value of H. */
  182. /* If INFO .GT. 0 and WANTT is .TRUE., then on exit */
  183. /* (*) (initial value of H)*U = U*(final value of H) */
  184. /* where U is an orthogonal matrix. The final */
  185. /* value of H is upper Hessenberg and quasi-triangular */
  186. /* in rows and columns INFO+1 through IHI. */
  187. /* If INFO .GT. 0 and WANTZ is .TRUE., then on exit */
  188. /* (final value of Z(ILO:IHI,ILOZ:IHIZ) */
  189. /* = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U */
  190. /* where U is the orthogonal matrix in (*) (regard- */
  191. /* less of the value of WANTT.) */
  192. /* If INFO .GT. 0 and WANTZ is .FALSE., then Z is not */
  193. /* accessed. */
  194. /* ================================================================ */
  195. /* Based on contributions by */
  196. /* Karen Braman and Ralph Byers, Department of Mathematics, */
  197. /* University of Kansas, USA */
  198. /* ================================================================ */
  199. /* References: */
  200. /* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
  201. /* Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
  202. /* Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
  203. /* 929--947, 2002. */
  204. /* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
  205. /* Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
  206. /* of Matrix Analysis, volume 23, pages 948--973, 2002. */
  207. /* ================================================================ */
  208. /* .. Parameters .. */
  209. /* ==== Matrices of order NTINY or smaller must be processed by */
  210. /* . DLAHQR because of insufficient subdiagonal scratch space. */
  211. /* . (This is a hard limit.) ==== */
  212. /* ==== Exceptional deflation windows: try to cure rare */
  213. /* . slow convergence by varying the size of the */
  214. /* . deflation window after KEXNW iterations. ==== */
  215. /* ==== Exceptional shifts: try to cure rare slow convergence */
  216. /* . with ad-hoc exceptional shifts every KEXSH iterations. */
  217. /* . ==== */
  218. /* ==== The constants WILK1 and WILK2 are used to form the */
  219. /* . exceptional shifts. ==== */
  220. /* .. */
  221. /* .. Local Scalars .. */
  222. /* .. */
  223. /* .. External Functions .. */
  224. /* .. */
  225. /* .. Local Arrays .. */
  226. /* .. */
  227. /* .. External Subroutines .. */
  228. /* .. */
  229. /* .. Intrinsic Functions .. */
  230. /* .. */
  231. /* .. Executable Statements .. */
  232. /* Parameter adjustments */
  233. h_dim1 = *ldh;
  234. h_offset = 1 + h_dim1;
  235. h__ -= h_offset;
  236. --wr;
  237. --wi;
  238. z_dim1 = *ldz;
  239. z_offset = 1 + z_dim1;
  240. z__ -= z_offset;
  241. --work;
  242. /* Function Body */
  243. *info = 0;
  244. /* ==== Quick return for N = 0: nothing to do. ==== */
  245. if (*n == 0) {
  246. work[1] = 1.;
  247. return 0;
  248. }
  249. if (*n <= 11) {
  250. /* ==== Tiny matrices must use DLAHQR. ==== */
  251. lwkopt = 1;
  252. if (*lwork != -1) {
  253. _starpu_dlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &
  254. wi[1], iloz, ihiz, &z__[z_offset], ldz, info);
  255. }
  256. } else {
  257. /* ==== Use small bulge multi-shift QR with aggressive early */
  258. /* . deflation on larger-than-tiny matrices. ==== */
  259. /* ==== Hope for the best. ==== */
  260. *info = 0;
  261. /* ==== Set up job flags for ILAENV. ==== */
  262. if (*wantt) {
  263. *(unsigned char *)jbcmpz = 'S';
  264. } else {
  265. *(unsigned char *)jbcmpz = 'E';
  266. }
  267. if (*wantz) {
  268. *(unsigned char *)&jbcmpz[1] = 'V';
  269. } else {
  270. *(unsigned char *)&jbcmpz[1] = 'N';
  271. }
  272. /* ==== NWR = recommended deflation window size. At this */
  273. /* . point, N .GT. NTINY = 11, so there is enough */
  274. /* . subdiagonal workspace for NWR.GE.2 as required. */
  275. /* . (In fact, there is enough subdiagonal space for */
  276. /* . NWR.GE.3.) ==== */
  277. nwr = _starpu_ilaenv_(&c__13, "DLAQR4", jbcmpz, n, ilo, ihi, lwork);
  278. nwr = max(2,nwr);
  279. /* Computing MIN */
  280. i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
  281. nwr = min(i__1,nwr);
  282. /* ==== NSR = recommended number of simultaneous shifts. */
  283. /* . At this point N .GT. NTINY = 11, so there is at */
  284. /* . enough subdiagonal workspace for NSR to be even */
  285. /* . and greater than or equal to two as required. ==== */
  286. nsr = _starpu_ilaenv_(&c__15, "DLAQR4", jbcmpz, n, ilo, ihi, lwork);
  287. /* Computing MIN */
  288. i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
  289. *ilo;
  290. nsr = min(i__1,i__2);
  291. /* Computing MAX */
  292. i__1 = 2, i__2 = nsr - nsr % 2;
  293. nsr = max(i__1,i__2);
  294. /* ==== Estimate optimal workspace ==== */
  295. /* ==== Workspace query call to DLAQR2 ==== */
  296. i__1 = nwr + 1;
  297. _starpu_dlaqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
  298. ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1], &h__[
  299. h_offset], ldh, n, &h__[h_offset], ldh, n, &h__[h_offset],
  300. ldh, &work[1], &c_n1);
  301. /* ==== Optimal workspace = MAX(DLAQR5, DLAQR2) ==== */
  302. /* Computing MAX */
  303. i__1 = nsr * 3 / 2, i__2 = (integer) work[1];
  304. lwkopt = max(i__1,i__2);
  305. /* ==== Quick return in case of workspace query. ==== */
  306. if (*lwork == -1) {
  307. work[1] = (doublereal) lwkopt;
  308. return 0;
  309. }
  310. /* ==== DLAHQR/DLAQR0 crossover point ==== */
  311. nmin = _starpu_ilaenv_(&c__12, "DLAQR4", jbcmpz, n, ilo, ihi, lwork);
  312. nmin = max(11,nmin);
  313. /* ==== Nibble crossover point ==== */
  314. nibble = _starpu_ilaenv_(&c__14, "DLAQR4", jbcmpz, n, ilo, ihi, lwork);
  315. nibble = max(0,nibble);
  316. /* ==== Accumulate reflections during ttswp? Use block */
  317. /* . 2-by-2 structure during matrix-matrix multiply? ==== */
  318. kacc22 = _starpu_ilaenv_(&c__16, "DLAQR4", jbcmpz, n, ilo, ihi, lwork);
  319. kacc22 = max(0,kacc22);
  320. kacc22 = min(2,kacc22);
  321. /* ==== NWMAX = the largest possible deflation window for */
  322. /* . which there is sufficient workspace. ==== */
  323. /* Computing MIN */
  324. i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
  325. nwmax = min(i__1,i__2);
  326. nw = nwmax;
  327. /* ==== NSMAX = the Largest number of simultaneous shifts */
  328. /* . for which there is sufficient workspace. ==== */
  329. /* Computing MIN */
  330. i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
  331. nsmax = min(i__1,i__2);
  332. nsmax -= nsmax % 2;
  333. /* ==== NDFL: an iteration count restarted at deflation. ==== */
  334. ndfl = 1;
  335. /* ==== ITMAX = iteration limit ==== */
  336. /* Computing MAX */
  337. i__1 = 10, i__2 = *ihi - *ilo + 1;
  338. itmax = max(i__1,i__2) * 30;
  339. /* ==== Last row and column in the active block ==== */
  340. kbot = *ihi;
  341. /* ==== Main Loop ==== */
  342. i__1 = itmax;
  343. for (it = 1; it <= i__1; ++it) {
  344. /* ==== Done when KBOT falls below ILO ==== */
  345. if (kbot < *ilo) {
  346. goto L90;
  347. }
  348. /* ==== Locate active block ==== */
  349. i__2 = *ilo + 1;
  350. for (k = kbot; k >= i__2; --k) {
  351. if (h__[k + (k - 1) * h_dim1] == 0.) {
  352. goto L20;
  353. }
  354. /* L10: */
  355. }
  356. k = *ilo;
  357. L20:
  358. ktop = k;
  359. /* ==== Select deflation window size: */
  360. /* . Typical Case: */
  361. /* . If possible and advisable, nibble the entire */
  362. /* . active block. If not, use size MIN(NWR,NWMAX) */
  363. /* . or MIN(NWR+1,NWMAX) depending upon which has */
  364. /* . the smaller corresponding subdiagonal entry */
  365. /* . (a heuristic). */
  366. /* . */
  367. /* . Exceptional Case: */
  368. /* . If there have been no deflations in KEXNW or */
  369. /* . more iterations, then vary the deflation window */
  370. /* . size. At first, because, larger windows are, */
  371. /* . in general, more powerful than smaller ones, */
  372. /* . rapidly increase the window to the maximum possible. */
  373. /* . Then, gradually reduce the window size. ==== */
  374. nh = kbot - ktop + 1;
  375. nwupbd = min(nh,nwmax);
  376. if (ndfl < 5) {
  377. nw = min(nwupbd,nwr);
  378. } else {
  379. /* Computing MIN */
  380. i__2 = nwupbd, i__3 = nw << 1;
  381. nw = min(i__2,i__3);
  382. }
  383. if (nw < nwmax) {
  384. if (nw >= nh - 1) {
  385. nw = nh;
  386. } else {
  387. kwtop = kbot - nw + 1;
  388. if ((d__1 = h__[kwtop + (kwtop - 1) * h_dim1], abs(d__1))
  389. > (d__2 = h__[kwtop - 1 + (kwtop - 2) * h_dim1],
  390. abs(d__2))) {
  391. ++nw;
  392. }
  393. }
  394. }
  395. if (ndfl < 5) {
  396. ndec = -1;
  397. } else if (ndec >= 0 || nw >= nwupbd) {
  398. ++ndec;
  399. if (nw - ndec < 2) {
  400. ndec = 0;
  401. }
  402. nw -= ndec;
  403. }
  404. /* ==== Aggressive early deflation: */
  405. /* . split workspace under the subdiagonal into */
  406. /* . - an nw-by-nw work array V in the lower */
  407. /* . left-hand-corner, */
  408. /* . - an NW-by-at-least-NW-but-more-is-better */
  409. /* . (NW-by-NHO) horizontal work array along */
  410. /* . the bottom edge, */
  411. /* . - an at-least-NW-but-more-is-better (NHV-by-NW) */
  412. /* . vertical work array along the left-hand-edge. */
  413. /* . ==== */
  414. kv = *n - nw + 1;
  415. kt = nw + 1;
  416. nho = *n - nw - 1 - kt + 1;
  417. kwv = nw + 2;
  418. nve = *n - nw - kwv + 1;
  419. /* ==== Aggressive early deflation ==== */
  420. _starpu_dlaqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
  421. iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &wr[1], &wi[1],
  422. &h__[kv + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1],
  423. ldh, &nve, &h__[kwv + h_dim1], ldh, &work[1], lwork);
  424. /* ==== Adjust KBOT accounting for new deflations. ==== */
  425. kbot -= ld;
  426. /* ==== KS points to the shifts. ==== */
  427. ks = kbot - ls + 1;
  428. /* ==== Skip an expensive QR sweep if there is a (partly */
  429. /* . heuristic) reason to expect that many eigenvalues */
  430. /* . will deflate without it. Here, the QR sweep is */
  431. /* . skipped if many eigenvalues have just been deflated */
  432. /* . or if the remaining active block is small. */
  433. if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
  434. nmin,nwmax)) {
  435. /* ==== NS = nominal number of simultaneous shifts. */
  436. /* . This may be lowered (slightly) if DLAQR2 */
  437. /* . did not provide that many shifts. ==== */
  438. /* Computing MIN */
  439. /* Computing MAX */
  440. i__4 = 2, i__5 = kbot - ktop;
  441. i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
  442. ns = min(i__2,i__3);
  443. ns -= ns % 2;
  444. /* ==== If there have been no deflations */
  445. /* . in a multiple of KEXSH iterations, */
  446. /* . then try exceptional shifts. */
  447. /* . Otherwise use shifts provided by */
  448. /* . DLAQR2 above or from the eigenvalues */
  449. /* . of a trailing principal submatrix. ==== */
  450. if (ndfl % 6 == 0) {
  451. ks = kbot - ns + 1;
  452. /* Computing MAX */
  453. i__3 = ks + 1, i__4 = ktop + 2;
  454. i__2 = max(i__3,i__4);
  455. for (i__ = kbot; i__ >= i__2; i__ += -2) {
  456. ss = (d__1 = h__[i__ + (i__ - 1) * h_dim1], abs(d__1))
  457. + (d__2 = h__[i__ - 1 + (i__ - 2) * h_dim1],
  458. abs(d__2));
  459. aa = ss * .75 + h__[i__ + i__ * h_dim1];
  460. bb = ss;
  461. cc = ss * -.4375;
  462. dd = aa;
  463. _starpu_dlanv2_(&aa, &bb, &cc, &dd, &wr[i__ - 1], &wi[i__ - 1]
  464. , &wr[i__], &wi[i__], &cs, &sn);
  465. /* L30: */
  466. }
  467. if (ks == ktop) {
  468. wr[ks + 1] = h__[ks + 1 + (ks + 1) * h_dim1];
  469. wi[ks + 1] = 0.;
  470. wr[ks] = wr[ks + 1];
  471. wi[ks] = wi[ks + 1];
  472. }
  473. } else {
  474. /* ==== Got NS/2 or fewer shifts? Use DLAHQR */
  475. /* . on a trailing principal submatrix to */
  476. /* . get more. (Since NS.LE.NSMAX.LE.(N+6)/9, */
  477. /* . there is enough space below the subdiagonal */
  478. /* . to fit an NS-by-NS scratch array.) ==== */
  479. if (kbot - ks + 1 <= ns / 2) {
  480. ks = kbot - ns + 1;
  481. kt = *n - ns + 1;
  482. _starpu_dlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
  483. h__[kt + h_dim1], ldh);
  484. _starpu_dlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt
  485. + h_dim1], ldh, &wr[ks], &wi[ks], &c__1, &
  486. c__1, zdum, &c__1, &inf);
  487. ks += inf;
  488. /* ==== In case of a rare QR failure use */
  489. /* . eigenvalues of the trailing 2-by-2 */
  490. /* . principal submatrix. ==== */
  491. if (ks >= kbot) {
  492. aa = h__[kbot - 1 + (kbot - 1) * h_dim1];
  493. cc = h__[kbot + (kbot - 1) * h_dim1];
  494. bb = h__[kbot - 1 + kbot * h_dim1];
  495. dd = h__[kbot + kbot * h_dim1];
  496. _starpu_dlanv2_(&aa, &bb, &cc, &dd, &wr[kbot - 1], &wi[
  497. kbot - 1], &wr[kbot], &wi[kbot], &cs, &sn)
  498. ;
  499. ks = kbot - 1;
  500. }
  501. }
  502. if (kbot - ks + 1 > ns) {
  503. /* ==== Sort the shifts (Helps a little) */
  504. /* . Bubble sort keeps complex conjugate */
  505. /* . pairs together. ==== */
  506. sorted = FALSE_;
  507. i__2 = ks + 1;
  508. for (k = kbot; k >= i__2; --k) {
  509. if (sorted) {
  510. goto L60;
  511. }
  512. sorted = TRUE_;
  513. i__3 = k - 1;
  514. for (i__ = ks; i__ <= i__3; ++i__) {
  515. if ((d__1 = wr[i__], abs(d__1)) + (d__2 = wi[
  516. i__], abs(d__2)) < (d__3 = wr[i__ + 1]
  517. , abs(d__3)) + (d__4 = wi[i__ + 1],
  518. abs(d__4))) {
  519. sorted = FALSE_;
  520. swap = wr[i__];
  521. wr[i__] = wr[i__ + 1];
  522. wr[i__ + 1] = swap;
  523. swap = wi[i__];
  524. wi[i__] = wi[i__ + 1];
  525. wi[i__ + 1] = swap;
  526. }
  527. /* L40: */
  528. }
  529. /* L50: */
  530. }
  531. L60:
  532. ;
  533. }
  534. /* ==== Shuffle shifts into pairs of real shifts */
  535. /* . and pairs of complex conjugate shifts */
  536. /* . assuming complex conjugate shifts are */
  537. /* . already adjacent to one another. (Yes, */
  538. /* . they are.) ==== */
  539. i__2 = ks + 2;
  540. for (i__ = kbot; i__ >= i__2; i__ += -2) {
  541. if (wi[i__] != -wi[i__ - 1]) {
  542. swap = wr[i__];
  543. wr[i__] = wr[i__ - 1];
  544. wr[i__ - 1] = wr[i__ - 2];
  545. wr[i__ - 2] = swap;
  546. swap = wi[i__];
  547. wi[i__] = wi[i__ - 1];
  548. wi[i__ - 1] = wi[i__ - 2];
  549. wi[i__ - 2] = swap;
  550. }
  551. /* L70: */
  552. }
  553. }
  554. /* ==== If there are only two shifts and both are */
  555. /* . real, then use only one. ==== */
  556. if (kbot - ks + 1 == 2) {
  557. if (wi[kbot] == 0.) {
  558. if ((d__1 = wr[kbot] - h__[kbot + kbot * h_dim1], abs(
  559. d__1)) < (d__2 = wr[kbot - 1] - h__[kbot +
  560. kbot * h_dim1], abs(d__2))) {
  561. wr[kbot - 1] = wr[kbot];
  562. } else {
  563. wr[kbot] = wr[kbot - 1];
  564. }
  565. }
  566. }
  567. /* ==== Use up to NS of the the smallest magnatiude */
  568. /* . shifts. If there aren't NS shifts available, */
  569. /* . then use them all, possibly dropping one to */
  570. /* . make the number of shifts even. ==== */
  571. /* Computing MIN */
  572. i__2 = ns, i__3 = kbot - ks + 1;
  573. ns = min(i__2,i__3);
  574. ns -= ns % 2;
  575. ks = kbot - ns + 1;
  576. /* ==== Small-bulge multi-shift QR sweep: */
  577. /* . split workspace under the subdiagonal into */
  578. /* . - a KDU-by-KDU work array U in the lower */
  579. /* . left-hand-corner, */
  580. /* . - a KDU-by-at-least-KDU-but-more-is-better */
  581. /* . (KDU-by-NHo) horizontal work array WH along */
  582. /* . the bottom edge, */
  583. /* . - and an at-least-KDU-but-more-is-better-by-KDU */
  584. /* . (NVE-by-KDU) vertical work WV arrow along */
  585. /* . the left-hand-edge. ==== */
  586. kdu = ns * 3 - 3;
  587. ku = *n - kdu + 1;
  588. kwh = kdu + 1;
  589. nho = *n - kdu - 3 - (kdu + 1) + 1;
  590. kwv = kdu + 4;
  591. nve = *n - kdu - kwv + 1;
  592. /* ==== Small-bulge multi-shift QR sweep ==== */
  593. _starpu_dlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &wr[ks],
  594. &wi[ks], &h__[h_offset], ldh, iloz, ihiz, &z__[
  595. z_offset], ldz, &work[1], &c__3, &h__[ku + h_dim1],
  596. ldh, &nve, &h__[kwv + h_dim1], ldh, &nho, &h__[ku +
  597. kwh * h_dim1], ldh);
  598. }
  599. /* ==== Note progress (or the lack of it). ==== */
  600. if (ld > 0) {
  601. ndfl = 1;
  602. } else {
  603. ++ndfl;
  604. }
  605. /* ==== End of main loop ==== */
  606. /* L80: */
  607. }
  608. /* ==== Iteration limit exceeded. Set INFO to show where */
  609. /* . the problem occurred and exit. ==== */
  610. *info = kbot;
  611. L90:
  612. ;
  613. }
  614. /* ==== Return the optimal value of LWORK. ==== */
  615. work[1] = (doublereal) lwkopt;
  616. /* ==== End of DLAQR4 ==== */
  617. return 0;
  618. } /* _starpu_dlaqr4_ */