dgbequb.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* dgbequb.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. /* Subroutine */ int _starpu_dgbequb_(integer *m, integer *n, integer *kl, integer *
  14. ku, doublereal *ab, integer *ldab, doublereal *r__, doublereal *c__,
  15. doublereal *rowcnd, doublereal *colcnd, doublereal *amax, integer *
  16. info)
  17. {
  18. /* System generated locals */
  19. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
  20. doublereal d__1, d__2, d__3;
  21. /* Builtin functions */
  22. double log(doublereal), pow_di(doublereal *, integer *);
  23. /* Local variables */
  24. integer i__, j, kd;
  25. doublereal radix, rcmin, rcmax;
  26. extern doublereal _starpu_dlamch_(char *);
  27. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  28. doublereal bignum, logrdx, smlnum;
  29. /* -- LAPACK routine (version 3.2) -- */
  30. /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
  31. /* -- Jason Riedy of Univ. of California Berkeley. -- */
  32. /* -- November 2008 -- */
  33. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  34. /* -- Univ. of California Berkeley and NAG Ltd. -- */
  35. /* .. */
  36. /* .. Scalar Arguments .. */
  37. /* .. */
  38. /* .. Array Arguments .. */
  39. /* .. */
  40. /* Purpose */
  41. /* ======= */
  42. /* DGBEQUB computes row and column scalings intended to equilibrate an */
  43. /* M-by-N matrix A and reduce its condition number. R returns the row */
  44. /* scale factors and C the column scale factors, chosen to try to make */
  45. /* the largest element in each row and column of the matrix B with */
  46. /* elements B(i,j)=R(i)*A(i,j)*C(j) have an absolute value of at most */
  47. /* the radix. */
  48. /* R(i) and C(j) are restricted to be a power of the radix between */
  49. /* SMLNUM = smallest safe number and BIGNUM = largest safe number. Use */
  50. /* of these scaling factors is not guaranteed to reduce the condition */
  51. /* number of A but works well in practice. */
  52. /* This routine differs from DGEEQU by restricting the scaling factors */
  53. /* to a power of the radix. Baring over- and underflow, scaling by */
  54. /* these factors introduces no additional rounding errors. However, the */
  55. /* scaled entries' magnitured are no longer approximately 1 but lie */
  56. /* between sqrt(radix) and 1/sqrt(radix). */
  57. /* Arguments */
  58. /* ========= */
  59. /* M (input) INTEGER */
  60. /* The number of rows of the matrix A. M >= 0. */
  61. /* N (input) INTEGER */
  62. /* The number of columns of the matrix A. N >= 0. */
  63. /* KL (input) INTEGER */
  64. /* The number of subdiagonals within the band of A. KL >= 0. */
  65. /* KU (input) INTEGER */
  66. /* The number of superdiagonals within the band of A. KU >= 0. */
  67. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  68. /* On entry, the matrix A in band storage, in rows 1 to KL+KU+1. */
  69. /* The j-th column of A is stored in the j-th column of the */
  70. /* array AB as follows: */
  71. /* AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl) */
  72. /* LDAB (input) INTEGER */
  73. /* The leading dimension of the array A. LDAB >= max(1,M). */
  74. /* R (output) DOUBLE PRECISION array, dimension (M) */
  75. /* If INFO = 0 or INFO > M, R contains the row scale factors */
  76. /* for A. */
  77. /* C (output) DOUBLE PRECISION array, dimension (N) */
  78. /* If INFO = 0, C contains the column scale factors for A. */
  79. /* ROWCND (output) DOUBLE PRECISION */
  80. /* If INFO = 0 or INFO > M, ROWCND contains the ratio of the */
  81. /* smallest R(i) to the largest R(i). If ROWCND >= 0.1 and */
  82. /* AMAX is neither too large nor too small, it is not worth */
  83. /* scaling by R. */
  84. /* COLCND (output) DOUBLE PRECISION */
  85. /* If INFO = 0, COLCND contains the ratio of the smallest */
  86. /* C(i) to the largest C(i). If COLCND >= 0.1, it is not */
  87. /* worth scaling by C. */
  88. /* AMAX (output) DOUBLE PRECISION */
  89. /* Absolute value of largest matrix element. If AMAX is very */
  90. /* close to overflow or very close to underflow, the matrix */
  91. /* should be scaled. */
  92. /* INFO (output) INTEGER */
  93. /* = 0: successful exit */
  94. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  95. /* > 0: if INFO = i, and i is */
  96. /* <= M: the i-th row of A is exactly zero */
  97. /* > M: the (i-M)-th column of A is exactly zero */
  98. /* ===================================================================== */
  99. /* .. Parameters .. */
  100. /* .. */
  101. /* .. Local Scalars .. */
  102. /* .. */
  103. /* .. External Functions .. */
  104. /* .. */
  105. /* .. External Subroutines .. */
  106. /* .. */
  107. /* .. Intrinsic Functions .. */
  108. /* .. */
  109. /* .. Executable Statements .. */
  110. /* Test the input parameters. */
  111. /* Parameter adjustments */
  112. ab_dim1 = *ldab;
  113. ab_offset = 1 + ab_dim1;
  114. ab -= ab_offset;
  115. --r__;
  116. --c__;
  117. /* Function Body */
  118. *info = 0;
  119. if (*m < 0) {
  120. *info = -1;
  121. } else if (*n < 0) {
  122. *info = -2;
  123. } else if (*kl < 0) {
  124. *info = -3;
  125. } else if (*ku < 0) {
  126. *info = -4;
  127. } else if (*ldab < *kl + *ku + 1) {
  128. *info = -6;
  129. }
  130. if (*info != 0) {
  131. i__1 = -(*info);
  132. _starpu_xerbla_("DGBEQUB", &i__1);
  133. return 0;
  134. }
  135. /* Quick return if possible. */
  136. if (*m == 0 || *n == 0) {
  137. *rowcnd = 1.;
  138. *colcnd = 1.;
  139. *amax = 0.;
  140. return 0;
  141. }
  142. /* Get machine constants. Assume SMLNUM is a power of the radix. */
  143. smlnum = _starpu_dlamch_("S");
  144. bignum = 1. / smlnum;
  145. radix = _starpu_dlamch_("B");
  146. logrdx = log(radix);
  147. /* Compute row scale factors. */
  148. i__1 = *m;
  149. for (i__ = 1; i__ <= i__1; ++i__) {
  150. r__[i__] = 0.;
  151. /* L10: */
  152. }
  153. /* Find the maximum element in each row. */
  154. kd = *ku + 1;
  155. i__1 = *n;
  156. for (j = 1; j <= i__1; ++j) {
  157. /* Computing MAX */
  158. i__2 = j - *ku;
  159. /* Computing MIN */
  160. i__4 = j + *kl;
  161. i__3 = min(i__4,*m);
  162. for (i__ = max(i__2,1); i__ <= i__3; ++i__) {
  163. /* Computing MAX */
  164. d__2 = r__[i__], d__3 = (d__1 = ab[kd + i__ - j + j * ab_dim1],
  165. abs(d__1));
  166. r__[i__] = max(d__2,d__3);
  167. /* L20: */
  168. }
  169. /* L30: */
  170. }
  171. i__1 = *m;
  172. for (i__ = 1; i__ <= i__1; ++i__) {
  173. if (r__[i__] > 0.) {
  174. i__3 = (integer) (log(r__[i__]) / logrdx);
  175. r__[i__] = pow_di(&radix, &i__3);
  176. }
  177. }
  178. /* Find the maximum and minimum scale factors. */
  179. rcmin = bignum;
  180. rcmax = 0.;
  181. i__1 = *m;
  182. for (i__ = 1; i__ <= i__1; ++i__) {
  183. /* Computing MAX */
  184. d__1 = rcmax, d__2 = r__[i__];
  185. rcmax = max(d__1,d__2);
  186. /* Computing MIN */
  187. d__1 = rcmin, d__2 = r__[i__];
  188. rcmin = min(d__1,d__2);
  189. /* L40: */
  190. }
  191. *amax = rcmax;
  192. if (rcmin == 0.) {
  193. /* Find the first zero scale factor and return an error code. */
  194. i__1 = *m;
  195. for (i__ = 1; i__ <= i__1; ++i__) {
  196. if (r__[i__] == 0.) {
  197. *info = i__;
  198. return 0;
  199. }
  200. /* L50: */
  201. }
  202. } else {
  203. /* Invert the scale factors. */
  204. i__1 = *m;
  205. for (i__ = 1; i__ <= i__1; ++i__) {
  206. /* Computing MIN */
  207. /* Computing MAX */
  208. d__2 = r__[i__];
  209. d__1 = max(d__2,smlnum);
  210. r__[i__] = 1. / min(d__1,bignum);
  211. /* L60: */
  212. }
  213. /* Compute ROWCND = min(R(I)) / max(R(I)). */
  214. *rowcnd = max(rcmin,smlnum) / min(rcmax,bignum);
  215. }
  216. /* Compute column scale factors. */
  217. i__1 = *n;
  218. for (j = 1; j <= i__1; ++j) {
  219. c__[j] = 0.;
  220. /* L70: */
  221. }
  222. /* Find the maximum element in each column, */
  223. /* assuming the row scaling computed above. */
  224. i__1 = *n;
  225. for (j = 1; j <= i__1; ++j) {
  226. /* Computing MAX */
  227. i__3 = j - *ku;
  228. /* Computing MIN */
  229. i__4 = j + *kl;
  230. i__2 = min(i__4,*m);
  231. for (i__ = max(i__3,1); i__ <= i__2; ++i__) {
  232. /* Computing MAX */
  233. d__2 = c__[j], d__3 = (d__1 = ab[kd + i__ - j + j * ab_dim1], abs(
  234. d__1)) * r__[i__];
  235. c__[j] = max(d__2,d__3);
  236. /* L80: */
  237. }
  238. if (c__[j] > 0.) {
  239. i__2 = (integer) (log(c__[j]) / logrdx);
  240. c__[j] = pow_di(&radix, &i__2);
  241. }
  242. /* L90: */
  243. }
  244. /* Find the maximum and minimum scale factors. */
  245. rcmin = bignum;
  246. rcmax = 0.;
  247. i__1 = *n;
  248. for (j = 1; j <= i__1; ++j) {
  249. /* Computing MIN */
  250. d__1 = rcmin, d__2 = c__[j];
  251. rcmin = min(d__1,d__2);
  252. /* Computing MAX */
  253. d__1 = rcmax, d__2 = c__[j];
  254. rcmax = max(d__1,d__2);
  255. /* L100: */
  256. }
  257. if (rcmin == 0.) {
  258. /* Find the first zero scale factor and return an error code. */
  259. i__1 = *n;
  260. for (j = 1; j <= i__1; ++j) {
  261. if (c__[j] == 0.) {
  262. *info = *m + j;
  263. return 0;
  264. }
  265. /* L110: */
  266. }
  267. } else {
  268. /* Invert the scale factors. */
  269. i__1 = *n;
  270. for (j = 1; j <= i__1; ++j) {
  271. /* Computing MIN */
  272. /* Computing MAX */
  273. d__2 = c__[j];
  274. d__1 = max(d__2,smlnum);
  275. c__[j] = 1. / min(d__1,bignum);
  276. /* L120: */
  277. }
  278. /* Compute COLCND = min(C(J)) / max(C(J)). */
  279. *colcnd = max(rcmin,smlnum) / min(rcmax,bignum);
  280. }
  281. return 0;
  282. /* End of DGBEQUB */
  283. } /* _starpu_dgbequb_ */