dsyrfs.c 13 KB

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