dlarre.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. /* dlarre.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__2 = 2;
  16. /* Subroutine */ int _starpu_dlarre_(char *range, integer *n, doublereal *vl,
  17. doublereal *vu, integer *il, integer *iu, doublereal *d__, doublereal
  18. *e, doublereal *e2, doublereal *rtol1, doublereal *rtol2, doublereal *
  19. spltol, integer *nsplit, integer *isplit, integer *m, doublereal *w,
  20. doublereal *werr, doublereal *wgap, integer *iblock, integer *indexw,
  21. doublereal *gers, doublereal *pivmin, doublereal *work, integer *
  22. iwork, integer *info)
  23. {
  24. /* System generated locals */
  25. integer i__1, i__2;
  26. doublereal d__1, d__2, d__3;
  27. /* Builtin functions */
  28. double sqrt(doublereal), log(doublereal);
  29. /* Local variables */
  30. integer i__, j;
  31. doublereal s1, s2;
  32. integer mb;
  33. doublereal gl;
  34. integer in, mm;
  35. doublereal gu;
  36. integer cnt;
  37. doublereal eps, tau, tmp, rtl;
  38. integer cnt1, cnt2;
  39. doublereal tmp1, eabs;
  40. integer iend, jblk;
  41. doublereal eold;
  42. integer indl;
  43. doublereal dmax__, emax;
  44. integer wend, idum, indu;
  45. doublereal rtol;
  46. integer iseed[4];
  47. doublereal avgap, sigma;
  48. extern logical _starpu_lsame_(char *, char *);
  49. integer iinfo;
  50. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  51. doublereal *, integer *);
  52. logical norep;
  53. extern /* Subroutine */ int _starpu_dlasq2_(integer *, doublereal *, integer *);
  54. extern doublereal _starpu_dlamch_(char *);
  55. integer ibegin;
  56. logical forceb;
  57. integer irange;
  58. doublereal sgndef;
  59. extern /* Subroutine */ int _starpu_dlarra_(integer *, doublereal *, doublereal *,
  60. doublereal *, doublereal *, doublereal *, integer *, integer *,
  61. integer *), _starpu_dlarrb_(integer *, doublereal *, doublereal *,
  62. integer *, integer *, doublereal *, doublereal *, integer *,
  63. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  64. doublereal *, doublereal *, integer *, integer *), _starpu_dlarrc_(char *
  65. , integer *, doublereal *, doublereal *, doublereal *, doublereal
  66. *, doublereal *, integer *, integer *, integer *, integer *);
  67. integer wbegin;
  68. extern /* Subroutine */ int _starpu_dlarrd_(char *, char *, integer *, doublereal
  69. *, doublereal *, integer *, integer *, doublereal *, doublereal *,
  70. doublereal *, doublereal *, doublereal *, doublereal *, integer *
  71. , integer *, integer *, doublereal *, doublereal *, doublereal *,
  72. doublereal *, integer *, integer *, doublereal *, integer *,
  73. integer *);
  74. doublereal safmin, spdiam;
  75. extern /* Subroutine */ int _starpu_dlarrk_(integer *, integer *, doublereal *,
  76. doublereal *, doublereal *, doublereal *, doublereal *,
  77. doublereal *, doublereal *, doublereal *, integer *);
  78. logical usedqd;
  79. doublereal clwdth, isleft;
  80. extern /* Subroutine */ int _starpu_dlarnv_(integer *, integer *, integer *,
  81. doublereal *);
  82. doublereal isrght, bsrtol, dpivot;
  83. /* -- LAPACK auxiliary 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. /* To find the desired eigenvalues of a given real symmetric */
  93. /* tridiagonal matrix T, DLARRE sets any "small" off-diagonal */
  94. /* elements to zero, and for each unreduced block T_i, it finds */
  95. /* (a) a suitable shift at one end of the block's spectrum, */
  96. /* (b) the base representation, T_i - sigma_i I = L_i D_i L_i^T, and */
  97. /* (c) eigenvalues of each L_i D_i L_i^T. */
  98. /* The representations and eigenvalues found are then used by */
  99. /* DSTEMR to compute the eigenvectors of T. */
  100. /* The accuracy varies depending on whether bisection is used to */
  101. /* find a few eigenvalues or the dqds algorithm (subroutine DLASQ2) to */
  102. /* conpute all and then discard any unwanted one. */
  103. /* As an added benefit, DLARRE also outputs the n */
  104. /* Gerschgorin intervals for the matrices L_i D_i L_i^T. */
  105. /* Arguments */
  106. /* ========= */
  107. /* RANGE (input) CHARACTER */
  108. /* = 'A': ("All") all eigenvalues will be found. */
  109. /* = 'V': ("Value") all eigenvalues in the half-open interval */
  110. /* (VL, VU] will be found. */
  111. /* = 'I': ("Index") the IL-th through IU-th eigenvalues (of the */
  112. /* entire matrix) will be found. */
  113. /* N (input) INTEGER */
  114. /* The order of the matrix. N > 0. */
  115. /* VL (input/output) DOUBLE PRECISION */
  116. /* VU (input/output) DOUBLE PRECISION */
  117. /* If RANGE='V', the lower and upper bounds for the eigenvalues. */
  118. /* Eigenvalues less than or equal to VL, or greater than VU, */
  119. /* will not be returned. VL < VU. */
  120. /* If RANGE='I' or ='A', DLARRE computes bounds on the desired */
  121. /* part of the spectrum. */
  122. /* IL (input) INTEGER */
  123. /* IU (input) INTEGER */
  124. /* If RANGE='I', the indices (in ascending order) of the */
  125. /* smallest and largest eigenvalues to be returned. */
  126. /* 1 <= IL <= IU <= N. */
  127. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  128. /* On entry, the N diagonal elements of the tridiagonal */
  129. /* matrix T. */
  130. /* On exit, the N diagonal elements of the diagonal */
  131. /* matrices D_i. */
  132. /* E (input/output) DOUBLE PRECISION array, dimension (N) */
  133. /* On entry, the first (N-1) entries contain the subdiagonal */
  134. /* elements of the tridiagonal matrix T; E(N) need not be set. */
  135. /* On exit, E contains the subdiagonal elements of the unit */
  136. /* bidiagonal matrices L_i. The entries E( ISPLIT( I ) ), */
  137. /* 1 <= I <= NSPLIT, contain the base points sigma_i on output. */
  138. /* E2 (input/output) DOUBLE PRECISION array, dimension (N) */
  139. /* On entry, the first (N-1) entries contain the SQUARES of the */
  140. /* subdiagonal elements of the tridiagonal matrix T; */
  141. /* E2(N) need not be set. */
  142. /* On exit, the entries E2( ISPLIT( I ) ), */
  143. /* 1 <= I <= NSPLIT, have been set to zero */
  144. /* RTOL1 (input) DOUBLE PRECISION */
  145. /* RTOL2 (input) DOUBLE PRECISION */
  146. /* Parameters for bisection. */
  147. /* An interval [LEFT,RIGHT] has converged if */
  148. /* RIGHT-LEFT.LT.MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
  149. /* SPLTOL (input) DOUBLE PRECISION */
  150. /* The threshold for splitting. */
  151. /* NSPLIT (output) INTEGER */
  152. /* The number of blocks T splits into. 1 <= NSPLIT <= N. */
  153. /* ISPLIT (output) INTEGER array, dimension (N) */
  154. /* The splitting points, at which T breaks up into blocks. */
  155. /* The first block consists of rows/columns 1 to ISPLIT(1), */
  156. /* the second of rows/columns ISPLIT(1)+1 through ISPLIT(2), */
  157. /* etc., and the NSPLIT-th consists of rows/columns */
  158. /* ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N. */
  159. /* M (output) INTEGER */
  160. /* The total number of eigenvalues (of all L_i D_i L_i^T) */
  161. /* found. */
  162. /* W (output) DOUBLE PRECISION array, dimension (N) */
  163. /* The first M elements contain the eigenvalues. The */
  164. /* eigenvalues of each of the blocks, L_i D_i L_i^T, are */
  165. /* sorted in ascending order ( DLARRE may use the */
  166. /* remaining N-M elements as workspace). */
  167. /* WERR (output) DOUBLE PRECISION array, dimension (N) */
  168. /* The error bound on the corresponding eigenvalue in W. */
  169. /* WGAP (output) DOUBLE PRECISION array, dimension (N) */
  170. /* The separation from the right neighbor eigenvalue in W. */
  171. /* The gap is only with respect to the eigenvalues of the same block */
  172. /* as each block has its own representation tree. */
  173. /* Exception: at the right end of a block we store the left gap */
  174. /* IBLOCK (output) INTEGER array, dimension (N) */
  175. /* The indices of the blocks (submatrices) associated with the */
  176. /* corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
  177. /* W(i) belongs to the first block from the top, =2 if W(i) */
  178. /* belongs to the second block, etc. */
  179. /* INDEXW (output) INTEGER array, dimension (N) */
  180. /* The indices of the eigenvalues within each block (submatrix); */
  181. /* for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
  182. /* i-th eigenvalue W(i) is the 10-th eigenvalue in block 2 */
  183. /* GERS (output) DOUBLE PRECISION array, dimension (2*N) */
  184. /* The N Gerschgorin intervals (the i-th Gerschgorin interval */
  185. /* is (GERS(2*i-1), GERS(2*i)). */
  186. /* PIVMIN (output) DOUBLE PRECISION */
  187. /* The minimum pivot in the Sturm sequence for T. */
  188. /* WORK (workspace) DOUBLE PRECISION array, dimension (6*N) */
  189. /* Workspace. */
  190. /* IWORK (workspace) INTEGER array, dimension (5*N) */
  191. /* Workspace. */
  192. /* INFO (output) INTEGER */
  193. /* = 0: successful exit */
  194. /* > 0: A problem occured in DLARRE. */
  195. /* < 0: One of the called subroutines signaled an internal problem. */
  196. /* Needs inspection of the corresponding parameter IINFO */
  197. /* for further information. */
  198. /* =-1: Problem in DLARRD. */
  199. /* = 2: No base representation could be found in MAXTRY iterations. */
  200. /* Increasing MAXTRY and recompilation might be a remedy. */
  201. /* =-3: Problem in DLARRB when computing the refined root */
  202. /* representation for DLASQ2. */
  203. /* =-4: Problem in DLARRB when preforming bisection on the */
  204. /* desired part of the spectrum. */
  205. /* =-5: Problem in DLASQ2. */
  206. /* =-6: Problem in DLASQ2. */
  207. /* Further Details */
  208. /* The base representations are required to suffer very little */
  209. /* element growth and consequently define all their eigenvalues to */
  210. /* high relative accuracy. */
  211. /* =============== */
  212. /* Based on contributions by */
  213. /* Beresford Parlett, University of California, Berkeley, USA */
  214. /* Jim Demmel, University of California, Berkeley, USA */
  215. /* Inderjit Dhillon, University of Texas, Austin, USA */
  216. /* Osni Marques, LBNL/NERSC, USA */
  217. /* Christof Voemel, University of California, Berkeley, USA */
  218. /* ===================================================================== */
  219. /* .. Parameters .. */
  220. /* .. */
  221. /* .. Local Scalars .. */
  222. /* .. */
  223. /* .. Local Arrays .. */
  224. /* .. */
  225. /* .. External Functions .. */
  226. /* .. */
  227. /* .. External Subroutines .. */
  228. /* .. */
  229. /* .. Intrinsic Functions .. */
  230. /* .. */
  231. /* .. Executable Statements .. */
  232. /* Parameter adjustments */
  233. --iwork;
  234. --work;
  235. --gers;
  236. --indexw;
  237. --iblock;
  238. --wgap;
  239. --werr;
  240. --w;
  241. --isplit;
  242. --e2;
  243. --e;
  244. --d__;
  245. /* Function Body */
  246. *info = 0;
  247. /* Decode RANGE */
  248. if (_starpu_lsame_(range, "A")) {
  249. irange = 1;
  250. } else if (_starpu_lsame_(range, "V")) {
  251. irange = 3;
  252. } else if (_starpu_lsame_(range, "I")) {
  253. irange = 2;
  254. }
  255. *m = 0;
  256. /* Get machine constants */
  257. safmin = _starpu_dlamch_("S");
  258. eps = _starpu_dlamch_("P");
  259. /* Set parameters */
  260. rtl = sqrt(eps);
  261. bsrtol = sqrt(eps);
  262. /* Treat case of 1x1 matrix for quick return */
  263. if (*n == 1) {
  264. if (irange == 1 || irange == 3 && d__[1] > *vl && d__[1] <= *vu ||
  265. irange == 2 && *il == 1 && *iu == 1) {
  266. *m = 1;
  267. w[1] = d__[1];
  268. /* The computation error of the eigenvalue is zero */
  269. werr[1] = 0.;
  270. wgap[1] = 0.;
  271. iblock[1] = 1;
  272. indexw[1] = 1;
  273. gers[1] = d__[1];
  274. gers[2] = d__[1];
  275. }
  276. /* store the shift for the initial RRR, which is zero in this case */
  277. e[1] = 0.;
  278. return 0;
  279. }
  280. /* General case: tridiagonal matrix of order > 1 */
  281. /* Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter. */
  282. /* Compute maximum off-diagonal entry and pivmin. */
  283. gl = d__[1];
  284. gu = d__[1];
  285. eold = 0.;
  286. emax = 0.;
  287. e[*n] = 0.;
  288. i__1 = *n;
  289. for (i__ = 1; i__ <= i__1; ++i__) {
  290. werr[i__] = 0.;
  291. wgap[i__] = 0.;
  292. eabs = (d__1 = e[i__], abs(d__1));
  293. if (eabs >= emax) {
  294. emax = eabs;
  295. }
  296. tmp1 = eabs + eold;
  297. gers[(i__ << 1) - 1] = d__[i__] - tmp1;
  298. /* Computing MIN */
  299. d__1 = gl, d__2 = gers[(i__ << 1) - 1];
  300. gl = min(d__1,d__2);
  301. gers[i__ * 2] = d__[i__] + tmp1;
  302. /* Computing MAX */
  303. d__1 = gu, d__2 = gers[i__ * 2];
  304. gu = max(d__1,d__2);
  305. eold = eabs;
  306. /* L5: */
  307. }
  308. /* The minimum pivot allowed in the Sturm sequence for T */
  309. /* Computing MAX */
  310. /* Computing 2nd power */
  311. d__3 = emax;
  312. d__1 = 1., d__2 = d__3 * d__3;
  313. *pivmin = safmin * max(d__1,d__2);
  314. /* Compute spectral diameter. The Gerschgorin bounds give an */
  315. /* estimate that is wrong by at most a factor of SQRT(2) */
  316. spdiam = gu - gl;
  317. /* Compute splitting points */
  318. _starpu_dlarra_(n, &d__[1], &e[1], &e2[1], spltol, &spdiam, nsplit, &isplit[1], &
  319. iinfo);
  320. /* Can force use of bisection instead of faster DQDS. */
  321. /* Option left in the code for future multisection work. */
  322. forceb = FALSE_;
  323. /* Initialize USEDQD, DQDS should be used for ALLRNG unless someone */
  324. /* explicitly wants bisection. */
  325. usedqd = irange == 1 && ! forceb;
  326. if (irange == 1 && ! forceb) {
  327. /* Set interval [VL,VU] that contains all eigenvalues */
  328. *vl = gl;
  329. *vu = gu;
  330. } else {
  331. /* We call DLARRD to find crude approximations to the eigenvalues */
  332. /* in the desired range. In case IRANGE = INDRNG, we also obtain the */
  333. /* interval (VL,VU] that contains all the wanted eigenvalues. */
  334. /* An interval [LEFT,RIGHT] has converged if */
  335. /* RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT)) */
  336. /* DLARRD needs a WORK of size 4*N, IWORK of size 3*N */
  337. _starpu_dlarrd_(range, "B", n, vl, vu, il, iu, &gers[1], &bsrtol, &d__[1], &e[
  338. 1], &e2[1], pivmin, nsplit, &isplit[1], &mm, &w[1], &werr[1],
  339. vl, vu, &iblock[1], &indexw[1], &work[1], &iwork[1], &iinfo);
  340. if (iinfo != 0) {
  341. *info = -1;
  342. return 0;
  343. }
  344. /* Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0 */
  345. i__1 = *n;
  346. for (i__ = mm + 1; i__ <= i__1; ++i__) {
  347. w[i__] = 0.;
  348. werr[i__] = 0.;
  349. iblock[i__] = 0;
  350. indexw[i__] = 0;
  351. /* L14: */
  352. }
  353. }
  354. /* ** */
  355. /* Loop over unreduced blocks */
  356. ibegin = 1;
  357. wbegin = 1;
  358. i__1 = *nsplit;
  359. for (jblk = 1; jblk <= i__1; ++jblk) {
  360. iend = isplit[jblk];
  361. in = iend - ibegin + 1;
  362. /* 1 X 1 block */
  363. if (in == 1) {
  364. if (irange == 1 || irange == 3 && d__[ibegin] > *vl && d__[ibegin]
  365. <= *vu || irange == 2 && iblock[wbegin] == jblk) {
  366. ++(*m);
  367. w[*m] = d__[ibegin];
  368. werr[*m] = 0.;
  369. /* The gap for a single block doesn't matter for the later */
  370. /* algorithm and is assigned an arbitrary large value */
  371. wgap[*m] = 0.;
  372. iblock[*m] = jblk;
  373. indexw[*m] = 1;
  374. ++wbegin;
  375. }
  376. /* E( IEND ) holds the shift for the initial RRR */
  377. e[iend] = 0.;
  378. ibegin = iend + 1;
  379. goto L170;
  380. }
  381. /* Blocks of size larger than 1x1 */
  382. /* E( IEND ) will hold the shift for the initial RRR, for now set it =0 */
  383. e[iend] = 0.;
  384. /* Find local outer bounds GL,GU for the block */
  385. gl = d__[ibegin];
  386. gu = d__[ibegin];
  387. i__2 = iend;
  388. for (i__ = ibegin; i__ <= i__2; ++i__) {
  389. /* Computing MIN */
  390. d__1 = gers[(i__ << 1) - 1];
  391. gl = min(d__1,gl);
  392. /* Computing MAX */
  393. d__1 = gers[i__ * 2];
  394. gu = max(d__1,gu);
  395. /* L15: */
  396. }
  397. spdiam = gu - gl;
  398. if (! (irange == 1 && ! forceb)) {
  399. /* Count the number of eigenvalues in the current block. */
  400. mb = 0;
  401. i__2 = mm;
  402. for (i__ = wbegin; i__ <= i__2; ++i__) {
  403. if (iblock[i__] == jblk) {
  404. ++mb;
  405. } else {
  406. goto L21;
  407. }
  408. /* L20: */
  409. }
  410. L21:
  411. if (mb == 0) {
  412. /* No eigenvalue in the current block lies in the desired range */
  413. /* E( IEND ) holds the shift for the initial RRR */
  414. e[iend] = 0.;
  415. ibegin = iend + 1;
  416. goto L170;
  417. } else {
  418. /* Decide whether dqds or bisection is more efficient */
  419. usedqd = (doublereal) mb > in * .5 && ! forceb;
  420. wend = wbegin + mb - 1;
  421. /* Calculate gaps for the current block */
  422. /* In later stages, when representations for individual */
  423. /* eigenvalues are different, we use SIGMA = E( IEND ). */
  424. sigma = 0.;
  425. i__2 = wend - 1;
  426. for (i__ = wbegin; i__ <= i__2; ++i__) {
  427. /* Computing MAX */
  428. d__1 = 0., d__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
  429. werr[i__]);
  430. wgap[i__] = max(d__1,d__2);
  431. /* L30: */
  432. }
  433. /* Computing MAX */
  434. d__1 = 0., d__2 = *vu - sigma - (w[wend] + werr[wend]);
  435. wgap[wend] = max(d__1,d__2);
  436. /* Find local index of the first and last desired evalue. */
  437. indl = indexw[wbegin];
  438. indu = indexw[wend];
  439. }
  440. }
  441. if (irange == 1 && ! forceb || usedqd) {
  442. /* Case of DQDS */
  443. /* Find approximations to the extremal eigenvalues of the block */
  444. _starpu_dlarrk_(&in, &c__1, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
  445. rtl, &tmp, &tmp1, &iinfo);
  446. if (iinfo != 0) {
  447. *info = -1;
  448. return 0;
  449. }
  450. /* Computing MAX */
  451. d__2 = gl, d__3 = tmp - tmp1 - eps * 100. * (d__1 = tmp - tmp1,
  452. abs(d__1));
  453. isleft = max(d__2,d__3);
  454. _starpu_dlarrk_(&in, &in, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
  455. rtl, &tmp, &tmp1, &iinfo);
  456. if (iinfo != 0) {
  457. *info = -1;
  458. return 0;
  459. }
  460. /* Computing MIN */
  461. d__2 = gu, d__3 = tmp + tmp1 + eps * 100. * (d__1 = tmp + tmp1,
  462. abs(d__1));
  463. isrght = min(d__2,d__3);
  464. /* Improve the estimate of the spectral diameter */
  465. spdiam = isrght - isleft;
  466. } else {
  467. /* Case of bisection */
  468. /* Find approximations to the wanted extremal eigenvalues */
  469. /* Computing MAX */
  470. d__2 = gl, d__3 = w[wbegin] - werr[wbegin] - eps * 100. * (d__1 =
  471. w[wbegin] - werr[wbegin], abs(d__1));
  472. isleft = max(d__2,d__3);
  473. /* Computing MIN */
  474. d__2 = gu, d__3 = w[wend] + werr[wend] + eps * 100. * (d__1 = w[
  475. wend] + werr[wend], abs(d__1));
  476. isrght = min(d__2,d__3);
  477. }
  478. /* Decide whether the base representation for the current block */
  479. /* L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I */
  480. /* should be on the left or the right end of the current block. */
  481. /* The strategy is to shift to the end which is "more populated" */
  482. /* Furthermore, decide whether to use DQDS for the computation of */
  483. /* the eigenvalue approximations at the end of DLARRE or bisection. */
  484. /* dqds is chosen if all eigenvalues are desired or the number of */
  485. /* eigenvalues to be computed is large compared to the blocksize. */
  486. if (irange == 1 && ! forceb) {
  487. /* If all the eigenvalues have to be computed, we use dqd */
  488. usedqd = TRUE_;
  489. /* INDL is the local index of the first eigenvalue to compute */
  490. indl = 1;
  491. indu = in;
  492. /* MB = number of eigenvalues to compute */
  493. mb = in;
  494. wend = wbegin + mb - 1;
  495. /* Define 1/4 and 3/4 points of the spectrum */
  496. s1 = isleft + spdiam * .25;
  497. s2 = isrght - spdiam * .25;
  498. } else {
  499. /* DLARRD has computed IBLOCK and INDEXW for each eigenvalue */
  500. /* approximation. */
  501. /* choose sigma */
  502. if (usedqd) {
  503. s1 = isleft + spdiam * .25;
  504. s2 = isrght - spdiam * .25;
  505. } else {
  506. tmp = min(isrght,*vu) - max(isleft,*vl);
  507. s1 = max(isleft,*vl) + tmp * .25;
  508. s2 = min(isrght,*vu) - tmp * .25;
  509. }
  510. }
  511. /* Compute the negcount at the 1/4 and 3/4 points */
  512. if (mb > 1) {
  513. _starpu_dlarrc_("T", &in, &s1, &s2, &d__[ibegin], &e[ibegin], pivmin, &
  514. cnt, &cnt1, &cnt2, &iinfo);
  515. }
  516. if (mb == 1) {
  517. sigma = gl;
  518. sgndef = 1.;
  519. } else if (cnt1 - indl >= indu - cnt2) {
  520. if (irange == 1 && ! forceb) {
  521. sigma = max(isleft,gl);
  522. } else if (usedqd) {
  523. /* use Gerschgorin bound as shift to get pos def matrix */
  524. /* for dqds */
  525. sigma = isleft;
  526. } else {
  527. /* use approximation of the first desired eigenvalue of the */
  528. /* block as shift */
  529. sigma = max(isleft,*vl);
  530. }
  531. sgndef = 1.;
  532. } else {
  533. if (irange == 1 && ! forceb) {
  534. sigma = min(isrght,gu);
  535. } else if (usedqd) {
  536. /* use Gerschgorin bound as shift to get neg def matrix */
  537. /* for dqds */
  538. sigma = isrght;
  539. } else {
  540. /* use approximation of the first desired eigenvalue of the */
  541. /* block as shift */
  542. sigma = min(isrght,*vu);
  543. }
  544. sgndef = -1.;
  545. }
  546. /* An initial SIGMA has been chosen that will be used for computing */
  547. /* T - SIGMA I = L D L^T */
  548. /* Define the increment TAU of the shift in case the initial shift */
  549. /* needs to be refined to obtain a factorization with not too much */
  550. /* element growth. */
  551. if (usedqd) {
  552. /* The initial SIGMA was to the outer end of the spectrum */
  553. /* the matrix is definite and we need not retreat. */
  554. tau = spdiam * eps * *n + *pivmin * 2.;
  555. } else {
  556. if (mb > 1) {
  557. clwdth = w[wend] + werr[wend] - w[wbegin] - werr[wbegin];
  558. avgap = (d__1 = clwdth / (doublereal) (wend - wbegin), abs(
  559. d__1));
  560. if (sgndef == 1.) {
  561. /* Computing MAX */
  562. d__1 = wgap[wbegin];
  563. tau = max(d__1,avgap) * .5;
  564. /* Computing MAX */
  565. d__1 = tau, d__2 = werr[wbegin];
  566. tau = max(d__1,d__2);
  567. } else {
  568. /* Computing MAX */
  569. d__1 = wgap[wend - 1];
  570. tau = max(d__1,avgap) * .5;
  571. /* Computing MAX */
  572. d__1 = tau, d__2 = werr[wend];
  573. tau = max(d__1,d__2);
  574. }
  575. } else {
  576. tau = werr[wbegin];
  577. }
  578. }
  579. for (idum = 1; idum <= 6; ++idum) {
  580. /* Compute L D L^T factorization of tridiagonal matrix T - sigma I. */
  581. /* Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of */
  582. /* pivots in WORK(2*IN+1:3*IN) */
  583. dpivot = d__[ibegin] - sigma;
  584. work[1] = dpivot;
  585. dmax__ = abs(work[1]);
  586. j = ibegin;
  587. i__2 = in - 1;
  588. for (i__ = 1; i__ <= i__2; ++i__) {
  589. work[(in << 1) + i__] = 1. / work[i__];
  590. tmp = e[j] * work[(in << 1) + i__];
  591. work[in + i__] = tmp;
  592. dpivot = d__[j + 1] - sigma - tmp * e[j];
  593. work[i__ + 1] = dpivot;
  594. /* Computing MAX */
  595. d__1 = dmax__, d__2 = abs(dpivot);
  596. dmax__ = max(d__1,d__2);
  597. ++j;
  598. /* L70: */
  599. }
  600. /* check for element growth */
  601. if (dmax__ > spdiam * 64.) {
  602. norep = TRUE_;
  603. } else {
  604. norep = FALSE_;
  605. }
  606. if (usedqd && ! norep) {
  607. /* Ensure the definiteness of the representation */
  608. /* All entries of D (of L D L^T) must have the same sign */
  609. i__2 = in;
  610. for (i__ = 1; i__ <= i__2; ++i__) {
  611. tmp = sgndef * work[i__];
  612. if (tmp < 0.) {
  613. norep = TRUE_;
  614. }
  615. /* L71: */
  616. }
  617. }
  618. if (norep) {
  619. /* Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin */
  620. /* shift which makes the matrix definite. So we should end up */
  621. /* here really only in the case of IRANGE = VALRNG or INDRNG. */
  622. if (idum == 5) {
  623. if (sgndef == 1.) {
  624. /* The fudged Gerschgorin shift should succeed */
  625. sigma = gl - spdiam * 2. * eps * *n - *pivmin * 4.;
  626. } else {
  627. sigma = gu + spdiam * 2. * eps * *n + *pivmin * 4.;
  628. }
  629. } else {
  630. sigma -= sgndef * tau;
  631. tau *= 2.;
  632. }
  633. } else {
  634. /* an initial RRR is found */
  635. goto L83;
  636. }
  637. /* L80: */
  638. }
  639. /* if the program reaches this point, no base representation could be */
  640. /* found in MAXTRY iterations. */
  641. *info = 2;
  642. return 0;
  643. L83:
  644. /* At this point, we have found an initial base representation */
  645. /* T - SIGMA I = L D L^T with not too much element growth. */
  646. /* Store the shift. */
  647. e[iend] = sigma;
  648. /* Store D and L. */
  649. _starpu_dcopy_(&in, &work[1], &c__1, &d__[ibegin], &c__1);
  650. i__2 = in - 1;
  651. _starpu_dcopy_(&i__2, &work[in + 1], &c__1, &e[ibegin], &c__1);
  652. if (mb > 1) {
  653. /* Perturb each entry of the base representation by a small */
  654. /* (but random) relative amount to overcome difficulties with */
  655. /* glued matrices. */
  656. for (i__ = 1; i__ <= 4; ++i__) {
  657. iseed[i__ - 1] = 1;
  658. /* L122: */
  659. }
  660. i__2 = (in << 1) - 1;
  661. _starpu_dlarnv_(&c__2, iseed, &i__2, &work[1]);
  662. i__2 = in - 1;
  663. for (i__ = 1; i__ <= i__2; ++i__) {
  664. d__[ibegin + i__ - 1] *= eps * 8. * work[i__] + 1.;
  665. e[ibegin + i__ - 1] *= eps * 8. * work[in + i__] + 1.;
  666. /* L125: */
  667. }
  668. d__[iend] *= eps * 4. * work[in] + 1.;
  669. }
  670. /* Don't update the Gerschgorin intervals because keeping track */
  671. /* of the updates would be too much work in DLARRV. */
  672. /* We update W instead and use it to locate the proper Gerschgorin */
  673. /* intervals. */
  674. /* Compute the required eigenvalues of L D L' by bisection or dqds */
  675. if (! usedqd) {
  676. /* If DLARRD has been used, shift the eigenvalue approximations */
  677. /* according to their representation. This is necessary for */
  678. /* a uniform DLARRV since dqds computes eigenvalues of the */
  679. /* shifted representation. In DLARRV, W will always hold the */
  680. /* UNshifted eigenvalue approximation. */
  681. i__2 = wend;
  682. for (j = wbegin; j <= i__2; ++j) {
  683. w[j] -= sigma;
  684. werr[j] += (d__1 = w[j], abs(d__1)) * eps;
  685. /* L134: */
  686. }
  687. /* call DLARRB to reduce eigenvalue error of the approximations */
  688. /* from DLARRD */
  689. i__2 = iend - 1;
  690. for (i__ = ibegin; i__ <= i__2; ++i__) {
  691. /* Computing 2nd power */
  692. d__1 = e[i__];
  693. work[i__] = d__[i__] * (d__1 * d__1);
  694. /* L135: */
  695. }
  696. /* use bisection to find EV from INDL to INDU */
  697. i__2 = indl - 1;
  698. _starpu_dlarrb_(&in, &d__[ibegin], &work[ibegin], &indl, &indu, rtol1,
  699. rtol2, &i__2, &w[wbegin], &wgap[wbegin], &werr[wbegin], &
  700. work[(*n << 1) + 1], &iwork[1], pivmin, &spdiam, &in, &
  701. iinfo);
  702. if (iinfo != 0) {
  703. *info = -4;
  704. return 0;
  705. }
  706. /* DLARRB computes all gaps correctly except for the last one */
  707. /* Record distance to VU/GU */
  708. /* Computing MAX */
  709. d__1 = 0., d__2 = *vu - sigma - (w[wend] + werr[wend]);
  710. wgap[wend] = max(d__1,d__2);
  711. i__2 = indu;
  712. for (i__ = indl; i__ <= i__2; ++i__) {
  713. ++(*m);
  714. iblock[*m] = jblk;
  715. indexw[*m] = i__;
  716. /* L138: */
  717. }
  718. } else {
  719. /* Call dqds to get all eigs (and then possibly delete unwanted */
  720. /* eigenvalues). */
  721. /* Note that dqds finds the eigenvalues of the L D L^T representation */
  722. /* of T to high relative accuracy. High relative accuracy */
  723. /* might be lost when the shift of the RRR is subtracted to obtain */
  724. /* the eigenvalues of T. However, T is not guaranteed to define its */
  725. /* eigenvalues to high relative accuracy anyway. */
  726. /* Set RTOL to the order of the tolerance used in DLASQ2 */
  727. /* This is an ESTIMATED error, the worst case bound is 4*N*EPS */
  728. /* which is usually too large and requires unnecessary work to be */
  729. /* done by bisection when computing the eigenvectors */
  730. rtol = log((doublereal) in) * 4. * eps;
  731. j = ibegin;
  732. i__2 = in - 1;
  733. for (i__ = 1; i__ <= i__2; ++i__) {
  734. work[(i__ << 1) - 1] = (d__1 = d__[j], abs(d__1));
  735. work[i__ * 2] = e[j] * e[j] * work[(i__ << 1) - 1];
  736. ++j;
  737. /* L140: */
  738. }
  739. work[(in << 1) - 1] = (d__1 = d__[iend], abs(d__1));
  740. work[in * 2] = 0.;
  741. _starpu_dlasq2_(&in, &work[1], &iinfo);
  742. if (iinfo != 0) {
  743. /* If IINFO = -5 then an index is part of a tight cluster */
  744. /* and should be changed. The index is in IWORK(1) and the */
  745. /* gap is in WORK(N+1) */
  746. *info = -5;
  747. return 0;
  748. } else {
  749. /* Test that all eigenvalues are positive as expected */
  750. i__2 = in;
  751. for (i__ = 1; i__ <= i__2; ++i__) {
  752. if (work[i__] < 0.) {
  753. *info = -6;
  754. return 0;
  755. }
  756. /* L149: */
  757. }
  758. }
  759. if (sgndef > 0.) {
  760. i__2 = indu;
  761. for (i__ = indl; i__ <= i__2; ++i__) {
  762. ++(*m);
  763. w[*m] = work[in - i__ + 1];
  764. iblock[*m] = jblk;
  765. indexw[*m] = i__;
  766. /* L150: */
  767. }
  768. } else {
  769. i__2 = indu;
  770. for (i__ = indl; i__ <= i__2; ++i__) {
  771. ++(*m);
  772. w[*m] = -work[i__];
  773. iblock[*m] = jblk;
  774. indexw[*m] = i__;
  775. /* L160: */
  776. }
  777. }
  778. i__2 = *m;
  779. for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
  780. /* the value of RTOL below should be the tolerance in DLASQ2 */
  781. werr[i__] = rtol * (d__1 = w[i__], abs(d__1));
  782. /* L165: */
  783. }
  784. i__2 = *m - 1;
  785. for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
  786. /* compute the right gap between the intervals */
  787. /* Computing MAX */
  788. d__1 = 0., d__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] + werr[
  789. i__]);
  790. wgap[i__] = max(d__1,d__2);
  791. /* L166: */
  792. }
  793. /* Computing MAX */
  794. d__1 = 0., d__2 = *vu - sigma - (w[*m] + werr[*m]);
  795. wgap[*m] = max(d__1,d__2);
  796. }
  797. /* proceed with next block */
  798. ibegin = iend + 1;
  799. wbegin = wend + 1;
  800. L170:
  801. ;
  802. }
  803. return 0;
  804. /* end of DLARRE */
  805. } /* _starpu_dlarre_ */