dla_porcond.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* _starpu_dla_porcond.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. doublereal _starpu_dla_porcond__(char *uplo, integer *n, doublereal *a, integer *lda,
  16. doublereal *af, integer *ldaf, integer *cmode, doublereal *c__,
  17. integer *info, doublereal *work, integer *iwork, ftnlen uplo_len)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, af_dim1, af_offset, i__1, i__2;
  21. doublereal ret_val, d__1;
  22. /* Local variables */
  23. integer i__, j;
  24. logical up;
  25. doublereal tmp;
  26. integer kase;
  27. extern logical _starpu_lsame_(char *, char *);
  28. integer isave[3];
  29. extern /* Subroutine */ int _starpu_dlacn2_(integer *, doublereal *, doublereal *,
  30. integer *, doublereal *, integer *, integer *), _starpu_xerbla_(char *,
  31. integer *);
  32. doublereal ainvnm;
  33. extern /* Subroutine */ int _starpu_dpotrs_(char *, integer *, integer *,
  34. doublereal *, integer *, doublereal *, integer *, integer *);
  35. /* -- LAPACK routine (version 3.2.1) -- */
  36. /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
  37. /* -- Jason Riedy of Univ. of California Berkeley. -- */
  38. /* -- April 2009 -- */
  39. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  40. /* -- Univ. of California Berkeley and NAG Ltd. -- */
  41. /* .. */
  42. /* .. Scalar Arguments .. */
  43. /* .. */
  44. /* .. Array Arguments .. */
  45. /* .. */
  46. /* Purpose */
  47. /* ======= */
  48. /* DLA_PORCOND Estimates the Skeel condition number of op(A) * op2(C) */
  49. /* where op2 is determined by CMODE as follows */
  50. /* CMODE = 1 op2(C) = C */
  51. /* CMODE = 0 op2(C) = I */
  52. /* CMODE = -1 op2(C) = inv(C) */
  53. /* The Skeel condition number cond(A) = norminf( |inv(A)||A| ) */
  54. /* is computed by computing scaling factors R such that */
  55. /* diag(R)*A*op2(C) is row equilibrated and computing the standard */
  56. /* infinity-norm condition number. */
  57. /* Arguments */
  58. /* ========== */
  59. /* UPLO (input) CHARACTER*1 */
  60. /* = 'U': Upper triangle of A is stored; */
  61. /* = 'L': Lower triangle of A is stored. */
  62. /* N (input) INTEGER */
  63. /* The number of linear equations, i.e., the order of the */
  64. /* matrix A. N >= 0. */
  65. /* A (input) REAL array, dimension (LDA,N) */
  66. /* On entry, the N-by-N matrix A. */
  67. /* LDA (input) INTEGER */
  68. /* The leading dimension of the array A. LDA >= max(1,N). */
  69. /* AF (input) DOUBLE PRECISION array, dimension (LDAF,N) */
  70. /* The triangular factor U or L from the Cholesky factorization */
  71. /* A = U**T*U or A = L*L**T, as computed by DPOTRF. */
  72. /* LDAF (input) INTEGER */
  73. /* The leading dimension of the array AF. LDAF >= max(1,N). */
  74. /* CMODE (input) INTEGER */
  75. /* Determines op2(C) in the formula op(A) * op2(C) as follows: */
  76. /* CMODE = 1 op2(C) = C */
  77. /* CMODE = 0 op2(C) = I */
  78. /* CMODE = -1 op2(C) = inv(C) */
  79. /* C (input) DOUBLE PRECISION array, dimension (N) */
  80. /* The vector C in the formula op(A) * op2(C). */
  81. /* INFO (output) INTEGER */
  82. /* = 0: Successful exit. */
  83. /* i > 0: The ith argument is invalid. */
  84. /* WORK (input) DOUBLE PRECISION array, dimension (3*N). */
  85. /* Workspace. */
  86. /* IWORK (input) INTEGER array, dimension (N). */
  87. /* Workspace. */
  88. /* ===================================================================== */
  89. /* .. Local Scalars .. */
  90. /* .. */
  91. /* .. Array Arguments .. */
  92. /* .. */
  93. /* .. External Functions .. */
  94. /* .. */
  95. /* .. External Subroutines .. */
  96. /* .. */
  97. /* .. Intrinsic Functions .. */
  98. /* .. */
  99. /* .. Executable Statements .. */
  100. /* Parameter adjustments */
  101. a_dim1 = *lda;
  102. a_offset = 1 + a_dim1;
  103. a -= a_offset;
  104. af_dim1 = *ldaf;
  105. af_offset = 1 + af_dim1;
  106. af -= af_offset;
  107. --c__;
  108. --work;
  109. --iwork;
  110. /* Function Body */
  111. ret_val = 0.;
  112. *info = 0;
  113. if (*n < 0) {
  114. *info = -2;
  115. }
  116. if (*info != 0) {
  117. i__1 = -(*info);
  118. _starpu_xerbla_("DLA_PORCOND", &i__1);
  119. return ret_val;
  120. }
  121. if (*n == 0) {
  122. ret_val = 1.;
  123. return ret_val;
  124. }
  125. up = FALSE_;
  126. if (_starpu_lsame_(uplo, "U")) {
  127. up = TRUE_;
  128. }
  129. /* Compute the equilibration matrix R such that */
  130. /* inv(R)*A*C has unit 1-norm. */
  131. if (up) {
  132. i__1 = *n;
  133. for (i__ = 1; i__ <= i__1; ++i__) {
  134. tmp = 0.;
  135. if (*cmode == 1) {
  136. i__2 = i__;
  137. for (j = 1; j <= i__2; ++j) {
  138. tmp += (d__1 = a[j + i__ * a_dim1] * c__[j], abs(d__1));
  139. }
  140. i__2 = *n;
  141. for (j = i__ + 1; j <= i__2; ++j) {
  142. tmp += (d__1 = a[i__ + j * a_dim1] * c__[j], abs(d__1));
  143. }
  144. } else if (*cmode == 0) {
  145. i__2 = i__;
  146. for (j = 1; j <= i__2; ++j) {
  147. tmp += (d__1 = a[j + i__ * a_dim1], abs(d__1));
  148. }
  149. i__2 = *n;
  150. for (j = i__ + 1; j <= i__2; ++j) {
  151. tmp += (d__1 = a[i__ + j * a_dim1], abs(d__1));
  152. }
  153. } else {
  154. i__2 = i__;
  155. for (j = 1; j <= i__2; ++j) {
  156. tmp += (d__1 = a[j + i__ * a_dim1] / c__[j], abs(d__1));
  157. }
  158. i__2 = *n;
  159. for (j = i__ + 1; j <= i__2; ++j) {
  160. tmp += (d__1 = a[i__ + j * a_dim1] / c__[j], abs(d__1));
  161. }
  162. }
  163. work[(*n << 1) + i__] = tmp;
  164. }
  165. } else {
  166. i__1 = *n;
  167. for (i__ = 1; i__ <= i__1; ++i__) {
  168. tmp = 0.;
  169. if (*cmode == 1) {
  170. i__2 = i__;
  171. for (j = 1; j <= i__2; ++j) {
  172. tmp += (d__1 = a[i__ + j * a_dim1] * c__[j], abs(d__1));
  173. }
  174. i__2 = *n;
  175. for (j = i__ + 1; j <= i__2; ++j) {
  176. tmp += (d__1 = a[j + i__ * a_dim1] * c__[j], abs(d__1));
  177. }
  178. } else if (*cmode == 0) {
  179. i__2 = i__;
  180. for (j = 1; j <= i__2; ++j) {
  181. tmp += (d__1 = a[i__ + j * a_dim1], abs(d__1));
  182. }
  183. i__2 = *n;
  184. for (j = i__ + 1; j <= i__2; ++j) {
  185. tmp += (d__1 = a[j + i__ * a_dim1], abs(d__1));
  186. }
  187. } else {
  188. i__2 = i__;
  189. for (j = 1; j <= i__2; ++j) {
  190. tmp += (d__1 = a[i__ + j * a_dim1] / c__[j], abs(d__1));
  191. }
  192. i__2 = *n;
  193. for (j = i__ + 1; j <= i__2; ++j) {
  194. tmp += (d__1 = a[j + i__ * a_dim1] / c__[j], abs(d__1));
  195. }
  196. }
  197. work[(*n << 1) + i__] = tmp;
  198. }
  199. }
  200. /* Estimate the norm of inv(op(A)). */
  201. ainvnm = 0.;
  202. kase = 0;
  203. L10:
  204. _starpu_dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
  205. if (kase != 0) {
  206. if (kase == 2) {
  207. /* Multiply by R. */
  208. i__1 = *n;
  209. for (i__ = 1; i__ <= i__1; ++i__) {
  210. work[i__] *= work[(*n << 1) + i__];
  211. }
  212. if (up) {
  213. _starpu_dpotrs_("Upper", n, &c__1, &af[af_offset], ldaf, &work[1], n,
  214. info);
  215. } else {
  216. _starpu_dpotrs_("Lower", n, &c__1, &af[af_offset], ldaf, &work[1], n,
  217. info);
  218. }
  219. /* Multiply by inv(C). */
  220. if (*cmode == 1) {
  221. i__1 = *n;
  222. for (i__ = 1; i__ <= i__1; ++i__) {
  223. work[i__] /= c__[i__];
  224. }
  225. } else if (*cmode == -1) {
  226. i__1 = *n;
  227. for (i__ = 1; i__ <= i__1; ++i__) {
  228. work[i__] *= c__[i__];
  229. }
  230. }
  231. } else {
  232. /* Multiply by inv(C'). */
  233. if (*cmode == 1) {
  234. i__1 = *n;
  235. for (i__ = 1; i__ <= i__1; ++i__) {
  236. work[i__] /= c__[i__];
  237. }
  238. } else if (*cmode == -1) {
  239. i__1 = *n;
  240. for (i__ = 1; i__ <= i__1; ++i__) {
  241. work[i__] *= c__[i__];
  242. }
  243. }
  244. if (up) {
  245. _starpu_dpotrs_("Upper", n, &c__1, &af[af_offset], ldaf, &work[1], n,
  246. info);
  247. } else {
  248. _starpu_dpotrs_("Lower", n, &c__1, &af[af_offset], ldaf, &work[1], n,
  249. info);
  250. }
  251. /* Multiply by R. */
  252. i__1 = *n;
  253. for (i__ = 1; i__ <= i__1; ++i__) {
  254. work[i__] *= work[(*n << 1) + i__];
  255. }
  256. }
  257. goto L10;
  258. }
  259. /* Compute the estimate of the reciprocal condition number. */
  260. if (ainvnm != 0.) {
  261. ret_val = 1. / ainvnm;
  262. }
  263. return ret_val;
  264. } /* _starpu_dla_porcond__ */