dlarrj.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* dlarrj.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_dlarrj_(integer *n, doublereal *d__, doublereal *e2,
  14. integer *ifirst, integer *ilast, doublereal *rtol, integer *offset,
  15. doublereal *w, doublereal *werr, doublereal *work, integer *iwork,
  16. doublereal *pivmin, doublereal *spdiam, integer *info)
  17. {
  18. /* System generated locals */
  19. integer i__1, i__2;
  20. doublereal d__1, d__2;
  21. /* Builtin functions */
  22. double log(doublereal);
  23. /* Local variables */
  24. integer i__, j, k, p;
  25. doublereal s;
  26. integer i1, i2, ii;
  27. doublereal fac, mid;
  28. integer cnt;
  29. doublereal tmp, left;
  30. integer iter, nint, prev, next, savi1;
  31. doublereal right, width, dplus;
  32. integer olnint, maxitr;
  33. /* -- LAPACK auxiliary routine (version 3.2) -- */
  34. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  35. /* November 2006 */
  36. /* .. Scalar Arguments .. */
  37. /* .. */
  38. /* .. Array Arguments .. */
  39. /* .. */
  40. /* Purpose */
  41. /* ======= */
  42. /* Given the initial eigenvalue approximations of T, DLARRJ */
  43. /* does bisection to refine the eigenvalues of T, */
  44. /* W( IFIRST-OFFSET ) through W( ILAST-OFFSET ), to more accuracy. Initial */
  45. /* guesses for these eigenvalues are input in W, the corresponding estimate */
  46. /* of the error in these guesses in WERR. During bisection, intervals */
  47. /* [left, right] are maintained by storing their mid-points and */
  48. /* semi-widths in the arrays W and WERR respectively. */
  49. /* Arguments */
  50. /* ========= */
  51. /* N (input) INTEGER */
  52. /* The order of the matrix. */
  53. /* D (input) DOUBLE PRECISION array, dimension (N) */
  54. /* The N diagonal elements of T. */
  55. /* E2 (input) DOUBLE PRECISION array, dimension (N-1) */
  56. /* The Squares of the (N-1) subdiagonal elements of T. */
  57. /* IFIRST (input) INTEGER */
  58. /* The index of the first eigenvalue to be computed. */
  59. /* ILAST (input) INTEGER */
  60. /* The index of the last eigenvalue to be computed. */
  61. /* RTOL (input) DOUBLE PRECISION */
  62. /* Tolerance for the convergence of the bisection intervals. */
  63. /* An interval [LEFT,RIGHT] has converged if */
  64. /* RIGHT-LEFT.LT.RTOL*MAX(|LEFT|,|RIGHT|). */
  65. /* OFFSET (input) INTEGER */
  66. /* Offset for the arrays W and WERR, i.e., the IFIRST-OFFSET */
  67. /* through ILAST-OFFSET elements of these arrays are to be used. */
  68. /* W (input/output) DOUBLE PRECISION array, dimension (N) */
  69. /* On input, W( IFIRST-OFFSET ) through W( ILAST-OFFSET ) are */
  70. /* estimates of the eigenvalues of L D L^T indexed IFIRST through */
  71. /* ILAST. */
  72. /* On output, these estimates are refined. */
  73. /* WERR (input/output) DOUBLE PRECISION array, dimension (N) */
  74. /* On input, WERR( IFIRST-OFFSET ) through WERR( ILAST-OFFSET ) are */
  75. /* the errors in the estimates of the corresponding elements in W. */
  76. /* On output, these errors are refined. */
  77. /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
  78. /* Workspace. */
  79. /* IWORK (workspace) INTEGER array, dimension (2*N) */
  80. /* Workspace. */
  81. /* PIVMIN (input) DOUBLE PRECISION */
  82. /* The minimum pivot in the Sturm sequence for T. */
  83. /* SPDIAM (input) DOUBLE PRECISION */
  84. /* The spectral diameter of T. */
  85. /* INFO (output) INTEGER */
  86. /* Error flag. */
  87. /* Further Details */
  88. /* =============== */
  89. /* Based on contributions by */
  90. /* Beresford Parlett, University of California, Berkeley, USA */
  91. /* Jim Demmel, University of California, Berkeley, USA */
  92. /* Inderjit Dhillon, University of Texas, Austin, USA */
  93. /* Osni Marques, LBNL/NERSC, USA */
  94. /* Christof Voemel, University of California, Berkeley, USA */
  95. /* ===================================================================== */
  96. /* .. Parameters .. */
  97. /* .. */
  98. /* .. Local Scalars .. */
  99. /* .. */
  100. /* .. Intrinsic Functions .. */
  101. /* .. */
  102. /* .. Executable Statements .. */
  103. /* Parameter adjustments */
  104. --iwork;
  105. --work;
  106. --werr;
  107. --w;
  108. --e2;
  109. --d__;
  110. /* Function Body */
  111. *info = 0;
  112. maxitr = (integer) ((log(*spdiam + *pivmin) - log(*pivmin)) / log(2.)) +
  113. 2;
  114. /* Initialize unconverged intervals in [ WORK(2*I-1), WORK(2*I) ]. */
  115. /* The Sturm Count, Count( WORK(2*I-1) ) is arranged to be I-1, while */
  116. /* Count( WORK(2*I) ) is stored in IWORK( 2*I ). The integer IWORK( 2*I-1 ) */
  117. /* for an unconverged interval is set to the index of the next unconverged */
  118. /* interval, and is -1 or 0 for a converged interval. Thus a linked */
  119. /* list of unconverged intervals is set up. */
  120. i1 = *ifirst;
  121. i2 = *ilast;
  122. /* The number of unconverged intervals */
  123. nint = 0;
  124. /* The last unconverged interval found */
  125. prev = 0;
  126. i__1 = i2;
  127. for (i__ = i1; i__ <= i__1; ++i__) {
  128. k = i__ << 1;
  129. ii = i__ - *offset;
  130. left = w[ii] - werr[ii];
  131. mid = w[ii];
  132. right = w[ii] + werr[ii];
  133. width = right - mid;
  134. /* Computing MAX */
  135. d__1 = abs(left), d__2 = abs(right);
  136. tmp = max(d__1,d__2);
  137. /* The following test prevents the test of converged intervals */
  138. if (width < *rtol * tmp) {
  139. /* This interval has already converged and does not need refinement. */
  140. /* (Note that the gaps might change through refining the */
  141. /* eigenvalues, however, they can only get bigger.) */
  142. /* Remove it from the list. */
  143. iwork[k - 1] = -1;
  144. /* Make sure that I1 always points to the first unconverged interval */
  145. if (i__ == i1 && i__ < i2) {
  146. i1 = i__ + 1;
  147. }
  148. if (prev >= i1 && i__ <= i2) {
  149. iwork[(prev << 1) - 1] = i__ + 1;
  150. }
  151. } else {
  152. /* unconverged interval found */
  153. prev = i__;
  154. /* Make sure that [LEFT,RIGHT] contains the desired eigenvalue */
  155. /* Do while( CNT(LEFT).GT.I-1 ) */
  156. fac = 1.;
  157. L20:
  158. cnt = 0;
  159. s = left;
  160. dplus = d__[1] - s;
  161. if (dplus < 0.) {
  162. ++cnt;
  163. }
  164. i__2 = *n;
  165. for (j = 2; j <= i__2; ++j) {
  166. dplus = d__[j] - s - e2[j - 1] / dplus;
  167. if (dplus < 0.) {
  168. ++cnt;
  169. }
  170. /* L30: */
  171. }
  172. if (cnt > i__ - 1) {
  173. left -= werr[ii] * fac;
  174. fac *= 2.;
  175. goto L20;
  176. }
  177. /* Do while( CNT(RIGHT).LT.I ) */
  178. fac = 1.;
  179. L50:
  180. cnt = 0;
  181. s = right;
  182. dplus = d__[1] - s;
  183. if (dplus < 0.) {
  184. ++cnt;
  185. }
  186. i__2 = *n;
  187. for (j = 2; j <= i__2; ++j) {
  188. dplus = d__[j] - s - e2[j - 1] / dplus;
  189. if (dplus < 0.) {
  190. ++cnt;
  191. }
  192. /* L60: */
  193. }
  194. if (cnt < i__) {
  195. right += werr[ii] * fac;
  196. fac *= 2.;
  197. goto L50;
  198. }
  199. ++nint;
  200. iwork[k - 1] = i__ + 1;
  201. iwork[k] = cnt;
  202. }
  203. work[k - 1] = left;
  204. work[k] = right;
  205. /* L75: */
  206. }
  207. savi1 = i1;
  208. /* Do while( NINT.GT.0 ), i.e. there are still unconverged intervals */
  209. /* and while (ITER.LT.MAXITR) */
  210. iter = 0;
  211. L80:
  212. prev = i1 - 1;
  213. i__ = i1;
  214. olnint = nint;
  215. i__1 = olnint;
  216. for (p = 1; p <= i__1; ++p) {
  217. k = i__ << 1;
  218. ii = i__ - *offset;
  219. next = iwork[k - 1];
  220. left = work[k - 1];
  221. right = work[k];
  222. mid = (left + right) * .5;
  223. /* semiwidth of interval */
  224. width = right - mid;
  225. /* Computing MAX */
  226. d__1 = abs(left), d__2 = abs(right);
  227. tmp = max(d__1,d__2);
  228. if (width < *rtol * tmp || iter == maxitr) {
  229. /* reduce number of unconverged intervals */
  230. --nint;
  231. /* Mark interval as converged. */
  232. iwork[k - 1] = 0;
  233. if (i1 == i__) {
  234. i1 = next;
  235. } else {
  236. /* Prev holds the last unconverged interval previously examined */
  237. if (prev >= i1) {
  238. iwork[(prev << 1) - 1] = next;
  239. }
  240. }
  241. i__ = next;
  242. goto L100;
  243. }
  244. prev = i__;
  245. /* Perform one bisection step */
  246. cnt = 0;
  247. s = mid;
  248. dplus = d__[1] - s;
  249. if (dplus < 0.) {
  250. ++cnt;
  251. }
  252. i__2 = *n;
  253. for (j = 2; j <= i__2; ++j) {
  254. dplus = d__[j] - s - e2[j - 1] / dplus;
  255. if (dplus < 0.) {
  256. ++cnt;
  257. }
  258. /* L90: */
  259. }
  260. if (cnt <= 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__ = savi1; 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. return 0;
  289. /* End of DLARRJ */
  290. } /* _starpu_dlarrj_ */