dtprfs.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /* dtprfs.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_b19 = -1.;
  16. /* Subroutine */ int _starpu_dtprfs_(char *uplo, char *trans, char *diag, integer *n,
  17. integer *nrhs, doublereal *ap, doublereal *b, integer *ldb,
  18. doublereal *x, integer *ldx, doublereal *ferr, doublereal *berr,
  19. doublereal *work, integer *iwork, integer *info)
  20. {
  21. /* System generated locals */
  22. integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3;
  23. doublereal d__1, d__2, d__3;
  24. /* Local variables */
  25. integer i__, j, k;
  26. doublereal s;
  27. integer kc;
  28. doublereal xk;
  29. integer nz;
  30. doublereal eps;
  31. integer kase;
  32. doublereal safe1, safe2;
  33. extern logical _starpu_lsame_(char *, char *);
  34. integer isave[3];
  35. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  36. doublereal *, integer *), _starpu_daxpy_(integer *, doublereal *,
  37. doublereal *, integer *, doublereal *, integer *), _starpu_dtpmv_(char *,
  38. char *, char *, integer *, doublereal *, doublereal *, integer *);
  39. logical upper;
  40. extern /* Subroutine */ int _starpu_dtpsv_(char *, char *, char *, integer *,
  41. doublereal *, doublereal *, integer *),
  42. _starpu_dlacn2_(integer *, doublereal *, doublereal *, integer *,
  43. doublereal *, integer *, integer *);
  44. extern doublereal _starpu_dlamch_(char *);
  45. doublereal safmin;
  46. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  47. logical notran;
  48. char transt[1];
  49. logical nounit;
  50. doublereal lstres;
  51. /* -- LAPACK routine (version 3.2) -- */
  52. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  53. /* November 2006 */
  54. /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
  55. /* .. Scalar Arguments .. */
  56. /* .. */
  57. /* .. Array Arguments .. */
  58. /* .. */
  59. /* Purpose */
  60. /* ======= */
  61. /* DTPRFS provides error bounds and backward error estimates for the */
  62. /* solution to a system of linear equations with a triangular packed */
  63. /* coefficient matrix. */
  64. /* The solution matrix X must be computed by DTPTRS or some other */
  65. /* means before entering this routine. DTPRFS does not do iterative */
  66. /* refinement because doing so cannot improve the backward error. */
  67. /* Arguments */
  68. /* ========= */
  69. /* UPLO (input) CHARACTER*1 */
  70. /* = 'U': A is upper triangular; */
  71. /* = 'L': A is lower triangular. */
  72. /* TRANS (input) CHARACTER*1 */
  73. /* Specifies the form of the system of equations: */
  74. /* = 'N': A * X = B (No transpose) */
  75. /* = 'T': A**T * X = B (Transpose) */
  76. /* = 'C': A**H * X = B (Conjugate transpose = Transpose) */
  77. /* DIAG (input) CHARACTER*1 */
  78. /* = 'N': A is non-unit triangular; */
  79. /* = 'U': A is unit triangular. */
  80. /* N (input) INTEGER */
  81. /* The order of the matrix A. N >= 0. */
  82. /* NRHS (input) INTEGER */
  83. /* The number of right hand sides, i.e., the number of columns */
  84. /* of the matrices B and X. NRHS >= 0. */
  85. /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  86. /* The upper or lower triangular matrix A, packed columnwise in */
  87. /* a linear array. The j-th column of A is stored in the array */
  88. /* AP as follows: */
  89. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  90. /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
  91. /* If DIAG = 'U', the diagonal elements of A are not referenced */
  92. /* and are assumed to be 1. */
  93. /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  94. /* The right hand side matrix B. */
  95. /* LDB (input) INTEGER */
  96. /* The leading dimension of the array B. LDB >= max(1,N). */
  97. /* X (input) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  98. /* The solution matrix X. */
  99. /* LDX (input) INTEGER */
  100. /* The leading dimension of the array X. LDX >= max(1,N). */
  101. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  102. /* The estimated forward error bound for each solution vector */
  103. /* X(j) (the j-th column of the solution matrix X). */
  104. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  105. /* is an estimated upper bound for the magnitude of the largest */
  106. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  107. /* largest element in X(j). The estimate is as reliable as */
  108. /* the estimate for RCOND, and is almost always a slight */
  109. /* overestimate of the true error. */
  110. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  111. /* The componentwise relative backward error of each solution */
  112. /* vector X(j) (i.e., the smallest relative change in */
  113. /* any element of A or B that makes X(j) an exact solution). */
  114. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  115. /* IWORK (workspace) INTEGER array, dimension (N) */
  116. /* INFO (output) INTEGER */
  117. /* = 0: successful exit */
  118. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  119. /* ===================================================================== */
  120. /* .. Parameters .. */
  121. /* .. */
  122. /* .. Local Scalars .. */
  123. /* .. */
  124. /* .. Local Arrays .. */
  125. /* .. */
  126. /* .. External Subroutines .. */
  127. /* .. */
  128. /* .. Intrinsic Functions .. */
  129. /* .. */
  130. /* .. External Functions .. */
  131. /* .. */
  132. /* .. Executable Statements .. */
  133. /* Test the input parameters. */
  134. /* Parameter adjustments */
  135. --ap;
  136. b_dim1 = *ldb;
  137. b_offset = 1 + b_dim1;
  138. b -= b_offset;
  139. x_dim1 = *ldx;
  140. x_offset = 1 + x_dim1;
  141. x -= x_offset;
  142. --ferr;
  143. --berr;
  144. --work;
  145. --iwork;
  146. /* Function Body */
  147. *info = 0;
  148. upper = _starpu_lsame_(uplo, "U");
  149. notran = _starpu_lsame_(trans, "N");
  150. nounit = _starpu_lsame_(diag, "N");
  151. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  152. *info = -1;
  153. } else if (! notran && ! _starpu_lsame_(trans, "T") && !
  154. _starpu_lsame_(trans, "C")) {
  155. *info = -2;
  156. } else if (! nounit && ! _starpu_lsame_(diag, "U")) {
  157. *info = -3;
  158. } else if (*n < 0) {
  159. *info = -4;
  160. } else if (*nrhs < 0) {
  161. *info = -5;
  162. } else if (*ldb < max(1,*n)) {
  163. *info = -8;
  164. } else if (*ldx < max(1,*n)) {
  165. *info = -10;
  166. }
  167. if (*info != 0) {
  168. i__1 = -(*info);
  169. _starpu_xerbla_("DTPRFS", &i__1);
  170. return 0;
  171. }
  172. /* Quick return if possible */
  173. if (*n == 0 || *nrhs == 0) {
  174. i__1 = *nrhs;
  175. for (j = 1; j <= i__1; ++j) {
  176. ferr[j] = 0.;
  177. berr[j] = 0.;
  178. /* L10: */
  179. }
  180. return 0;
  181. }
  182. if (notran) {
  183. *(unsigned char *)transt = 'T';
  184. } else {
  185. *(unsigned char *)transt = 'N';
  186. }
  187. /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
  188. nz = *n + 1;
  189. eps = _starpu_dlamch_("Epsilon");
  190. safmin = _starpu_dlamch_("Safe minimum");
  191. safe1 = nz * safmin;
  192. safe2 = safe1 / eps;
  193. /* Do for each right hand side */
  194. i__1 = *nrhs;
  195. for (j = 1; j <= i__1; ++j) {
  196. /* Compute residual R = B - op(A) * X, */
  197. /* where op(A) = A or A', depending on TRANS. */
  198. _starpu_dcopy_(n, &x[j * x_dim1 + 1], &c__1, &work[*n + 1], &c__1);
  199. _starpu_dtpmv_(uplo, trans, diag, n, &ap[1], &work[*n + 1], &c__1);
  200. _starpu_daxpy_(n, &c_b19, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
  201. /* Compute componentwise relative backward error from formula */
  202. /* max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */
  203. /* where abs(Z) is the componentwise absolute value of the matrix */
  204. /* or vector Z. If the i-th component of the denominator is less */
  205. /* than SAFE2, then SAFE1 is added to the i-th components of the */
  206. /* numerator and denominator before dividing. */
  207. i__2 = *n;
  208. for (i__ = 1; i__ <= i__2; ++i__) {
  209. work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
  210. /* L20: */
  211. }
  212. if (notran) {
  213. /* Compute abs(A)*abs(X) + abs(B). */
  214. if (upper) {
  215. kc = 1;
  216. if (nounit) {
  217. i__2 = *n;
  218. for (k = 1; k <= i__2; ++k) {
  219. xk = (d__1 = x[k + j * x_dim1], abs(d__1));
  220. i__3 = k;
  221. for (i__ = 1; i__ <= i__3; ++i__) {
  222. work[i__] += (d__1 = ap[kc + i__ - 1], abs(d__1))
  223. * xk;
  224. /* L30: */
  225. }
  226. kc += k;
  227. /* L40: */
  228. }
  229. } else {
  230. i__2 = *n;
  231. for (k = 1; k <= i__2; ++k) {
  232. xk = (d__1 = x[k + j * x_dim1], abs(d__1));
  233. i__3 = k - 1;
  234. for (i__ = 1; i__ <= i__3; ++i__) {
  235. work[i__] += (d__1 = ap[kc + i__ - 1], abs(d__1))
  236. * xk;
  237. /* L50: */
  238. }
  239. work[k] += xk;
  240. kc += k;
  241. /* L60: */
  242. }
  243. }
  244. } else {
  245. kc = 1;
  246. if (nounit) {
  247. i__2 = *n;
  248. for (k = 1; k <= i__2; ++k) {
  249. xk = (d__1 = x[k + j * x_dim1], abs(d__1));
  250. i__3 = *n;
  251. for (i__ = k; i__ <= i__3; ++i__) {
  252. work[i__] += (d__1 = ap[kc + i__ - k], abs(d__1))
  253. * xk;
  254. /* L70: */
  255. }
  256. kc = kc + *n - k + 1;
  257. /* L80: */
  258. }
  259. } else {
  260. i__2 = *n;
  261. for (k = 1; k <= i__2; ++k) {
  262. xk = (d__1 = x[k + j * x_dim1], abs(d__1));
  263. i__3 = *n;
  264. for (i__ = k + 1; i__ <= i__3; ++i__) {
  265. work[i__] += (d__1 = ap[kc + i__ - k], abs(d__1))
  266. * xk;
  267. /* L90: */
  268. }
  269. work[k] += xk;
  270. kc = kc + *n - k + 1;
  271. /* L100: */
  272. }
  273. }
  274. }
  275. } else {
  276. /* Compute abs(A')*abs(X) + abs(B). */
  277. if (upper) {
  278. kc = 1;
  279. if (nounit) {
  280. i__2 = *n;
  281. for (k = 1; k <= i__2; ++k) {
  282. s = 0.;
  283. i__3 = k;
  284. for (i__ = 1; i__ <= i__3; ++i__) {
  285. s += (d__1 = ap[kc + i__ - 1], abs(d__1)) * (d__2
  286. = x[i__ + j * x_dim1], abs(d__2));
  287. /* L110: */
  288. }
  289. work[k] += s;
  290. kc += k;
  291. /* L120: */
  292. }
  293. } else {
  294. i__2 = *n;
  295. for (k = 1; k <= i__2; ++k) {
  296. s = (d__1 = x[k + j * x_dim1], abs(d__1));
  297. i__3 = k - 1;
  298. for (i__ = 1; i__ <= i__3; ++i__) {
  299. s += (d__1 = ap[kc + i__ - 1], abs(d__1)) * (d__2
  300. = x[i__ + j * x_dim1], abs(d__2));
  301. /* L130: */
  302. }
  303. work[k] += s;
  304. kc += k;
  305. /* L140: */
  306. }
  307. }
  308. } else {
  309. kc = 1;
  310. if (nounit) {
  311. i__2 = *n;
  312. for (k = 1; k <= i__2; ++k) {
  313. s = 0.;
  314. i__3 = *n;
  315. for (i__ = k; i__ <= i__3; ++i__) {
  316. s += (d__1 = ap[kc + i__ - k], abs(d__1)) * (d__2
  317. = x[i__ + j * x_dim1], abs(d__2));
  318. /* L150: */
  319. }
  320. work[k] += s;
  321. kc = kc + *n - k + 1;
  322. /* L160: */
  323. }
  324. } else {
  325. i__2 = *n;
  326. for (k = 1; k <= i__2; ++k) {
  327. s = (d__1 = x[k + j * x_dim1], abs(d__1));
  328. i__3 = *n;
  329. for (i__ = k + 1; i__ <= i__3; ++i__) {
  330. s += (d__1 = ap[kc + i__ - k], abs(d__1)) * (d__2
  331. = x[i__ + j * x_dim1], abs(d__2));
  332. /* L170: */
  333. }
  334. work[k] += s;
  335. kc = kc + *n - k + 1;
  336. /* L180: */
  337. }
  338. }
  339. }
  340. }
  341. s = 0.;
  342. i__2 = *n;
  343. for (i__ = 1; i__ <= i__2; ++i__) {
  344. if (work[i__] > safe2) {
  345. /* Computing MAX */
  346. d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
  347. i__];
  348. s = max(d__2,d__3);
  349. } else {
  350. /* Computing MAX */
  351. d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
  352. / (work[i__] + safe1);
  353. s = max(d__2,d__3);
  354. }
  355. /* L190: */
  356. }
  357. berr[j] = s;
  358. /* Bound error from formula */
  359. /* norm(X - XTRUE) / norm(X) .le. FERR = */
  360. /* norm( abs(inv(op(A)))* */
  361. /* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
  362. /* where */
  363. /* norm(Z) is the magnitude of the largest component of Z */
  364. /* inv(op(A)) is the inverse of op(A) */
  365. /* abs(Z) is the componentwise absolute value of the matrix or */
  366. /* vector Z */
  367. /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
  368. /* EPS is machine epsilon */
  369. /* The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
  370. /* is incremented by SAFE1 if the i-th component of */
  371. /* abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
  372. /* Use DLACN2 to estimate the infinity-norm of the matrix */
  373. /* inv(op(A)) * diag(W), */
  374. /* where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
  375. i__2 = *n;
  376. for (i__ = 1; i__ <= i__2; ++i__) {
  377. if (work[i__] > safe2) {
  378. work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
  379. work[i__];
  380. } else {
  381. work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
  382. work[i__] + safe1;
  383. }
  384. /* L200: */
  385. }
  386. kase = 0;
  387. L210:
  388. _starpu_dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
  389. kase, isave);
  390. if (kase != 0) {
  391. if (kase == 1) {
  392. /* Multiply by diag(W)*inv(op(A)'). */
  393. _starpu_dtpsv_(uplo, transt, diag, n, &ap[1], &work[*n + 1], &c__1);
  394. i__2 = *n;
  395. for (i__ = 1; i__ <= i__2; ++i__) {
  396. work[*n + i__] = work[i__] * work[*n + i__];
  397. /* L220: */
  398. }
  399. } else {
  400. /* Multiply by inv(op(A))*diag(W). */
  401. i__2 = *n;
  402. for (i__ = 1; i__ <= i__2; ++i__) {
  403. work[*n + i__] = work[i__] * work[*n + i__];
  404. /* L230: */
  405. }
  406. _starpu_dtpsv_(uplo, trans, diag, n, &ap[1], &work[*n + 1], &c__1);
  407. }
  408. goto L210;
  409. }
  410. /* Normalize error. */
  411. lstres = 0.;
  412. i__2 = *n;
  413. for (i__ = 1; i__ <= i__2; ++i__) {
  414. /* Computing MAX */
  415. d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
  416. lstres = max(d__2,d__3);
  417. /* L240: */
  418. }
  419. if (lstres != 0.) {
  420. ferr[j] /= lstres;
  421. }
  422. /* L250: */
  423. }
  424. return 0;
  425. /* End of DTPRFS */
  426. } /* _starpu_dtprfs_ */