dlacon.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* dlacon.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. static doublereal c_b11 = 1.;
  16. /* Subroutine */ int _starpu_dlacon_(integer *n, doublereal *v, doublereal *x,
  17. integer *isgn, doublereal *est, integer *kase)
  18. {
  19. /* System generated locals */
  20. integer i__1;
  21. doublereal d__1;
  22. /* Builtin functions */
  23. double d_sign(doublereal *, doublereal *);
  24. integer i_dnnt(doublereal *);
  25. /* Local variables */
  26. static integer i__, j, iter;
  27. static doublereal temp;
  28. static integer jump;
  29. extern doublereal _starpu_dasum_(integer *, doublereal *, integer *);
  30. static integer jlast;
  31. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  32. doublereal *, integer *);
  33. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  34. static doublereal altsgn, estold;
  35. /* -- LAPACK auxiliary routine (version 3.2) -- */
  36. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  37. /* November 2006 */
  38. /* .. Scalar Arguments .. */
  39. /* .. */
  40. /* .. Array Arguments .. */
  41. /* .. */
  42. /* Purpose */
  43. /* ======= */
  44. /* DLACON estimates the 1-norm of a square, real matrix A. */
  45. /* Reverse communication is used for evaluating matrix-vector products. */
  46. /* Arguments */
  47. /* ========= */
  48. /* N (input) INTEGER */
  49. /* The order of the matrix. N >= 1. */
  50. /* V (workspace) DOUBLE PRECISION array, dimension (N) */
  51. /* On the final return, V = A*W, where EST = norm(V)/norm(W) */
  52. /* (W is not returned). */
  53. /* X (input/output) DOUBLE PRECISION array, dimension (N) */
  54. /* On an intermediate return, X should be overwritten by */
  55. /* A * X, if KASE=1, */
  56. /* A' * X, if KASE=2, */
  57. /* and DLACON must be re-called with all the other parameters */
  58. /* unchanged. */
  59. /* ISGN (workspace) INTEGER array, dimension (N) */
  60. /* EST (input/output) DOUBLE PRECISION */
  61. /* On entry with KASE = 1 or 2 and JUMP = 3, EST should be */
  62. /* unchanged from the previous call to DLACON. */
  63. /* On exit, EST is an estimate (a lower bound) for norm(A). */
  64. /* KASE (input/output) INTEGER */
  65. /* On the initial call to DLACON, KASE should be 0. */
  66. /* On an intermediate return, KASE will be 1 or 2, indicating */
  67. /* whether X should be overwritten by A * X or A' * X. */
  68. /* On the final return from DLACON, KASE will again be 0. */
  69. /* Further Details */
  70. /* ======= ======= */
  71. /* Contributed by Nick Higham, University of Manchester. */
  72. /* Originally named SONEST, dated March 16, 1988. */
  73. /* Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of */
  74. /* a real or complex matrix, with applications to condition estimation", */
  75. /* ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988. */
  76. /* ===================================================================== */
  77. /* .. Parameters .. */
  78. /* .. */
  79. /* .. Local Scalars .. */
  80. /* .. */
  81. /* .. External Functions .. */
  82. /* .. */
  83. /* .. External Subroutines .. */
  84. /* .. */
  85. /* .. Intrinsic Functions .. */
  86. /* .. */
  87. /* .. Save statement .. */
  88. /* .. */
  89. /* .. Executable Statements .. */
  90. /* Parameter adjustments */
  91. --isgn;
  92. --x;
  93. --v;
  94. /* Function Body */
  95. if (*kase == 0) {
  96. i__1 = *n;
  97. for (i__ = 1; i__ <= i__1; ++i__) {
  98. x[i__] = 1. / (doublereal) (*n);
  99. /* L10: */
  100. }
  101. *kase = 1;
  102. jump = 1;
  103. return 0;
  104. }
  105. switch (jump) {
  106. case 1: goto L20;
  107. case 2: goto L40;
  108. case 3: goto L70;
  109. case 4: goto L110;
  110. case 5: goto L140;
  111. }
  112. /* ................ ENTRY (JUMP = 1) */
  113. /* FIRST ITERATION. X HAS BEEN OVERWRITTEN BY A*X. */
  114. L20:
  115. if (*n == 1) {
  116. v[1] = x[1];
  117. *est = abs(v[1]);
  118. /* ... QUIT */
  119. goto L150;
  120. }
  121. *est = _starpu_dasum_(n, &x[1], &c__1);
  122. i__1 = *n;
  123. for (i__ = 1; i__ <= i__1; ++i__) {
  124. x[i__] = d_sign(&c_b11, &x[i__]);
  125. isgn[i__] = i_dnnt(&x[i__]);
  126. /* L30: */
  127. }
  128. *kase = 2;
  129. jump = 2;
  130. return 0;
  131. /* ................ ENTRY (JUMP = 2) */
  132. /* FIRST ITERATION. X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
  133. L40:
  134. j = _starpu_idamax_(n, &x[1], &c__1);
  135. iter = 2;
  136. /* MAIN LOOP - ITERATIONS 2,3,...,ITMAX. */
  137. L50:
  138. i__1 = *n;
  139. for (i__ = 1; i__ <= i__1; ++i__) {
  140. x[i__] = 0.;
  141. /* L60: */
  142. }
  143. x[j] = 1.;
  144. *kase = 1;
  145. jump = 3;
  146. return 0;
  147. /* ................ ENTRY (JUMP = 3) */
  148. /* X HAS BEEN OVERWRITTEN BY A*X. */
  149. L70:
  150. _starpu_dcopy_(n, &x[1], &c__1, &v[1], &c__1);
  151. estold = *est;
  152. *est = _starpu_dasum_(n, &v[1], &c__1);
  153. i__1 = *n;
  154. for (i__ = 1; i__ <= i__1; ++i__) {
  155. d__1 = d_sign(&c_b11, &x[i__]);
  156. if (i_dnnt(&d__1) != isgn[i__]) {
  157. goto L90;
  158. }
  159. /* L80: */
  160. }
  161. /* REPEATED SIGN VECTOR DETECTED, HENCE ALGORITHM HAS CONVERGED. */
  162. goto L120;
  163. L90:
  164. /* TEST FOR CYCLING. */
  165. if (*est <= estold) {
  166. goto L120;
  167. }
  168. i__1 = *n;
  169. for (i__ = 1; i__ <= i__1; ++i__) {
  170. x[i__] = d_sign(&c_b11, &x[i__]);
  171. isgn[i__] = i_dnnt(&x[i__]);
  172. /* L100: */
  173. }
  174. *kase = 2;
  175. jump = 4;
  176. return 0;
  177. /* ................ ENTRY (JUMP = 4) */
  178. /* X HAS BEEN OVERWRITTEN BY TRANSPOSE(A)*X. */
  179. L110:
  180. jlast = j;
  181. j = _starpu_idamax_(n, &x[1], &c__1);
  182. if (x[jlast] != (d__1 = x[j], abs(d__1)) && iter < 5) {
  183. ++iter;
  184. goto L50;
  185. }
  186. /* ITERATION COMPLETE. FINAL STAGE. */
  187. L120:
  188. altsgn = 1.;
  189. i__1 = *n;
  190. for (i__ = 1; i__ <= i__1; ++i__) {
  191. x[i__] = altsgn * ((doublereal) (i__ - 1) / (doublereal) (*n - 1) +
  192. 1.);
  193. altsgn = -altsgn;
  194. /* L130: */
  195. }
  196. *kase = 1;
  197. jump = 5;
  198. return 0;
  199. /* ................ ENTRY (JUMP = 5) */
  200. /* X HAS BEEN OVERWRITTEN BY A*X. */
  201. L140:
  202. temp = _starpu_dasum_(n, &x[1], &c__1) / (doublereal) (*n * 3) * 2.;
  203. if (temp > *est) {
  204. _starpu_dcopy_(n, &x[1], &c__1, &v[1], &c__1);
  205. *est = temp;
  206. }
  207. L150:
  208. *kase = 0;
  209. return 0;
  210. /* End of DLACON */
  211. } /* _starpu_dlacon_ */