dla_gercond.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* _starpu_dla_gercond.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_gercond__(char *trans, 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 trans_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. 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_dgetrs_(char *, integer *, integer *,
  34. doublereal *, integer *, integer *, doublereal *, integer *,
  35. integer *);
  36. logical notrans;
  37. /* -- LAPACK routine (version 3.2.1) -- */
  38. /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
  39. /* -- Jason Riedy of Univ. of California Berkeley. -- */
  40. /* -- April 2009 -- */
  41. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  42. /* -- Univ. of California Berkeley and NAG Ltd. -- */
  43. /* .. */
  44. /* .. Scalar Arguments .. */
  45. /* .. */
  46. /* .. Array Arguments .. */
  47. /* .. */
  48. /* Purpose */
  49. /* ======= */
  50. /* DLA_GERCOND estimates the Skeel condition number of op(A) * op2(C) */
  51. /* where op2 is determined by CMODE as follows */
  52. /* CMODE = 1 op2(C) = C */
  53. /* CMODE = 0 op2(C) = I */
  54. /* CMODE = -1 op2(C) = inv(C) */
  55. /* The Skeel condition number cond(A) = norminf( |inv(A)||A| ) */
  56. /* is computed by computing scaling factors R such that */
  57. /* diag(R)*A*op2(C) is row equilibrated and computing the standard */
  58. /* infinity-norm condition number. */
  59. /* Arguments */
  60. /* ========== */
  61. /* TRANS (input) CHARACTER*1 */
  62. /* Specifies the form of the system of equations: */
  63. /* = 'N': A * X = B (No transpose) */
  64. /* = 'T': A**T * X = B (Transpose) */
  65. /* = 'C': A**H * X = B (Conjugate Transpose = Transpose) */
  66. /* N (input) INTEGER */
  67. /* The number of linear equations, i.e., the order of the */
  68. /* matrix A. N >= 0. */
  69. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  70. /* On entry, the N-by-N matrix A. */
  71. /* LDA (input) INTEGER */
  72. /* The leading dimension of the array A. LDA >= max(1,N). */
  73. /* AF (input) DOUBLE PRECISION array, dimension (LDAF,N) */
  74. /* The factors L and U from the factorization */
  75. /* A = P*L*U as computed by DGETRF. */
  76. /* LDAF (input) INTEGER */
  77. /* The leading dimension of the array AF. LDAF >= max(1,N). */
  78. /* IPIV (input) INTEGER array, dimension (N) */
  79. /* The pivot indices from the factorization A = P*L*U */
  80. /* as computed by DGETRF; row i of the matrix was interchanged */
  81. /* with row IPIV(i). */
  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. notrans = _starpu_lsame_(trans, "N");
  123. if (! notrans && ! _starpu_lsame_(trans, "T") && ! _starpu_lsame_(
  124. trans, "C")) {
  125. *info = -1;
  126. } else if (*n < 0) {
  127. *info = -2;
  128. } else if (*lda < max(1,*n)) {
  129. *info = -4;
  130. } else if (*ldaf < max(1,*n)) {
  131. *info = -6;
  132. }
  133. if (*info != 0) {
  134. i__1 = -(*info);
  135. _starpu_xerbla_("DLA_GERCOND", &i__1);
  136. return ret_val;
  137. }
  138. if (*n == 0) {
  139. ret_val = 1.;
  140. return ret_val;
  141. }
  142. /* Compute the equilibration matrix R such that */
  143. /* inv(R)*A*C has unit 1-norm. */
  144. if (notrans) {
  145. i__1 = *n;
  146. for (i__ = 1; i__ <= i__1; ++i__) {
  147. tmp = 0.;
  148. if (*cmode == 1) {
  149. i__2 = *n;
  150. for (j = 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 = *n;
  155. for (j = 1; j <= i__2; ++j) {
  156. tmp += (d__1 = a[i__ + j * a_dim1], abs(d__1));
  157. }
  158. } else {
  159. i__2 = *n;
  160. for (j = 1; j <= i__2; ++j) {
  161. tmp += (d__1 = a[i__ + j * a_dim1] / c__[j], abs(d__1));
  162. }
  163. }
  164. work[(*n << 1) + i__] = tmp;
  165. }
  166. } else {
  167. i__1 = *n;
  168. for (i__ = 1; i__ <= i__1; ++i__) {
  169. tmp = 0.;
  170. if (*cmode == 1) {
  171. i__2 = *n;
  172. for (j = 1; j <= i__2; ++j) {
  173. tmp += (d__1 = a[j + i__ * a_dim1] * c__[j], abs(d__1));
  174. }
  175. } else if (*cmode == 0) {
  176. i__2 = *n;
  177. for (j = 1; j <= i__2; ++j) {
  178. tmp += (d__1 = a[j + i__ * a_dim1], abs(d__1));
  179. }
  180. } else {
  181. i__2 = *n;
  182. for (j = 1; j <= i__2; ++j) {
  183. tmp += (d__1 = a[j + i__ * a_dim1] / c__[j], abs(d__1));
  184. }
  185. }
  186. work[(*n << 1) + i__] = tmp;
  187. }
  188. }
  189. /* Estimate the norm of inv(op(A)). */
  190. ainvnm = 0.;
  191. kase = 0;
  192. L10:
  193. _starpu_dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
  194. if (kase != 0) {
  195. if (kase == 2) {
  196. /* Multiply by R. */
  197. i__1 = *n;
  198. for (i__ = 1; i__ <= i__1; ++i__) {
  199. work[i__] *= work[(*n << 1) + i__];
  200. }
  201. if (notrans) {
  202. _starpu_dgetrs_("No transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[
  203. 1], &work[1], n, info);
  204. } else {
  205. _starpu_dgetrs_("Transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[1],
  206. &work[1], n, info);
  207. }
  208. /* Multiply by inv(C). */
  209. if (*cmode == 1) {
  210. i__1 = *n;
  211. for (i__ = 1; i__ <= i__1; ++i__) {
  212. work[i__] /= c__[i__];
  213. }
  214. } else if (*cmode == -1) {
  215. i__1 = *n;
  216. for (i__ = 1; i__ <= i__1; ++i__) {
  217. work[i__] *= c__[i__];
  218. }
  219. }
  220. } else {
  221. /* Multiply by inv(C'). */
  222. if (*cmode == 1) {
  223. i__1 = *n;
  224. for (i__ = 1; i__ <= i__1; ++i__) {
  225. work[i__] /= c__[i__];
  226. }
  227. } else if (*cmode == -1) {
  228. i__1 = *n;
  229. for (i__ = 1; i__ <= i__1; ++i__) {
  230. work[i__] *= c__[i__];
  231. }
  232. }
  233. if (notrans) {
  234. _starpu_dgetrs_("Transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[1],
  235. &work[1], n, info);
  236. } else {
  237. _starpu_dgetrs_("No transpose", n, &c__1, &af[af_offset], ldaf, &ipiv[
  238. 1], &work[1], n, info);
  239. }
  240. /* Multiply by R. */
  241. i__1 = *n;
  242. for (i__ = 1; i__ <= i__1; ++i__) {
  243. work[i__] *= work[(*n << 1) + i__];
  244. }
  245. }
  246. goto L10;
  247. }
  248. /* Compute the estimate of the reciprocal condition number. */
  249. if (ainvnm != 0.) {
  250. ret_val = 1. / ainvnm;
  251. }
  252. return ret_val;
  253. } /* _starpu_dla_gercond__ */