dpprfs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /* dpprfs.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 doublereal c_b12 = -1.;
  16. static doublereal c_b14 = 1.;
  17. /* Subroutine */ int _starpu_dpprfs_(char *uplo, integer *n, integer *nrhs,
  18. doublereal *ap, doublereal *afp, doublereal *b, integer *ldb,
  19. doublereal *x, integer *ldx, doublereal *ferr, doublereal *berr,
  20. doublereal *work, integer *iwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3;
  24. doublereal d__1, d__2, d__3;
  25. /* Local variables */
  26. integer i__, j, k;
  27. doublereal s;
  28. integer ik, kk;
  29. doublereal xk;
  30. integer nz;
  31. doublereal eps;
  32. integer kase;
  33. doublereal safe1, safe2;
  34. extern logical _starpu_lsame_(char *, char *);
  35. integer isave[3];
  36. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  37. doublereal *, integer *), _starpu_daxpy_(integer *, doublereal *,
  38. doublereal *, integer *, doublereal *, integer *);
  39. integer count;
  40. extern /* Subroutine */ int _starpu_dspmv_(char *, integer *, doublereal *,
  41. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  42. integer *);
  43. logical upper;
  44. extern /* Subroutine */ int _starpu_dlacn2_(integer *, doublereal *, doublereal *,
  45. integer *, doublereal *, integer *, integer *);
  46. extern doublereal _starpu_dlamch_(char *);
  47. doublereal safmin;
  48. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  49. doublereal lstres;
  50. extern /* Subroutine */ int _starpu_dpptrs_(char *, integer *, integer *,
  51. doublereal *, doublereal *, integer *, integer *);
  52. /* -- LAPACK routine (version 3.2) -- */
  53. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  54. /* November 2006 */
  55. /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
  56. /* .. Scalar Arguments .. */
  57. /* .. */
  58. /* .. Array Arguments .. */
  59. /* .. */
  60. /* Purpose */
  61. /* ======= */
  62. /* DPPRFS improves the computed solution to a system of linear */
  63. /* equations when the coefficient matrix is symmetric positive definite */
  64. /* and packed, and provides error bounds and backward error estimates */
  65. /* for the solution. */
  66. /* Arguments */
  67. /* ========= */
  68. /* UPLO (input) CHARACTER*1 */
  69. /* = 'U': Upper triangle of A is stored; */
  70. /* = 'L': Lower triangle of A is stored. */
  71. /* N (input) INTEGER */
  72. /* The order of the matrix A. N >= 0. */
  73. /* NRHS (input) INTEGER */
  74. /* The number of right hand sides, i.e., the number of columns */
  75. /* of the matrices B and X. NRHS >= 0. */
  76. /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  77. /* The upper or lower triangle of the symmetric matrix A, packed */
  78. /* columnwise in a linear array. The j-th column of A is stored */
  79. /* in the array AP as follows: */
  80. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  81. /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
  82. /* AFP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  83. /* The triangular factor U or L from the Cholesky factorization */
  84. /* A = U**T*U or A = L*L**T, as computed by DPPTRF/ZPPTRF, */
  85. /* packed columnwise in a linear array in the same format as A */
  86. /* (see AP). */
  87. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  88. /* The right hand side matrix B. */
  89. /* LDB (input) INTEGER */
  90. /* The leading dimension of the array B. LDB >= max(1,N). */
  91. /* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  92. /* On entry, the solution matrix X, as computed by DPPTRS. */
  93. /* On exit, the improved solution matrix X. */
  94. /* LDX (input) INTEGER */
  95. /* The leading dimension of the array X. LDX >= max(1,N). */
  96. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  97. /* The estimated forward error bound for each solution vector */
  98. /* X(j) (the j-th column of the solution matrix X). */
  99. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  100. /* is an estimated upper bound for the magnitude of the largest */
  101. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  102. /* largest element in X(j). The estimate is as reliable as */
  103. /* the estimate for RCOND, and is almost always a slight */
  104. /* overestimate of the true error. */
  105. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  106. /* The componentwise relative backward error of each solution */
  107. /* vector X(j) (i.e., the smallest relative change in */
  108. /* any element of A or B that makes X(j) an exact solution). */
  109. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  110. /* IWORK (workspace) INTEGER array, dimension (N) */
  111. /* INFO (output) INTEGER */
  112. /* = 0: successful exit */
  113. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  114. /* Internal Parameters */
  115. /* =================== */
  116. /* ITMAX is the maximum number of steps of iterative refinement. */
  117. /* ===================================================================== */
  118. /* .. Parameters .. */
  119. /* .. */
  120. /* .. Local Scalars .. */
  121. /* .. */
  122. /* .. Local Arrays .. */
  123. /* .. */
  124. /* .. External Subroutines .. */
  125. /* .. */
  126. /* .. Intrinsic Functions .. */
  127. /* .. */
  128. /* .. External Functions .. */
  129. /* .. */
  130. /* .. Executable Statements .. */
  131. /* Test the input parameters. */
  132. /* Parameter adjustments */
  133. --ap;
  134. --afp;
  135. b_dim1 = *ldb;
  136. b_offset = 1 + b_dim1;
  137. b -= b_offset;
  138. x_dim1 = *ldx;
  139. x_offset = 1 + x_dim1;
  140. x -= x_offset;
  141. --ferr;
  142. --berr;
  143. --work;
  144. --iwork;
  145. /* Function Body */
  146. *info = 0;
  147. upper = _starpu_lsame_(uplo, "U");
  148. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  149. *info = -1;
  150. } else if (*n < 0) {
  151. *info = -2;
  152. } else if (*nrhs < 0) {
  153. *info = -3;
  154. } else if (*ldb < max(1,*n)) {
  155. *info = -7;
  156. } else if (*ldx < max(1,*n)) {
  157. *info = -9;
  158. }
  159. if (*info != 0) {
  160. i__1 = -(*info);
  161. _starpu_xerbla_("DPPRFS", &i__1);
  162. return 0;
  163. }
  164. /* Quick return if possible */
  165. if (*n == 0 || *nrhs == 0) {
  166. i__1 = *nrhs;
  167. for (j = 1; j <= i__1; ++j) {
  168. ferr[j] = 0.;
  169. berr[j] = 0.;
  170. /* L10: */
  171. }
  172. return 0;
  173. }
  174. /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
  175. nz = *n + 1;
  176. eps = _starpu_dlamch_("Epsilon");
  177. safmin = _starpu_dlamch_("Safe minimum");
  178. safe1 = nz * safmin;
  179. safe2 = safe1 / eps;
  180. /* Do for each right hand side */
  181. i__1 = *nrhs;
  182. for (j = 1; j <= i__1; ++j) {
  183. count = 1;
  184. lstres = 3.;
  185. L20:
  186. /* Loop until stopping criterion is satisfied. */
  187. /* Compute residual R = B - A * X */
  188. _starpu_dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
  189. _starpu_dspmv_(uplo, n, &c_b12, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b14, &
  190. work[*n + 1], &c__1);
  191. /* Compute componentwise relative backward error from formula */
  192. /* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
  193. /* where abs(Z) is the componentwise absolute value of the matrix */
  194. /* or vector Z. If the i-th component of the denominator is less */
  195. /* than SAFE2, then SAFE1 is added to the i-th components of the */
  196. /* numerator and denominator before dividing. */
  197. i__2 = *n;
  198. for (i__ = 1; i__ <= i__2; ++i__) {
  199. work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
  200. /* L30: */
  201. }
  202. /* Compute abs(A)*abs(X) + abs(B). */
  203. kk = 1;
  204. if (upper) {
  205. i__2 = *n;
  206. for (k = 1; k <= i__2; ++k) {
  207. s = 0.;
  208. xk = (d__1 = x[k + j * x_dim1], abs(d__1));
  209. ik = kk;
  210. i__3 = k - 1;
  211. for (i__ = 1; i__ <= i__3; ++i__) {
  212. work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
  213. s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j *
  214. x_dim1], abs(d__2));
  215. ++ik;
  216. /* L40: */
  217. }
  218. work[k] = work[k] + (d__1 = ap[kk + k - 1], abs(d__1)) * xk +
  219. s;
  220. kk += k;
  221. /* L50: */
  222. }
  223. } else {
  224. i__2 = *n;
  225. for (k = 1; k <= i__2; ++k) {
  226. s = 0.;
  227. xk = (d__1 = x[k + j * x_dim1], abs(d__1));
  228. work[k] += (d__1 = ap[kk], abs(d__1)) * xk;
  229. ik = kk + 1;
  230. i__3 = *n;
  231. for (i__ = k + 1; i__ <= i__3; ++i__) {
  232. work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
  233. s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j *
  234. x_dim1], abs(d__2));
  235. ++ik;
  236. /* L60: */
  237. }
  238. work[k] += s;
  239. kk += *n - k + 1;
  240. /* L70: */
  241. }
  242. }
  243. s = 0.;
  244. i__2 = *n;
  245. for (i__ = 1; i__ <= i__2; ++i__) {
  246. if (work[i__] > safe2) {
  247. /* Computing MAX */
  248. d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
  249. i__];
  250. s = max(d__2,d__3);
  251. } else {
  252. /* Computing MAX */
  253. d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
  254. / (work[i__] + safe1);
  255. s = max(d__2,d__3);
  256. }
  257. /* L80: */
  258. }
  259. berr[j] = s;
  260. /* Test stopping criterion. Continue iterating if */
  261. /* 1) The residual BERR(J) is larger than machine epsilon, and */
  262. /* 2) BERR(J) decreased by at least a factor of 2 during the */
  263. /* last iteration, and */
  264. /* 3) At most ITMAX iterations tried. */
  265. if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
  266. /* Update solution and try again. */
  267. _starpu_dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
  268. _starpu_daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
  269. ;
  270. lstres = berr[j];
  271. ++count;
  272. goto L20;
  273. }
  274. /* Bound error from formula */
  275. /* norm(X - XTRUE) / norm(X) .le. FERR = */
  276. /* norm( abs(inv(A))* */
  277. /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
  278. /* where */
  279. /* norm(Z) is the magnitude of the largest component of Z */
  280. /* inv(A) is the inverse of A */
  281. /* abs(Z) is the componentwise absolute value of the matrix or */
  282. /* vector Z */
  283. /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
  284. /* EPS is machine epsilon */
  285. /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
  286. /* is incremented by SAFE1 if the i-th component of */
  287. /* abs(A)*abs(X) + abs(B) is less than SAFE2. */
  288. /* Use DLACN2 to estimate the infinity-norm of the matrix */
  289. /* inv(A) * diag(W), */
  290. /* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
  291. i__2 = *n;
  292. for (i__ = 1; i__ <= i__2; ++i__) {
  293. if (work[i__] > safe2) {
  294. work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
  295. work[i__];
  296. } else {
  297. work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
  298. work[i__] + safe1;
  299. }
  300. /* L90: */
  301. }
  302. kase = 0;
  303. L100:
  304. _starpu_dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
  305. kase, isave);
  306. if (kase != 0) {
  307. if (kase == 1) {
  308. /* Multiply by diag(W)*inv(A'). */
  309. _starpu_dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
  310. i__2 = *n;
  311. for (i__ = 1; i__ <= i__2; ++i__) {
  312. work[*n + i__] = work[i__] * work[*n + i__];
  313. /* L110: */
  314. }
  315. } else if (kase == 2) {
  316. /* Multiply by inv(A)*diag(W). */
  317. i__2 = *n;
  318. for (i__ = 1; i__ <= i__2; ++i__) {
  319. work[*n + i__] = work[i__] * work[*n + i__];
  320. /* L120: */
  321. }
  322. _starpu_dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
  323. }
  324. goto L100;
  325. }
  326. /* Normalize error. */
  327. lstres = 0.;
  328. i__2 = *n;
  329. for (i__ = 1; i__ <= i__2; ++i__) {
  330. /* Computing MAX */
  331. d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
  332. lstres = max(d__2,d__3);
  333. /* L130: */
  334. }
  335. if (lstres != 0.) {
  336. ferr[j] /= lstres;
  337. }
  338. /* L140: */
  339. }
  340. return 0;
  341. /* End of DPPRFS */
  342. } /* _starpu_dpprfs_ */