dgbequ.c 8.1 KB

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