dgees.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /* dgees.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__1 = 1;
  15. static integer c__0 = 0;
  16. static integer c_n1 = -1;
  17. /* Subroutine */ int _starpu_dgees_(char *jobvs, char *sort, L_fp select, integer *n,
  18. doublereal *a, integer *lda, integer *sdim, doublereal *wr,
  19. doublereal *wi, doublereal *vs, integer *ldvs, doublereal *work,
  20. integer *lwork, logical *bwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, vs_dim1, vs_offset, i__1, i__2, i__3;
  24. /* Builtin functions */
  25. double sqrt(doublereal);
  26. /* Local variables */
  27. integer i__;
  28. doublereal s;
  29. integer i1, i2, ip, ihi, ilo;
  30. doublereal dum[1], eps, sep;
  31. integer ibal;
  32. doublereal anrm;
  33. integer idum[1], ierr, itau, iwrk, inxt, icond, ieval;
  34. extern logical _starpu_lsame_(char *, char *);
  35. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  36. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  37. *, doublereal *, integer *);
  38. logical cursl;
  39. extern /* Subroutine */ int _starpu_dlabad_(doublereal *, doublereal *), _starpu_dgebak_(
  40. char *, char *, integer *, integer *, integer *, doublereal *,
  41. integer *, doublereal *, integer *, integer *),
  42. _starpu_dgebal_(char *, integer *, doublereal *, integer *, integer *,
  43. integer *, doublereal *, integer *);
  44. logical lst2sl, scalea;
  45. extern doublereal _starpu_dlamch_(char *);
  46. doublereal cscale;
  47. extern doublereal _starpu_dlange_(char *, integer *, integer *, doublereal *,
  48. integer *, doublereal *);
  49. extern /* Subroutine */ int _starpu_dgehrd_(integer *, integer *, integer *,
  50. doublereal *, integer *, doublereal *, doublereal *, integer *,
  51. integer *), _starpu_dlascl_(char *, integer *, integer *, doublereal *,
  52. doublereal *, integer *, integer *, doublereal *, integer *,
  53. integer *), _starpu_dlacpy_(char *, integer *, integer *,
  54. doublereal *, integer *, doublereal *, integer *),
  55. _starpu_xerbla_(char *, integer *);
  56. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  57. integer *, integer *);
  58. doublereal bignum;
  59. extern /* Subroutine */ int _starpu_dorghr_(integer *, integer *, integer *,
  60. doublereal *, integer *, doublereal *, doublereal *, integer *,
  61. integer *), _starpu_dhseqr_(char *, char *, integer *, integer *, integer
  62. *, doublereal *, integer *, doublereal *, doublereal *,
  63. doublereal *, integer *, doublereal *, integer *, integer *), _starpu_dtrsen_(char *, char *, logical *, integer *,
  64. doublereal *, integer *, doublereal *, integer *, doublereal *,
  65. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  66. integer *, integer *, integer *, integer *);
  67. logical lastsl;
  68. integer minwrk, maxwrk;
  69. doublereal smlnum;
  70. integer hswork;
  71. logical wantst, lquery, wantvs;
  72. /* -- LAPACK driver routine (version 3.2) -- */
  73. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  74. /* November 2006 */
  75. /* .. Scalar Arguments .. */
  76. /* .. */
  77. /* .. Array Arguments .. */
  78. /* .. */
  79. /* .. Function Arguments .. */
  80. /* .. */
  81. /* Purpose */
  82. /* ======= */
  83. /* DGEES computes for an N-by-N real nonsymmetric matrix A, the */
  84. /* eigenvalues, the real Schur form T, and, optionally, the matrix of */
  85. /* Schur vectors Z. This gives the Schur factorization A = Z*T*(Z**T). */
  86. /* Optionally, it also orders the eigenvalues on the diagonal of the */
  87. /* real Schur form so that selected eigenvalues are at the top left. */
  88. /* The leading columns of Z then form an orthonormal basis for the */
  89. /* invariant subspace corresponding to the selected eigenvalues. */
  90. /* A matrix is in real Schur form if it is upper quasi-triangular with */
  91. /* 1-by-1 and 2-by-2 blocks. 2-by-2 blocks will be standardized in the */
  92. /* form */
  93. /* [ a b ] */
  94. /* [ c a ] */
  95. /* where b*c < 0. The eigenvalues of such a block are a +- sqrt(bc). */
  96. /* Arguments */
  97. /* ========= */
  98. /* JOBVS (input) CHARACTER*1 */
  99. /* = 'N': Schur vectors are not computed; */
  100. /* = 'V': Schur vectors are computed. */
  101. /* SORT (input) CHARACTER*1 */
  102. /* Specifies whether or not to order the eigenvalues on the */
  103. /* diagonal of the Schur form. */
  104. /* = 'N': Eigenvalues are not ordered; */
  105. /* = 'S': Eigenvalues are ordered (see SELECT). */
  106. /* SELECT (external procedure) LOGICAL FUNCTION of two DOUBLE PRECISION arguments */
  107. /* SELECT must be declared EXTERNAL in the calling subroutine. */
  108. /* If SORT = 'S', SELECT is used to select eigenvalues to sort */
  109. /* to the top left of the Schur form. */
  110. /* If SORT = 'N', SELECT is not referenced. */
  111. /* An eigenvalue WR(j)+sqrt(-1)*WI(j) is selected if */
  112. /* SELECT(WR(j),WI(j)) is true; i.e., if either one of a complex */
  113. /* conjugate pair of eigenvalues is selected, then both complex */
  114. /* eigenvalues are selected. */
  115. /* Note that a selected complex eigenvalue may no longer */
  116. /* satisfy SELECT(WR(j),WI(j)) = .TRUE. after ordering, since */
  117. /* ordering may change the value of complex eigenvalues */
  118. /* (especially if the eigenvalue is ill-conditioned); in this */
  119. /* case INFO is set to N+2 (see INFO below). */
  120. /* N (input) INTEGER */
  121. /* The order of the matrix A. N >= 0. */
  122. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  123. /* On entry, the N-by-N matrix A. */
  124. /* On exit, A has been overwritten by its real Schur form T. */
  125. /* LDA (input) INTEGER */
  126. /* The leading dimension of the array A. LDA >= max(1,N). */
  127. /* SDIM (output) INTEGER */
  128. /* If SORT = 'N', SDIM = 0. */
  129. /* If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
  130. /* for which SELECT is true. (Complex conjugate */
  131. /* pairs for which SELECT is true for either */
  132. /* eigenvalue count as 2.) */
  133. /* WR (output) DOUBLE PRECISION array, dimension (N) */
  134. /* WI (output) DOUBLE PRECISION array, dimension (N) */
  135. /* WR and WI contain the real and imaginary parts, */
  136. /* respectively, of the computed eigenvalues in the same order */
  137. /* that they appear on the diagonal of the output Schur form T. */
  138. /* Complex conjugate pairs of eigenvalues will appear */
  139. /* consecutively with the eigenvalue having the positive */
  140. /* imaginary part first. */
  141. /* VS (output) DOUBLE PRECISION array, dimension (LDVS,N) */
  142. /* If JOBVS = 'V', VS contains the orthogonal matrix Z of Schur */
  143. /* vectors. */
  144. /* If JOBVS = 'N', VS is not referenced. */
  145. /* LDVS (input) INTEGER */
  146. /* The leading dimension of the array VS. LDVS >= 1; if */
  147. /* JOBVS = 'V', LDVS >= N. */
  148. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  149. /* On exit, if INFO = 0, WORK(1) contains the optimal LWORK. */
  150. /* LWORK (input) INTEGER */
  151. /* The dimension of the array WORK. LWORK >= max(1,3*N). */
  152. /* For good performance, LWORK must generally be larger. */
  153. /* If LWORK = -1, then a workspace query is assumed; the routine */
  154. /* only calculates the optimal size of the WORK array, returns */
  155. /* this value as the first entry of the WORK array, and no error */
  156. /* message related to LWORK is issued by XERBLA. */
  157. /* BWORK (workspace) LOGICAL array, dimension (N) */
  158. /* Not referenced if SORT = 'N'. */
  159. /* INFO (output) INTEGER */
  160. /* = 0: successful exit */
  161. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  162. /* > 0: if INFO = i, and i is */
  163. /* <= N: the QR algorithm failed to compute all the */
  164. /* eigenvalues; elements 1:ILO-1 and i+1:N of WR and WI */
  165. /* contain those eigenvalues which have converged; if */
  166. /* JOBVS = 'V', VS contains the matrix which reduces A */
  167. /* to its partially converged Schur form. */
  168. /* = N+1: the eigenvalues could not be reordered because some */
  169. /* eigenvalues were too close to separate (the problem */
  170. /* is very ill-conditioned); */
  171. /* = N+2: after reordering, roundoff changed values of some */
  172. /* complex eigenvalues so that leading eigenvalues in */
  173. /* the Schur form no longer satisfy SELECT=.TRUE. This */
  174. /* could also be caused by underflow due to scaling. */
  175. /* ===================================================================== */
  176. /* .. Parameters .. */
  177. /* .. */
  178. /* .. Local Scalars .. */
  179. /* .. */
  180. /* .. Local Arrays .. */
  181. /* .. */
  182. /* .. External Subroutines .. */
  183. /* .. */
  184. /* .. External Functions .. */
  185. /* .. */
  186. /* .. Intrinsic Functions .. */
  187. /* .. */
  188. /* .. Executable Statements .. */
  189. /* Test the input arguments */
  190. /* Parameter adjustments */
  191. a_dim1 = *lda;
  192. a_offset = 1 + a_dim1;
  193. a -= a_offset;
  194. --wr;
  195. --wi;
  196. vs_dim1 = *ldvs;
  197. vs_offset = 1 + vs_dim1;
  198. vs -= vs_offset;
  199. --work;
  200. --bwork;
  201. /* Function Body */
  202. *info = 0;
  203. lquery = *lwork == -1;
  204. wantvs = _starpu_lsame_(jobvs, "V");
  205. wantst = _starpu_lsame_(sort, "S");
  206. if (! wantvs && ! _starpu_lsame_(jobvs, "N")) {
  207. *info = -1;
  208. } else if (! wantst && ! _starpu_lsame_(sort, "N")) {
  209. *info = -2;
  210. } else if (*n < 0) {
  211. *info = -4;
  212. } else if (*lda < max(1,*n)) {
  213. *info = -6;
  214. } else if (*ldvs < 1 || wantvs && *ldvs < *n) {
  215. *info = -11;
  216. }
  217. /* Compute workspace */
  218. /* (Note: Comments in the code beginning "Workspace:" describe the */
  219. /* minimal amount of workspace needed at that point in the code, */
  220. /* as well as the preferred amount for good performance. */
  221. /* NB refers to the optimal block size for the immediately */
  222. /* following subroutine, as returned by ILAENV. */
  223. /* HSWORK refers to the workspace preferred by DHSEQR, as */
  224. /* calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
  225. /* the worst case.) */
  226. if (*info == 0) {
  227. if (*n == 0) {
  228. minwrk = 1;
  229. maxwrk = 1;
  230. } else {
  231. maxwrk = (*n << 1) + *n * _starpu_ilaenv_(&c__1, "DGEHRD", " ", n, &c__1,
  232. n, &c__0);
  233. minwrk = *n * 3;
  234. _starpu_dhseqr_("S", jobvs, n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[1]
  235. , &vs[vs_offset], ldvs, &work[1], &c_n1, &ieval);
  236. hswork = (integer) work[1];
  237. if (! wantvs) {
  238. /* Computing MAX */
  239. i__1 = maxwrk, i__2 = *n + hswork;
  240. maxwrk = max(i__1,i__2);
  241. } else {
  242. /* Computing MAX */
  243. i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * _starpu_ilaenv_(&c__1,
  244. "DORGHR", " ", n, &c__1, n, &c_n1);
  245. maxwrk = max(i__1,i__2);
  246. /* Computing MAX */
  247. i__1 = maxwrk, i__2 = *n + hswork;
  248. maxwrk = max(i__1,i__2);
  249. }
  250. }
  251. work[1] = (doublereal) maxwrk;
  252. if (*lwork < minwrk && ! lquery) {
  253. *info = -13;
  254. }
  255. }
  256. if (*info != 0) {
  257. i__1 = -(*info);
  258. _starpu_xerbla_("DGEES ", &i__1);
  259. return 0;
  260. } else if (lquery) {
  261. return 0;
  262. }
  263. /* Quick return if possible */
  264. if (*n == 0) {
  265. *sdim = 0;
  266. return 0;
  267. }
  268. /* Get machine constants */
  269. eps = _starpu_dlamch_("P");
  270. smlnum = _starpu_dlamch_("S");
  271. bignum = 1. / smlnum;
  272. _starpu_dlabad_(&smlnum, &bignum);
  273. smlnum = sqrt(smlnum) / eps;
  274. bignum = 1. / smlnum;
  275. /* Scale A if max element outside range [SMLNUM,BIGNUM] */
  276. anrm = _starpu_dlange_("M", n, n, &a[a_offset], lda, dum);
  277. scalea = FALSE_;
  278. if (anrm > 0. && anrm < smlnum) {
  279. scalea = TRUE_;
  280. cscale = smlnum;
  281. } else if (anrm > bignum) {
  282. scalea = TRUE_;
  283. cscale = bignum;
  284. }
  285. if (scalea) {
  286. _starpu_dlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
  287. ierr);
  288. }
  289. /* Permute the matrix to make it more nearly triangular */
  290. /* (Workspace: need N) */
  291. ibal = 1;
  292. _starpu_dgebal_("P", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
  293. /* Reduce to upper Hessenberg form */
  294. /* (Workspace: need 3*N, prefer 2*N+N*NB) */
  295. itau = *n + ibal;
  296. iwrk = *n + itau;
  297. i__1 = *lwork - iwrk + 1;
  298. _starpu_dgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
  299. &ierr);
  300. if (wantvs) {
  301. /* Copy Householder vectors to VS */
  302. _starpu_dlacpy_("L", n, n, &a[a_offset], lda, &vs[vs_offset], ldvs)
  303. ;
  304. /* Generate orthogonal matrix in VS */
  305. /* (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB) */
  306. i__1 = *lwork - iwrk + 1;
  307. _starpu_dorghr_(n, &ilo, &ihi, &vs[vs_offset], ldvs, &work[itau], &work[iwrk],
  308. &i__1, &ierr);
  309. }
  310. *sdim = 0;
  311. /* Perform QR iteration, accumulating Schur vectors in VS if desired */
  312. /* (Workspace: need N+1, prefer N+HSWORK (see comments) ) */
  313. iwrk = itau;
  314. i__1 = *lwork - iwrk + 1;
  315. _starpu_dhseqr_("S", jobvs, n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &vs[
  316. vs_offset], ldvs, &work[iwrk], &i__1, &ieval);
  317. if (ieval > 0) {
  318. *info = ieval;
  319. }
  320. /* Sort eigenvalues if desired */
  321. if (wantst && *info == 0) {
  322. if (scalea) {
  323. _starpu_dlascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wr[1], n, &
  324. ierr);
  325. _starpu_dlascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &wi[1], n, &
  326. ierr);
  327. }
  328. i__1 = *n;
  329. for (i__ = 1; i__ <= i__1; ++i__) {
  330. bwork[i__] = (*select)(&wr[i__], &wi[i__]);
  331. /* L10: */
  332. }
  333. /* Reorder eigenvalues and transform Schur vectors */
  334. /* (Workspace: none needed) */
  335. i__1 = *lwork - iwrk + 1;
  336. _starpu_dtrsen_("N", jobvs, &bwork[1], n, &a[a_offset], lda, &vs[vs_offset],
  337. ldvs, &wr[1], &wi[1], sdim, &s, &sep, &work[iwrk], &i__1,
  338. idum, &c__1, &icond);
  339. if (icond > 0) {
  340. *info = *n + icond;
  341. }
  342. }
  343. if (wantvs) {
  344. /* Undo balancing */
  345. /* (Workspace: need N) */
  346. _starpu_dgebak_("P", "R", n, &ilo, &ihi, &work[ibal], n, &vs[vs_offset], ldvs,
  347. &ierr);
  348. }
  349. if (scalea) {
  350. /* Undo scaling for the Schur form of A */
  351. _starpu_dlascl_("H", &c__0, &c__0, &cscale, &anrm, n, n, &a[a_offset], lda, &
  352. ierr);
  353. i__1 = *lda + 1;
  354. _starpu_dcopy_(n, &a[a_offset], &i__1, &wr[1], &c__1);
  355. if (cscale == smlnum) {
  356. /* If scaling back towards underflow, adjust WI if an */
  357. /* offdiagonal element of a 2-by-2 block in the Schur form */
  358. /* underflows. */
  359. if (ieval > 0) {
  360. i1 = ieval + 1;
  361. i2 = ihi - 1;
  362. i__1 = ilo - 1;
  363. /* Computing MAX */
  364. i__3 = ilo - 1;
  365. i__2 = max(i__3,1);
  366. _starpu_dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[
  367. 1], &i__2, &ierr);
  368. } else if (wantst) {
  369. i1 = 1;
  370. i2 = *n - 1;
  371. } else {
  372. i1 = ilo;
  373. i2 = ihi - 1;
  374. }
  375. inxt = i1 - 1;
  376. i__1 = i2;
  377. for (i__ = i1; i__ <= i__1; ++i__) {
  378. if (i__ < inxt) {
  379. goto L20;
  380. }
  381. if (wi[i__] == 0.) {
  382. inxt = i__ + 1;
  383. } else {
  384. if (a[i__ + 1 + i__ * a_dim1] == 0.) {
  385. wi[i__] = 0.;
  386. wi[i__ + 1] = 0.;
  387. } else if (a[i__ + 1 + i__ * a_dim1] != 0. && a[i__ + (
  388. i__ + 1) * a_dim1] == 0.) {
  389. wi[i__] = 0.;
  390. wi[i__ + 1] = 0.;
  391. if (i__ > 1) {
  392. i__2 = i__ - 1;
  393. _starpu_dswap_(&i__2, &a[i__ * a_dim1 + 1], &c__1, &a[(
  394. i__ + 1) * a_dim1 + 1], &c__1);
  395. }
  396. if (*n > i__ + 1) {
  397. i__2 = *n - i__ - 1;
  398. _starpu_dswap_(&i__2, &a[i__ + (i__ + 2) * a_dim1], lda, &
  399. a[i__ + 1 + (i__ + 2) * a_dim1], lda);
  400. }
  401. if (wantvs) {
  402. _starpu_dswap_(n, &vs[i__ * vs_dim1 + 1], &c__1, &vs[(i__
  403. + 1) * vs_dim1 + 1], &c__1);
  404. }
  405. a[i__ + (i__ + 1) * a_dim1] = a[i__ + 1 + i__ *
  406. a_dim1];
  407. a[i__ + 1 + i__ * a_dim1] = 0.;
  408. }
  409. inxt = i__ + 2;
  410. }
  411. L20:
  412. ;
  413. }
  414. }
  415. /* Undo scaling for the imaginary part of the eigenvalues */
  416. i__1 = *n - ieval;
  417. /* Computing MAX */
  418. i__3 = *n - ieval;
  419. i__2 = max(i__3,1);
  420. _starpu_dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[ieval +
  421. 1], &i__2, &ierr);
  422. }
  423. if (wantst && *info == 0) {
  424. /* Check if reordering successful */
  425. lastsl = TRUE_;
  426. lst2sl = TRUE_;
  427. *sdim = 0;
  428. ip = 0;
  429. i__1 = *n;
  430. for (i__ = 1; i__ <= i__1; ++i__) {
  431. cursl = (*select)(&wr[i__], &wi[i__]);
  432. if (wi[i__] == 0.) {
  433. if (cursl) {
  434. ++(*sdim);
  435. }
  436. ip = 0;
  437. if (cursl && ! lastsl) {
  438. *info = *n + 2;
  439. }
  440. } else {
  441. if (ip == 1) {
  442. /* Last eigenvalue of conjugate pair */
  443. cursl = cursl || lastsl;
  444. lastsl = cursl;
  445. if (cursl) {
  446. *sdim += 2;
  447. }
  448. ip = -1;
  449. if (cursl && ! lst2sl) {
  450. *info = *n + 2;
  451. }
  452. } else {
  453. /* First eigenvalue of conjugate pair */
  454. ip = 1;
  455. }
  456. }
  457. lst2sl = lastsl;
  458. lastsl = cursl;
  459. /* L30: */
  460. }
  461. }
  462. work[1] = (doublereal) maxwrk;
  463. return 0;
  464. /* End of DGEES */
  465. } /* _starpu_dgees_ */