dstevr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /* dstevr.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__10 = 10;
  15. static integer c__1 = 1;
  16. static integer c__2 = 2;
  17. static integer c__3 = 3;
  18. static integer c__4 = 4;
  19. /* Subroutine */ int _starpu_dstevr_(char *jobz, char *range, integer *n, doublereal *
  20. d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il,
  21. integer *iu, doublereal *abstol, integer *m, doublereal *w,
  22. doublereal *z__, integer *ldz, integer *isuppz, doublereal *work,
  23. integer *lwork, integer *iwork, integer *liwork, integer *info)
  24. {
  25. /* System generated locals */
  26. integer z_dim1, z_offset, i__1, i__2;
  27. doublereal d__1, d__2;
  28. /* Builtin functions */
  29. double sqrt(doublereal);
  30. /* Local variables */
  31. integer i__, j, jj;
  32. doublereal eps, vll, vuu, tmp1;
  33. integer imax;
  34. doublereal rmin, rmax;
  35. logical test;
  36. doublereal tnrm;
  37. integer itmp1;
  38. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  39. integer *);
  40. doublereal sigma;
  41. extern logical _starpu_lsame_(char *, char *);
  42. char order[1];
  43. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  44. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  45. *, doublereal *, integer *);
  46. integer lwmin;
  47. logical wantz;
  48. extern doublereal _starpu_dlamch_(char *);
  49. logical alleig, indeig;
  50. integer iscale, ieeeok, indibl, indifl;
  51. logical valeig;
  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 bignum;
  57. extern doublereal _starpu_dlanst_(char *, integer *, doublereal *, doublereal *);
  58. integer indisp;
  59. extern /* Subroutine */ int _starpu_dstein_(integer *, doublereal *, doublereal *,
  60. integer *, doublereal *, integer *, integer *, doublereal *,
  61. integer *, doublereal *, integer *, integer *, integer *),
  62. _starpu_dsterf_(integer *, doublereal *, doublereal *, integer *);
  63. integer indiwo;
  64. extern /* Subroutine */ int _starpu_dstebz_(char *, char *, integer *, doublereal
  65. *, doublereal *, integer *, integer *, doublereal *, doublereal *,
  66. doublereal *, integer *, integer *, doublereal *, integer *,
  67. integer *, doublereal *, integer *, integer *),
  68. _starpu_dstemr_(char *, char *, integer *, doublereal *, doublereal *,
  69. doublereal *, doublereal *, integer *, integer *, integer *,
  70. doublereal *, doublereal *, integer *, integer *, integer *,
  71. logical *, doublereal *, integer *, integer *, integer *, integer
  72. *);
  73. integer liwmin;
  74. logical tryrac;
  75. integer nsplit;
  76. doublereal smlnum;
  77. logical lquery;
  78. /* -- LAPACK driver routine (version 3.2) -- */
  79. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  80. /* November 2006 */
  81. /* .. Scalar Arguments .. */
  82. /* .. */
  83. /* .. Array Arguments .. */
  84. /* .. */
  85. /* Purpose */
  86. /* ======= */
  87. /* DSTEVR computes selected eigenvalues and, optionally, eigenvectors */
  88. /* of a real symmetric tridiagonal matrix T. Eigenvalues and */
  89. /* eigenvectors can be selected by specifying either a range of values */
  90. /* or a range of indices for the desired eigenvalues. */
  91. /* Whenever possible, DSTEVR calls DSTEMR to compute the */
  92. /* eigenspectrum using Relatively Robust Representations. DSTEMR */
  93. /* computes eigenvalues by the dqds algorithm, while orthogonal */
  94. /* eigenvectors are computed from various "good" L D L^T representations */
  95. /* (also known as Relatively Robust Representations). Gram-Schmidt */
  96. /* orthogonalization is avoided as far as possible. More specifically, */
  97. /* the various steps of the algorithm are as follows. For the i-th */
  98. /* unreduced block of T, */
  99. /* (a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T */
  100. /* is a relatively robust representation, */
  101. /* (b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high */
  102. /* relative accuracy by the dqds algorithm, */
  103. /* (c) If there is a cluster of close eigenvalues, "choose" sigma_i */
  104. /* close to the cluster, and go to step (a), */
  105. /* (d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T, */
  106. /* compute the corresponding eigenvector by forming a */
  107. /* rank-revealing twisted factorization. */
  108. /* The desired accuracy of the output can be specified by the input */
  109. /* parameter ABSTOL. */
  110. /* For more details, see "A new O(n^2) algorithm for the symmetric */
  111. /* tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon, */
  112. /* Computer Science Division Technical Report No. UCB//CSD-97-971, */
  113. /* UC Berkeley, May 1997. */
  114. /* Note 1 : DSTEVR calls DSTEMR when the full spectrum is requested */
  115. /* on machines which conform to the ieee-754 floating point standard. */
  116. /* DSTEVR calls DSTEBZ and DSTEIN on non-ieee machines and */
  117. /* when partial spectrum requests are made. */
  118. /* Normal execution of DSTEMR may create NaNs and infinities and */
  119. /* hence may abort due to a floating point exception in environments */
  120. /* which do not handle NaNs and infinities in the ieee standard default */
  121. /* manner. */
  122. /* Arguments */
  123. /* ========= */
  124. /* JOBZ (input) CHARACTER*1 */
  125. /* = 'N': Compute eigenvalues only; */
  126. /* = 'V': Compute eigenvalues and eigenvectors. */
  127. /* RANGE (input) CHARACTER*1 */
  128. /* = 'A': all eigenvalues will be found. */
  129. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  130. /* will be found. */
  131. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  132. /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */
  133. /* ********* DSTEIN are called */
  134. /* N (input) INTEGER */
  135. /* The order of the matrix. N >= 0. */
  136. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  137. /* On entry, the n diagonal elements of the tridiagonal matrix */
  138. /* A. */
  139. /* On exit, D may be multiplied by a constant factor chosen */
  140. /* to avoid over/underflow in computing the eigenvalues. */
  141. /* E (input/output) DOUBLE PRECISION array, dimension (max(1,N-1)) */
  142. /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
  143. /* matrix A in elements 1 to N-1 of E. */
  144. /* On exit, E may be multiplied by a constant factor chosen */
  145. /* to avoid over/underflow in computing the eigenvalues. */
  146. /* VL (input) DOUBLE PRECISION */
  147. /* VU (input) DOUBLE PRECISION */
  148. /* If RANGE='V', the lower and upper bounds of the interval to */
  149. /* be searched for eigenvalues. VL < VU. */
  150. /* Not referenced if RANGE = 'A' or 'I'. */
  151. /* IL (input) INTEGER */
  152. /* IU (input) INTEGER */
  153. /* If RANGE='I', the indices (in ascending order) of the */
  154. /* smallest and largest eigenvalues to be returned. */
  155. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  156. /* Not referenced if RANGE = 'A' or 'V'. */
  157. /* ABSTOL (input) DOUBLE PRECISION */
  158. /* The absolute error tolerance for the eigenvalues. */
  159. /* An approximate eigenvalue is accepted as converged */
  160. /* when it is determined to lie in an interval [a,b] */
  161. /* of width less than or equal to */
  162. /* ABSTOL + EPS * max( |a|,|b| ) , */
  163. /* where EPS is the machine precision. If ABSTOL is less than */
  164. /* or equal to zero, then EPS*|T| will be used in its place, */
  165. /* where |T| is the 1-norm of the tridiagonal matrix obtained */
  166. /* by reducing A to tridiagonal form. */
  167. /* See "Computing Small Singular Values of Bidiagonal Matrices */
  168. /* with Guaranteed High Relative Accuracy," by Demmel and */
  169. /* Kahan, LAPACK Working Note #3. */
  170. /* If high relative accuracy is important, set ABSTOL to */
  171. /* DLAMCH( 'Safe minimum' ). Doing so will guarantee that */
  172. /* eigenvalues are computed to high relative accuracy when */
  173. /* possible in future releases. The current code does not */
  174. /* make any guarantees about high relative accuracy, but */
  175. /* future releases will. See J. Barlow and J. Demmel, */
  176. /* "Computing Accurate Eigensystems of Scaled Diagonally */
  177. /* Dominant Matrices", LAPACK Working Note #7, for a discussion */
  178. /* of which matrices define their eigenvalues to high relative */
  179. /* accuracy. */
  180. /* M (output) INTEGER */
  181. /* The total number of eigenvalues found. 0 <= M <= N. */
  182. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  183. /* W (output) DOUBLE PRECISION array, dimension (N) */
  184. /* The first M elements contain the selected eigenvalues in */
  185. /* ascending order. */
  186. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */
  187. /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  188. /* contain the orthonormal eigenvectors of the matrix A */
  189. /* corresponding to the selected eigenvalues, with the i-th */
  190. /* column of Z holding the eigenvector associated with W(i). */
  191. /* Note: the user must ensure that at least max(1,M) columns are */
  192. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  193. /* is not known in advance and an upper bound must be used. */
  194. /* LDZ (input) INTEGER */
  195. /* The leading dimension of the array Z. LDZ >= 1, and if */
  196. /* JOBZ = 'V', LDZ >= max(1,N). */
  197. /* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */
  198. /* The support of the eigenvectors in Z, i.e., the indices */
  199. /* indicating the nonzero elements in Z. The i-th eigenvector */
  200. /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  201. /* ISUPPZ( 2*i ). */
  202. /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
  203. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  204. /* On exit, if INFO = 0, WORK(1) returns the optimal (and */
  205. /* minimal) LWORK. */
  206. /* LWORK (input) INTEGER */
  207. /* The dimension of the array WORK. LWORK >= max(1,20*N). */
  208. /* If LWORK = -1, then a workspace query is assumed; the routine */
  209. /* only calculates the optimal sizes of the WORK and IWORK */
  210. /* arrays, returns these values as the first entries of the WORK */
  211. /* and IWORK arrays, and no error message related to LWORK or */
  212. /* LIWORK is issued by XERBLA. */
  213. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  214. /* On exit, if INFO = 0, IWORK(1) returns the optimal (and */
  215. /* minimal) LIWORK. */
  216. /* LIWORK (input) INTEGER */
  217. /* The dimension of the array IWORK. LIWORK >= max(1,10*N). */
  218. /* If LIWORK = -1, then a workspace query is assumed; the */
  219. /* routine only calculates the optimal sizes of the WORK and */
  220. /* IWORK arrays, returns these values as the first entries of */
  221. /* the WORK and IWORK arrays, and no error message related to */
  222. /* LWORK or LIWORK is issued by XERBLA. */
  223. /* INFO (output) INTEGER */
  224. /* = 0: successful exit */
  225. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  226. /* > 0: Internal error */
  227. /* Further Details */
  228. /* =============== */
  229. /* Based on contributions by */
  230. /* Inderjit Dhillon, IBM Almaden, USA */
  231. /* Osni Marques, LBNL/NERSC, USA */
  232. /* Ken Stanley, Computer Science Division, University of */
  233. /* California at Berkeley, USA */
  234. /* ===================================================================== */
  235. /* .. Parameters .. */
  236. /* .. */
  237. /* .. Local Scalars .. */
  238. /* .. */
  239. /* .. External Functions .. */
  240. /* .. */
  241. /* .. External Subroutines .. */
  242. /* .. */
  243. /* .. Intrinsic Functions .. */
  244. /* .. */
  245. /* .. Executable Statements .. */
  246. /* Test the input parameters. */
  247. /* Parameter adjustments */
  248. --d__;
  249. --e;
  250. --w;
  251. z_dim1 = *ldz;
  252. z_offset = 1 + z_dim1;
  253. z__ -= z_offset;
  254. --isuppz;
  255. --work;
  256. --iwork;
  257. /* Function Body */
  258. ieeeok = _starpu_ilaenv_(&c__10, "DSTEVR", "N", &c__1, &c__2, &c__3, &c__4);
  259. wantz = _starpu_lsame_(jobz, "V");
  260. alleig = _starpu_lsame_(range, "A");
  261. valeig = _starpu_lsame_(range, "V");
  262. indeig = _starpu_lsame_(range, "I");
  263. lquery = *lwork == -1 || *liwork == -1;
  264. /* Computing MAX */
  265. i__1 = 1, i__2 = *n * 20;
  266. lwmin = max(i__1,i__2);
  267. /* Computing MAX */
  268. i__1 = 1, i__2 = *n * 10;
  269. liwmin = max(i__1,i__2);
  270. *info = 0;
  271. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  272. *info = -1;
  273. } else if (! (alleig || valeig || indeig)) {
  274. *info = -2;
  275. } else if (*n < 0) {
  276. *info = -3;
  277. } else {
  278. if (valeig) {
  279. if (*n > 0 && *vu <= *vl) {
  280. *info = -7;
  281. }
  282. } else if (indeig) {
  283. if (*il < 1 || *il > max(1,*n)) {
  284. *info = -8;
  285. } else if (*iu < min(*n,*il) || *iu > *n) {
  286. *info = -9;
  287. }
  288. }
  289. }
  290. if (*info == 0) {
  291. if (*ldz < 1 || wantz && *ldz < *n) {
  292. *info = -14;
  293. }
  294. }
  295. if (*info == 0) {
  296. work[1] = (doublereal) lwmin;
  297. iwork[1] = liwmin;
  298. if (*lwork < lwmin && ! lquery) {
  299. *info = -17;
  300. } else if (*liwork < liwmin && ! lquery) {
  301. *info = -19;
  302. }
  303. }
  304. if (*info != 0) {
  305. i__1 = -(*info);
  306. _starpu_xerbla_("DSTEVR", &i__1);
  307. return 0;
  308. } else if (lquery) {
  309. return 0;
  310. }
  311. /* Quick return if possible */
  312. *m = 0;
  313. if (*n == 0) {
  314. return 0;
  315. }
  316. if (*n == 1) {
  317. if (alleig || indeig) {
  318. *m = 1;
  319. w[1] = d__[1];
  320. } else {
  321. if (*vl < d__[1] && *vu >= d__[1]) {
  322. *m = 1;
  323. w[1] = d__[1];
  324. }
  325. }
  326. if (wantz) {
  327. z__[z_dim1 + 1] = 1.;
  328. }
  329. return 0;
  330. }
  331. /* Get machine constants. */
  332. safmin = _starpu_dlamch_("Safe minimum");
  333. eps = _starpu_dlamch_("Precision");
  334. smlnum = safmin / eps;
  335. bignum = 1. / smlnum;
  336. rmin = sqrt(smlnum);
  337. /* Computing MIN */
  338. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  339. rmax = min(d__1,d__2);
  340. /* Scale matrix to allowable range, if necessary. */
  341. iscale = 0;
  342. vll = *vl;
  343. vuu = *vu;
  344. tnrm = _starpu_dlanst_("M", n, &d__[1], &e[1]);
  345. if (tnrm > 0. && tnrm < rmin) {
  346. iscale = 1;
  347. sigma = rmin / tnrm;
  348. } else if (tnrm > rmax) {
  349. iscale = 1;
  350. sigma = rmax / tnrm;
  351. }
  352. if (iscale == 1) {
  353. _starpu_dscal_(n, &sigma, &d__[1], &c__1);
  354. i__1 = *n - 1;
  355. _starpu_dscal_(&i__1, &sigma, &e[1], &c__1);
  356. if (valeig) {
  357. vll = *vl * sigma;
  358. vuu = *vu * sigma;
  359. }
  360. }
  361. /* Initialize indices into workspaces. Note: These indices are used only */
  362. /* if DSTERF or DSTEMR fail. */
  363. /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and */
  364. /* stores the block indices of each of the M<=N eigenvalues. */
  365. indibl = 1;
  366. /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and */
  367. /* stores the starting and finishing indices of each block. */
  368. indisp = indibl + *n;
  369. /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
  370. /* that corresponding to eigenvectors that fail to converge in */
  371. /* DSTEIN. This information is discarded; if any fail, the driver */
  372. /* returns INFO > 0. */
  373. indifl = indisp + *n;
  374. /* INDIWO is the offset of the remaining integer workspace. */
  375. indiwo = indisp + *n;
  376. /* If all eigenvalues are desired, then */
  377. /* call DSTERF or DSTEMR. If this fails for some eigenvalue, then */
  378. /* try DSTEBZ. */
  379. test = FALSE_;
  380. if (indeig) {
  381. if (*il == 1 && *iu == *n) {
  382. test = TRUE_;
  383. }
  384. }
  385. if ((alleig || test) && ieeeok == 1) {
  386. i__1 = *n - 1;
  387. _starpu_dcopy_(&i__1, &e[1], &c__1, &work[1], &c__1);
  388. if (! wantz) {
  389. _starpu_dcopy_(n, &d__[1], &c__1, &w[1], &c__1);
  390. _starpu_dsterf_(n, &w[1], &work[1], info);
  391. } else {
  392. _starpu_dcopy_(n, &d__[1], &c__1, &work[*n + 1], &c__1);
  393. if (*abstol <= *n * 2. * eps) {
  394. tryrac = TRUE_;
  395. } else {
  396. tryrac = FALSE_;
  397. }
  398. i__1 = *lwork - (*n << 1);
  399. _starpu_dstemr_(jobz, "A", n, &work[*n + 1], &work[1], vl, vu, il, iu, m,
  400. &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &work[
  401. (*n << 1) + 1], &i__1, &iwork[1], liwork, info);
  402. }
  403. if (*info == 0) {
  404. *m = *n;
  405. goto L10;
  406. }
  407. *info = 0;
  408. }
  409. /* Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN. */
  410. if (wantz) {
  411. *(unsigned char *)order = 'B';
  412. } else {
  413. *(unsigned char *)order = 'E';
  414. }
  415. _starpu_dstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, &
  416. nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[1], &iwork[
  417. indiwo], info);
  418. if (wantz) {
  419. _starpu_dstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], &
  420. z__[z_offset], ldz, &work[1], &iwork[indiwo], &iwork[indifl],
  421. info);
  422. }
  423. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  424. L10:
  425. if (iscale == 1) {
  426. if (*info == 0) {
  427. imax = *m;
  428. } else {
  429. imax = *info - 1;
  430. }
  431. d__1 = 1. / sigma;
  432. _starpu_dscal_(&imax, &d__1, &w[1], &c__1);
  433. }
  434. /* If eigenvalues are not in order, then sort them, along with */
  435. /* eigenvectors. */
  436. if (wantz) {
  437. i__1 = *m - 1;
  438. for (j = 1; j <= i__1; ++j) {
  439. i__ = 0;
  440. tmp1 = w[j];
  441. i__2 = *m;
  442. for (jj = j + 1; jj <= i__2; ++jj) {
  443. if (w[jj] < tmp1) {
  444. i__ = jj;
  445. tmp1 = w[jj];
  446. }
  447. /* L20: */
  448. }
  449. if (i__ != 0) {
  450. itmp1 = iwork[i__];
  451. w[i__] = w[j];
  452. iwork[i__] = iwork[j];
  453. w[j] = tmp1;
  454. iwork[j] = itmp1;
  455. _starpu_dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  456. &c__1);
  457. }
  458. /* L30: */
  459. }
  460. }
  461. /* Causes problems with tests 19 & 20: */
  462. /* IF (wantz .and. INDEIG ) Z( 1,1) = Z(1,1) / 1.002 + .002 */
  463. work[1] = (doublereal) lwmin;
  464. iwork[1] = liwmin;
  465. return 0;
  466. /* End of DSTEVR */
  467. } /* _starpu_dstevr_ */