dlagts.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /* dlagts.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_dlagts_(integer *job, integer *n, doublereal *a,
  14. doublereal *b, doublereal *c__, doublereal *d__, integer *in,
  15. doublereal *y, doublereal *tol, integer *info)
  16. {
  17. /* System generated locals */
  18. integer i__1;
  19. doublereal d__1, d__2, d__3, d__4, d__5;
  20. /* Builtin functions */
  21. double d_sign(doublereal *, doublereal *);
  22. /* Local variables */
  23. integer k;
  24. doublereal ak, eps, temp, pert, absak, sfmin;
  25. extern doublereal _starpu_dlamch_(char *);
  26. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  27. doublereal bignum;
  28. /* -- LAPACK auxiliary routine (version 3.2) -- */
  29. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  30. /* November 2006 */
  31. /* .. Scalar Arguments .. */
  32. /* .. */
  33. /* .. Array Arguments .. */
  34. /* .. */
  35. /* Purpose */
  36. /* ======= */
  37. /* DLAGTS may be used to solve one of the systems of equations */
  38. /* (T - lambda*I)*x = y or (T - lambda*I)'*x = y, */
  39. /* where T is an n by n tridiagonal matrix, for x, following the */
  40. /* factorization of (T - lambda*I) as */
  41. /* (T - lambda*I) = P*L*U , */
  42. /* by routine DLAGTF. The choice of equation to be solved is */
  43. /* controlled by the argument JOB, and in each case there is an option */
  44. /* to perturb zero or very small diagonal elements of U, this option */
  45. /* being intended for use in applications such as inverse iteration. */
  46. /* Arguments */
  47. /* ========= */
  48. /* JOB (input) INTEGER */
  49. /* Specifies the job to be performed by DLAGTS as follows: */
  50. /* = 1: The equations (T - lambda*I)x = y are to be solved, */
  51. /* but diagonal elements of U are not to be perturbed. */
  52. /* = -1: The equations (T - lambda*I)x = y are to be solved */
  53. /* and, if overflow would otherwise occur, the diagonal */
  54. /* elements of U are to be perturbed. See argument TOL */
  55. /* below. */
  56. /* = 2: The equations (T - lambda*I)'x = y are to be solved, */
  57. /* but diagonal elements of U are not to be perturbed. */
  58. /* = -2: The equations (T - lambda*I)'x = y are to be solved */
  59. /* and, if overflow would otherwise occur, the diagonal */
  60. /* elements of U are to be perturbed. See argument TOL */
  61. /* below. */
  62. /* N (input) INTEGER */
  63. /* The order of the matrix T. */
  64. /* A (input) DOUBLE PRECISION array, dimension (N) */
  65. /* On entry, A must contain the diagonal elements of U as */
  66. /* returned from DLAGTF. */
  67. /* B (input) DOUBLE PRECISION array, dimension (N-1) */
  68. /* On entry, B must contain the first super-diagonal elements of */
  69. /* U as returned from DLAGTF. */
  70. /* C (input) DOUBLE PRECISION array, dimension (N-1) */
  71. /* On entry, C must contain the sub-diagonal elements of L as */
  72. /* returned from DLAGTF. */
  73. /* D (input) DOUBLE PRECISION array, dimension (N-2) */
  74. /* On entry, D must contain the second super-diagonal elements */
  75. /* of U as returned from DLAGTF. */
  76. /* IN (input) INTEGER array, dimension (N) */
  77. /* On entry, IN must contain details of the matrix P as returned */
  78. /* from DLAGTF. */
  79. /* Y (input/output) DOUBLE PRECISION array, dimension (N) */
  80. /* On entry, the right hand side vector y. */
  81. /* On exit, Y is overwritten by the solution vector x. */
  82. /* TOL (input/output) DOUBLE PRECISION */
  83. /* On entry, with JOB .lt. 0, TOL should be the minimum */
  84. /* perturbation to be made to very small diagonal elements of U. */
  85. /* TOL should normally be chosen as about eps*norm(U), where eps */
  86. /* is the relative machine precision, but if TOL is supplied as */
  87. /* non-positive, then it is reset to eps*max( abs( u(i,j) ) ). */
  88. /* If JOB .gt. 0 then TOL is not referenced. */
  89. /* On exit, TOL is changed as described above, only if TOL is */
  90. /* non-positive on entry. Otherwise TOL is unchanged. */
  91. /* INFO (output) INTEGER */
  92. /* = 0 : successful exit */
  93. /* .lt. 0: if INFO = -i, the i-th argument had an illegal value */
  94. /* .gt. 0: overflow would occur when computing the INFO(th) */
  95. /* element of the solution vector x. This can only occur */
  96. /* when JOB is supplied as positive and either means */
  97. /* that a diagonal element of U is very small, or that */
  98. /* the elements of the right-hand side vector y are very */
  99. /* large. */
  100. /* ===================================================================== */
  101. /* .. Parameters .. */
  102. /* .. */
  103. /* .. Local Scalars .. */
  104. /* .. */
  105. /* .. Intrinsic Functions .. */
  106. /* .. */
  107. /* .. External Functions .. */
  108. /* .. */
  109. /* .. External Subroutines .. */
  110. /* .. */
  111. /* .. Executable Statements .. */
  112. /* Parameter adjustments */
  113. --y;
  114. --in;
  115. --d__;
  116. --c__;
  117. --b;
  118. --a;
  119. /* Function Body */
  120. *info = 0;
  121. if (abs(*job) > 2 || *job == 0) {
  122. *info = -1;
  123. } else if (*n < 0) {
  124. *info = -2;
  125. }
  126. if (*info != 0) {
  127. i__1 = -(*info);
  128. _starpu_xerbla_("DLAGTS", &i__1);
  129. return 0;
  130. }
  131. if (*n == 0) {
  132. return 0;
  133. }
  134. eps = _starpu_dlamch_("Epsilon");
  135. sfmin = _starpu_dlamch_("Safe minimum");
  136. bignum = 1. / sfmin;
  137. if (*job < 0) {
  138. if (*tol <= 0.) {
  139. *tol = abs(a[1]);
  140. if (*n > 1) {
  141. /* Computing MAX */
  142. d__1 = *tol, d__2 = abs(a[2]), d__1 = max(d__1,d__2), d__2 =
  143. abs(b[1]);
  144. *tol = max(d__1,d__2);
  145. }
  146. i__1 = *n;
  147. for (k = 3; k <= i__1; ++k) {
  148. /* Computing MAX */
  149. d__4 = *tol, d__5 = (d__1 = a[k], abs(d__1)), d__4 = max(d__4,
  150. d__5), d__5 = (d__2 = b[k - 1], abs(d__2)), d__4 =
  151. max(d__4,d__5), d__5 = (d__3 = d__[k - 2], abs(d__3));
  152. *tol = max(d__4,d__5);
  153. /* L10: */
  154. }
  155. *tol *= eps;
  156. if (*tol == 0.) {
  157. *tol = eps;
  158. }
  159. }
  160. }
  161. if (abs(*job) == 1) {
  162. i__1 = *n;
  163. for (k = 2; k <= i__1; ++k) {
  164. if (in[k - 1] == 0) {
  165. y[k] -= c__[k - 1] * y[k - 1];
  166. } else {
  167. temp = y[k - 1];
  168. y[k - 1] = y[k];
  169. y[k] = temp - c__[k - 1] * y[k];
  170. }
  171. /* L20: */
  172. }
  173. if (*job == 1) {
  174. for (k = *n; k >= 1; --k) {
  175. if (k <= *n - 2) {
  176. temp = y[k] - b[k] * y[k + 1] - d__[k] * y[k + 2];
  177. } else if (k == *n - 1) {
  178. temp = y[k] - b[k] * y[k + 1];
  179. } else {
  180. temp = y[k];
  181. }
  182. ak = a[k];
  183. absak = abs(ak);
  184. if (absak < 1.) {
  185. if (absak < sfmin) {
  186. if (absak == 0. || abs(temp) * sfmin > absak) {
  187. *info = k;
  188. return 0;
  189. } else {
  190. temp *= bignum;
  191. ak *= bignum;
  192. }
  193. } else if (abs(temp) > absak * bignum) {
  194. *info = k;
  195. return 0;
  196. }
  197. }
  198. y[k] = temp / ak;
  199. /* L30: */
  200. }
  201. } else {
  202. for (k = *n; k >= 1; --k) {
  203. if (k <= *n - 2) {
  204. temp = y[k] - b[k] * y[k + 1] - d__[k] * y[k + 2];
  205. } else if (k == *n - 1) {
  206. temp = y[k] - b[k] * y[k + 1];
  207. } else {
  208. temp = y[k];
  209. }
  210. ak = a[k];
  211. pert = d_sign(tol, &ak);
  212. L40:
  213. absak = abs(ak);
  214. if (absak < 1.) {
  215. if (absak < sfmin) {
  216. if (absak == 0. || abs(temp) * sfmin > absak) {
  217. ak += pert;
  218. pert *= 2;
  219. goto L40;
  220. } else {
  221. temp *= bignum;
  222. ak *= bignum;
  223. }
  224. } else if (abs(temp) > absak * bignum) {
  225. ak += pert;
  226. pert *= 2;
  227. goto L40;
  228. }
  229. }
  230. y[k] = temp / ak;
  231. /* L50: */
  232. }
  233. }
  234. } else {
  235. /* Come to here if JOB = 2 or -2 */
  236. if (*job == 2) {
  237. i__1 = *n;
  238. for (k = 1; k <= i__1; ++k) {
  239. if (k >= 3) {
  240. temp = y[k] - b[k - 1] * y[k - 1] - d__[k - 2] * y[k - 2];
  241. } else if (k == 2) {
  242. temp = y[k] - b[k - 1] * y[k - 1];
  243. } else {
  244. temp = y[k];
  245. }
  246. ak = a[k];
  247. absak = abs(ak);
  248. if (absak < 1.) {
  249. if (absak < sfmin) {
  250. if (absak == 0. || abs(temp) * sfmin > absak) {
  251. *info = k;
  252. return 0;
  253. } else {
  254. temp *= bignum;
  255. ak *= bignum;
  256. }
  257. } else if (abs(temp) > absak * bignum) {
  258. *info = k;
  259. return 0;
  260. }
  261. }
  262. y[k] = temp / ak;
  263. /* L60: */
  264. }
  265. } else {
  266. i__1 = *n;
  267. for (k = 1; k <= i__1; ++k) {
  268. if (k >= 3) {
  269. temp = y[k] - b[k - 1] * y[k - 1] - d__[k - 2] * y[k - 2];
  270. } else if (k == 2) {
  271. temp = y[k] - b[k - 1] * y[k - 1];
  272. } else {
  273. temp = y[k];
  274. }
  275. ak = a[k];
  276. pert = d_sign(tol, &ak);
  277. L70:
  278. absak = abs(ak);
  279. if (absak < 1.) {
  280. if (absak < sfmin) {
  281. if (absak == 0. || abs(temp) * sfmin > absak) {
  282. ak += pert;
  283. pert *= 2;
  284. goto L70;
  285. } else {
  286. temp *= bignum;
  287. ak *= bignum;
  288. }
  289. } else if (abs(temp) > absak * bignum) {
  290. ak += pert;
  291. pert *= 2;
  292. goto L70;
  293. }
  294. }
  295. y[k] = temp / ak;
  296. /* L80: */
  297. }
  298. }
  299. for (k = *n; k >= 2; --k) {
  300. if (in[k - 1] == 0) {
  301. y[k - 1] -= c__[k - 1] * y[k];
  302. } else {
  303. temp = y[k - 1];
  304. y[k - 1] = y[k];
  305. y[k] = temp - c__[k - 1] * y[k];
  306. }
  307. /* L90: */
  308. }
  309. }
  310. /* End of DLAGTS */
  311. return 0;
  312. } /* _starpu_dlagts_ */