dlaed9.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* dlaed9.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. /* Subroutine */ int _starpu_dlaed9_(integer *k, integer *kstart, integer *kstop,
  16. integer *n, doublereal *d__, doublereal *q, integer *ldq, doublereal *
  17. rho, doublereal *dlamda, doublereal *w, doublereal *s, integer *lds,
  18. integer *info)
  19. {
  20. /* System generated locals */
  21. integer q_dim1, q_offset, s_dim1, s_offset, i__1, i__2;
  22. doublereal d__1;
  23. /* Builtin functions */
  24. double sqrt(doublereal), d_sign(doublereal *, doublereal *);
  25. /* Local variables */
  26. integer i__, j;
  27. doublereal temp;
  28. extern doublereal _starpu_dnrm2_(integer *, doublereal *, integer *);
  29. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  30. doublereal *, integer *), _starpu_dlaed4_(integer *, integer *,
  31. doublereal *, doublereal *, doublereal *, doublereal *,
  32. doublereal *, integer *);
  33. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  34. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  35. /* -- LAPACK 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. /* DLAED9 finds the roots of the secular equation, as defined by the */
  45. /* values in D, Z, and RHO, between KSTART and KSTOP. It makes the */
  46. /* appropriate calls to DLAED4 and then stores the new matrix of */
  47. /* eigenvectors for use in calculating the next level of Z vectors. */
  48. /* Arguments */
  49. /* ========= */
  50. /* K (input) INTEGER */
  51. /* The number of terms in the rational function to be solved by */
  52. /* DLAED4. K >= 0. */
  53. /* KSTART (input) INTEGER */
  54. /* KSTOP (input) INTEGER */
  55. /* The updated eigenvalues Lambda(I), KSTART <= I <= KSTOP */
  56. /* are to be computed. 1 <= KSTART <= KSTOP <= K. */
  57. /* N (input) INTEGER */
  58. /* The number of rows and columns in the Q matrix. */
  59. /* N >= K (delation may result in N > K). */
  60. /* D (output) DOUBLE PRECISION array, dimension (N) */
  61. /* D(I) contains the updated eigenvalues */
  62. /* for KSTART <= I <= KSTOP. */
  63. /* Q (workspace) DOUBLE PRECISION array, dimension (LDQ,N) */
  64. /* LDQ (input) INTEGER */
  65. /* The leading dimension of the array Q. LDQ >= max( 1, N ). */
  66. /* RHO (input) DOUBLE PRECISION */
  67. /* The value of the parameter in the rank one update equation. */
  68. /* RHO >= 0 required. */
  69. /* DLAMDA (input) DOUBLE PRECISION array, dimension (K) */
  70. /* The first K elements of this array contain the old roots */
  71. /* of the deflated updating problem. These are the poles */
  72. /* of the secular equation. */
  73. /* W (input) DOUBLE PRECISION array, dimension (K) */
  74. /* The first K elements of this array contain the components */
  75. /* of the deflation-adjusted updating vector. */
  76. /* S (output) DOUBLE PRECISION array, dimension (LDS, K) */
  77. /* Will contain the eigenvectors of the repaired matrix which */
  78. /* will be stored for subsequent Z vector calculation and */
  79. /* multiplied by the previously accumulated eigenvectors */
  80. /* to update the system. */
  81. /* LDS (input) INTEGER */
  82. /* The leading dimension of S. LDS >= max( 1, K ). */
  83. /* INFO (output) INTEGER */
  84. /* = 0: successful exit. */
  85. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  86. /* > 0: if INFO = 1, an eigenvalue did not converge */
  87. /* Further Details */
  88. /* =============== */
  89. /* Based on contributions by */
  90. /* Jeff Rutter, Computer Science Division, University of California */
  91. /* at Berkeley, USA */
  92. /* ===================================================================== */
  93. /* .. Local Scalars .. */
  94. /* .. */
  95. /* .. External Functions .. */
  96. /* .. */
  97. /* .. External Subroutines .. */
  98. /* .. */
  99. /* .. Intrinsic Functions .. */
  100. /* .. */
  101. /* .. Executable Statements .. */
  102. /* Test the input parameters. */
  103. /* Parameter adjustments */
  104. --d__;
  105. q_dim1 = *ldq;
  106. q_offset = 1 + q_dim1;
  107. q -= q_offset;
  108. --dlamda;
  109. --w;
  110. s_dim1 = *lds;
  111. s_offset = 1 + s_dim1;
  112. s -= s_offset;
  113. /* Function Body */
  114. *info = 0;
  115. if (*k < 0) {
  116. *info = -1;
  117. } else if (*kstart < 1 || *kstart > max(1,*k)) {
  118. *info = -2;
  119. } else if (max(1,*kstop) < *kstart || *kstop > max(1,*k)) {
  120. *info = -3;
  121. } else if (*n < *k) {
  122. *info = -4;
  123. } else if (*ldq < max(1,*k)) {
  124. *info = -7;
  125. } else if (*lds < max(1,*k)) {
  126. *info = -12;
  127. }
  128. if (*info != 0) {
  129. i__1 = -(*info);
  130. _starpu_xerbla_("DLAED9", &i__1);
  131. return 0;
  132. }
  133. /* Quick return if possible */
  134. if (*k == 0) {
  135. return 0;
  136. }
  137. /* Modify values DLAMDA(i) to make sure all DLAMDA(i)-DLAMDA(j) can */
  138. /* be computed with high relative accuracy (barring over/underflow). */
  139. /* This is a problem on machines without a guard digit in */
  140. /* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
  141. /* The following code replaces DLAMDA(I) by 2*DLAMDA(I)-DLAMDA(I), */
  142. /* which on any of these machines zeros out the bottommost */
  143. /* bit of DLAMDA(I) if it is 1; this makes the subsequent */
  144. /* subtractions DLAMDA(I)-DLAMDA(J) unproblematic when cancellation */
  145. /* occurs. On binary machines with a guard digit (almost all */
  146. /* machines) it does not change DLAMDA(I) at all. On hexadecimal */
  147. /* and decimal machines with a guard digit, it slightly */
  148. /* changes the bottommost bits of DLAMDA(I). It does not account */
  149. /* for hexadecimal or decimal machines without guard digits */
  150. /* (we know of none). We use a subroutine call to compute */
  151. /* 2*DLAMBDA(I) to prevent optimizing compilers from eliminating */
  152. /* this code. */
  153. i__1 = *n;
  154. for (i__ = 1; i__ <= i__1; ++i__) {
  155. dlamda[i__] = _starpu_dlamc3_(&dlamda[i__], &dlamda[i__]) - dlamda[i__];
  156. /* L10: */
  157. }
  158. i__1 = *kstop;
  159. for (j = *kstart; j <= i__1; ++j) {
  160. _starpu_dlaed4_(k, &j, &dlamda[1], &w[1], &q[j * q_dim1 + 1], rho, &d__[j],
  161. info);
  162. /* If the zero finder fails, the computation is terminated. */
  163. if (*info != 0) {
  164. goto L120;
  165. }
  166. /* L20: */
  167. }
  168. if (*k == 1 || *k == 2) {
  169. i__1 = *k;
  170. for (i__ = 1; i__ <= i__1; ++i__) {
  171. i__2 = *k;
  172. for (j = 1; j <= i__2; ++j) {
  173. s[j + i__ * s_dim1] = q[j + i__ * q_dim1];
  174. /* L30: */
  175. }
  176. /* L40: */
  177. }
  178. goto L120;
  179. }
  180. /* Compute updated W. */
  181. _starpu_dcopy_(k, &w[1], &c__1, &s[s_offset], &c__1);
  182. /* Initialize W(I) = Q(I,I) */
  183. i__1 = *ldq + 1;
  184. _starpu_dcopy_(k, &q[q_offset], &i__1, &w[1], &c__1);
  185. i__1 = *k;
  186. for (j = 1; j <= i__1; ++j) {
  187. i__2 = j - 1;
  188. for (i__ = 1; i__ <= i__2; ++i__) {
  189. w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
  190. /* L50: */
  191. }
  192. i__2 = *k;
  193. for (i__ = j + 1; i__ <= i__2; ++i__) {
  194. w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
  195. /* L60: */
  196. }
  197. /* L70: */
  198. }
  199. i__1 = *k;
  200. for (i__ = 1; i__ <= i__1; ++i__) {
  201. d__1 = sqrt(-w[i__]);
  202. w[i__] = d_sign(&d__1, &s[i__ + s_dim1]);
  203. /* L80: */
  204. }
  205. /* Compute eigenvectors of the modified rank-1 modification. */
  206. i__1 = *k;
  207. for (j = 1; j <= i__1; ++j) {
  208. i__2 = *k;
  209. for (i__ = 1; i__ <= i__2; ++i__) {
  210. q[i__ + j * q_dim1] = w[i__] / q[i__ + j * q_dim1];
  211. /* L90: */
  212. }
  213. temp = _starpu_dnrm2_(k, &q[j * q_dim1 + 1], &c__1);
  214. i__2 = *k;
  215. for (i__ = 1; i__ <= i__2; ++i__) {
  216. s[i__ + j * s_dim1] = q[i__ + j * q_dim1] / temp;
  217. /* L100: */
  218. }
  219. /* L110: */
  220. }
  221. L120:
  222. return 0;
  223. /* End of DLAED9 */
  224. } /* _starpu_dlaed9_ */