dsyevx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /* dsyevx.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_n1 = -1;
  16. /* Subroutine */ int _starpu_dsyevx_(char *jobz, char *range, char *uplo, integer *n,
  17. doublereal *a, integer *lda, doublereal *vl, doublereal *vu, integer *
  18. il, integer *iu, doublereal *abstol, integer *m, doublereal *w,
  19. doublereal *z__, integer *ldz, doublereal *work, integer *lwork,
  20. integer *iwork, integer *ifail, integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
  24. doublereal d__1, d__2;
  25. /* Builtin functions */
  26. double sqrt(doublereal);
  27. /* Local variables */
  28. integer i__, j, nb, jj;
  29. doublereal eps, vll, vuu, tmp1;
  30. integer indd, inde;
  31. doublereal anrm;
  32. integer imax;
  33. doublereal rmin, rmax;
  34. logical test;
  35. integer itmp1, indee;
  36. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  37. integer *);
  38. doublereal sigma;
  39. extern logical _starpu_lsame_(char *, char *);
  40. integer iinfo;
  41. char order[1];
  42. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  43. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  44. *, doublereal *, integer *);
  45. logical lower, wantz;
  46. extern doublereal _starpu_dlamch_(char *);
  47. logical alleig, indeig;
  48. integer iscale, indibl;
  49. logical valeig;
  50. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  51. doublereal *, integer *, doublereal *, integer *);
  52. doublereal safmin;
  53. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  54. integer *, integer *);
  55. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  56. doublereal abstll, bignum;
  57. integer indtau, indisp;
  58. extern /* Subroutine */ int _starpu_dstein_(integer *, doublereal *, doublereal *,
  59. integer *, doublereal *, integer *, integer *, doublereal *,
  60. integer *, doublereal *, integer *, integer *, integer *),
  61. _starpu_dsterf_(integer *, doublereal *, doublereal *, integer *);
  62. integer indiwo, indwkn;
  63. extern doublereal _starpu_dlansy_(char *, char *, integer *, doublereal *,
  64. integer *, doublereal *);
  65. extern /* Subroutine */ int _starpu_dstebz_(char *, char *, integer *, doublereal
  66. *, doublereal *, integer *, integer *, doublereal *, doublereal *,
  67. doublereal *, integer *, integer *, doublereal *, integer *,
  68. integer *, doublereal *, integer *, integer *);
  69. integer indwrk, lwkmin;
  70. extern /* Subroutine */ int _starpu_dorgtr_(char *, integer *, doublereal *,
  71. integer *, doublereal *, doublereal *, integer *, integer *), _starpu_dsteqr_(char *, integer *, doublereal *, doublereal *,
  72. doublereal *, integer *, doublereal *, integer *),
  73. _starpu_dormtr_(char *, char *, char *, integer *, integer *, doublereal *
  74. , integer *, doublereal *, doublereal *, integer *, doublereal *,
  75. integer *, integer *);
  76. integer llwrkn, llwork, nsplit;
  77. doublereal smlnum;
  78. extern /* Subroutine */ int _starpu_dsytrd_(char *, integer *, doublereal *,
  79. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  80. integer *, integer *);
  81. integer lwkopt;
  82. logical lquery;
  83. /* -- LAPACK driver routine (version 3.2) -- */
  84. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  85. /* November 2006 */
  86. /* .. Scalar Arguments .. */
  87. /* .. */
  88. /* .. Array Arguments .. */
  89. /* .. */
  90. /* Purpose */
  91. /* ======= */
  92. /* DSYEVX computes selected eigenvalues and, optionally, eigenvectors */
  93. /* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */
  94. /* selected by specifying either a range of values or a range of indices */
  95. /* for the desired eigenvalues. */
  96. /* Arguments */
  97. /* ========= */
  98. /* JOBZ (input) CHARACTER*1 */
  99. /* = 'N': Compute eigenvalues only; */
  100. /* = 'V': Compute eigenvalues and eigenvectors. */
  101. /* RANGE (input) CHARACTER*1 */
  102. /* = 'A': all eigenvalues will be found. */
  103. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  104. /* will be found. */
  105. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  106. /* UPLO (input) CHARACTER*1 */
  107. /* = 'U': Upper triangle of A is stored; */
  108. /* = 'L': Lower triangle of A is stored. */
  109. /* N (input) INTEGER */
  110. /* The order of the matrix A. N >= 0. */
  111. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  112. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  113. /* leading N-by-N upper triangular part of A contains the */
  114. /* upper triangular part of the matrix A. If UPLO = 'L', */
  115. /* the leading N-by-N lower triangular part of A contains */
  116. /* the lower triangular part of the matrix A. */
  117. /* On exit, the lower triangle (if UPLO='L') or the upper */
  118. /* triangle (if UPLO='U') of A, including the diagonal, is */
  119. /* destroyed. */
  120. /* LDA (input) INTEGER */
  121. /* The leading dimension of the array A. LDA >= max(1,N). */
  122. /* VL (input) DOUBLE PRECISION */
  123. /* VU (input) DOUBLE PRECISION */
  124. /* If RANGE='V', the lower and upper bounds of the interval to */
  125. /* be searched for eigenvalues. VL < VU. */
  126. /* Not referenced if RANGE = 'A' or 'I'. */
  127. /* IL (input) INTEGER */
  128. /* IU (input) INTEGER */
  129. /* If RANGE='I', the indices (in ascending order) of the */
  130. /* smallest and largest eigenvalues to be returned. */
  131. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  132. /* Not referenced if RANGE = 'A' or 'V'. */
  133. /* ABSTOL (input) DOUBLE PRECISION */
  134. /* The absolute error tolerance for the eigenvalues. */
  135. /* An approximate eigenvalue is accepted as converged */
  136. /* when it is determined to lie in an interval [a,b] */
  137. /* of width less than or equal to */
  138. /* ABSTOL + EPS * max( |a|,|b| ) , */
  139. /* where EPS is the machine precision. If ABSTOL is less than */
  140. /* or equal to zero, then EPS*|T| will be used in its place, */
  141. /* where |T| is the 1-norm of the tridiagonal matrix obtained */
  142. /* by reducing A to tridiagonal form. */
  143. /* Eigenvalues will be computed most accurately when ABSTOL is */
  144. /* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
  145. /* If this routine returns with INFO>0, indicating that some */
  146. /* eigenvectors did not converge, try setting ABSTOL to */
  147. /* 2*DLAMCH('S'). */
  148. /* See "Computing Small Singular Values of Bidiagonal Matrices */
  149. /* with Guaranteed High Relative Accuracy," by Demmel and */
  150. /* Kahan, LAPACK Working Note #3. */
  151. /* M (output) INTEGER */
  152. /* The total number of eigenvalues found. 0 <= M <= N. */
  153. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  154. /* W (output) DOUBLE PRECISION array, dimension (N) */
  155. /* On normal exit, the first M elements contain the selected */
  156. /* eigenvalues in ascending order. */
  157. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */
  158. /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  159. /* contain the orthonormal eigenvectors of the matrix A */
  160. /* corresponding to the selected eigenvalues, with the i-th */
  161. /* column of Z holding the eigenvector associated with W(i). */
  162. /* If an eigenvector fails to converge, then that column of Z */
  163. /* contains the latest approximation to the eigenvector, and the */
  164. /* index of the eigenvector is returned in IFAIL. */
  165. /* If JOBZ = 'N', then Z is not referenced. */
  166. /* Note: the user must ensure that at least max(1,M) columns are */
  167. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  168. /* is not known in advance and an upper bound must be used. */
  169. /* LDZ (input) INTEGER */
  170. /* The leading dimension of the array Z. LDZ >= 1, and if */
  171. /* JOBZ = 'V', LDZ >= max(1,N). */
  172. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  173. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  174. /* LWORK (input) INTEGER */
  175. /* The length of the array WORK. LWORK >= 1, when N <= 1; */
  176. /* otherwise 8*N. */
  177. /* For optimal efficiency, LWORK >= (NB+3)*N, */
  178. /* where NB is the max of the blocksize for DSYTRD and DORMTR */
  179. /* returned by ILAENV. */
  180. /* If LWORK = -1, then a workspace query is assumed; the routine */
  181. /* only calculates the optimal size of the WORK array, returns */
  182. /* this value as the first entry of the WORK array, and no error */
  183. /* message related to LWORK is issued by XERBLA. */
  184. /* IWORK (workspace) INTEGER array, dimension (5*N) */
  185. /* IFAIL (output) INTEGER array, dimension (N) */
  186. /* If JOBZ = 'V', then if INFO = 0, the first M elements of */
  187. /* IFAIL are zero. If INFO > 0, then IFAIL contains the */
  188. /* indices of the eigenvectors that failed to converge. */
  189. /* If JOBZ = 'N', then IFAIL is not referenced. */
  190. /* INFO (output) INTEGER */
  191. /* = 0: successful exit */
  192. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  193. /* > 0: if INFO = i, then i eigenvectors failed to converge. */
  194. /* Their indices are stored in array IFAIL. */
  195. /* ===================================================================== */
  196. /* .. Parameters .. */
  197. /* .. */
  198. /* .. Local Scalars .. */
  199. /* .. */
  200. /* .. External Functions .. */
  201. /* .. */
  202. /* .. External Subroutines .. */
  203. /* .. */
  204. /* .. Intrinsic Functions .. */
  205. /* .. */
  206. /* .. Executable Statements .. */
  207. /* Test the input parameters. */
  208. /* Parameter adjustments */
  209. a_dim1 = *lda;
  210. a_offset = 1 + a_dim1;
  211. a -= a_offset;
  212. --w;
  213. z_dim1 = *ldz;
  214. z_offset = 1 + z_dim1;
  215. z__ -= z_offset;
  216. --work;
  217. --iwork;
  218. --ifail;
  219. /* Function Body */
  220. lower = _starpu_lsame_(uplo, "L");
  221. wantz = _starpu_lsame_(jobz, "V");
  222. alleig = _starpu_lsame_(range, "A");
  223. valeig = _starpu_lsame_(range, "V");
  224. indeig = _starpu_lsame_(range, "I");
  225. lquery = *lwork == -1;
  226. *info = 0;
  227. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  228. *info = -1;
  229. } else if (! (alleig || valeig || indeig)) {
  230. *info = -2;
  231. } else if (! (lower || _starpu_lsame_(uplo, "U"))) {
  232. *info = -3;
  233. } else if (*n < 0) {
  234. *info = -4;
  235. } else if (*lda < max(1,*n)) {
  236. *info = -6;
  237. } else {
  238. if (valeig) {
  239. if (*n > 0 && *vu <= *vl) {
  240. *info = -8;
  241. }
  242. } else if (indeig) {
  243. if (*il < 1 || *il > max(1,*n)) {
  244. *info = -9;
  245. } else if (*iu < min(*n,*il) || *iu > *n) {
  246. *info = -10;
  247. }
  248. }
  249. }
  250. if (*info == 0) {
  251. if (*ldz < 1 || wantz && *ldz < *n) {
  252. *info = -15;
  253. }
  254. }
  255. if (*info == 0) {
  256. if (*n <= 1) {
  257. lwkmin = 1;
  258. work[1] = (doublereal) lwkmin;
  259. } else {
  260. lwkmin = *n << 3;
  261. nb = _starpu_ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  262. /* Computing MAX */
  263. i__1 = nb, i__2 = _starpu_ilaenv_(&c__1, "DORMTR", uplo, n, &c_n1, &c_n1,
  264. &c_n1);
  265. nb = max(i__1,i__2);
  266. /* Computing MAX */
  267. i__1 = lwkmin, i__2 = (nb + 3) * *n;
  268. lwkopt = max(i__1,i__2);
  269. work[1] = (doublereal) lwkopt;
  270. }
  271. if (*lwork < lwkmin && ! lquery) {
  272. *info = -17;
  273. }
  274. }
  275. if (*info != 0) {
  276. i__1 = -(*info);
  277. _starpu_xerbla_("DSYEVX", &i__1);
  278. return 0;
  279. } else if (lquery) {
  280. return 0;
  281. }
  282. /* Quick return if possible */
  283. *m = 0;
  284. if (*n == 0) {
  285. return 0;
  286. }
  287. if (*n == 1) {
  288. if (alleig || indeig) {
  289. *m = 1;
  290. w[1] = a[a_dim1 + 1];
  291. } else {
  292. if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) {
  293. *m = 1;
  294. w[1] = a[a_dim1 + 1];
  295. }
  296. }
  297. if (wantz) {
  298. z__[z_dim1 + 1] = 1.;
  299. }
  300. return 0;
  301. }
  302. /* Get machine constants. */
  303. safmin = _starpu_dlamch_("Safe minimum");
  304. eps = _starpu_dlamch_("Precision");
  305. smlnum = safmin / eps;
  306. bignum = 1. / smlnum;
  307. rmin = sqrt(smlnum);
  308. /* Computing MIN */
  309. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  310. rmax = min(d__1,d__2);
  311. /* Scale matrix to allowable range, if necessary. */
  312. iscale = 0;
  313. abstll = *abstol;
  314. if (valeig) {
  315. vll = *vl;
  316. vuu = *vu;
  317. }
  318. anrm = _starpu_dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
  319. if (anrm > 0. && anrm < rmin) {
  320. iscale = 1;
  321. sigma = rmin / anrm;
  322. } else if (anrm > rmax) {
  323. iscale = 1;
  324. sigma = rmax / anrm;
  325. }
  326. if (iscale == 1) {
  327. if (lower) {
  328. i__1 = *n;
  329. for (j = 1; j <= i__1; ++j) {
  330. i__2 = *n - j + 1;
  331. _starpu_dscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
  332. /* L10: */
  333. }
  334. } else {
  335. i__1 = *n;
  336. for (j = 1; j <= i__1; ++j) {
  337. _starpu_dscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
  338. /* L20: */
  339. }
  340. }
  341. if (*abstol > 0.) {
  342. abstll = *abstol * sigma;
  343. }
  344. if (valeig) {
  345. vll = *vl * sigma;
  346. vuu = *vu * sigma;
  347. }
  348. }
  349. /* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
  350. indtau = 1;
  351. inde = indtau + *n;
  352. indd = inde + *n;
  353. indwrk = indd + *n;
  354. llwork = *lwork - indwrk + 1;
  355. _starpu_dsytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[
  356. indtau], &work[indwrk], &llwork, &iinfo);
  357. /* If all eigenvalues are desired and ABSTOL is less than or equal to */
  358. /* zero, then call DSTERF or DORGTR and SSTEQR. If this fails for */
  359. /* some eigenvalue, then try DSTEBZ. */
  360. test = FALSE_;
  361. if (indeig) {
  362. if (*il == 1 && *iu == *n) {
  363. test = TRUE_;
  364. }
  365. }
  366. if ((alleig || test) && *abstol <= 0.) {
  367. _starpu_dcopy_(n, &work[indd], &c__1, &w[1], &c__1);
  368. indee = indwrk + (*n << 1);
  369. if (! wantz) {
  370. i__1 = *n - 1;
  371. _starpu_dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
  372. _starpu_dsterf_(n, &w[1], &work[indee], info);
  373. } else {
  374. _starpu_dlacpy_("A", n, n, &a[a_offset], lda, &z__[z_offset], ldz);
  375. _starpu_dorgtr_(uplo, n, &z__[z_offset], ldz, &work[indtau], &work[indwrk]
  376. , &llwork, &iinfo);
  377. i__1 = *n - 1;
  378. _starpu_dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
  379. _starpu_dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[
  380. indwrk], info);
  381. if (*info == 0) {
  382. i__1 = *n;
  383. for (i__ = 1; i__ <= i__1; ++i__) {
  384. ifail[i__] = 0;
  385. /* L30: */
  386. }
  387. }
  388. }
  389. if (*info == 0) {
  390. *m = *n;
  391. goto L40;
  392. }
  393. *info = 0;
  394. }
  395. /* Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */
  396. if (wantz) {
  397. *(unsigned char *)order = 'B';
  398. } else {
  399. *(unsigned char *)order = 'E';
  400. }
  401. indibl = 1;
  402. indisp = indibl + *n;
  403. indiwo = indisp + *n;
  404. _starpu_dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[
  405. inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[
  406. indwrk], &iwork[indiwo], info);
  407. if (wantz) {
  408. _starpu_dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[
  409. indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], &
  410. ifail[1], info);
  411. /* Apply orthogonal matrix used in reduction to tridiagonal */
  412. /* form to eigenvectors returned by DSTEIN. */
  413. indwkn = inde;
  414. llwrkn = *lwork - indwkn + 1;
  415. _starpu_dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
  416. z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  417. }
  418. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  419. L40:
  420. if (iscale == 1) {
  421. if (*info == 0) {
  422. imax = *m;
  423. } else {
  424. imax = *info - 1;
  425. }
  426. d__1 = 1. / sigma;
  427. _starpu_dscal_(&imax, &d__1, &w[1], &c__1);
  428. }
  429. /* If eigenvalues are not in order, then sort them, along with */
  430. /* eigenvectors. */
  431. if (wantz) {
  432. i__1 = *m - 1;
  433. for (j = 1; j <= i__1; ++j) {
  434. i__ = 0;
  435. tmp1 = w[j];
  436. i__2 = *m;
  437. for (jj = j + 1; jj <= i__2; ++jj) {
  438. if (w[jj] < tmp1) {
  439. i__ = jj;
  440. tmp1 = w[jj];
  441. }
  442. /* L50: */
  443. }
  444. if (i__ != 0) {
  445. itmp1 = iwork[indibl + i__ - 1];
  446. w[i__] = w[j];
  447. iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
  448. w[j] = tmp1;
  449. iwork[indibl + j - 1] = itmp1;
  450. _starpu_dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  451. &c__1);
  452. if (*info != 0) {
  453. itmp1 = ifail[i__];
  454. ifail[i__] = ifail[j];
  455. ifail[j] = itmp1;
  456. }
  457. }
  458. /* L60: */
  459. }
  460. }
  461. /* Set WORK(1) to optimal workspace size. */
  462. work[1] = (doublereal) lwkopt;
  463. return 0;
  464. /* End of DSYEVX */
  465. } /* _starpu_dsyevx_ */