dpoequb.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* dpoequb.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_dpoequb_(integer *n, doublereal *a, integer *lda,
  14. doublereal *s, doublereal *scond, doublereal *amax, integer *info)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2;
  18. doublereal d__1, d__2;
  19. /* Builtin functions */
  20. double log(doublereal), pow_di(doublereal *, integer *), sqrt(doublereal);
  21. /* Local variables */
  22. integer i__;
  23. doublereal tmp, base, smin;
  24. extern doublereal _starpu_dlamch_(char *);
  25. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  26. /* -- LAPACK routine (version 3.2) -- */
  27. /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
  28. /* -- Jason Riedy of Univ. of California Berkeley. -- */
  29. /* -- November 2008 -- */
  30. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  31. /* -- Univ. of California Berkeley and NAG Ltd. -- */
  32. /* .. */
  33. /* .. Scalar Arguments .. */
  34. /* .. */
  35. /* .. Array Arguments .. */
  36. /* .. */
  37. /* Purpose */
  38. /* ======= */
  39. /* DPOEQU computes row and column scalings intended to equilibrate a */
  40. /* symmetric positive definite matrix A and reduce its condition number */
  41. /* (with respect to the two-norm). S contains the scale factors, */
  42. /* S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */
  43. /* elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This */
  44. /* choice of S puts the condition number of B within a factor N of the */
  45. /* smallest possible condition number over all possible diagonal */
  46. /* scalings. */
  47. /* Arguments */
  48. /* ========= */
  49. /* N (input) INTEGER */
  50. /* The order of the matrix A. N >= 0. */
  51. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  52. /* The N-by-N symmetric positive definite matrix whose scaling */
  53. /* factors are to be computed. Only the diagonal elements of A */
  54. /* are referenced. */
  55. /* LDA (input) INTEGER */
  56. /* The leading dimension of the array A. LDA >= max(1,N). */
  57. /* S (output) DOUBLE PRECISION array, dimension (N) */
  58. /* If INFO = 0, S contains the scale factors for A. */
  59. /* SCOND (output) DOUBLE PRECISION */
  60. /* If INFO = 0, S contains the ratio of the smallest S(i) to */
  61. /* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */
  62. /* large nor too small, it is not worth scaling by S. */
  63. /* AMAX (output) DOUBLE PRECISION */
  64. /* Absolute value of largest matrix element. If AMAX is very */
  65. /* close to overflow or very close to underflow, the matrix */
  66. /* should be scaled. */
  67. /* INFO (output) INTEGER */
  68. /* = 0: successful exit */
  69. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  70. /* > 0: if INFO = i, the i-th diagonal element is nonpositive. */
  71. /* ===================================================================== */
  72. /* .. Parameters .. */
  73. /* .. */
  74. /* .. Local Scalars .. */
  75. /* .. */
  76. /* .. External Functions .. */
  77. /* .. */
  78. /* .. External Subroutines .. */
  79. /* .. */
  80. /* .. Intrinsic Functions .. */
  81. /* .. */
  82. /* .. Executable Statements .. */
  83. /* Test the input parameters. */
  84. /* Positive definite only performs 1 pass of equilibration. */
  85. /* Parameter adjustments */
  86. a_dim1 = *lda;
  87. a_offset = 1 + a_dim1;
  88. a -= a_offset;
  89. --s;
  90. /* Function Body */
  91. *info = 0;
  92. if (*n < 0) {
  93. *info = -1;
  94. } else if (*lda < max(1,*n)) {
  95. *info = -3;
  96. }
  97. if (*info != 0) {
  98. i__1 = -(*info);
  99. _starpu_xerbla_("DPOEQUB", &i__1);
  100. return 0;
  101. }
  102. /* Quick return if possible. */
  103. if (*n == 0) {
  104. *scond = 1.;
  105. *amax = 0.;
  106. return 0;
  107. }
  108. base = _starpu_dlamch_("B");
  109. tmp = -.5 / log(base);
  110. /* Find the minimum and maximum diagonal elements. */
  111. s[1] = a[a_dim1 + 1];
  112. smin = s[1];
  113. *amax = s[1];
  114. i__1 = *n;
  115. for (i__ = 2; i__ <= i__1; ++i__) {
  116. s[i__] = a[i__ + i__ * a_dim1];
  117. /* Computing MIN */
  118. d__1 = smin, d__2 = s[i__];
  119. smin = min(d__1,d__2);
  120. /* Computing MAX */
  121. d__1 = *amax, d__2 = s[i__];
  122. *amax = max(d__1,d__2);
  123. /* L10: */
  124. }
  125. if (smin <= 0.) {
  126. /* Find the first non-positive diagonal element and return. */
  127. i__1 = *n;
  128. for (i__ = 1; i__ <= i__1; ++i__) {
  129. if (s[i__] <= 0.) {
  130. *info = i__;
  131. return 0;
  132. }
  133. /* L20: */
  134. }
  135. } else {
  136. /* Set the scale factors to the reciprocals */
  137. /* of the diagonal elements. */
  138. i__1 = *n;
  139. for (i__ = 1; i__ <= i__1; ++i__) {
  140. i__2 = (integer) (tmp * log(s[i__]));
  141. s[i__] = pow_di(&base, &i__2);
  142. /* L30: */
  143. }
  144. /* Compute SCOND = min(S(I)) / max(S(I)). */
  145. *scond = sqrt(smin) / sqrt(*amax);
  146. }
  147. return 0;
  148. /* End of DPOEQUB */
  149. } /* _starpu_dpoequb_ */