dsposv.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /* dsposv.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 doublereal c_b10 = -1.;
  15. static doublereal c_b11 = 1.;
  16. static integer c__1 = 1;
  17. /* Subroutine */ int _starpu__starpu_dsposv_(char *uplo, integer *n, integer *nrhs,
  18. doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
  19. x, integer *ldx, doublereal *work, real *swork, integer *iter,
  20. integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, b_dim1, b_offset, work_dim1, work_offset,
  24. x_dim1, x_offset, i__1;
  25. doublereal d__1;
  26. /* Builtin functions */
  27. double sqrt(doublereal);
  28. /* Local variables */
  29. integer i__;
  30. doublereal cte, eps, anrm;
  31. integer ptsa;
  32. doublereal rnrm, xnrm;
  33. integer ptsx;
  34. extern logical _starpu_lsame_(char *, char *);
  35. integer iiter;
  36. extern /* Subroutine */ int _starpu_daxpy_(integer *, doublereal *, doublereal *,
  37. integer *, doublereal *, integer *), _starpu_dsymm_(char *, char *,
  38. integer *, integer *, doublereal *, doublereal *, integer *,
  39. doublereal *, integer *, doublereal *, doublereal *, integer *), _starpu_dlag2s_(integer *, integer *, doublereal *,
  40. integer *, real *, integer *, integer *), _starpu_slag2d_(integer *,
  41. integer *, real *, integer *, doublereal *, integer *, integer *),
  42. _starpu_dlat2s_(char *, integer *, doublereal *, integer *, real *,
  43. integer *, integer *);
  44. extern doublereal _starpu_dlamch_(char *);
  45. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  46. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  47. doublereal *, integer *, doublereal *, integer *),
  48. _starpu_xerbla_(char *, integer *);
  49. extern doublereal _starpu_dlansy_(char *, char *, integer *, doublereal *,
  50. integer *, doublereal *);
  51. extern /* Subroutine */ int _starpu_dpotrf_(char *, integer *, doublereal *,
  52. integer *, integer *), _starpu_dpotrs_(char *, integer *, integer
  53. *, doublereal *, integer *, doublereal *, integer *, integer *), _starpu_spotrf_(char *, integer *, real *, integer *, integer *), _starpu_spotrs_(char *, integer *, integer *, real *, integer *,
  54. real *, integer *, integer *);
  55. /* -- LAPACK PROTOTYPE driver routine (version 3.1.2) -- */
  56. /* Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */
  57. /* May 2007 */
  58. /* .. */
  59. /* .. Scalar Arguments .. */
  60. /* .. */
  61. /* .. Array Arguments .. */
  62. /* .. */
  63. /* Purpose */
  64. /* ======= */
  65. /* DSPOSV computes the solution to a real system of linear equations */
  66. /* A * X = B, */
  67. /* where A is an N-by-N symmetric positive definite matrix and X and B */
  68. /* are N-by-NRHS matrices. */
  69. /* DSPOSV first attempts to factorize the matrix in SINGLE PRECISION */
  70. /* and use this factorization within an iterative refinement procedure */
  71. /* to produce a solution with DOUBLE PRECISION normwise backward error */
  72. /* quality (see below). If the approach fails the method switches to a */
  73. /* DOUBLE PRECISION factorization and solve. */
  74. /* The iterative refinement is not going to be a winning strategy if */
  75. /* the ratio SINGLE PRECISION performance over DOUBLE PRECISION */
  76. /* performance is too small. A reasonable strategy should take the */
  77. /* number of right-hand sides and the size of the matrix into account. */
  78. /* This might be done with a call to ILAENV in the future. Up to now, we */
  79. /* always try iterative refinement. */
  80. /* The iterative refinement process is stopped if */
  81. /* ITER > ITERMAX */
  82. /* or for all the RHS we have: */
  83. /* RNRM < SQRT(N)*XNRM*ANRM*EPS*BWDMAX */
  84. /* where */
  85. /* o ITER is the number of the current iteration in the iterative */
  86. /* refinement process */
  87. /* o RNRM is the infinity-norm of the residual */
  88. /* o XNRM is the infinity-norm of the solution */
  89. /* o ANRM is the infinity-operator-norm of the matrix A */
  90. /* o EPS is the machine epsilon returned by DLAMCH('Epsilon') */
  91. /* The value ITERMAX and BWDMAX are fixed to 30 and 1.0D+00 */
  92. /* respectively. */
  93. /* Arguments */
  94. /* ========= */
  95. /* UPLO (input) CHARACTER */
  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 matrix B. NRHS >= 0. */
  104. /* A (input or input/ouptut) DOUBLE PRECISION array, */
  105. /* dimension (LDA,N) */
  106. /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  107. /* N-by-N upper triangular part of A contains the upper */
  108. /* triangular part of the matrix A, and the strictly lower */
  109. /* triangular part of A is not referenced. If UPLO = 'L', the */
  110. /* leading N-by-N lower triangular part of A contains the lower */
  111. /* triangular part of the matrix A, and the strictly upper */
  112. /* triangular part of A is not referenced. */
  113. /* On exit, if iterative refinement has been successfully used */
  114. /* (INFO.EQ.0 and ITER.GE.0, see description below), then A is */
  115. /* unchanged, if double precision factorization has been used */
  116. /* (INFO.EQ.0 and ITER.LT.0, see description below), then the */
  117. /* array A contains the factor U or L from the Cholesky */
  118. /* factorization A = U**T*U or A = L*L**T. */
  119. /* LDA (input) INTEGER */
  120. /* The leading dimension of the array A. LDA >= max(1,N). */
  121. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  122. /* The N-by-NRHS right hand side matrix B. */
  123. /* LDB (input) INTEGER */
  124. /* The leading dimension of the array B. LDB >= max(1,N). */
  125. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  126. /* If INFO = 0, the N-by-NRHS solution matrix X. */
  127. /* LDX (input) INTEGER */
  128. /* The leading dimension of the array X. LDX >= max(1,N). */
  129. /* WORK (workspace) DOUBLE PRECISION array, dimension (N*NRHS) */
  130. /* This array is used to hold the residual vectors. */
  131. /* SWORK (workspace) REAL array, dimension (N*(N+NRHS)) */
  132. /* This array is used to use the single precision matrix and the */
  133. /* right-hand sides or solutions in single precision. */
  134. /* ITER (output) INTEGER */
  135. /* < 0: iterative refinement has failed, double precision */
  136. /* factorization has been performed */
  137. /* -1 : the routine fell back to full precision for */
  138. /* implementation- or machine-specific reasons */
  139. /* -2 : narrowing the precision induced an overflow, */
  140. /* the routine fell back to full precision */
  141. /* -3 : failure of SPOTRF */
  142. /* -31: stop the iterative refinement after the 30th */
  143. /* iterations */
  144. /* > 0: iterative refinement has been sucessfully used. */
  145. /* Returns the number of iterations */
  146. /* INFO (output) INTEGER */
  147. /* = 0: successful exit */
  148. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  149. /* > 0: if INFO = i, the leading minor of order i of (DOUBLE */
  150. /* PRECISION) A is not positive definite, so the */
  151. /* factorization could not be completed, and the solution */
  152. /* has not been computed. */
  153. /* ========= */
  154. /* .. Parameters .. */
  155. /* .. Local Scalars .. */
  156. /* .. External Subroutines .. */
  157. /* .. */
  158. /* .. External Functions .. */
  159. /* .. */
  160. /* .. Intrinsic Functions .. */
  161. /* .. */
  162. /* .. Executable Statements .. */
  163. /* Parameter adjustments */
  164. work_dim1 = *n;
  165. work_offset = 1 + work_dim1;
  166. work -= work_offset;
  167. a_dim1 = *lda;
  168. a_offset = 1 + a_dim1;
  169. a -= a_offset;
  170. b_dim1 = *ldb;
  171. b_offset = 1 + b_dim1;
  172. b -= b_offset;
  173. x_dim1 = *ldx;
  174. x_offset = 1 + x_dim1;
  175. x -= x_offset;
  176. --swork;
  177. /* Function Body */
  178. *info = 0;
  179. *iter = 0;
  180. /* Test the input parameters. */
  181. if (! _starpu_lsame_(uplo, "U") && ! _starpu_lsame_(uplo, "L")) {
  182. *info = -1;
  183. } else if (*n < 0) {
  184. *info = -2;
  185. } else if (*nrhs < 0) {
  186. *info = -3;
  187. } else if (*lda < max(1,*n)) {
  188. *info = -5;
  189. } else if (*ldb < max(1,*n)) {
  190. *info = -7;
  191. } else if (*ldx < max(1,*n)) {
  192. *info = -9;
  193. }
  194. if (*info != 0) {
  195. i__1 = -(*info);
  196. _starpu_xerbla_("DSPOSV", &i__1);
  197. return 0;
  198. }
  199. /* Quick return if (N.EQ.0). */
  200. if (*n == 0) {
  201. return 0;
  202. }
  203. /* Skip single precision iterative refinement if a priori slower */
  204. /* than double precision factorization. */
  205. if (FALSE_) {
  206. *iter = -1;
  207. goto L40;
  208. }
  209. /* Compute some constants. */
  210. anrm = _starpu_dlansy_("I", uplo, n, &a[a_offset], lda, &work[work_offset]);
  211. eps = _starpu_dlamch_("Epsilon");
  212. cte = anrm * eps * sqrt((doublereal) (*n)) * 1.;
  213. /* Set the indices PTSA, PTSX for referencing SA and SX in SWORK. */
  214. ptsa = 1;
  215. ptsx = ptsa + *n * *n;
  216. /* Convert B from double precision to single precision and store the */
  217. /* result in SX. */
  218. _starpu_dlag2s_(n, nrhs, &b[b_offset], ldb, &swork[ptsx], n, info);
  219. if (*info != 0) {
  220. *iter = -2;
  221. goto L40;
  222. }
  223. /* Convert A from double precision to single precision and store the */
  224. /* result in SA. */
  225. _starpu_dlat2s_(uplo, n, &a[a_offset], lda, &swork[ptsa], n, info);
  226. if (*info != 0) {
  227. *iter = -2;
  228. goto L40;
  229. }
  230. /* Compute the Cholesky factorization of SA. */
  231. _starpu_spotrf_(uplo, n, &swork[ptsa], n, info);
  232. if (*info != 0) {
  233. *iter = -3;
  234. goto L40;
  235. }
  236. /* Solve the system SA*SX = SB. */
  237. _starpu_spotrs_(uplo, n, nrhs, &swork[ptsa], n, &swork[ptsx], n, info);
  238. /* Convert SX back to double precision */
  239. _starpu_slag2d_(n, nrhs, &swork[ptsx], n, &x[x_offset], ldx, info);
  240. /* Compute R = B - AX (R is WORK). */
  241. _starpu_dlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
  242. _starpu_dsymm_("Left", uplo, n, nrhs, &c_b10, &a[a_offset], lda, &x[x_offset],
  243. ldx, &c_b11, &work[work_offset], n);
  244. /* Check whether the NRHS normwise backward errors satisfy the */
  245. /* stopping criterion. If yes, set ITER=0 and return. */
  246. i__1 = *nrhs;
  247. for (i__ = 1; i__ <= i__1; ++i__) {
  248. xnrm = (d__1 = x[_starpu_idamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ *
  249. x_dim1], abs(d__1));
  250. rnrm = (d__1 = work[_starpu_idamax_(n, &work[i__ * work_dim1 + 1], &c__1) +
  251. i__ * work_dim1], abs(d__1));
  252. if (rnrm > xnrm * cte) {
  253. goto L10;
  254. }
  255. }
  256. /* If we are here, the NRHS normwise backward errors satisfy the */
  257. /* stopping criterion. We are good to exit. */
  258. *iter = 0;
  259. return 0;
  260. L10:
  261. for (iiter = 1; iiter <= 30; ++iiter) {
  262. /* Convert R (in WORK) from double precision to single precision */
  263. /* and store the result in SX. */
  264. _starpu_dlag2s_(n, nrhs, &work[work_offset], n, &swork[ptsx], n, info);
  265. if (*info != 0) {
  266. *iter = -2;
  267. goto L40;
  268. }
  269. /* Solve the system SA*SX = SR. */
  270. _starpu_spotrs_(uplo, n, nrhs, &swork[ptsa], n, &swork[ptsx], n, info);
  271. /* Convert SX back to double precision and update the current */
  272. /* iterate. */
  273. _starpu_slag2d_(n, nrhs, &swork[ptsx], n, &work[work_offset], n, info);
  274. i__1 = *nrhs;
  275. for (i__ = 1; i__ <= i__1; ++i__) {
  276. _starpu_daxpy_(n, &c_b11, &work[i__ * work_dim1 + 1], &c__1, &x[i__ *
  277. x_dim1 + 1], &c__1);
  278. }
  279. /* Compute R = B - AX (R is WORK). */
  280. _starpu_dlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n);
  281. _starpu_dsymm_("L", uplo, n, nrhs, &c_b10, &a[a_offset], lda, &x[x_offset],
  282. ldx, &c_b11, &work[work_offset], n);
  283. /* Check whether the NRHS normwise backward errors satisfy the */
  284. /* stopping criterion. If yes, set ITER=IITER>0 and return. */
  285. i__1 = *nrhs;
  286. for (i__ = 1; i__ <= i__1; ++i__) {
  287. xnrm = (d__1 = x[_starpu_idamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ *
  288. x_dim1], abs(d__1));
  289. rnrm = (d__1 = work[_starpu_idamax_(n, &work[i__ * work_dim1 + 1], &c__1)
  290. + i__ * work_dim1], abs(d__1));
  291. if (rnrm > xnrm * cte) {
  292. goto L20;
  293. }
  294. }
  295. /* If we are here, the NRHS normwise backward errors satisfy the */
  296. /* stopping criterion, we are good to exit. */
  297. *iter = iiter;
  298. return 0;
  299. L20:
  300. /* L30: */
  301. ;
  302. }
  303. /* If we are at this place of the code, this is because we have */
  304. /* performed ITER=ITERMAX iterations and never satisified the */
  305. /* stopping criterion, set up the ITER flag accordingly and follow */
  306. /* up on double precision routine. */
  307. *iter = -31;
  308. L40:
  309. /* Single-precision iterative refinement failed to converge to a */
  310. /* satisfactory solution, so we resort to double precision. */
  311. _starpu_dpotrf_(uplo, n, &a[a_offset], lda, info);
  312. if (*info != 0) {
  313. return 0;
  314. }
  315. _starpu_dlacpy_("All", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  316. _starpu_dpotrs_(uplo, n, nrhs, &a[a_offset], lda, &x[x_offset], ldx, info);
  317. return 0;
  318. /* End of DSPOSV. */
  319. } /* _starpu__starpu_dsposv_ */