dposvx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /* dposvx.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_dposvx_(char *fact, char *uplo, integer *n, integer *
  14. nrhs, doublereal *a, integer *lda, doublereal *af, integer *ldaf,
  15. char *equed, doublereal *s, doublereal *b, integer *ldb, doublereal *
  16. x, integer *ldx, doublereal *rcond, doublereal *ferr, doublereal *
  17. berr, doublereal *work, integer *iwork, integer *info)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
  21. x_offset, i__1, i__2;
  22. doublereal d__1, d__2;
  23. /* Local variables */
  24. integer i__, j;
  25. doublereal amax, smin, smax;
  26. extern logical _starpu_lsame_(char *, char *);
  27. doublereal scond, anorm;
  28. logical equil, rcequ;
  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. doublereal bignum;
  35. extern /* Subroutine */ int _starpu_dpocon_(char *, integer *, doublereal *,
  36. integer *, doublereal *, doublereal *, doublereal *, integer *,
  37. integer *);
  38. integer infequ;
  39. extern doublereal _starpu_dlansy_(char *, char *, integer *, doublereal *,
  40. integer *, doublereal *);
  41. extern /* Subroutine */ int _starpu_dlaqsy_(char *, integer *, doublereal *,
  42. integer *, doublereal *, doublereal *, doublereal *, char *), _starpu_dpoequ_(integer *, doublereal *, integer *,
  43. doublereal *, doublereal *, doublereal *, integer *), _starpu_dporfs_(
  44. char *, integer *, integer *, doublereal *, integer *, doublereal
  45. *, integer *, doublereal *, integer *, doublereal *, integer *,
  46. doublereal *, doublereal *, doublereal *, integer *, integer *), _starpu_dpotrf_(char *, integer *, doublereal *, integer *,
  47. integer *);
  48. doublereal smlnum;
  49. extern /* Subroutine */ int _starpu_dpotrs_(char *, integer *, integer *,
  50. doublereal *, integer *, doublereal *, integer *, 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. /* DPOSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */
  61. /* compute the solution to a real system of linear equations */
  62. /* A * X = B, */
  63. /* where A is an N-by-N symmetric positive definite matrix and X and B */
  64. /* are N-by-NRHS matrices. */
  65. /* Error bounds on the solution and a condition estimate are also */
  66. /* provided. */
  67. /* Description */
  68. /* =========== */
  69. /* The following steps are performed: */
  70. /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */
  71. /* the system: */
  72. /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
  73. /* Whether or not the system will be equilibrated depends on the */
  74. /* scaling of the matrix A, but if equilibration is used, A is */
  75. /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
  76. /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
  77. /* factor the matrix A (after equilibration if FACT = 'E') as */
  78. /* A = U**T* U, if UPLO = 'U', or */
  79. /* A = L * L**T, if UPLO = 'L', */
  80. /* where U is an upper triangular matrix and L is a lower triangular */
  81. /* matrix. */
  82. /* 3. If the leading i-by-i principal minor is not positive definite, */
  83. /* then the routine returns with INFO = i. Otherwise, the factored */
  84. /* form of A is used to estimate the condition number of the matrix */
  85. /* A. If the reciprocal of the condition number is less than machine */
  86. /* precision, INFO = N+1 is returned as a warning, but the routine */
  87. /* still goes on to solve for X and compute error bounds as */
  88. /* described below. */
  89. /* 4. The system of equations is solved for X using the factored form */
  90. /* of A. */
  91. /* 5. Iterative refinement is applied to improve the computed solution */
  92. /* matrix and calculate error bounds and backward error estimates */
  93. /* for it. */
  94. /* 6. If equilibration was used, the matrix X is premultiplied by */
  95. /* diag(S) so that it solves the original system before */
  96. /* equilibration. */
  97. /* Arguments */
  98. /* ========= */
  99. /* FACT (input) CHARACTER*1 */
  100. /* Specifies whether or not the factored form of the matrix A is */
  101. /* supplied on entry, and if not, whether the matrix A should be */
  102. /* equilibrated before it is factored. */
  103. /* = 'F': On entry, AF contains the factored form of A. */
  104. /* If EQUED = 'Y', the matrix A has been equilibrated */
  105. /* with scaling factors given by S. A and AF will not */
  106. /* be modified. */
  107. /* = 'N': The matrix A will be copied to AF and factored. */
  108. /* = 'E': The matrix A will be equilibrated if necessary, then */
  109. /* copied to AF and factored. */
  110. /* UPLO (input) CHARACTER*1 */
  111. /* = 'U': Upper triangle of A is stored; */
  112. /* = 'L': Lower triangle of A is stored. */
  113. /* N (input) INTEGER */
  114. /* The number of linear equations, i.e., the order of the */
  115. /* matrix A. N >= 0. */
  116. /* NRHS (input) INTEGER */
  117. /* The number of right hand sides, i.e., the number of columns */
  118. /* of the matrices B and X. NRHS >= 0. */
  119. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  120. /* On entry, the symmetric matrix A, except if FACT = 'F' and */
  121. /* EQUED = 'Y', then A must contain the equilibrated matrix */
  122. /* diag(S)*A*diag(S). If UPLO = 'U', the leading */
  123. /* N-by-N upper triangular part of A contains the upper */
  124. /* triangular part of the matrix A, and the strictly lower */
  125. /* triangular part of A is not referenced. If UPLO = 'L', the */
  126. /* leading N-by-N lower triangular part of A contains the lower */
  127. /* triangular part of the matrix A, and the strictly upper */
  128. /* triangular part of A is not referenced. A is not modified if */
  129. /* FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit. */
  130. /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
  131. /* diag(S)*A*diag(S). */
  132. /* LDA (input) INTEGER */
  133. /* The leading dimension of the array A. LDA >= max(1,N). */
  134. /* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N) */
  135. /* If FACT = 'F', then AF is an input argument and on entry */
  136. /* contains the triangular factor U or L from the Cholesky */
  137. /* factorization A = U**T*U or A = L*L**T, in the same storage */
  138. /* format as A. If EQUED .ne. 'N', then AF is the factored form */
  139. /* of the equilibrated matrix diag(S)*A*diag(S). */
  140. /* If FACT = 'N', then AF is an output argument and on exit */
  141. /* returns the triangular factor U or L from the Cholesky */
  142. /* factorization A = U**T*U or A = L*L**T of the original */
  143. /* matrix A. */
  144. /* If FACT = 'E', then AF is an output argument and on exit */
  145. /* returns the triangular factor U or L from the Cholesky */
  146. /* factorization A = U**T*U or A = L*L**T of the equilibrated */
  147. /* matrix A (see the description of A for the form of the */
  148. /* equilibrated matrix). */
  149. /* LDAF (input) INTEGER */
  150. /* The leading dimension of the array AF. LDAF >= max(1,N). */
  151. /* EQUED (input or output) CHARACTER*1 */
  152. /* Specifies the form of equilibration that was done. */
  153. /* = 'N': No equilibration (always true if FACT = 'N'). */
  154. /* = 'Y': Equilibration was done, i.e., A has been replaced by */
  155. /* diag(S) * A * diag(S). */
  156. /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */
  157. /* output argument. */
  158. /* S (input or output) DOUBLE PRECISION array, dimension (N) */
  159. /* The scale factors for A; not accessed if EQUED = 'N'. S is */
  160. /* an input argument if FACT = 'F'; otherwise, S is an output */
  161. /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */
  162. /* must be positive. */
  163. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  164. /* On entry, the N-by-NRHS right hand side matrix B. */
  165. /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
  166. /* B is overwritten by diag(S) * B. */
  167. /* LDB (input) INTEGER */
  168. /* The leading dimension of the array B. LDB >= max(1,N). */
  169. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  170. /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
  171. /* the original system of equations. Note that if EQUED = 'Y', */
  172. /* A and B are modified on exit, and the solution to the */
  173. /* equilibrated system is inv(diag(S))*X. */
  174. /* LDX (input) INTEGER */
  175. /* The leading dimension of the array X. LDX >= max(1,N). */
  176. /* RCOND (output) DOUBLE PRECISION */
  177. /* The estimate of the reciprocal condition number of the matrix */
  178. /* A after equilibration (if done). If RCOND is less than the */
  179. /* machine precision (in particular, if RCOND = 0), the matrix */
  180. /* is singular to working precision. This condition is */
  181. /* indicated by a return code of INFO > 0. */
  182. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  183. /* The estimated forward error bound for each solution vector */
  184. /* X(j) (the j-th column of the solution matrix X). */
  185. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  186. /* is an estimated upper bound for the magnitude of the largest */
  187. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  188. /* largest element in X(j). The estimate is as reliable as */
  189. /* the estimate for RCOND, and is almost always a slight */
  190. /* overestimate of the true error. */
  191. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  192. /* The componentwise relative backward error of each solution */
  193. /* vector X(j) (i.e., the smallest relative change in */
  194. /* any element of A or B that makes X(j) an exact solution). */
  195. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  196. /* IWORK (workspace) INTEGER array, dimension (N) */
  197. /* INFO (output) INTEGER */
  198. /* = 0: successful exit */
  199. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  200. /* > 0: if INFO = i, and i is */
  201. /* <= N: the leading minor of order i of A is */
  202. /* not positive definite, so the factorization */
  203. /* could not be completed, and the solution has not */
  204. /* been computed. RCOND = 0 is returned. */
  205. /* = N+1: U is nonsingular, but RCOND is less than machine */
  206. /* precision, meaning that the matrix is singular */
  207. /* to working precision. Nevertheless, the */
  208. /* solution and error bounds are computed because */
  209. /* there are a number of situations where the */
  210. /* computed solution can be more accurate than the */
  211. /* value of RCOND would suggest. */
  212. /* ===================================================================== */
  213. /* .. Parameters .. */
  214. /* .. */
  215. /* .. Local Scalars .. */
  216. /* .. */
  217. /* .. External Functions .. */
  218. /* .. */
  219. /* .. External Subroutines .. */
  220. /* .. */
  221. /* .. Intrinsic Functions .. */
  222. /* .. */
  223. /* .. Executable Statements .. */
  224. /* Parameter adjustments */
  225. a_dim1 = *lda;
  226. a_offset = 1 + a_dim1;
  227. a -= a_offset;
  228. af_dim1 = *ldaf;
  229. af_offset = 1 + af_dim1;
  230. af -= af_offset;
  231. --s;
  232. b_dim1 = *ldb;
  233. b_offset = 1 + b_dim1;
  234. b -= b_offset;
  235. x_dim1 = *ldx;
  236. x_offset = 1 + x_dim1;
  237. x -= x_offset;
  238. --ferr;
  239. --berr;
  240. --work;
  241. --iwork;
  242. /* Function Body */
  243. *info = 0;
  244. nofact = _starpu_lsame_(fact, "N");
  245. equil = _starpu_lsame_(fact, "E");
  246. if (nofact || equil) {
  247. *(unsigned char *)equed = 'N';
  248. rcequ = FALSE_;
  249. } else {
  250. rcequ = _starpu_lsame_(equed, "Y");
  251. smlnum = _starpu_dlamch_("Safe minimum");
  252. bignum = 1. / smlnum;
  253. }
  254. /* Test the input parameters. */
  255. if (! nofact && ! equil && ! _starpu_lsame_(fact, "F")) {
  256. *info = -1;
  257. } else if (! _starpu_lsame_(uplo, "U") && ! _starpu_lsame_(uplo,
  258. "L")) {
  259. *info = -2;
  260. } else if (*n < 0) {
  261. *info = -3;
  262. } else if (*nrhs < 0) {
  263. *info = -4;
  264. } else if (*lda < max(1,*n)) {
  265. *info = -6;
  266. } else if (*ldaf < max(1,*n)) {
  267. *info = -8;
  268. } else if (_starpu_lsame_(fact, "F") && ! (rcequ || _starpu_lsame_(
  269. equed, "N"))) {
  270. *info = -9;
  271. } else {
  272. if (rcequ) {
  273. smin = bignum;
  274. smax = 0.;
  275. i__1 = *n;
  276. for (j = 1; j <= i__1; ++j) {
  277. /* Computing MIN */
  278. d__1 = smin, d__2 = s[j];
  279. smin = min(d__1,d__2);
  280. /* Computing MAX */
  281. d__1 = smax, d__2 = s[j];
  282. smax = max(d__1,d__2);
  283. /* L10: */
  284. }
  285. if (smin <= 0.) {
  286. *info = -10;
  287. } else if (*n > 0) {
  288. scond = max(smin,smlnum) / min(smax,bignum);
  289. } else {
  290. scond = 1.;
  291. }
  292. }
  293. if (*info == 0) {
  294. if (*ldb < max(1,*n)) {
  295. *info = -12;
  296. } else if (*ldx < max(1,*n)) {
  297. *info = -14;
  298. }
  299. }
  300. }
  301. if (*info != 0) {
  302. i__1 = -(*info);
  303. _starpu_xerbla_("DPOSVX", &i__1);
  304. return 0;
  305. }
  306. if (equil) {
  307. /* Compute row and column scalings to equilibrate the matrix A. */
  308. _starpu_dpoequ_(n, &a[a_offset], lda, &s[1], &scond, &amax, &infequ);
  309. if (infequ == 0) {
  310. /* Equilibrate the matrix. */
  311. _starpu_dlaqsy_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, equed);
  312. rcequ = _starpu_lsame_(equed, "Y");
  313. }
  314. }
  315. /* Scale the right hand side. */
  316. if (rcequ) {
  317. i__1 = *nrhs;
  318. for (j = 1; j <= i__1; ++j) {
  319. i__2 = *n;
  320. for (i__ = 1; i__ <= i__2; ++i__) {
  321. b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1];
  322. /* L20: */
  323. }
  324. /* L30: */
  325. }
  326. }
  327. if (nofact || equil) {
  328. /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
  329. _starpu_dlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf);
  330. _starpu_dpotrf_(uplo, n, &af[af_offset], ldaf, info);
  331. /* Return if INFO is non-zero. */
  332. if (*info > 0) {
  333. *rcond = 0.;
  334. return 0;
  335. }
  336. }
  337. /* Compute the norm of the matrix A. */
  338. anorm = _starpu_dlansy_("1", uplo, n, &a[a_offset], lda, &work[1]);
  339. /* Compute the reciprocal of the condition number of A. */
  340. _starpu_dpocon_(uplo, n, &af[af_offset], ldaf, &anorm, rcond, &work[1], &iwork[1],
  341. info);
  342. /* Compute the solution matrix X. */
  343. _starpu_dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  344. _starpu_dpotrs_(uplo, n, nrhs, &af[af_offset], ldaf, &x[x_offset], ldx, info);
  345. /* Use iterative refinement to improve the computed solution and */
  346. /* compute error bounds and backward error estimates for it. */
  347. _starpu_dporfs_(uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &b[
  348. b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1], &
  349. iwork[1], info);
  350. /* Transform the solution matrix X to a solution of the original */
  351. /* system. */
  352. if (rcequ) {
  353. i__1 = *nrhs;
  354. for (j = 1; j <= i__1; ++j) {
  355. i__2 = *n;
  356. for (i__ = 1; i__ <= i__2; ++i__) {
  357. x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1];
  358. /* L40: */
  359. }
  360. /* L50: */
  361. }
  362. i__1 = *nrhs;
  363. for (j = 1; j <= i__1; ++j) {
  364. ferr[j] /= scond;
  365. /* L60: */
  366. }
  367. }
  368. /* Set INFO = N+1 if the matrix is singular to working precision. */
  369. if (*rcond < _starpu_dlamch_("Epsilon")) {
  370. *info = *n + 1;
  371. }
  372. return 0;
  373. /* End of DPOSVX */
  374. } /* _starpu_dposvx_ */