dptsvx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* dptsvx.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_dptsvx_(char *fact, integer *n, integer *nrhs,
  16. doublereal *d__, doublereal *e, doublereal *df, doublereal *ef,
  17. doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal *
  18. rcond, doublereal *ferr, doublereal *berr, doublereal *work, integer *
  19. info)
  20. {
  21. /* System generated locals */
  22. integer b_dim1, b_offset, x_dim1, x_offset, i__1;
  23. /* Local variables */
  24. extern logical _starpu_lsame_(char *, char *);
  25. doublereal anorm;
  26. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  27. doublereal *, integer *);
  28. extern doublereal _starpu_dlamch_(char *);
  29. logical nofact;
  30. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  31. doublereal *, integer *, doublereal *, integer *),
  32. _starpu_xerbla_(char *, integer *);
  33. extern doublereal _starpu_dlanst_(char *, integer *, doublereal *, doublereal *);
  34. extern /* Subroutine */ int _starpu_dptcon_(integer *, doublereal *, doublereal *,
  35. doublereal *, doublereal *, doublereal *, integer *), _starpu_dptrfs_(
  36. integer *, integer *, doublereal *, doublereal *, doublereal *,
  37. doublereal *, doublereal *, integer *, doublereal *, integer *,
  38. doublereal *, doublereal *, doublereal *, integer *), _starpu_dpttrf_(
  39. integer *, doublereal *, doublereal *, integer *), _starpu_dpttrs_(
  40. integer *, integer *, doublereal *, doublereal *, doublereal *,
  41. integer *, integer *);
  42. /* -- LAPACK routine (version 3.2) -- */
  43. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  44. /* November 2006 */
  45. /* .. Scalar Arguments .. */
  46. /* .. */
  47. /* .. Array Arguments .. */
  48. /* .. */
  49. /* Purpose */
  50. /* ======= */
  51. /* DPTSVX uses the factorization A = L*D*L**T to compute the solution */
  52. /* to a real system of linear equations A*X = B, where A is an N-by-N */
  53. /* symmetric positive definite tridiagonal matrix and X and B are */
  54. /* N-by-NRHS matrices. */
  55. /* Error bounds on the solution and a condition estimate are also */
  56. /* provided. */
  57. /* Description */
  58. /* =========== */
  59. /* The following steps are performed: */
  60. /* 1. If FACT = 'N', the matrix A is factored as A = L*D*L**T, where L */
  61. /* is a unit lower bidiagonal matrix and D is diagonal. The */
  62. /* factorization can also be regarded as having the form */
  63. /* A = U**T*D*U. */
  64. /* 2. If the leading i-by-i principal minor is not positive definite, */
  65. /* then the routine returns with INFO = i. Otherwise, the factored */
  66. /* form of A is used to estimate the condition number of the matrix */
  67. /* A. If the reciprocal of the condition number is less than machine */
  68. /* precision, INFO = N+1 is returned as a warning, but the routine */
  69. /* still goes on to solve for X and compute error bounds as */
  70. /* described below. */
  71. /* 3. The system of equations is solved for X using the factored form */
  72. /* of A. */
  73. /* 4. Iterative refinement is applied to improve the computed solution */
  74. /* matrix and calculate error bounds and backward error estimates */
  75. /* for it. */
  76. /* Arguments */
  77. /* ========= */
  78. /* FACT (input) CHARACTER*1 */
  79. /* Specifies whether or not the factored form of A has been */
  80. /* supplied on entry. */
  81. /* = 'F': On entry, DF and EF contain the factored form of A. */
  82. /* D, E, DF, and EF will not be modified. */
  83. /* = 'N': The matrix A will be copied to DF and EF and */
  84. /* factored. */
  85. /* N (input) INTEGER */
  86. /* The order of the matrix A. N >= 0. */
  87. /* NRHS (input) INTEGER */
  88. /* The number of right hand sides, i.e., the number of columns */
  89. /* of the matrices B and X. NRHS >= 0. */
  90. /* D (input) DOUBLE PRECISION array, dimension (N) */
  91. /* The n diagonal elements of the tridiagonal matrix A. */
  92. /* E (input) DOUBLE PRECISION array, dimension (N-1) */
  93. /* The (n-1) subdiagonal elements of the tridiagonal matrix A. */
  94. /* DF (input or output) DOUBLE PRECISION array, dimension (N) */
  95. /* If FACT = 'F', then DF is an input argument and on entry */
  96. /* contains the n diagonal elements of the diagonal matrix D */
  97. /* from the L*D*L**T factorization of A. */
  98. /* If FACT = 'N', then DF is an output argument and on exit */
  99. /* contains the n diagonal elements of the diagonal matrix D */
  100. /* from the L*D*L**T factorization of A. */
  101. /* EF (input or output) DOUBLE PRECISION array, dimension (N-1) */
  102. /* If FACT = 'F', then EF is an input argument and on entry */
  103. /* contains the (n-1) subdiagonal elements of the unit */
  104. /* bidiagonal factor L from the L*D*L**T factorization of A. */
  105. /* If FACT = 'N', then EF is an output argument and on exit */
  106. /* contains the (n-1) subdiagonal elements of the unit */
  107. /* bidiagonal factor L from the L*D*L**T factorization of A. */
  108. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  109. /* The N-by-NRHS right hand side matrix B. */
  110. /* LDB (input) INTEGER */
  111. /* The leading dimension of the array B. LDB >= max(1,N). */
  112. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  113. /* If INFO = 0 of INFO = N+1, the N-by-NRHS solution matrix X. */
  114. /* LDX (input) INTEGER */
  115. /* The leading dimension of the array X. LDX >= max(1,N). */
  116. /* RCOND (output) DOUBLE PRECISION */
  117. /* The reciprocal condition number of the matrix A. If RCOND */
  118. /* is less than the machine precision (in particular, if */
  119. /* RCOND = 0), the matrix is singular to working precision. */
  120. /* This condition is indicated by a return code of INFO > 0. */
  121. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  122. /* The forward error bound for each solution vector */
  123. /* X(j) (the j-th column of the solution matrix X). */
  124. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  125. /* is an estimated upper bound for the magnitude of the largest */
  126. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  127. /* largest element in X(j). */
  128. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  129. /* The componentwise relative backward error of each solution */
  130. /* vector X(j) (i.e., the smallest relative change in any */
  131. /* element of A or B that makes X(j) an exact solution). */
  132. /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
  133. /* INFO (output) INTEGER */
  134. /* = 0: successful exit */
  135. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  136. /* > 0: if INFO = i, and i is */
  137. /* <= N: the leading minor of order i of A is */
  138. /* not positive definite, so the factorization */
  139. /* could not be completed, and the solution has not */
  140. /* been computed. RCOND = 0 is returned. */
  141. /* = N+1: U is nonsingular, but RCOND is less than machine */
  142. /* precision, meaning that the matrix is singular */
  143. /* to working precision. Nevertheless, the */
  144. /* solution and error bounds are computed because */
  145. /* there are a number of situations where the */
  146. /* computed solution can be more accurate than the */
  147. /* value of RCOND would suggest. */
  148. /* ===================================================================== */
  149. /* .. Parameters .. */
  150. /* .. */
  151. /* .. Local Scalars .. */
  152. /* .. */
  153. /* .. External Functions .. */
  154. /* .. */
  155. /* .. External Subroutines .. */
  156. /* .. */
  157. /* .. Intrinsic Functions .. */
  158. /* .. */
  159. /* .. Executable Statements .. */
  160. /* Test the input parameters. */
  161. /* Parameter adjustments */
  162. --d__;
  163. --e;
  164. --df;
  165. --ef;
  166. b_dim1 = *ldb;
  167. b_offset = 1 + b_dim1;
  168. b -= b_offset;
  169. x_dim1 = *ldx;
  170. x_offset = 1 + x_dim1;
  171. x -= x_offset;
  172. --ferr;
  173. --berr;
  174. --work;
  175. /* Function Body */
  176. *info = 0;
  177. nofact = _starpu_lsame_(fact, "N");
  178. if (! nofact && ! _starpu_lsame_(fact, "F")) {
  179. *info = -1;
  180. } else if (*n < 0) {
  181. *info = -2;
  182. } else if (*nrhs < 0) {
  183. *info = -3;
  184. } else if (*ldb < max(1,*n)) {
  185. *info = -9;
  186. } else if (*ldx < max(1,*n)) {
  187. *info = -11;
  188. }
  189. if (*info != 0) {
  190. i__1 = -(*info);
  191. _starpu_xerbla_("DPTSVX", &i__1);
  192. return 0;
  193. }
  194. if (nofact) {
  195. /* Compute the L*D*L' (or U'*D*U) factorization of A. */
  196. _starpu_dcopy_(n, &d__[1], &c__1, &df[1], &c__1);
  197. if (*n > 1) {
  198. i__1 = *n - 1;
  199. _starpu_dcopy_(&i__1, &e[1], &c__1, &ef[1], &c__1);
  200. }
  201. _starpu_dpttrf_(n, &df[1], &ef[1], info);
  202. /* Return if INFO is non-zero. */
  203. if (*info > 0) {
  204. *rcond = 0.;
  205. return 0;
  206. }
  207. }
  208. /* Compute the norm of the matrix A. */
  209. anorm = _starpu_dlanst_("1", n, &d__[1], &e[1]);
  210. /* Compute the reciprocal of the condition number of A. */
  211. _starpu_dptcon_(n, &df[1], &ef[1], &anorm, rcond, &work[1], info);
  212. /* Compute the solution vectors X. */
  213. _starpu_dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  214. _starpu_dpttrs_(n, nrhs, &df[1], &ef[1], &x[x_offset], ldx, info);
  215. /* Use iterative refinement to improve the computed solutions and */
  216. /* compute error bounds and backward error estimates for them. */
  217. _starpu_dptrfs_(n, nrhs, &d__[1], &e[1], &df[1], &ef[1], &b[b_offset], ldb, &x[
  218. x_offset], ldx, &ferr[1], &berr[1], &work[1], info);
  219. /* Set INFO = N+1 if the matrix is singular to working precision. */
  220. if (*rcond < _starpu_dlamch_("Epsilon")) {
  221. *info = *n + 1;
  222. }
  223. return 0;
  224. /* End of DPTSVX */
  225. } /* _starpu_dptsvx_ */