dla_syrcond.c 8.5 KB

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