dsysvx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /* dsysvx.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. static integer c_n1 = -1;
  16. /* Subroutine */ int _starpu_dsysvx_(char *fact, char *uplo, integer *n, integer *
  17. nrhs, doublereal *a, integer *lda, doublereal *af, integer *ldaf,
  18. integer *ipiv, doublereal *b, integer *ldb, doublereal *x, integer *
  19. ldx, doublereal *rcond, doublereal *ferr, doublereal *berr,
  20. doublereal *work, integer *lwork, integer *iwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
  24. x_offset, i__1, i__2;
  25. /* Local variables */
  26. integer nb;
  27. extern logical _starpu_lsame_(char *, char *);
  28. doublereal anorm;
  29. extern doublereal _starpu_dlamch_(char *);
  30. logical nofact;
  31. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  32. doublereal *, integer *, doublereal *, integer *),
  33. _starpu_xerbla_(char *, integer *);
  34. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  35. integer *, integer *);
  36. extern doublereal _starpu_dlansy_(char *, char *, integer *, doublereal *,
  37. integer *, doublereal *);
  38. extern /* Subroutine */ int _starpu_dsycon_(char *, integer *, doublereal *,
  39. integer *, integer *, doublereal *, doublereal *, doublereal *,
  40. integer *, integer *), _starpu_dsyrfs_(char *, integer *, integer
  41. *, doublereal *, integer *, doublereal *, integer *, integer *,
  42. doublereal *, integer *, doublereal *, integer *, doublereal *,
  43. doublereal *, doublereal *, integer *, integer *),
  44. _starpu_dsytrf_(char *, integer *, doublereal *, integer *, integer *,
  45. doublereal *, integer *, integer *);
  46. integer lwkopt;
  47. logical lquery;
  48. extern /* Subroutine */ int _starpu_dsytrs_(char *, integer *, integer *,
  49. doublereal *, integer *, integer *, doublereal *, integer *,
  50. integer *);
  51. /* -- LAPACK driver routine (version 3.2) -- */
  52. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  53. /* November 2006 */
  54. /* .. Scalar Arguments .. */
  55. /* .. */
  56. /* .. Array Arguments .. */
  57. /* .. */
  58. /* Purpose */
  59. /* ======= */
  60. /* DSYSVX uses the diagonal pivoting factorization to compute the */
  61. /* solution to a real system of linear equations A * X = B, */
  62. /* where A is an N-by-N symmetric matrix and X and B are N-by-NRHS */
  63. /* matrices. */
  64. /* Error bounds on the solution and a condition estimate are also */
  65. /* provided. */
  66. /* Description */
  67. /* =========== */
  68. /* The following steps are performed: */
  69. /* 1. If FACT = 'N', the diagonal pivoting method is used to factor A. */
  70. /* The form of the factorization is */
  71. /* A = U * D * U**T, if UPLO = 'U', or */
  72. /* A = L * D * L**T, if UPLO = 'L', */
  73. /* where U (or L) is a product of permutation and unit upper (lower) */
  74. /* triangular matrices, and D is symmetric and block diagonal with */
  75. /* 1-by-1 and 2-by-2 diagonal blocks. */
  76. /* 2. If some D(i,i)=0, so that D is exactly singular, then the routine */
  77. /* returns with INFO = i. Otherwise, the factored form of A is used */
  78. /* to estimate the condition number of the matrix A. If the */
  79. /* reciprocal of the condition number is less than machine precision, */
  80. /* INFO = N+1 is returned as a warning, but the routine still goes on */
  81. /* to solve for X and compute error bounds as described below. */
  82. /* 3. The system of equations is solved for X using the factored form */
  83. /* of A. */
  84. /* 4. Iterative refinement is applied to improve the computed solution */
  85. /* matrix and calculate error bounds and backward error estimates */
  86. /* for it. */
  87. /* Arguments */
  88. /* ========= */
  89. /* FACT (input) CHARACTER*1 */
  90. /* Specifies whether or not the factored form of A has been */
  91. /* supplied on entry. */
  92. /* = 'F': On entry, AF and IPIV contain the factored form of */
  93. /* A. AF and IPIV will not be modified. */
  94. /* = 'N': The matrix A will be copied to AF and factored. */
  95. /* UPLO (input) CHARACTER*1 */
  96. /* = 'U': Upper triangle of A is stored; */
  97. /* = 'L': Lower triangle of A is stored. */
  98. /* N (input) INTEGER */
  99. /* The number of linear equations, i.e., the order of the */
  100. /* matrix A. N >= 0. */
  101. /* NRHS (input) INTEGER */
  102. /* The number of right hand sides, i.e., the number of columns */
  103. /* of the matrices B and X. NRHS >= 0. */
  104. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  105. /* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */
  106. /* upper triangular part of A contains the upper triangular part */
  107. /* of the matrix A, and the strictly lower triangular part of A */
  108. /* is not referenced. If UPLO = 'L', the leading N-by-N lower */
  109. /* triangular part of A contains the lower triangular part of */
  110. /* the matrix A, and the strictly upper triangular part of A is */
  111. /* not referenced. */
  112. /* LDA (input) INTEGER */
  113. /* The leading dimension of the array A. LDA >= max(1,N). */
  114. /* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N) */
  115. /* If FACT = 'F', then AF is an input argument and on entry */
  116. /* contains the block diagonal matrix D and the multipliers used */
  117. /* to obtain the factor U or L from the factorization */
  118. /* A = U*D*U**T or A = L*D*L**T as computed by DSYTRF. */
  119. /* If FACT = 'N', then AF is an output argument and on exit */
  120. /* returns the block diagonal matrix D and the multipliers used */
  121. /* to obtain the factor U or L from the factorization */
  122. /* A = U*D*U**T or A = L*D*L**T. */
  123. /* LDAF (input) INTEGER */
  124. /* The leading dimension of the array AF. LDAF >= max(1,N). */
  125. /* IPIV (input or output) INTEGER array, dimension (N) */
  126. /* If FACT = 'F', then IPIV is an input argument and on entry */
  127. /* contains details of the interchanges and the block structure */
  128. /* of D, as determined by DSYTRF. */
  129. /* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  130. /* interchanged and D(k,k) is a 1-by-1 diagonal block. */
  131. /* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
  132. /* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  133. /* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */
  134. /* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
  135. /* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  136. /* If FACT = 'N', then IPIV is an output argument and on exit */
  137. /* contains details of the interchanges and the block structure */
  138. /* of D, as determined by DSYTRF. */
  139. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  140. /* The N-by-NRHS right hand side matrix B. */
  141. /* LDB (input) INTEGER */
  142. /* The leading dimension of the array B. LDB >= max(1,N). */
  143. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  144. /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */
  145. /* LDX (input) INTEGER */
  146. /* The leading dimension of the array X. LDX >= max(1,N). */
  147. /* RCOND (output) DOUBLE PRECISION */
  148. /* The estimate of the reciprocal condition number of the matrix */
  149. /* A. If RCOND is less than the machine precision (in */
  150. /* particular, if RCOND = 0), the matrix is singular to working */
  151. /* precision. This condition is indicated by a return code of */
  152. /* INFO > 0. */
  153. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  154. /* The estimated forward error bound for each solution vector */
  155. /* X(j) (the j-th column of the solution matrix X). */
  156. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  157. /* is an estimated upper bound for the magnitude of the largest */
  158. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  159. /* largest element in X(j). The estimate is as reliable as */
  160. /* the estimate for RCOND, and is almost always a slight */
  161. /* overestimate of the true error. */
  162. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  163. /* The componentwise relative backward error of each solution */
  164. /* vector X(j) (i.e., the smallest relative change in */
  165. /* any element of A or B that makes X(j) an exact solution). */
  166. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  167. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  168. /* LWORK (input) INTEGER */
  169. /* The length of WORK. LWORK >= max(1,3*N), and for best */
  170. /* performance, when FACT = 'N', LWORK >= max(1,3*N,N*NB), where */
  171. /* NB is the optimal blocksize for DSYTRF. */
  172. /* If LWORK = -1, then a workspace query is assumed; the routine */
  173. /* only calculates the optimal size of the WORK array, returns */
  174. /* this value as the first entry of the WORK array, and no error */
  175. /* message related to LWORK is issued by XERBLA. */
  176. /* IWORK (workspace) INTEGER array, dimension (N) */
  177. /* INFO (output) INTEGER */
  178. /* = 0: successful exit */
  179. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  180. /* > 0: if INFO = i, and i is */
  181. /* <= N: D(i,i) is exactly zero. The factorization */
  182. /* has been completed but the factor D is exactly */
  183. /* singular, so the solution and error bounds could */
  184. /* not be computed. RCOND = 0 is returned. */
  185. /* = N+1: D is nonsingular, but RCOND is less than machine */
  186. /* precision, meaning that the matrix is singular */
  187. /* to working precision. Nevertheless, the */
  188. /* solution and error bounds are computed because */
  189. /* there are a number of situations where the */
  190. /* computed solution can be more accurate than the */
  191. /* value of RCOND would suggest. */
  192. /* ===================================================================== */
  193. /* .. Parameters .. */
  194. /* .. */
  195. /* .. Local Scalars .. */
  196. /* .. */
  197. /* .. External Functions .. */
  198. /* .. */
  199. /* .. External Subroutines .. */
  200. /* .. */
  201. /* .. Intrinsic Functions .. */
  202. /* .. */
  203. /* .. Executable Statements .. */
  204. /* Test the input parameters. */
  205. /* Parameter adjustments */
  206. a_dim1 = *lda;
  207. a_offset = 1 + a_dim1;
  208. a -= a_offset;
  209. af_dim1 = *ldaf;
  210. af_offset = 1 + af_dim1;
  211. af -= af_offset;
  212. --ipiv;
  213. b_dim1 = *ldb;
  214. b_offset = 1 + b_dim1;
  215. b -= b_offset;
  216. x_dim1 = *ldx;
  217. x_offset = 1 + x_dim1;
  218. x -= x_offset;
  219. --ferr;
  220. --berr;
  221. --work;
  222. --iwork;
  223. /* Function Body */
  224. *info = 0;
  225. nofact = _starpu_lsame_(fact, "N");
  226. lquery = *lwork == -1;
  227. if (! nofact && ! _starpu_lsame_(fact, "F")) {
  228. *info = -1;
  229. } else if (! _starpu_lsame_(uplo, "U") && ! _starpu_lsame_(uplo,
  230. "L")) {
  231. *info = -2;
  232. } else if (*n < 0) {
  233. *info = -3;
  234. } else if (*nrhs < 0) {
  235. *info = -4;
  236. } else if (*lda < max(1,*n)) {
  237. *info = -6;
  238. } else if (*ldaf < max(1,*n)) {
  239. *info = -8;
  240. } else if (*ldb < max(1,*n)) {
  241. *info = -11;
  242. } else if (*ldx < max(1,*n)) {
  243. *info = -13;
  244. } else /* if(complicated condition) */ {
  245. /* Computing MAX */
  246. i__1 = 1, i__2 = *n * 3;
  247. if (*lwork < max(i__1,i__2) && ! lquery) {
  248. *info = -18;
  249. }
  250. }
  251. if (*info == 0) {
  252. /* Computing MAX */
  253. i__1 = 1, i__2 = *n * 3;
  254. lwkopt = max(i__1,i__2);
  255. if (nofact) {
  256. nb = _starpu_ilaenv_(&c__1, "DSYTRF", uplo, n, &c_n1, &c_n1, &c_n1);
  257. /* Computing MAX */
  258. i__1 = lwkopt, i__2 = *n * nb;
  259. lwkopt = max(i__1,i__2);
  260. }
  261. work[1] = (doublereal) lwkopt;
  262. }
  263. if (*info != 0) {
  264. i__1 = -(*info);
  265. _starpu_xerbla_("DSYSVX", &i__1);
  266. return 0;
  267. } else if (lquery) {
  268. return 0;
  269. }
  270. if (nofact) {
  271. /* Compute the factorization A = U*D*U' or A = L*D*L'. */
  272. _starpu_dlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf);
  273. _starpu_dsytrf_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &work[1], lwork,
  274. info);
  275. /* Return if INFO is non-zero. */
  276. if (*info > 0) {
  277. *rcond = 0.;
  278. return 0;
  279. }
  280. }
  281. /* Compute the norm of the matrix A. */
  282. anorm = _starpu_dlansy_("I", uplo, n, &a[a_offset], lda, &work[1]);
  283. /* Compute the reciprocal of the condition number of A. */
  284. _starpu_dsycon_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &anorm, rcond, &work[1],
  285. &iwork[1], info);
  286. /* Compute the solution vectors X. */
  287. _starpu_dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  288. _starpu_dsytrs_(uplo, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &x[x_offset], ldx,
  289. info);
  290. /* Use iterative refinement to improve the computed solutions and */
  291. /* compute error bounds and backward error estimates for them. */
  292. _starpu_dsyrfs_(uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &ipiv[1],
  293. &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1]
  294. , &iwork[1], info);
  295. /* Set INFO = N+1 if the matrix is singular to working precision. */
  296. if (*rcond < _starpu_dlamch_("Epsilon")) {
  297. *info = *n + 1;
  298. }
  299. work[1] = (doublereal) lwkopt;
  300. return 0;
  301. /* End of DSYSVX */
  302. } /* _starpu_dsysvx_ */