dstemr.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /* dstemr.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 doublereal c_b18 = .001;
  16. /* Subroutine */ int _starpu_dstemr_(char *jobz, char *range, integer *n, doublereal *
  17. d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il,
  18. integer *iu, integer *m, doublereal *w, doublereal *z__, integer *ldz,
  19. integer *nzc, integer *isuppz, logical *tryrac, doublereal *work,
  20. integer *lwork, integer *iwork, integer *liwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer 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;
  29. doublereal r1, r2;
  30. integer jj;
  31. doublereal cs;
  32. integer in;
  33. doublereal sn, wl, wu;
  34. integer iil, iiu;
  35. doublereal eps, tmp;
  36. integer indd, iend, jblk, wend;
  37. doublereal rmin, rmax;
  38. integer itmp;
  39. doublereal tnrm;
  40. extern /* Subroutine */ int _starpu_dlae2_(doublereal *, doublereal *, doublereal
  41. *, doublereal *, doublereal *);
  42. integer inde2, itmp2;
  43. doublereal rtol1, rtol2;
  44. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  45. integer *);
  46. doublereal scale;
  47. integer indgp;
  48. extern logical _starpu_lsame_(char *, char *);
  49. integer iinfo, iindw, ilast;
  50. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  51. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  52. *, doublereal *, integer *);
  53. integer lwmin;
  54. logical wantz;
  55. extern /* Subroutine */ int _starpu_dlaev2_(doublereal *, doublereal *,
  56. doublereal *, doublereal *, doublereal *, doublereal *,
  57. doublereal *);
  58. extern doublereal _starpu_dlamch_(char *);
  59. logical alleig;
  60. integer ibegin;
  61. logical indeig;
  62. integer iindbl;
  63. logical valeig;
  64. extern /* Subroutine */ int _starpu_dlarrc_(char *, integer *, doublereal *,
  65. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  66. integer *, integer *, integer *), _starpu_dlarre_(char *,
  67. integer *, doublereal *, doublereal *, integer *, integer *,
  68. doublereal *, doublereal *, doublereal *, doublereal *,
  69. doublereal *, doublereal *, integer *, integer *, integer *,
  70. doublereal *, doublereal *, doublereal *, integer *, integer *,
  71. doublereal *, doublereal *, doublereal *, integer *, integer *);
  72. integer wbegin;
  73. doublereal safmin;
  74. extern /* Subroutine */ int _starpu_dlarrj_(integer *, doublereal *, doublereal *,
  75. integer *, integer *, doublereal *, integer *, doublereal *,
  76. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  77. integer *), _starpu_xerbla_(char *, integer *);
  78. doublereal bignum;
  79. integer inderr, iindwk, indgrs, offset;
  80. extern doublereal _starpu_dlanst_(char *, integer *, doublereal *, doublereal *);
  81. extern /* Subroutine */ int _starpu_dlarrr_(integer *, doublereal *, doublereal *,
  82. integer *), _starpu_dlarrv_(integer *, doublereal *, doublereal *,
  83. doublereal *, doublereal *, doublereal *, integer *, integer *,
  84. integer *, integer *, doublereal *, doublereal *, doublereal *,
  85. doublereal *, doublereal *, doublereal *, integer *, integer *,
  86. doublereal *, doublereal *, integer *, integer *, doublereal *,
  87. integer *, integer *), _starpu_dlasrt_(char *, integer *, doublereal *,
  88. integer *);
  89. doublereal thresh;
  90. integer iinspl, ifirst, indwrk, liwmin, nzcmin;
  91. doublereal pivmin;
  92. integer nsplit;
  93. doublereal smlnum;
  94. logical lquery, zquery;
  95. /* -- LAPACK computational routine (version 3.2) -- */
  96. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  97. /* November 2006 */
  98. /* .. Scalar Arguments .. */
  99. /* .. */
  100. /* .. Array Arguments .. */
  101. /* .. */
  102. /* Purpose */
  103. /* ======= */
  104. /* DSTEMR computes selected eigenvalues and, optionally, eigenvectors */
  105. /* of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
  106. /* a well defined set of pairwise different real eigenvalues, the corresponding */
  107. /* real eigenvectors are pairwise orthogonal. */
  108. /* The spectrum may be computed either completely or partially by specifying */
  109. /* either an interval (VL,VU] or a range of indices IL:IU for the desired */
  110. /* eigenvalues. */
  111. /* Depending on the number of desired eigenvalues, these are computed either */
  112. /* by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
  113. /* computed by the use of various suitable L D L^T factorizations near clusters */
  114. /* of close eigenvalues (referred to as RRRs, Relatively Robust */
  115. /* Representations). An informal sketch of the algorithm follows. */
  116. /* For each unreduced block (submatrix) of T, */
  117. /* (a) Compute T - sigma I = L D L^T, so that L and D */
  118. /* define all the wanted eigenvalues to high relative accuracy. */
  119. /* This means that small relative changes in the entries of D and L */
  120. /* cause only small relative changes in the eigenvalues and */
  121. /* eigenvectors. The standard (unfactored) representation of the */
  122. /* tridiagonal matrix T does not have this property in general. */
  123. /* (b) Compute the eigenvalues to suitable accuracy. */
  124. /* If the eigenvectors are desired, the algorithm attains full */
  125. /* accuracy of the computed eigenvalues only right before */
  126. /* the corresponding vectors have to be computed, see steps c) and d). */
  127. /* (c) For each cluster of close eigenvalues, select a new */
  128. /* shift close to the cluster, find a new factorization, and refine */
  129. /* the shifted eigenvalues to suitable accuracy. */
  130. /* (d) For each eigenvalue with a large enough relative separation compute */
  131. /* the corresponding eigenvector by forming a rank revealing twisted */
  132. /* factorization. Go back to (c) for any clusters that remain. */
  133. /* For more details, see: */
  134. /* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
  135. /* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
  136. /* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
  137. /* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
  138. /* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
  139. /* 2004. Also LAPACK Working Note 154. */
  140. /* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
  141. /* tridiagonal eigenvalue/eigenvector problem", */
  142. /* Computer Science Division Technical Report No. UCB/CSD-97-971, */
  143. /* UC Berkeley, May 1997. */
  144. /* Notes: */
  145. /* 1.DSTEMR works only on machines which follow IEEE-754 */
  146. /* floating-point standard in their handling of infinities and NaNs. */
  147. /* This permits the use of efficient inner loops avoiding a check for */
  148. /* zero divisors. */
  149. /* Arguments */
  150. /* ========= */
  151. /* JOBZ (input) CHARACTER*1 */
  152. /* = 'N': Compute eigenvalues only; */
  153. /* = 'V': Compute eigenvalues and eigenvectors. */
  154. /* RANGE (input) CHARACTER*1 */
  155. /* = 'A': all eigenvalues will be found. */
  156. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  157. /* will be found. */
  158. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  159. /* N (input) INTEGER */
  160. /* The order of the matrix. N >= 0. */
  161. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  162. /* On entry, the N diagonal elements of the tridiagonal matrix */
  163. /* T. On exit, D is overwritten. */
  164. /* E (input/output) DOUBLE PRECISION array, dimension (N) */
  165. /* On entry, the (N-1) subdiagonal elements of the tridiagonal */
  166. /* matrix T in elements 1 to N-1 of E. E(N) need not be set on */
  167. /* input, but is used internally as workspace. */
  168. /* On exit, E is overwritten. */
  169. /* VL (input) DOUBLE PRECISION */
  170. /* VU (input) DOUBLE PRECISION */
  171. /* If RANGE='V', the lower and upper bounds of the interval to */
  172. /* be searched for eigenvalues. VL < VU. */
  173. /* Not referenced if RANGE = 'A' or 'I'. */
  174. /* IL (input) INTEGER */
  175. /* IU (input) INTEGER */
  176. /* If RANGE='I', the indices (in ascending order) of the */
  177. /* smallest and largest eigenvalues to be returned. */
  178. /* 1 <= IL <= IU <= N, if N > 0. */
  179. /* Not referenced if RANGE = 'A' or 'V'. */
  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', and if INFO = 0, then the first M columns of Z */
  188. /* contain the orthonormal eigenvectors of the matrix T */
  189. /* corresponding to the selected eigenvalues, with the i-th */
  190. /* column of Z holding the eigenvector associated with W(i). */
  191. /* If JOBZ = 'N', then Z is not referenced. */
  192. /* Note: the user must ensure that at least max(1,M) columns are */
  193. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  194. /* is not known in advance and can be computed with a workspace */
  195. /* query by setting NZC = -1, see below. */
  196. /* LDZ (input) INTEGER */
  197. /* The leading dimension of the array Z. LDZ >= 1, and if */
  198. /* JOBZ = 'V', then LDZ >= max(1,N). */
  199. /* NZC (input) INTEGER */
  200. /* The number of eigenvectors to be held in the array Z. */
  201. /* If RANGE = 'A', then NZC >= max(1,N). */
  202. /* If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
  203. /* If RANGE = 'I', then NZC >= IU-IL+1. */
  204. /* If NZC = -1, then a workspace query is assumed; the */
  205. /* routine calculates the number of columns of the array Z that */
  206. /* are needed to hold the eigenvectors. */
  207. /* This value is returned as the first entry of the Z array, and */
  208. /* no error message related to NZC is issued by XERBLA. */
  209. /* ISUPPZ (output) INTEGER ARRAY, dimension ( 2*max(1,M) ) */
  210. /* The support of the eigenvectors in Z, i.e., the indices */
  211. /* indicating the nonzero elements in Z. The i-th computed eigenvector */
  212. /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  213. /* ISUPPZ( 2*i ). This is relevant in the case when the matrix */
  214. /* is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
  215. /* TRYRAC (input/output) LOGICAL */
  216. /* If TRYRAC.EQ..TRUE., indicates that the code should check whether */
  217. /* the tridiagonal matrix defines its eigenvalues to high relative */
  218. /* accuracy. If so, the code uses relative-accuracy preserving */
  219. /* algorithms that might be (a bit) slower depending on the matrix. */
  220. /* If the matrix does not define its eigenvalues to high relative */
  221. /* accuracy, the code can uses possibly faster algorithms. */
  222. /* If TRYRAC.EQ..FALSE., the code is not required to guarantee */
  223. /* relatively accurate eigenvalues and can use the fastest possible */
  224. /* techniques. */
  225. /* On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
  226. /* does not define its eigenvalues to high relative accuracy. */
  227. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */
  228. /* On exit, if INFO = 0, WORK(1) returns the optimal */
  229. /* (and minimal) LWORK. */
  230. /* LWORK (input) INTEGER */
  231. /* The dimension of the array WORK. LWORK >= max(1,18*N) */
  232. /* if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. */
  233. /* If LWORK = -1, then a workspace query is assumed; the routine */
  234. /* only calculates the optimal size of the WORK array, returns */
  235. /* this value as the first entry of the WORK array, and no error */
  236. /* message related to LWORK is issued by XERBLA. */
  237. /* IWORK (workspace/output) INTEGER array, dimension (LIWORK) */
  238. /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  239. /* LIWORK (input) INTEGER */
  240. /* The dimension of the array IWORK. LIWORK >= max(1,10*N) */
  241. /* if the eigenvectors are desired, and LIWORK >= max(1,8*N) */
  242. /* if only the eigenvalues are to be computed. */
  243. /* If LIWORK = -1, then a workspace query is assumed; the */
  244. /* routine only calculates the optimal size of the IWORK array, */
  245. /* returns this value as the first entry of the IWORK array, and */
  246. /* no error message related to LIWORK is issued by XERBLA. */
  247. /* INFO (output) INTEGER */
  248. /* On exit, INFO */
  249. /* = 0: successful exit */
  250. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  251. /* > 0: if INFO = 1X, internal error in DLARRE, */
  252. /* if INFO = 2X, internal error in DLARRV. */
  253. /* Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
  254. /* the nonzero error code returned by DLARRE or */
  255. /* DLARRV, respectively. */
  256. /* Further Details */
  257. /* =============== */
  258. /* Based on contributions by */
  259. /* Beresford Parlett, University of California, Berkeley, USA */
  260. /* Jim Demmel, University of California, Berkeley, USA */
  261. /* Inderjit Dhillon, University of Texas, Austin, USA */
  262. /* Osni Marques, LBNL/NERSC, USA */
  263. /* Christof Voemel, University of California, Berkeley, USA */
  264. /* ===================================================================== */
  265. /* .. Parameters .. */
  266. /* .. */
  267. /* .. Local Scalars .. */
  268. /* .. */
  269. /* .. */
  270. /* .. External Functions .. */
  271. /* .. */
  272. /* .. External Subroutines .. */
  273. /* .. */
  274. /* .. Intrinsic Functions .. */
  275. /* .. */
  276. /* .. Executable Statements .. */
  277. /* Test the input parameters. */
  278. /* Parameter adjustments */
  279. --d__;
  280. --e;
  281. --w;
  282. z_dim1 = *ldz;
  283. z_offset = 1 + z_dim1;
  284. z__ -= z_offset;
  285. --isuppz;
  286. --work;
  287. --iwork;
  288. /* Function Body */
  289. wantz = _starpu_lsame_(jobz, "V");
  290. alleig = _starpu_lsame_(range, "A");
  291. valeig = _starpu_lsame_(range, "V");
  292. indeig = _starpu_lsame_(range, "I");
  293. lquery = *lwork == -1 || *liwork == -1;
  294. zquery = *nzc == -1;
  295. /* DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
  296. /* In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
  297. /* Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N. */
  298. if (wantz) {
  299. lwmin = *n * 18;
  300. liwmin = *n * 10;
  301. } else {
  302. /* need less workspace if only the eigenvalues are wanted */
  303. lwmin = *n * 12;
  304. liwmin = *n << 3;
  305. }
  306. wl = 0.;
  307. wu = 0.;
  308. iil = 0;
  309. iiu = 0;
  310. if (valeig) {
  311. /* We do not reference VL, VU in the cases RANGE = 'I','A' */
  312. /* The interval (WL, WU] contains all the wanted eigenvalues. */
  313. /* It is either given by the user or computed in DLARRE. */
  314. wl = *vl;
  315. wu = *vu;
  316. } else if (indeig) {
  317. /* We do not reference IL, IU in the cases RANGE = 'V','A' */
  318. iil = *il;
  319. iiu = *iu;
  320. }
  321. *info = 0;
  322. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  323. *info = -1;
  324. } else if (! (alleig || valeig || indeig)) {
  325. *info = -2;
  326. } else if (*n < 0) {
  327. *info = -3;
  328. } else if (valeig && *n > 0 && wu <= wl) {
  329. *info = -7;
  330. } else if (indeig && (iil < 1 || iil > *n)) {
  331. *info = -8;
  332. } else if (indeig && (iiu < iil || iiu > *n)) {
  333. *info = -9;
  334. } else if (*ldz < 1 || wantz && *ldz < *n) {
  335. *info = -13;
  336. } else if (*lwork < lwmin && ! lquery) {
  337. *info = -17;
  338. } else if (*liwork < liwmin && ! lquery) {
  339. *info = -19;
  340. }
  341. /* Get machine constants. */
  342. safmin = _starpu_dlamch_("Safe minimum");
  343. eps = _starpu_dlamch_("Precision");
  344. smlnum = safmin / eps;
  345. bignum = 1. / smlnum;
  346. rmin = sqrt(smlnum);
  347. /* Computing MIN */
  348. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  349. rmax = min(d__1,d__2);
  350. if (*info == 0) {
  351. work[1] = (doublereal) lwmin;
  352. iwork[1] = liwmin;
  353. if (wantz && alleig) {
  354. nzcmin = *n;
  355. } else if (wantz && valeig) {
  356. _starpu_dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
  357. itmp2, info);
  358. } else if (wantz && indeig) {
  359. nzcmin = iiu - iil + 1;
  360. } else {
  361. /* WANTZ .EQ. FALSE. */
  362. nzcmin = 0;
  363. }
  364. if (zquery && *info == 0) {
  365. z__[z_dim1 + 1] = (doublereal) nzcmin;
  366. } else if (*nzc < nzcmin && ! zquery) {
  367. *info = -14;
  368. }
  369. }
  370. if (*info != 0) {
  371. i__1 = -(*info);
  372. _starpu_xerbla_("DSTEMR", &i__1);
  373. return 0;
  374. } else if (lquery || zquery) {
  375. return 0;
  376. }
  377. /* Handle N = 0, 1, and 2 cases immediately */
  378. *m = 0;
  379. if (*n == 0) {
  380. return 0;
  381. }
  382. if (*n == 1) {
  383. if (alleig || indeig) {
  384. *m = 1;
  385. w[1] = d__[1];
  386. } else {
  387. if (wl < d__[1] && wu >= d__[1]) {
  388. *m = 1;
  389. w[1] = d__[1];
  390. }
  391. }
  392. if (wantz && ! zquery) {
  393. z__[z_dim1 + 1] = 1.;
  394. isuppz[1] = 1;
  395. isuppz[2] = 1;
  396. }
  397. return 0;
  398. }
  399. if (*n == 2) {
  400. if (! wantz) {
  401. _starpu_dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
  402. } else if (wantz && ! zquery) {
  403. _starpu_dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
  404. }
  405. if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
  406. ++(*m);
  407. w[*m] = r2;
  408. if (wantz && ! zquery) {
  409. z__[*m * z_dim1 + 1] = -sn;
  410. z__[*m * z_dim1 + 2] = cs;
  411. /* Note: At most one of SN and CS can be zero. */
  412. if (sn != 0.) {
  413. if (cs != 0.) {
  414. isuppz[(*m << 1) - 1] = 1;
  415. isuppz[(*m << 1) - 1] = 2;
  416. } else {
  417. isuppz[(*m << 1) - 1] = 1;
  418. isuppz[(*m << 1) - 1] = 1;
  419. }
  420. } else {
  421. isuppz[(*m << 1) - 1] = 2;
  422. isuppz[*m * 2] = 2;
  423. }
  424. }
  425. }
  426. if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
  427. ++(*m);
  428. w[*m] = r1;
  429. if (wantz && ! zquery) {
  430. z__[*m * z_dim1 + 1] = cs;
  431. z__[*m * z_dim1 + 2] = sn;
  432. /* Note: At most one of SN and CS can be zero. */
  433. if (sn != 0.) {
  434. if (cs != 0.) {
  435. isuppz[(*m << 1) - 1] = 1;
  436. isuppz[(*m << 1) - 1] = 2;
  437. } else {
  438. isuppz[(*m << 1) - 1] = 1;
  439. isuppz[(*m << 1) - 1] = 1;
  440. }
  441. } else {
  442. isuppz[(*m << 1) - 1] = 2;
  443. isuppz[*m * 2] = 2;
  444. }
  445. }
  446. }
  447. return 0;
  448. }
  449. /* Continue with general N */
  450. indgrs = 1;
  451. inderr = (*n << 1) + 1;
  452. indgp = *n * 3 + 1;
  453. indd = (*n << 2) + 1;
  454. inde2 = *n * 5 + 1;
  455. indwrk = *n * 6 + 1;
  456. iinspl = 1;
  457. iindbl = *n + 1;
  458. iindw = (*n << 1) + 1;
  459. iindwk = *n * 3 + 1;
  460. /* Scale matrix to allowable range, if necessary. */
  461. /* The allowable range is related to the PIVMIN parameter; see the */
  462. /* comments in DLARRD. The preference for scaling small values */
  463. /* up is heuristic; we expect users' matrices not to be close to the */
  464. /* RMAX threshold. */
  465. scale = 1.;
  466. tnrm = _starpu_dlanst_("M", n, &d__[1], &e[1]);
  467. if (tnrm > 0. && tnrm < rmin) {
  468. scale = rmin / tnrm;
  469. } else if (tnrm > rmax) {
  470. scale = rmax / tnrm;
  471. }
  472. if (scale != 1.) {
  473. _starpu_dscal_(n, &scale, &d__[1], &c__1);
  474. i__1 = *n - 1;
  475. _starpu_dscal_(&i__1, &scale, &e[1], &c__1);
  476. tnrm *= scale;
  477. if (valeig) {
  478. /* If eigenvalues in interval have to be found, */
  479. /* scale (WL, WU] accordingly */
  480. wl *= scale;
  481. wu *= scale;
  482. }
  483. }
  484. /* Compute the desired eigenvalues of the tridiagonal after splitting */
  485. /* into smaller subblocks if the corresponding off-diagonal elements */
  486. /* are small */
  487. /* THRESH is the splitting parameter for DLARRE */
  488. /* A negative THRESH forces the old splitting criterion based on the */
  489. /* size of the off-diagonal. A positive THRESH switches to splitting */
  490. /* which preserves relative accuracy. */
  491. if (*tryrac) {
  492. /* Test whether the matrix warrants the more expensive relative approach. */
  493. _starpu_dlarrr_(n, &d__[1], &e[1], &iinfo);
  494. } else {
  495. /* The user does not care about relative accurately eigenvalues */
  496. iinfo = -1;
  497. }
  498. /* Set the splitting criterion */
  499. if (iinfo == 0) {
  500. thresh = eps;
  501. } else {
  502. thresh = -eps;
  503. /* relative accuracy is desired but T does not guarantee it */
  504. *tryrac = FALSE_;
  505. }
  506. if (*tryrac) {
  507. /* Copy original diagonal, needed to guarantee relative accuracy */
  508. _starpu_dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
  509. }
  510. /* Store the squares of the offdiagonal values of T */
  511. i__1 = *n - 1;
  512. for (j = 1; j <= i__1; ++j) {
  513. /* Computing 2nd power */
  514. d__1 = e[j];
  515. work[inde2 + j - 1] = d__1 * d__1;
  516. /* L5: */
  517. }
  518. /* Set the tolerance parameters for bisection */
  519. if (! wantz) {
  520. /* DLARRE computes the eigenvalues to full precision. */
  521. rtol1 = eps * 4.;
  522. rtol2 = eps * 4.;
  523. } else {
  524. /* DLARRE computes the eigenvalues to less than full precision. */
  525. /* DLARRV will refine the eigenvalue approximations, and we can */
  526. /* need less accurate initial bisection in DLARRE. */
  527. /* Note: these settings do only affect the subset case and DLARRE */
  528. rtol1 = sqrt(eps);
  529. /* Computing MAX */
  530. d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
  531. rtol2 = max(d__1,d__2);
  532. }
  533. _starpu_dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2], &
  534. rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &work[
  535. inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &work[
  536. indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
  537. if (iinfo != 0) {
  538. *info = abs(iinfo) + 10;
  539. return 0;
  540. }
  541. /* Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
  542. /* part of the spectrum. All desired eigenvalues are contained in */
  543. /* (WL,WU] */
  544. if (wantz) {
  545. /* Compute the desired eigenvectors corresponding to the computed */
  546. /* eigenvalues */
  547. _starpu_dlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
  548. c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &work[
  549. indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs], &z__[
  550. z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[iindwk], &
  551. iinfo);
  552. if (iinfo != 0) {
  553. *info = abs(iinfo) + 20;
  554. return 0;
  555. }
  556. } else {
  557. /* DLARRE computes eigenvalues of the (shifted) root representation */
  558. /* DLARRV returns the eigenvalues of the unshifted matrix. */
  559. /* However, if the eigenvectors are not desired by the user, we need */
  560. /* to apply the corresponding shifts from DLARRE to obtain the */
  561. /* eigenvalues of the original matrix. */
  562. i__1 = *m;
  563. for (j = 1; j <= i__1; ++j) {
  564. itmp = iwork[iindbl + j - 1];
  565. w[j] += e[iwork[iinspl + itmp - 1]];
  566. /* L20: */
  567. }
  568. }
  569. if (*tryrac) {
  570. /* Refine computed eigenvalues so that they are relatively accurate */
  571. /* with respect to the original matrix T. */
  572. ibegin = 1;
  573. wbegin = 1;
  574. i__1 = iwork[iindbl + *m - 1];
  575. for (jblk = 1; jblk <= i__1; ++jblk) {
  576. iend = iwork[iinspl + jblk - 1];
  577. in = iend - ibegin + 1;
  578. wend = wbegin - 1;
  579. /* check if any eigenvalues have to be refined in this block */
  580. L36:
  581. if (wend < *m) {
  582. if (iwork[iindbl + wend] == jblk) {
  583. ++wend;
  584. goto L36;
  585. }
  586. }
  587. if (wend < wbegin) {
  588. ibegin = iend + 1;
  589. goto L39;
  590. }
  591. offset = iwork[iindw + wbegin - 1] - 1;
  592. ifirst = iwork[iindw + wbegin - 1];
  593. ilast = iwork[iindw + wend - 1];
  594. rtol2 = eps * 4.;
  595. _starpu_dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin - 1],
  596. &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &work[
  597. inderr + wbegin - 1], &work[indwrk], &iwork[iindwk], &
  598. pivmin, &tnrm, &iinfo);
  599. ibegin = iend + 1;
  600. wbegin = wend + 1;
  601. L39:
  602. ;
  603. }
  604. }
  605. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  606. if (scale != 1.) {
  607. d__1 = 1. / scale;
  608. _starpu_dscal_(m, &d__1, &w[1], &c__1);
  609. }
  610. /* If eigenvalues are not in increasing order, then sort them, */
  611. /* possibly along with eigenvectors. */
  612. if (nsplit > 1) {
  613. if (! wantz) {
  614. _starpu_dlasrt_("I", m, &w[1], &iinfo);
  615. if (iinfo != 0) {
  616. *info = 3;
  617. return 0;
  618. }
  619. } else {
  620. i__1 = *m - 1;
  621. for (j = 1; j <= i__1; ++j) {
  622. i__ = 0;
  623. tmp = w[j];
  624. i__2 = *m;
  625. for (jj = j + 1; jj <= i__2; ++jj) {
  626. if (w[jj] < tmp) {
  627. i__ = jj;
  628. tmp = w[jj];
  629. }
  630. /* L50: */
  631. }
  632. if (i__ != 0) {
  633. w[i__] = w[j];
  634. w[j] = tmp;
  635. if (wantz) {
  636. _starpu_dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j *
  637. z_dim1 + 1], &c__1);
  638. itmp = isuppz[(i__ << 1) - 1];
  639. isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
  640. isuppz[(j << 1) - 1] = itmp;
  641. itmp = isuppz[i__ * 2];
  642. isuppz[i__ * 2] = isuppz[j * 2];
  643. isuppz[j * 2] = itmp;
  644. }
  645. }
  646. /* L60: */
  647. }
  648. }
  649. }
  650. work[1] = (doublereal) lwmin;
  651. iwork[1] = liwmin;
  652. return 0;
  653. /* End of DSTEMR */
  654. } /* _starpu_dstemr_ */