dlacn2.c 6.8 KB

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