dhsein.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /* dhsein.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 logical c_false = FALSE_;
  15. static logical c_true = TRUE_;
  16. /* Subroutine */ int _starpu_dhsein_(char *side, char *eigsrc, char *initv, logical *
  17. select, integer *n, doublereal *h__, integer *ldh, doublereal *wr,
  18. doublereal *wi, doublereal *vl, integer *ldvl, doublereal *vr,
  19. integer *ldvr, integer *mm, integer *m, doublereal *work, integer *
  20. ifaill, integer *ifailr, integer *info)
  21. {
  22. /* System generated locals */
  23. integer h_dim1, h_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  24. i__2;
  25. doublereal d__1, d__2;
  26. /* Local variables */
  27. integer i__, k, kl, kr, kln, ksi;
  28. doublereal wki;
  29. integer ksr;
  30. doublereal ulp, wkr, eps3;
  31. logical pair;
  32. doublereal unfl;
  33. extern logical _starpu_lsame_(char *, char *);
  34. integer iinfo;
  35. logical leftv, bothv;
  36. doublereal hnorm;
  37. extern doublereal _starpu_dlamch_(char *);
  38. extern /* Subroutine */ int _starpu_dlaein_(logical *, logical *, integer *,
  39. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  40. doublereal *, doublereal *, integer *, doublereal *, doublereal *
  41. , doublereal *, doublereal *, integer *);
  42. extern doublereal _starpu_dlanhs_(char *, integer *, doublereal *, integer *,
  43. doublereal *);
  44. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  45. doublereal bignum;
  46. logical noinit;
  47. integer ldwork;
  48. logical rightv, fromqr;
  49. doublereal smlnum;
  50. /* -- LAPACK routine (version 3.2) -- */
  51. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  52. /* November 2006 */
  53. /* .. Scalar Arguments .. */
  54. /* .. */
  55. /* .. Array Arguments .. */
  56. /* .. */
  57. /* Purpose */
  58. /* ======= */
  59. /* DHSEIN uses inverse iteration to find specified right and/or left */
  60. /* eigenvectors of a real upper Hessenberg matrix H. */
  61. /* The right eigenvector x and the left eigenvector y of the matrix H */
  62. /* corresponding to an eigenvalue w are defined by: */
  63. /* H * x = w * x, y**h * H = w * y**h */
  64. /* where y**h denotes the conjugate transpose of the vector y. */
  65. /* Arguments */
  66. /* ========= */
  67. /* SIDE (input) CHARACTER*1 */
  68. /* = 'R': compute right eigenvectors only; */
  69. /* = 'L': compute left eigenvectors only; */
  70. /* = 'B': compute both right and left eigenvectors. */
  71. /* EIGSRC (input) CHARACTER*1 */
  72. /* Specifies the source of eigenvalues supplied in (WR,WI): */
  73. /* = 'Q': the eigenvalues were found using DHSEQR; thus, if */
  74. /* H has zero subdiagonal elements, and so is */
  75. /* block-triangular, then the j-th eigenvalue can be */
  76. /* assumed to be an eigenvalue of the block containing */
  77. /* the j-th row/column. This property allows DHSEIN to */
  78. /* perform inverse iteration on just one diagonal block. */
  79. /* = 'N': no assumptions are made on the correspondence */
  80. /* between eigenvalues and diagonal blocks. In this */
  81. /* case, DHSEIN must always perform inverse iteration */
  82. /* using the whole matrix H. */
  83. /* INITV (input) CHARACTER*1 */
  84. /* = 'N': no initial vectors are supplied; */
  85. /* = 'U': user-supplied initial vectors are stored in the arrays */
  86. /* VL and/or VR. */
  87. /* SELECT (input/output) LOGICAL array, dimension (N) */
  88. /* Specifies the eigenvectors to be computed. To select the */
  89. /* real eigenvector corresponding to a real eigenvalue WR(j), */
  90. /* SELECT(j) must be set to .TRUE.. To select the complex */
  91. /* eigenvector corresponding to a complex eigenvalue */
  92. /* (WR(j),WI(j)), with complex conjugate (WR(j+1),WI(j+1)), */
  93. /* either SELECT(j) or SELECT(j+1) or both must be set to */
  94. /* .TRUE.; then on exit SELECT(j) is .TRUE. and SELECT(j+1) is */
  95. /* .FALSE.. */
  96. /* N (input) INTEGER */
  97. /* The order of the matrix H. N >= 0. */
  98. /* H (input) DOUBLE PRECISION array, dimension (LDH,N) */
  99. /* The upper Hessenberg matrix H. */
  100. /* LDH (input) INTEGER */
  101. /* The leading dimension of the array H. LDH >= max(1,N). */
  102. /* WR (input/output) DOUBLE PRECISION array, dimension (N) */
  103. /* WI (input) DOUBLE PRECISION array, dimension (N) */
  104. /* On entry, the real and imaginary parts of the eigenvalues of */
  105. /* H; a complex conjugate pair of eigenvalues must be stored in */
  106. /* consecutive elements of WR and WI. */
  107. /* On exit, WR may have been altered since close eigenvalues */
  108. /* are perturbed slightly in searching for independent */
  109. /* eigenvectors. */
  110. /* VL (input/output) DOUBLE PRECISION array, dimension (LDVL,MM) */
  111. /* On entry, if INITV = 'U' and SIDE = 'L' or 'B', VL must */
  112. /* contain starting vectors for the inverse iteration for the */
  113. /* left eigenvectors; the starting vector for each eigenvector */
  114. /* must be in the same column(s) in which the eigenvector will */
  115. /* be stored. */
  116. /* On exit, if SIDE = 'L' or 'B', the left eigenvectors */
  117. /* specified by SELECT will be stored consecutively in the */
  118. /* columns of VL, in the same order as their eigenvalues. A */
  119. /* complex eigenvector corresponding to a complex eigenvalue is */
  120. /* stored in two consecutive columns, the first holding the real */
  121. /* part and the second the imaginary part. */
  122. /* If SIDE = 'R', VL is not referenced. */
  123. /* LDVL (input) INTEGER */
  124. /* The leading dimension of the array VL. */
  125. /* LDVL >= max(1,N) if SIDE = 'L' or 'B'; LDVL >= 1 otherwise. */
  126. /* VR (input/output) DOUBLE PRECISION array, dimension (LDVR,MM) */
  127. /* On entry, if INITV = 'U' and SIDE = 'R' or 'B', VR must */
  128. /* contain starting vectors for the inverse iteration for the */
  129. /* right eigenvectors; the starting vector for each eigenvector */
  130. /* must be in the same column(s) in which the eigenvector will */
  131. /* be stored. */
  132. /* On exit, if SIDE = 'R' or 'B', the right eigenvectors */
  133. /* specified by SELECT will be stored consecutively in the */
  134. /* columns of VR, in the same order as their eigenvalues. A */
  135. /* complex eigenvector corresponding to a complex eigenvalue is */
  136. /* stored in two consecutive columns, the first holding the real */
  137. /* part and the second the imaginary part. */
  138. /* If SIDE = 'L', VR is not referenced. */
  139. /* LDVR (input) INTEGER */
  140. /* The leading dimension of the array VR. */
  141. /* LDVR >= max(1,N) if SIDE = 'R' or 'B'; LDVR >= 1 otherwise. */
  142. /* MM (input) INTEGER */
  143. /* The number of columns in the arrays VL and/or VR. MM >= M. */
  144. /* M (output) INTEGER */
  145. /* The number of columns in the arrays VL and/or VR required to */
  146. /* store the eigenvectors; each selected real eigenvector */
  147. /* occupies one column and each selected complex eigenvector */
  148. /* occupies two columns. */
  149. /* WORK (workspace) DOUBLE PRECISION array, dimension ((N+2)*N) */
  150. /* IFAILL (output) INTEGER array, dimension (MM) */
  151. /* If SIDE = 'L' or 'B', IFAILL(i) = j > 0 if the left */
  152. /* eigenvector in the i-th column of VL (corresponding to the */
  153. /* eigenvalue w(j)) failed to converge; IFAILL(i) = 0 if the */
  154. /* eigenvector converged satisfactorily. If the i-th and (i+1)th */
  155. /* columns of VL hold a complex eigenvector, then IFAILL(i) and */
  156. /* IFAILL(i+1) are set to the same value. */
  157. /* If SIDE = 'R', IFAILL is not referenced. */
  158. /* IFAILR (output) INTEGER array, dimension (MM) */
  159. /* If SIDE = 'R' or 'B', IFAILR(i) = j > 0 if the right */
  160. /* eigenvector in the i-th column of VR (corresponding to the */
  161. /* eigenvalue w(j)) failed to converge; IFAILR(i) = 0 if the */
  162. /* eigenvector converged satisfactorily. If the i-th and (i+1)th */
  163. /* columns of VR hold a complex eigenvector, then IFAILR(i) and */
  164. /* IFAILR(i+1) are set to the same value. */
  165. /* If SIDE = 'L', IFAILR is not referenced. */
  166. /* INFO (output) INTEGER */
  167. /* = 0: successful exit */
  168. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  169. /* > 0: if INFO = i, i is the number of eigenvectors which */
  170. /* failed to converge; see IFAILL and IFAILR for further */
  171. /* details. */
  172. /* Further Details */
  173. /* =============== */
  174. /* Each eigenvector is normalized so that the element of largest */
  175. /* magnitude has magnitude 1; here the magnitude of a complex number */
  176. /* (x,y) is taken to be |x|+|y|. */
  177. /* ===================================================================== */
  178. /* .. Parameters .. */
  179. /* .. */
  180. /* .. Local Scalars .. */
  181. /* .. */
  182. /* .. External Functions .. */
  183. /* .. */
  184. /* .. External Subroutines .. */
  185. /* .. */
  186. /* .. Intrinsic Functions .. */
  187. /* .. */
  188. /* .. Executable Statements .. */
  189. /* Decode and test the input parameters. */
  190. /* Parameter adjustments */
  191. --select;
  192. h_dim1 = *ldh;
  193. h_offset = 1 + h_dim1;
  194. h__ -= h_offset;
  195. --wr;
  196. --wi;
  197. vl_dim1 = *ldvl;
  198. vl_offset = 1 + vl_dim1;
  199. vl -= vl_offset;
  200. vr_dim1 = *ldvr;
  201. vr_offset = 1 + vr_dim1;
  202. vr -= vr_offset;
  203. --work;
  204. --ifaill;
  205. --ifailr;
  206. /* Function Body */
  207. bothv = _starpu_lsame_(side, "B");
  208. rightv = _starpu_lsame_(side, "R") || bothv;
  209. leftv = _starpu_lsame_(side, "L") || bothv;
  210. fromqr = _starpu_lsame_(eigsrc, "Q");
  211. noinit = _starpu_lsame_(initv, "N");
  212. /* Set M to the number of columns required to store the selected */
  213. /* eigenvectors, and standardize the array SELECT. */
  214. *m = 0;
  215. pair = FALSE_;
  216. i__1 = *n;
  217. for (k = 1; k <= i__1; ++k) {
  218. if (pair) {
  219. pair = FALSE_;
  220. select[k] = FALSE_;
  221. } else {
  222. if (wi[k] == 0.) {
  223. if (select[k]) {
  224. ++(*m);
  225. }
  226. } else {
  227. pair = TRUE_;
  228. if (select[k] || select[k + 1]) {
  229. select[k] = TRUE_;
  230. *m += 2;
  231. }
  232. }
  233. }
  234. /* L10: */
  235. }
  236. *info = 0;
  237. if (! rightv && ! leftv) {
  238. *info = -1;
  239. } else if (! fromqr && ! _starpu_lsame_(eigsrc, "N")) {
  240. *info = -2;
  241. } else if (! noinit && ! _starpu_lsame_(initv, "U")) {
  242. *info = -3;
  243. } else if (*n < 0) {
  244. *info = -5;
  245. } else if (*ldh < max(1,*n)) {
  246. *info = -7;
  247. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  248. *info = -11;
  249. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  250. *info = -13;
  251. } else if (*mm < *m) {
  252. *info = -14;
  253. }
  254. if (*info != 0) {
  255. i__1 = -(*info);
  256. _starpu_xerbla_("DHSEIN", &i__1);
  257. return 0;
  258. }
  259. /* Quick return if possible. */
  260. if (*n == 0) {
  261. return 0;
  262. }
  263. /* Set machine-dependent constants. */
  264. unfl = _starpu_dlamch_("Safe minimum");
  265. ulp = _starpu_dlamch_("Precision");
  266. smlnum = unfl * (*n / ulp);
  267. bignum = (1. - ulp) / smlnum;
  268. ldwork = *n + 1;
  269. kl = 1;
  270. kln = 0;
  271. if (fromqr) {
  272. kr = 0;
  273. } else {
  274. kr = *n;
  275. }
  276. ksr = 1;
  277. i__1 = *n;
  278. for (k = 1; k <= i__1; ++k) {
  279. if (select[k]) {
  280. /* Compute eigenvector(s) corresponding to W(K). */
  281. if (fromqr) {
  282. /* If affiliation of eigenvalues is known, check whether */
  283. /* the matrix splits. */
  284. /* Determine KL and KR such that 1 <= KL <= K <= KR <= N */
  285. /* and H(KL,KL-1) and H(KR+1,KR) are zero (or KL = 1 or */
  286. /* KR = N). */
  287. /* Then inverse iteration can be performed with the */
  288. /* submatrix H(KL:N,KL:N) for a left eigenvector, and with */
  289. /* the submatrix H(1:KR,1:KR) for a right eigenvector. */
  290. i__2 = kl + 1;
  291. for (i__ = k; i__ >= i__2; --i__) {
  292. if (h__[i__ + (i__ - 1) * h_dim1] == 0.) {
  293. goto L30;
  294. }
  295. /* L20: */
  296. }
  297. L30:
  298. kl = i__;
  299. if (k > kr) {
  300. i__2 = *n - 1;
  301. for (i__ = k; i__ <= i__2; ++i__) {
  302. if (h__[i__ + 1 + i__ * h_dim1] == 0.) {
  303. goto L50;
  304. }
  305. /* L40: */
  306. }
  307. L50:
  308. kr = i__;
  309. }
  310. }
  311. if (kl != kln) {
  312. kln = kl;
  313. /* Compute infinity-norm of submatrix H(KL:KR,KL:KR) if it */
  314. /* has not ben computed before. */
  315. i__2 = kr - kl + 1;
  316. hnorm = _starpu_dlanhs_("I", &i__2, &h__[kl + kl * h_dim1], ldh, &
  317. work[1]);
  318. if (hnorm > 0.) {
  319. eps3 = hnorm * ulp;
  320. } else {
  321. eps3 = smlnum;
  322. }
  323. }
  324. /* Perturb eigenvalue if it is close to any previous */
  325. /* selected eigenvalues affiliated to the submatrix */
  326. /* H(KL:KR,KL:KR). Close roots are modified by EPS3. */
  327. wkr = wr[k];
  328. wki = wi[k];
  329. L60:
  330. i__2 = kl;
  331. for (i__ = k - 1; i__ >= i__2; --i__) {
  332. if (select[i__] && (d__1 = wr[i__] - wkr, abs(d__1)) + (d__2 =
  333. wi[i__] - wki, abs(d__2)) < eps3) {
  334. wkr += eps3;
  335. goto L60;
  336. }
  337. /* L70: */
  338. }
  339. wr[k] = wkr;
  340. pair = wki != 0.;
  341. if (pair) {
  342. ksi = ksr + 1;
  343. } else {
  344. ksi = ksr;
  345. }
  346. if (leftv) {
  347. /* Compute left eigenvector. */
  348. i__2 = *n - kl + 1;
  349. _starpu_dlaein_(&c_false, &noinit, &i__2, &h__[kl + kl * h_dim1], ldh,
  350. &wkr, &wki, &vl[kl + ksr * vl_dim1], &vl[kl + ksi *
  351. vl_dim1], &work[1], &ldwork, &work[*n * *n + *n + 1],
  352. &eps3, &smlnum, &bignum, &iinfo);
  353. if (iinfo > 0) {
  354. if (pair) {
  355. *info += 2;
  356. } else {
  357. ++(*info);
  358. }
  359. ifaill[ksr] = k;
  360. ifaill[ksi] = k;
  361. } else {
  362. ifaill[ksr] = 0;
  363. ifaill[ksi] = 0;
  364. }
  365. i__2 = kl - 1;
  366. for (i__ = 1; i__ <= i__2; ++i__) {
  367. vl[i__ + ksr * vl_dim1] = 0.;
  368. /* L80: */
  369. }
  370. if (pair) {
  371. i__2 = kl - 1;
  372. for (i__ = 1; i__ <= i__2; ++i__) {
  373. vl[i__ + ksi * vl_dim1] = 0.;
  374. /* L90: */
  375. }
  376. }
  377. }
  378. if (rightv) {
  379. /* Compute right eigenvector. */
  380. _starpu_dlaein_(&c_true, &noinit, &kr, &h__[h_offset], ldh, &wkr, &
  381. wki, &vr[ksr * vr_dim1 + 1], &vr[ksi * vr_dim1 + 1], &
  382. work[1], &ldwork, &work[*n * *n + *n + 1], &eps3, &
  383. smlnum, &bignum, &iinfo);
  384. if (iinfo > 0) {
  385. if (pair) {
  386. *info += 2;
  387. } else {
  388. ++(*info);
  389. }
  390. ifailr[ksr] = k;
  391. ifailr[ksi] = k;
  392. } else {
  393. ifailr[ksr] = 0;
  394. ifailr[ksi] = 0;
  395. }
  396. i__2 = *n;
  397. for (i__ = kr + 1; i__ <= i__2; ++i__) {
  398. vr[i__ + ksr * vr_dim1] = 0.;
  399. /* L100: */
  400. }
  401. if (pair) {
  402. i__2 = *n;
  403. for (i__ = kr + 1; i__ <= i__2; ++i__) {
  404. vr[i__ + ksi * vr_dim1] = 0.;
  405. /* L110: */
  406. }
  407. }
  408. }
  409. if (pair) {
  410. ksr += 2;
  411. } else {
  412. ++ksr;
  413. }
  414. }
  415. /* L120: */
  416. }
  417. return 0;
  418. /* End of DHSEIN */
  419. } /* _starpu_dhsein_ */