dgtsvx.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /* dgtsvx.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. /* Subroutine */ int _starpu_dgtsvx_(char *fact, char *trans, integer *n, integer *
  16. nrhs, doublereal *dl, doublereal *d__, doublereal *du, doublereal *
  17. dlf, doublereal *df, doublereal *duf, doublereal *du2, integer *ipiv,
  18. doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal *
  19. rcond, doublereal *ferr, doublereal *berr, doublereal *work, integer *
  20. iwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer b_dim1, b_offset, x_dim1, x_offset, i__1;
  24. /* Local variables */
  25. char norm[1];
  26. extern logical _starpu_lsame_(char *, char *);
  27. doublereal anorm;
  28. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  29. doublereal *, integer *);
  30. extern doublereal _starpu_dlamch_(char *), _starpu_dlangt_(char *, integer *,
  31. doublereal *, doublereal *, doublereal *);
  32. logical nofact;
  33. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  34. doublereal *, integer *, doublereal *, integer *),
  35. _starpu_xerbla_(char *, integer *), _starpu_dgtcon_(char *, integer *,
  36. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  37. doublereal *, doublereal *, doublereal *, integer *, integer *), _starpu_dgtrfs_(char *, integer *, integer *, doublereal *,
  38. doublereal *, doublereal *, doublereal *, doublereal *,
  39. doublereal *, doublereal *, integer *, doublereal *, integer *,
  40. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  41. integer *, integer *), _starpu_dgttrf_(integer *, doublereal *,
  42. doublereal *, doublereal *, doublereal *, integer *, integer *);
  43. logical notran;
  44. extern /* Subroutine */ int _starpu_dgttrs_(char *, integer *, integer *,
  45. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  46. doublereal *, integer *, integer *);
  47. /* -- LAPACK routine (version 3.2) -- */
  48. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  49. /* November 2006 */
  50. /* .. Scalar Arguments .. */
  51. /* .. */
  52. /* .. Array Arguments .. */
  53. /* .. */
  54. /* Purpose */
  55. /* ======= */
  56. /* DGTSVX uses the LU factorization to compute the solution to a real */
  57. /* system of linear equations A * X = B or A**T * X = B, */
  58. /* where A is a tridiagonal matrix of order N and X and B are N-by-NRHS */
  59. /* matrices. */
  60. /* Error bounds on the solution and a condition estimate are also */
  61. /* provided. */
  62. /* Description */
  63. /* =========== */
  64. /* The following steps are performed: */
  65. /* 1. If FACT = 'N', the LU decomposition is used to factor the matrix A */
  66. /* as A = L * U, where L is a product of permutation and unit lower */
  67. /* bidiagonal matrices and U is upper triangular with nonzeros in */
  68. /* only the main diagonal and first two superdiagonals. */
  69. /* 2. If some U(i,i)=0, so that U is exactly singular, then the routine */
  70. /* returns with INFO = i. Otherwise, the factored form of A is used */
  71. /* to estimate the condition number of the matrix A. If the */
  72. /* reciprocal of the condition number is less than machine precision, */
  73. /* INFO = N+1 is returned as a warning, but the routine still goes on */
  74. /* to solve for X and compute error bounds as described below. */
  75. /* 3. The system of equations is solved for X using the factored form */
  76. /* of A. */
  77. /* 4. Iterative refinement is applied to improve the computed solution */
  78. /* matrix and calculate error bounds and backward error estimates */
  79. /* for it. */
  80. /* Arguments */
  81. /* ========= */
  82. /* FACT (input) CHARACTER*1 */
  83. /* Specifies whether or not the factored form of A has been */
  84. /* supplied on entry. */
  85. /* = 'F': DLF, DF, DUF, DU2, and IPIV contain the factored */
  86. /* form of A; DL, D, DU, DLF, DF, DUF, DU2 and IPIV */
  87. /* will not be modified. */
  88. /* = 'N': The matrix will be copied to DLF, DF, and DUF */
  89. /* and factored. */
  90. /* TRANS (input) CHARACTER*1 */
  91. /* Specifies the form of the system of equations: */
  92. /* = 'N': A * X = B (No transpose) */
  93. /* = 'T': A**T * X = B (Transpose) */
  94. /* = 'C': A**H * X = B (Conjugate transpose = Transpose) */
  95. /* N (input) INTEGER */
  96. /* The order of the matrix A. N >= 0. */
  97. /* NRHS (input) INTEGER */
  98. /* The number of right hand sides, i.e., the number of columns */
  99. /* of the matrix B. NRHS >= 0. */
  100. /* DL (input) DOUBLE PRECISION array, dimension (N-1) */
  101. /* The (n-1) subdiagonal elements of A. */
  102. /* D (input) DOUBLE PRECISION array, dimension (N) */
  103. /* The n diagonal elements of A. */
  104. /* DU (input) DOUBLE PRECISION array, dimension (N-1) */
  105. /* The (n-1) superdiagonal elements of A. */
  106. /* DLF (input or output) DOUBLE PRECISION array, dimension (N-1) */
  107. /* If FACT = 'F', then DLF is an input argument and on entry */
  108. /* contains the (n-1) multipliers that define the matrix L from */
  109. /* the LU factorization of A as computed by DGTTRF. */
  110. /* If FACT = 'N', then DLF is an output argument and on exit */
  111. /* contains the (n-1) multipliers that define the matrix L from */
  112. /* the LU factorization of A. */
  113. /* DF (input or output) DOUBLE PRECISION array, dimension (N) */
  114. /* If FACT = 'F', then DF is an input argument and on entry */
  115. /* contains the n diagonal elements of the upper triangular */
  116. /* matrix U from the LU factorization of A. */
  117. /* If FACT = 'N', then DF is an output argument and on exit */
  118. /* contains the n diagonal elements of the upper triangular */
  119. /* matrix U from the LU factorization of A. */
  120. /* DUF (input or output) DOUBLE PRECISION array, dimension (N-1) */
  121. /* If FACT = 'F', then DUF is an input argument and on entry */
  122. /* contains the (n-1) elements of the first superdiagonal of U. */
  123. /* If FACT = 'N', then DUF is an output argument and on exit */
  124. /* contains the (n-1) elements of the first superdiagonal of U. */
  125. /* DU2 (input or output) DOUBLE PRECISION array, dimension (N-2) */
  126. /* If FACT = 'F', then DU2 is an input argument and on entry */
  127. /* contains the (n-2) elements of the second superdiagonal of */
  128. /* U. */
  129. /* If FACT = 'N', then DU2 is an output argument and on exit */
  130. /* contains the (n-2) elements of the second superdiagonal of */
  131. /* U. */
  132. /* IPIV (input or output) INTEGER array, dimension (N) */
  133. /* If FACT = 'F', then IPIV is an input argument and on entry */
  134. /* contains the pivot indices from the LU factorization of A as */
  135. /* computed by DGTTRF. */
  136. /* If FACT = 'N', then IPIV is an output argument and on exit */
  137. /* contains the pivot indices from the LU factorization of A; */
  138. /* row i of the matrix was interchanged with row IPIV(i). */
  139. /* IPIV(i) will always be either i or i+1; IPIV(i) = i indicates */
  140. /* a row interchange was not required. */
  141. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  142. /* The N-by-NRHS right hand side matrix B. */
  143. /* LDB (input) INTEGER */
  144. /* The leading dimension of the array B. LDB >= max(1,N). */
  145. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  146. /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */
  147. /* LDX (input) INTEGER */
  148. /* The leading dimension of the array X. LDX >= max(1,N). */
  149. /* RCOND (output) DOUBLE PRECISION */
  150. /* The estimate of the reciprocal condition number of the matrix */
  151. /* A. If RCOND is less than the machine precision (in */
  152. /* particular, if RCOND = 0), the matrix is singular to working */
  153. /* precision. This condition is indicated by a return code of */
  154. /* INFO > 0. */
  155. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  156. /* The estimated forward error bound for each solution vector */
  157. /* X(j) (the j-th column of the solution matrix X). */
  158. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  159. /* is an estimated upper bound for the magnitude of the largest */
  160. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  161. /* largest element in X(j). The estimate is as reliable as */
  162. /* the estimate for RCOND, and is almost always a slight */
  163. /* overestimate of the true error. */
  164. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  165. /* The componentwise relative backward error of each solution */
  166. /* vector X(j) (i.e., the smallest relative change in */
  167. /* any element of A or B that makes X(j) an exact solution). */
  168. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  169. /* IWORK (workspace) INTEGER array, dimension (N) */
  170. /* INFO (output) INTEGER */
  171. /* = 0: successful exit */
  172. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  173. /* > 0: if INFO = i, and i is */
  174. /* <= N: U(i,i) is exactly zero. The factorization */
  175. /* has not been completed unless i = N, but the */
  176. /* factor U is exactly singular, so the solution */
  177. /* and error bounds could not be computed. */
  178. /* RCOND = 0 is returned. */
  179. /* = N+1: U is nonsingular, but RCOND is less than machine */
  180. /* precision, meaning that the matrix is singular */
  181. /* to working precision. Nevertheless, the */
  182. /* solution and error bounds are computed because */
  183. /* there are a number of situations where the */
  184. /* computed solution can be more accurate than the */
  185. /* value of RCOND would suggest. */
  186. /* ===================================================================== */
  187. /* .. Parameters .. */
  188. /* .. */
  189. /* .. Local Scalars .. */
  190. /* .. */
  191. /* .. External Functions .. */
  192. /* .. */
  193. /* .. External Subroutines .. */
  194. /* .. */
  195. /* .. Intrinsic Functions .. */
  196. /* .. */
  197. /* .. Executable Statements .. */
  198. /* Parameter adjustments */
  199. --dl;
  200. --d__;
  201. --du;
  202. --dlf;
  203. --df;
  204. --duf;
  205. --du2;
  206. --ipiv;
  207. b_dim1 = *ldb;
  208. b_offset = 1 + b_dim1;
  209. b -= b_offset;
  210. x_dim1 = *ldx;
  211. x_offset = 1 + x_dim1;
  212. x -= x_offset;
  213. --ferr;
  214. --berr;
  215. --work;
  216. --iwork;
  217. /* Function Body */
  218. *info = 0;
  219. nofact = _starpu_lsame_(fact, "N");
  220. notran = _starpu_lsame_(trans, "N");
  221. if (! nofact && ! _starpu_lsame_(fact, "F")) {
  222. *info = -1;
  223. } else if (! notran && ! _starpu_lsame_(trans, "T") && !
  224. _starpu_lsame_(trans, "C")) {
  225. *info = -2;
  226. } else if (*n < 0) {
  227. *info = -3;
  228. } else if (*nrhs < 0) {
  229. *info = -4;
  230. } else if (*ldb < max(1,*n)) {
  231. *info = -14;
  232. } else if (*ldx < max(1,*n)) {
  233. *info = -16;
  234. }
  235. if (*info != 0) {
  236. i__1 = -(*info);
  237. _starpu_xerbla_("DGTSVX", &i__1);
  238. return 0;
  239. }
  240. if (nofact) {
  241. /* Compute the LU factorization of A. */
  242. _starpu_dcopy_(n, &d__[1], &c__1, &df[1], &c__1);
  243. if (*n > 1) {
  244. i__1 = *n - 1;
  245. _starpu_dcopy_(&i__1, &dl[1], &c__1, &dlf[1], &c__1);
  246. i__1 = *n - 1;
  247. _starpu_dcopy_(&i__1, &du[1], &c__1, &duf[1], &c__1);
  248. }
  249. _starpu_dgttrf_(n, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[1], info);
  250. /* Return if INFO is non-zero. */
  251. if (*info > 0) {
  252. *rcond = 0.;
  253. return 0;
  254. }
  255. }
  256. /* Compute the norm of the matrix A. */
  257. if (notran) {
  258. *(unsigned char *)norm = '1';
  259. } else {
  260. *(unsigned char *)norm = 'I';
  261. }
  262. anorm = _starpu_dlangt_(norm, n, &dl[1], &d__[1], &du[1]);
  263. /* Compute the reciprocal of the condition number of A. */
  264. _starpu_dgtcon_(norm, n, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[1], &anorm,
  265. rcond, &work[1], &iwork[1], info);
  266. /* Compute the solution vectors X. */
  267. _starpu_dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  268. _starpu_dgttrs_(trans, n, nrhs, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[1], &x[
  269. x_offset], ldx, info);
  270. /* Use iterative refinement to improve the computed solutions and */
  271. /* compute error bounds and backward error estimates for them. */
  272. _starpu_dgtrfs_(trans, n, nrhs, &dl[1], &d__[1], &du[1], &dlf[1], &df[1], &duf[1],
  273. &du2[1], &ipiv[1], &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1]
  274. , &berr[1], &work[1], &iwork[1], info);
  275. /* Set INFO = N+1 if the matrix is singular to working precision. */
  276. if (*rcond < _starpu_dlamch_("Epsilon")) {
  277. *info = *n + 1;
  278. }
  279. return 0;
  280. /* End of DGTSVX */
  281. } /* _starpu_dgtsvx_ */