dlarrb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /* dlarrb.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. /* Subroutine */ int _starpu_dlarrb_(integer *n, doublereal *d__, doublereal *lld,
  14. integer *ifirst, integer *ilast, doublereal *rtol1, doublereal *rtol2,
  15. integer *offset, doublereal *w, doublereal *wgap, doublereal *werr,
  16. doublereal *work, integer *iwork, doublereal *pivmin, doublereal *
  17. spdiam, integer *twist, integer *info)
  18. {
  19. /* System generated locals */
  20. integer i__1;
  21. doublereal d__1, d__2;
  22. /* Builtin functions */
  23. double log(doublereal);
  24. /* Local variables */
  25. integer i__, k, r__, i1, ii, ip;
  26. doublereal gap, mid, tmp, back, lgap, rgap, left;
  27. integer iter, nint, prev, next;
  28. doublereal cvrgd, right, width;
  29. extern integer _starpu_dlaneg_(integer *, doublereal *, doublereal *, doublereal *
  30. , doublereal *, integer *);
  31. integer negcnt;
  32. doublereal mnwdth;
  33. integer olnint, maxitr;
  34. /* -- LAPACK auxiliary routine (version 3.2) -- */
  35. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  36. /* November 2006 */
  37. /* .. Scalar Arguments .. */
  38. /* .. */
  39. /* .. Array Arguments .. */
  40. /* .. */
  41. /* Purpose */
  42. /* ======= */
  43. /* Given the relatively robust representation(RRR) L D L^T, DLARRB */
  44. /* does "limited" bisection to refine the eigenvalues of L D L^T, */
  45. /* W( IFIRST-OFFSET ) through W( ILAST-OFFSET ), to more accuracy. Initial */
  46. /* guesses for these eigenvalues are input in W, the corresponding estimate */
  47. /* of the error in these guesses and their gaps are input in WERR */
  48. /* and WGAP, respectively. During bisection, intervals */
  49. /* [left, right] are maintained by storing their mid-points and */
  50. /* semi-widths in the arrays W and WERR respectively. */
  51. /* Arguments */
  52. /* ========= */
  53. /* N (input) INTEGER */
  54. /* The order of the matrix. */
  55. /* D (input) DOUBLE PRECISION array, dimension (N) */
  56. /* The N diagonal elements of the diagonal matrix D. */
  57. /* LLD (input) DOUBLE PRECISION array, dimension (N-1) */
  58. /* The (N-1) elements L(i)*L(i)*D(i). */
  59. /* IFIRST (input) INTEGER */
  60. /* The index of the first eigenvalue to be computed. */
  61. /* ILAST (input) INTEGER */
  62. /* The index of the last eigenvalue to be computed. */
  63. /* RTOL1 (input) DOUBLE PRECISION */
  64. /* RTOL2 (input) DOUBLE PRECISION */
  65. /* Tolerance for the convergence of the bisection intervals. */
  66. /* An interval [LEFT,RIGHT] has converged if */
  67. /* RIGHT-LEFT.LT.MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
  68. /* where GAP is the (estimated) distance to the nearest */
  69. /* eigenvalue. */
  70. /* OFFSET (input) INTEGER */
  71. /* Offset for the arrays W, WGAP and WERR, i.e., the IFIRST-OFFSET */
  72. /* through ILAST-OFFSET elements of these arrays are to be used. */
  73. /* W (input/output) DOUBLE PRECISION array, dimension (N) */
  74. /* On input, W( IFIRST-OFFSET ) through W( ILAST-OFFSET ) are */
  75. /* estimates of the eigenvalues of L D L^T indexed IFIRST throug */
  76. /* ILAST. */
  77. /* On output, these estimates are refined. */
  78. /* WGAP (input/output) DOUBLE PRECISION array, dimension (N-1) */
  79. /* On input, the (estimated) gaps between consecutive */
  80. /* eigenvalues of L D L^T, i.e., WGAP(I-OFFSET) is the gap between */
  81. /* eigenvalues I and I+1. Note that if IFIRST.EQ.ILAST */
  82. /* then WGAP(IFIRST-OFFSET) must be set to ZERO. */
  83. /* On output, these gaps are refined. */
  84. /* WERR (input/output) DOUBLE PRECISION array, dimension (N) */
  85. /* On input, WERR( IFIRST-OFFSET ) through WERR( ILAST-OFFSET ) are */
  86. /* the errors in the estimates of the corresponding elements in W. */
  87. /* On output, these errors are refined. */
  88. /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
  89. /* Workspace. */
  90. /* IWORK (workspace) INTEGER array, dimension (2*N) */
  91. /* Workspace. */
  92. /* PIVMIN (input) DOUBLE PRECISION */
  93. /* The minimum pivot in the Sturm sequence. */
  94. /* SPDIAM (input) DOUBLE PRECISION */
  95. /* The spectral diameter of the matrix. */
  96. /* TWIST (input) INTEGER */
  97. /* The twist index for the twisted factorization that is used */
  98. /* for the negcount. */
  99. /* TWIST = N: Compute negcount from L D L^T - LAMBDA I = L+ D+ L+^T */
  100. /* TWIST = 1: Compute negcount from L D L^T - LAMBDA I = U- D- U-^T */
  101. /* TWIST = R: Compute negcount from L D L^T - LAMBDA I = N(r) D(r) N(r) */
  102. /* INFO (output) INTEGER */
  103. /* Error flag. */
  104. /* Further Details */
  105. /* =============== */
  106. /* Based on contributions by */
  107. /* Beresford Parlett, University of California, Berkeley, USA */
  108. /* Jim Demmel, University of California, Berkeley, USA */
  109. /* Inderjit Dhillon, University of Texas, Austin, USA */
  110. /* Osni Marques, LBNL/NERSC, USA */
  111. /* Christof Voemel, University of California, Berkeley, USA */
  112. /* ===================================================================== */
  113. /* .. Parameters .. */
  114. /* .. */
  115. /* .. Local Scalars .. */
  116. /* .. */
  117. /* .. External Functions .. */
  118. /* .. */
  119. /* .. Intrinsic Functions .. */
  120. /* .. */
  121. /* .. Executable Statements .. */
  122. /* Parameter adjustments */
  123. --iwork;
  124. --work;
  125. --werr;
  126. --wgap;
  127. --w;
  128. --lld;
  129. --d__;
  130. /* Function Body */
  131. *info = 0;
  132. maxitr = (integer) ((log(*spdiam + *pivmin) - log(*pivmin)) / log(2.)) +
  133. 2;
  134. mnwdth = *pivmin * 2.;
  135. r__ = *twist;
  136. if (r__ < 1 || r__ > *n) {
  137. r__ = *n;
  138. }
  139. /* Initialize unconverged intervals in [ WORK(2*I-1), WORK(2*I) ]. */
  140. /* The Sturm Count, Count( WORK(2*I-1) ) is arranged to be I-1, while */
  141. /* Count( WORK(2*I) ) is stored in IWORK( 2*I ). The integer IWORK( 2*I-1 ) */
  142. /* for an unconverged interval is set to the index of the next unconverged */
  143. /* interval, and is -1 or 0 for a converged interval. Thus a linked */
  144. /* list of unconverged intervals is set up. */
  145. i1 = *ifirst;
  146. /* The number of unconverged intervals */
  147. nint = 0;
  148. /* The last unconverged interval found */
  149. prev = 0;
  150. rgap = wgap[i1 - *offset];
  151. i__1 = *ilast;
  152. for (i__ = i1; i__ <= i__1; ++i__) {
  153. k = i__ << 1;
  154. ii = i__ - *offset;
  155. left = w[ii] - werr[ii];
  156. right = w[ii] + werr[ii];
  157. lgap = rgap;
  158. rgap = wgap[ii];
  159. gap = min(lgap,rgap);
  160. /* Make sure that [LEFT,RIGHT] contains the desired eigenvalue */
  161. /* Compute negcount from dstqds facto L+D+L+^T = L D L^T - LEFT */
  162. /* Do while( NEGCNT(LEFT).GT.I-1 ) */
  163. back = werr[ii];
  164. L20:
  165. negcnt = _starpu_dlaneg_(n, &d__[1], &lld[1], &left, pivmin, &r__);
  166. if (negcnt > i__ - 1) {
  167. left -= back;
  168. back *= 2.;
  169. goto L20;
  170. }
  171. /* Do while( NEGCNT(RIGHT).LT.I ) */
  172. /* Compute negcount from dstqds facto L+D+L+^T = L D L^T - RIGHT */
  173. back = werr[ii];
  174. L50:
  175. negcnt = _starpu_dlaneg_(n, &d__[1], &lld[1], &right, pivmin, &r__);
  176. if (negcnt < i__) {
  177. right += back;
  178. back *= 2.;
  179. goto L50;
  180. }
  181. width = (d__1 = left - right, abs(d__1)) * .5;
  182. /* Computing MAX */
  183. d__1 = abs(left), d__2 = abs(right);
  184. tmp = max(d__1,d__2);
  185. /* Computing MAX */
  186. d__1 = *rtol1 * gap, d__2 = *rtol2 * tmp;
  187. cvrgd = max(d__1,d__2);
  188. if (width <= cvrgd || width <= mnwdth) {
  189. /* This interval has already converged and does not need refinement. */
  190. /* (Note that the gaps might change through refining the */
  191. /* eigenvalues, however, they can only get bigger.) */
  192. /* Remove it from the list. */
  193. iwork[k - 1] = -1;
  194. /* Make sure that I1 always points to the first unconverged interval */
  195. if (i__ == i1 && i__ < *ilast) {
  196. i1 = i__ + 1;
  197. }
  198. if (prev >= i1 && i__ <= *ilast) {
  199. iwork[(prev << 1) - 1] = i__ + 1;
  200. }
  201. } else {
  202. /* unconverged interval found */
  203. prev = i__;
  204. ++nint;
  205. iwork[k - 1] = i__ + 1;
  206. iwork[k] = negcnt;
  207. }
  208. work[k - 1] = left;
  209. work[k] = right;
  210. /* L75: */
  211. }
  212. /* Do while( NINT.GT.0 ), i.e. there are still unconverged intervals */
  213. /* and while (ITER.LT.MAXITR) */
  214. iter = 0;
  215. L80:
  216. prev = i1 - 1;
  217. i__ = i1;
  218. olnint = nint;
  219. i__1 = olnint;
  220. for (ip = 1; ip <= i__1; ++ip) {
  221. k = i__ << 1;
  222. ii = i__ - *offset;
  223. rgap = wgap[ii];
  224. lgap = rgap;
  225. if (ii > 1) {
  226. lgap = wgap[ii - 1];
  227. }
  228. gap = min(lgap,rgap);
  229. next = iwork[k - 1];
  230. left = work[k - 1];
  231. right = work[k];
  232. mid = (left + right) * .5;
  233. /* semiwidth of interval */
  234. width = right - mid;
  235. /* Computing MAX */
  236. d__1 = abs(left), d__2 = abs(right);
  237. tmp = max(d__1,d__2);
  238. /* Computing MAX */
  239. d__1 = *rtol1 * gap, d__2 = *rtol2 * tmp;
  240. cvrgd = max(d__1,d__2);
  241. if (width <= cvrgd || width <= mnwdth || iter == maxitr) {
  242. /* reduce number of unconverged intervals */
  243. --nint;
  244. /* Mark interval as converged. */
  245. iwork[k - 1] = 0;
  246. if (i1 == i__) {
  247. i1 = next;
  248. } else {
  249. /* Prev holds the last unconverged interval previously examined */
  250. if (prev >= i1) {
  251. iwork[(prev << 1) - 1] = next;
  252. }
  253. }
  254. i__ = next;
  255. goto L100;
  256. }
  257. prev = i__;
  258. /* Perform one bisection step */
  259. negcnt = _starpu_dlaneg_(n, &d__[1], &lld[1], &mid, pivmin, &r__);
  260. if (negcnt <= i__ - 1) {
  261. work[k - 1] = mid;
  262. } else {
  263. work[k] = mid;
  264. }
  265. i__ = next;
  266. L100:
  267. ;
  268. }
  269. ++iter;
  270. /* do another loop if there are still unconverged intervals */
  271. /* However, in the last iteration, all intervals are accepted */
  272. /* since this is the best we can do. */
  273. if (nint > 0 && iter <= maxitr) {
  274. goto L80;
  275. }
  276. /* At this point, all the intervals have converged */
  277. i__1 = *ilast;
  278. for (i__ = *ifirst; i__ <= i__1; ++i__) {
  279. k = i__ << 1;
  280. ii = i__ - *offset;
  281. /* All intervals marked by '0' have been refined. */
  282. if (iwork[k - 1] == 0) {
  283. w[ii] = (work[k - 1] + work[k]) * .5;
  284. werr[ii] = work[k] - w[ii];
  285. }
  286. /* L110: */
  287. }
  288. i__1 = *ilast;
  289. for (i__ = *ifirst + 1; i__ <= i__1; ++i__) {
  290. k = i__ << 1;
  291. ii = i__ - *offset;
  292. /* Computing MAX */
  293. d__1 = 0., d__2 = w[ii] - werr[ii] - w[ii - 1] - werr[ii - 1];
  294. wgap[ii - 1] = max(d__1,d__2);
  295. /* L111: */
  296. }
  297. return 0;
  298. /* End of DLARRB */
  299. } /* _starpu_dlarrb_ */