dla_gbrcond.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /* _starpu_dla_gbrcond.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_gbrcond__(char *trans, integer *n, integer *kl, integer *ku,
  16. doublereal *ab, integer *ldab, doublereal *afb, integer *ldafb,
  17. integer *ipiv, integer *cmode, doublereal *c__, integer *info,
  18. doublereal *work, integer *iwork, ftnlen trans_len)
  19. {
  20. /* System generated locals */
  21. integer ab_dim1, ab_offset, afb_dim1, afb_offset, i__1, i__2, i__3, i__4;
  22. doublereal ret_val, d__1;
  23. /* Local variables */
  24. integer i__, j, kd, ke;
  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 *), _starpu_dgbtrs_(char *, integer *, integer *, integer
  32. *, integer *, doublereal *, integer *, integer *, doublereal *,
  33. integer *, integer *);
  34. doublereal ainvnm;
  35. logical notrans;
  36. /* -- LAPACK routine (version 3.2.1) -- */
  37. /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
  38. /* -- Jason Riedy of Univ. of California Berkeley. -- */
  39. /* -- April 2009 -- */
  40. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  41. /* -- Univ. of California Berkeley and NAG Ltd. -- */
  42. /* .. */
  43. /* .. Scalar Arguments .. */
  44. /* .. */
  45. /* .. Array Arguments .. */
  46. /* .. */
  47. /* Purpose */
  48. /* ======= */
  49. /* DLA_GERCOND Estimates the Skeel condition number of op(A) * op2(C) */
  50. /* where op2 is determined by CMODE as follows */
  51. /* CMODE = 1 op2(C) = C */
  52. /* CMODE = 0 op2(C) = I */
  53. /* CMODE = -1 op2(C) = inv(C) */
  54. /* The Skeel condition number cond(A) = norminf( |inv(A)||A| ) */
  55. /* is computed by computing scaling factors R such that */
  56. /* diag(R)*A*op2(C) is row equilibrated and computing the standard */
  57. /* infinity-norm condition number. */
  58. /* Arguments */
  59. /* ========= */
  60. /* TRANS (input) CHARACTER*1 */
  61. /* Specifies the form of the system of equations: */
  62. /* = 'N': A * X = B (No transpose) */
  63. /* = 'T': A**T * X = B (Transpose) */
  64. /* = 'C': A**H * X = B (Conjugate Transpose = Transpose) */
  65. /* N (input) INTEGER */
  66. /* The number of linear equations, i.e., the order of the */
  67. /* matrix A. N >= 0. */
  68. /* KL (input) INTEGER */
  69. /* The number of subdiagonals within the band of A. KL >= 0. */
  70. /* KU (input) INTEGER */
  71. /* The number of superdiagonals within the band of A. KU >= 0. */
  72. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  73. /* On entry, the matrix A in band storage, in rows 1 to KL+KU+1. */
  74. /* The j-th column of A is stored in the j-th column of the */
  75. /* array AB as follows: */
  76. /* AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl) */
  77. /* LDAB (input) INTEGER */
  78. /* The leading dimension of the array AB. LDAB >= KL+KU+1. */
  79. /* AFB (input) DOUBLE PRECISION array, dimension (LDAFB,N) */
  80. /* Details of the LU factorization of the band matrix A, as */
  81. /* computed by DGBTRF. U is stored as an upper triangular */
  82. /* band matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, */
  83. /* and the multipliers used during the factorization are stored */
  84. /* in rows KL+KU+2 to 2*KL+KU+1. */
  85. /* LDAFB (input) INTEGER */
  86. /* The leading dimension of the array AFB. LDAFB >= 2*KL+KU+1. */
  87. /* IPIV (input) INTEGER array, dimension (N) */
  88. /* The pivot indices from the factorization A = P*L*U */
  89. /* as computed by DGBTRF; row i of the matrix was interchanged */
  90. /* with row IPIV(i). */
  91. /* CMODE (input) INTEGER */
  92. /* Determines op2(C) in the formula op(A) * op2(C) as follows: */
  93. /* CMODE = 1 op2(C) = C */
  94. /* CMODE = 0 op2(C) = I */
  95. /* CMODE = -1 op2(C) = inv(C) */
  96. /* C (input) DOUBLE PRECISION array, dimension (N) */
  97. /* The vector C in the formula op(A) * op2(C). */
  98. /* INFO (output) INTEGER */
  99. /* = 0: Successful exit. */
  100. /* i > 0: The ith argument is invalid. */
  101. /* WORK (input) DOUBLE PRECISION array, dimension (5*N). */
  102. /* Workspace. */
  103. /* IWORK (input) INTEGER array, dimension (N). */
  104. /* Workspace. */
  105. /* ===================================================================== */
  106. /* .. Local Scalars .. */
  107. /* .. */
  108. /* .. Local Arrays .. */
  109. /* .. */
  110. /* .. External Functions .. */
  111. /* .. */
  112. /* .. External Subroutines .. */
  113. /* .. */
  114. /* .. Intrinsic Functions .. */
  115. /* .. */
  116. /* .. Executable Statements .. */
  117. /* Parameter adjustments */
  118. ab_dim1 = *ldab;
  119. ab_offset = 1 + ab_dim1;
  120. ab -= ab_offset;
  121. afb_dim1 = *ldafb;
  122. afb_offset = 1 + afb_dim1;
  123. afb -= afb_offset;
  124. --ipiv;
  125. --c__;
  126. --work;
  127. --iwork;
  128. /* Function Body */
  129. ret_val = 0.;
  130. *info = 0;
  131. notrans = _starpu_lsame_(trans, "N");
  132. if (! notrans && ! _starpu_lsame_(trans, "T") && ! _starpu_lsame_(
  133. trans, "C")) {
  134. *info = -1;
  135. } else if (*n < 0) {
  136. *info = -2;
  137. } else if (*kl < 0 || *kl > *n - 1) {
  138. *info = -3;
  139. } else if (*ku < 0 || *ku > *n - 1) {
  140. *info = -4;
  141. } else if (*ldab < *kl + *ku + 1) {
  142. *info = -6;
  143. } else if (*ldafb < (*kl << 1) + *ku + 1) {
  144. *info = -8;
  145. }
  146. if (*info != 0) {
  147. i__1 = -(*info);
  148. _starpu_xerbla_("DLA_GBRCOND", &i__1);
  149. return ret_val;
  150. }
  151. if (*n == 0) {
  152. ret_val = 1.;
  153. return ret_val;
  154. }
  155. /* Compute the equilibration matrix R such that */
  156. /* inv(R)*A*C has unit 1-norm. */
  157. kd = *ku + 1;
  158. ke = *kl + 1;
  159. if (notrans) {
  160. i__1 = *n;
  161. for (i__ = 1; i__ <= i__1; ++i__) {
  162. tmp = 0.;
  163. if (*cmode == 1) {
  164. /* Computing MAX */
  165. i__2 = i__ - *kl;
  166. /* Computing MIN */
  167. i__4 = i__ + *ku;
  168. i__3 = min(i__4,*n);
  169. for (j = max(i__2,1); j <= i__3; ++j) {
  170. tmp += (d__1 = ab[kd + i__ - j + j * ab_dim1] * c__[j],
  171. abs(d__1));
  172. }
  173. } else if (*cmode == 0) {
  174. /* Computing MAX */
  175. i__3 = i__ - *kl;
  176. /* Computing MIN */
  177. i__4 = i__ + *ku;
  178. i__2 = min(i__4,*n);
  179. for (j = max(i__3,1); j <= i__2; ++j) {
  180. tmp += (d__1 = ab[kd + i__ - j + j * ab_dim1], abs(d__1));
  181. }
  182. } else {
  183. /* Computing MAX */
  184. i__2 = i__ - *kl;
  185. /* Computing MIN */
  186. i__4 = i__ + *ku;
  187. i__3 = min(i__4,*n);
  188. for (j = max(i__2,1); j <= i__3; ++j) {
  189. tmp += (d__1 = ab[kd + i__ - j + j * ab_dim1] / c__[j],
  190. abs(d__1));
  191. }
  192. }
  193. work[(*n << 1) + i__] = tmp;
  194. }
  195. } else {
  196. i__1 = *n;
  197. for (i__ = 1; i__ <= i__1; ++i__) {
  198. tmp = 0.;
  199. if (*cmode == 1) {
  200. /* Computing MAX */
  201. i__3 = i__ - *kl;
  202. /* Computing MIN */
  203. i__4 = i__ + *ku;
  204. i__2 = min(i__4,*n);
  205. for (j = max(i__3,1); j <= i__2; ++j) {
  206. tmp += (d__1 = ab[ke - i__ + j + i__ * ab_dim1] * c__[j],
  207. abs(d__1));
  208. }
  209. } else if (*cmode == 0) {
  210. /* Computing MAX */
  211. i__2 = i__ - *kl;
  212. /* Computing MIN */
  213. i__4 = i__ + *ku;
  214. i__3 = min(i__4,*n);
  215. for (j = max(i__2,1); j <= i__3; ++j) {
  216. tmp += (d__1 = ab[ke - i__ + j + i__ * ab_dim1], abs(d__1)
  217. );
  218. }
  219. } else {
  220. /* Computing MAX */
  221. i__3 = i__ - *kl;
  222. /* Computing MIN */
  223. i__4 = i__ + *ku;
  224. i__2 = min(i__4,*n);
  225. for (j = max(i__3,1); j <= i__2; ++j) {
  226. tmp += (d__1 = ab[ke - i__ + j + i__ * ab_dim1] / c__[j],
  227. abs(d__1));
  228. }
  229. }
  230. work[(*n << 1) + i__] = tmp;
  231. }
  232. }
  233. /* Estimate the norm of inv(op(A)). */
  234. ainvnm = 0.;
  235. kase = 0;
  236. L10:
  237. _starpu_dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
  238. if (kase != 0) {
  239. if (kase == 2) {
  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. if (notrans) {
  246. _starpu_dgbtrs_("No transpose", n, kl, ku, &c__1, &afb[afb_offset],
  247. ldafb, &ipiv[1], &work[1], n, info);
  248. } else {
  249. _starpu_dgbtrs_("Transpose", n, kl, ku, &c__1, &afb[afb_offset],
  250. ldafb, &ipiv[1], &work[1], n, info);
  251. }
  252. /* Multiply by inv(C). */
  253. if (*cmode == 1) {
  254. i__1 = *n;
  255. for (i__ = 1; i__ <= i__1; ++i__) {
  256. work[i__] /= c__[i__];
  257. }
  258. } else if (*cmode == -1) {
  259. i__1 = *n;
  260. for (i__ = 1; i__ <= i__1; ++i__) {
  261. work[i__] *= c__[i__];
  262. }
  263. }
  264. } else {
  265. /* Multiply by inv(C'). */
  266. if (*cmode == 1) {
  267. i__1 = *n;
  268. for (i__ = 1; i__ <= i__1; ++i__) {
  269. work[i__] /= c__[i__];
  270. }
  271. } else if (*cmode == -1) {
  272. i__1 = *n;
  273. for (i__ = 1; i__ <= i__1; ++i__) {
  274. work[i__] *= c__[i__];
  275. }
  276. }
  277. if (notrans) {
  278. _starpu_dgbtrs_("Transpose", n, kl, ku, &c__1, &afb[afb_offset],
  279. ldafb, &ipiv[1], &work[1], n, info);
  280. } else {
  281. _starpu_dgbtrs_("No transpose", n, kl, ku, &c__1, &afb[afb_offset],
  282. ldafb, &ipiv[1], &work[1], n, info);
  283. }
  284. /* Multiply by R. */
  285. i__1 = *n;
  286. for (i__ = 1; i__ <= i__1; ++i__) {
  287. work[i__] *= work[(*n << 1) + i__];
  288. }
  289. }
  290. goto L10;
  291. }
  292. /* Compute the estimate of the reciprocal condition number. */
  293. if (ainvnm != 0.) {
  294. ret_val = 1. / ainvnm;
  295. }
  296. return ret_val;
  297. } /* _starpu_dla_gbrcond__ */