dspsvx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* dspsvx.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_dspsvx_(char *fact, char *uplo, integer *n, integer *
  16. nrhs, doublereal *ap, doublereal *afp, integer *ipiv, doublereal *b,
  17. integer *ldb, doublereal *x, integer *ldx, doublereal *rcond,
  18. doublereal *ferr, doublereal *berr, doublereal *work, integer *iwork,
  19. integer *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_dlansp_(char *, char *, integer *, doublereal *,
  34. doublereal *);
  35. extern /* Subroutine */ int _starpu_dspcon_(char *, integer *, doublereal *,
  36. integer *, doublereal *, doublereal *, doublereal *, integer *,
  37. integer *), _starpu_dsprfs_(char *, integer *, integer *,
  38. doublereal *, doublereal *, integer *, doublereal *, integer *,
  39. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  40. integer *, integer *), _starpu_dsptrf_(char *, integer *,
  41. doublereal *, integer *, integer *), _starpu_dsptrs_(char *,
  42. integer *, integer *, doublereal *, integer *, doublereal *,
  43. integer *, integer *);
  44. /* -- LAPACK driver routine (version 3.2) -- */
  45. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  46. /* November 2006 */
  47. /* .. Scalar Arguments .. */
  48. /* .. */
  49. /* .. Array Arguments .. */
  50. /* .. */
  51. /* Purpose */
  52. /* ======= */
  53. /* DSPSVX uses the diagonal pivoting factorization A = U*D*U**T or */
  54. /* A = L*D*L**T to compute the solution to a real system of linear */
  55. /* equations A * X = B, where A is an N-by-N symmetric matrix stored */
  56. /* in packed format and X and B are N-by-NRHS matrices. */
  57. /* Error bounds on the solution and a condition estimate are also */
  58. /* provided. */
  59. /* Description */
  60. /* =========== */
  61. /* The following steps are performed: */
  62. /* 1. If FACT = 'N', the diagonal pivoting method is used to factor A as */
  63. /* A = U * D * U**T, if UPLO = 'U', or */
  64. /* A = L * D * L**T, if UPLO = 'L', */
  65. /* where U (or L) is a product of permutation and unit upper (lower) */
  66. /* triangular matrices and D is symmetric and block diagonal with */
  67. /* 1-by-1 and 2-by-2 diagonal blocks. */
  68. /* 2. If some D(i,i)=0, so that D is exactly singular, then the routine */
  69. /* returns with INFO = i. Otherwise, the factored form of A is used */
  70. /* to estimate the condition number of the matrix A. If the */
  71. /* reciprocal of the condition number is less than machine precision, */
  72. /* INFO = N+1 is returned as a warning, but the routine still goes on */
  73. /* to solve for X and compute error bounds as described below. */
  74. /* 3. The system of equations is solved for X using the factored form */
  75. /* of A. */
  76. /* 4. Iterative refinement is applied to improve the computed solution */
  77. /* matrix and calculate error bounds and backward error estimates */
  78. /* for it. */
  79. /* Arguments */
  80. /* ========= */
  81. /* FACT (input) CHARACTER*1 */
  82. /* Specifies whether or not the factored form of A has been */
  83. /* supplied on entry. */
  84. /* = 'F': On entry, AFP and IPIV contain the factored form of */
  85. /* A. AP, AFP and IPIV will not be modified. */
  86. /* = 'N': The matrix A will be copied to AFP and factored. */
  87. /* UPLO (input) CHARACTER*1 */
  88. /* = 'U': Upper triangle of A is stored; */
  89. /* = 'L': Lower triangle of A is stored. */
  90. /* N (input) INTEGER */
  91. /* The number of linear equations, i.e., the order of the */
  92. /* matrix A. N >= 0. */
  93. /* NRHS (input) INTEGER */
  94. /* The number of right hand sides, i.e., the number of columns */
  95. /* of the matrices B and X. NRHS >= 0. */
  96. /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  97. /* The upper or lower triangle of the symmetric matrix A, packed */
  98. /* columnwise in a linear array. The j-th column of A is stored */
  99. /* in the array AP as follows: */
  100. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  101. /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
  102. /* See below for further details. */
  103. /* AFP (input or output) DOUBLE PRECISION array, dimension */
  104. /* (N*(N+1)/2) */
  105. /* If FACT = 'F', then AFP is an input argument and on entry */
  106. /* contains the block diagonal matrix D and the multipliers used */
  107. /* to obtain the factor U or L from the factorization */
  108. /* A = U*D*U**T or A = L*D*L**T as computed by DSPTRF, stored as */
  109. /* a packed triangular matrix in the same storage format as A. */
  110. /* If FACT = 'N', then AFP is an output argument and on exit */
  111. /* contains the block diagonal matrix D and the multipliers used */
  112. /* to obtain the factor U or L from the factorization */
  113. /* A = U*D*U**T or A = L*D*L**T as computed by DSPTRF, stored as */
  114. /* a packed triangular matrix in the same storage format as A. */
  115. /* IPIV (input or output) INTEGER array, dimension (N) */
  116. /* If FACT = 'F', then IPIV is an input argument and on entry */
  117. /* contains details of the interchanges and the block structure */
  118. /* of D, as determined by DSPTRF. */
  119. /* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  120. /* interchanged and D(k,k) is a 1-by-1 diagonal block. */
  121. /* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
  122. /* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  123. /* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */
  124. /* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
  125. /* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  126. /* If FACT = 'N', then IPIV is an output argument and on exit */
  127. /* contains details of the interchanges and the block structure */
  128. /* of D, as determined by DSPTRF. */
  129. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  130. /* The N-by-NRHS right hand side matrix B. */
  131. /* LDB (input) INTEGER */
  132. /* The leading dimension of the array B. LDB >= max(1,N). */
  133. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  134. /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */
  135. /* LDX (input) INTEGER */
  136. /* The leading dimension of the array X. LDX >= max(1,N). */
  137. /* RCOND (output) DOUBLE PRECISION */
  138. /* The estimate of the reciprocal condition number of the matrix */
  139. /* A. If RCOND is less than the machine precision (in */
  140. /* particular, if RCOND = 0), the matrix is singular to working */
  141. /* precision. This condition is indicated by a return code of */
  142. /* INFO > 0. */
  143. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  144. /* The estimated forward error bound for each solution vector */
  145. /* X(j) (the j-th column of the solution matrix X). */
  146. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  147. /* is an estimated upper bound for the magnitude of the largest */
  148. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  149. /* largest element in X(j). The estimate is as reliable as */
  150. /* the estimate for RCOND, and is almost always a slight */
  151. /* overestimate of the true error. */
  152. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  153. /* The componentwise relative backward error of each solution */
  154. /* vector X(j) (i.e., the smallest relative change in */
  155. /* any element of A or B that makes X(j) an exact solution). */
  156. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  157. /* IWORK (workspace) INTEGER array, dimension (N) */
  158. /* INFO (output) INTEGER */
  159. /* = 0: successful exit */
  160. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  161. /* > 0: if INFO = i, and i is */
  162. /* <= N: D(i,i) is exactly zero. The factorization */
  163. /* has been completed but the factor D is exactly */
  164. /* singular, so the solution and error bounds could */
  165. /* not be computed. RCOND = 0 is returned. */
  166. /* = N+1: D is nonsingular, but RCOND is less than machine */
  167. /* precision, meaning that the matrix is singular */
  168. /* to working precision. Nevertheless, the */
  169. /* solution and error bounds are computed because */
  170. /* there are a number of situations where the */
  171. /* computed solution can be more accurate than the */
  172. /* value of RCOND would suggest. */
  173. /* Further Details */
  174. /* =============== */
  175. /* The packed storage scheme is illustrated by the following example */
  176. /* when N = 4, UPLO = 'U': */
  177. /* Two-dimensional storage of the symmetric matrix A: */
  178. /* a11 a12 a13 a14 */
  179. /* a22 a23 a24 */
  180. /* a33 a34 (aij = aji) */
  181. /* a44 */
  182. /* Packed storage of the upper triangle of A: */
  183. /* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */
  184. /* ===================================================================== */
  185. /* .. Parameters .. */
  186. /* .. */
  187. /* .. Local Scalars .. */
  188. /* .. */
  189. /* .. External Functions .. */
  190. /* .. */
  191. /* .. External Subroutines .. */
  192. /* .. */
  193. /* .. Intrinsic Functions .. */
  194. /* .. */
  195. /* .. Executable Statements .. */
  196. /* Test the input parameters. */
  197. /* Parameter adjustments */
  198. --ap;
  199. --afp;
  200. --ipiv;
  201. b_dim1 = *ldb;
  202. b_offset = 1 + b_dim1;
  203. b -= b_offset;
  204. x_dim1 = *ldx;
  205. x_offset = 1 + x_dim1;
  206. x -= x_offset;
  207. --ferr;
  208. --berr;
  209. --work;
  210. --iwork;
  211. /* Function Body */
  212. *info = 0;
  213. nofact = _starpu_lsame_(fact, "N");
  214. if (! nofact && ! _starpu_lsame_(fact, "F")) {
  215. *info = -1;
  216. } else if (! _starpu_lsame_(uplo, "U") && ! _starpu_lsame_(uplo,
  217. "L")) {
  218. *info = -2;
  219. } else if (*n < 0) {
  220. *info = -3;
  221. } else if (*nrhs < 0) {
  222. *info = -4;
  223. } else if (*ldb < max(1,*n)) {
  224. *info = -9;
  225. } else if (*ldx < max(1,*n)) {
  226. *info = -11;
  227. }
  228. if (*info != 0) {
  229. i__1 = -(*info);
  230. _starpu_xerbla_("DSPSVX", &i__1);
  231. return 0;
  232. }
  233. if (nofact) {
  234. /* Compute the factorization A = U*D*U' or A = L*D*L'. */
  235. i__1 = *n * (*n + 1) / 2;
  236. _starpu_dcopy_(&i__1, &ap[1], &c__1, &afp[1], &c__1);
  237. _starpu_dsptrf_(uplo, n, &afp[1], &ipiv[1], info);
  238. /* Return if INFO is non-zero. */
  239. if (*info > 0) {
  240. *rcond = 0.;
  241. return 0;
  242. }
  243. }
  244. /* Compute the norm of the matrix A. */
  245. anorm = _starpu_dlansp_("I", uplo, n, &ap[1], &work[1]);
  246. /* Compute the reciprocal of the condition number of A. */
  247. _starpu_dspcon_(uplo, n, &afp[1], &ipiv[1], &anorm, rcond, &work[1], &iwork[1],
  248. info);
  249. /* Compute the solution vectors X. */
  250. _starpu_dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  251. _starpu_dsptrs_(uplo, n, nrhs, &afp[1], &ipiv[1], &x[x_offset], ldx, info);
  252. /* Use iterative refinement to improve the computed solutions and */
  253. /* compute error bounds and backward error estimates for them. */
  254. _starpu_dsprfs_(uplo, n, nrhs, &ap[1], &afp[1], &ipiv[1], &b[b_offset], ldb, &x[
  255. x_offset], ldx, &ferr[1], &berr[1], &work[1], &iwork[1], info);
  256. /* Set INFO = N+1 if the matrix is singular to working precision. */
  257. if (*rcond < _starpu_dlamch_("Epsilon")) {
  258. *info = *n + 1;
  259. }
  260. return 0;
  261. /* End of DSPSVX */
  262. } /* _starpu_dspsvx_ */