dlaed3.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* dlaed3.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_b22 = 1.;
  16. static doublereal c_b23 = 0.;
  17. /* Subroutine */ int _starpu_dlaed3_(integer *k, integer *n, integer *n1, doublereal *
  18. d__, doublereal *q, integer *ldq, doublereal *rho, doublereal *dlamda,
  19. doublereal *q2, integer *indx, integer *ctot, doublereal *w,
  20. doublereal *s, integer *info)
  21. {
  22. /* System generated locals */
  23. integer q_dim1, q_offset, i__1, i__2;
  24. doublereal d__1;
  25. /* Builtin functions */
  26. double sqrt(doublereal), d_sign(doublereal *, doublereal *);
  27. /* Local variables */
  28. integer i__, j, n2, n12, ii, n23, iq2;
  29. doublereal temp;
  30. extern doublereal _starpu_dnrm2_(integer *, doublereal *, integer *);
  31. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  32. integer *, doublereal *, doublereal *, integer *, doublereal *,
  33. integer *, doublereal *, doublereal *, integer *),
  34. _starpu_dcopy_(integer *, doublereal *, integer *, doublereal *, integer
  35. *), _starpu_dlaed4_(integer *, integer *, doublereal *, doublereal *,
  36. doublereal *, doublereal *, doublereal *, integer *);
  37. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  38. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  39. doublereal *, integer *, doublereal *, integer *),
  40. _starpu_dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
  41. doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  42. /* -- LAPACK routine (version 3.2) -- */
  43. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  44. /* November 2006 */
  45. /* .. Scalar Arguments .. */
  46. /* .. */
  47. /* .. Array Arguments .. */
  48. /* .. */
  49. /* Purpose */
  50. /* ======= */
  51. /* DLAED3 finds the roots of the secular equation, as defined by the */
  52. /* values in D, W, and RHO, between 1 and K. It makes the */
  53. /* appropriate calls to DLAED4 and then updates the eigenvectors by */
  54. /* multiplying the matrix of eigenvectors of the pair of eigensystems */
  55. /* being combined by the matrix of eigenvectors of the K-by-K system */
  56. /* which is solved here. */
  57. /* This code makes very mild assumptions about floating point */
  58. /* arithmetic. It will work on machines with a guard digit in */
  59. /* add/subtract, or on those binary machines without guard digits */
  60. /* which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2. */
  61. /* It could conceivably fail on hexadecimal or decimal machines */
  62. /* without guard digits, but we know of none. */
  63. /* Arguments */
  64. /* ========= */
  65. /* K (input) INTEGER */
  66. /* The number of terms in the rational function to be solved by */
  67. /* DLAED4. K >= 0. */
  68. /* N (input) INTEGER */
  69. /* The number of rows and columns in the Q matrix. */
  70. /* N >= K (deflation may result in N>K). */
  71. /* N1 (input) INTEGER */
  72. /* The location of the last eigenvalue in the leading submatrix. */
  73. /* min(1,N) <= N1 <= N/2. */
  74. /* D (output) DOUBLE PRECISION array, dimension (N) */
  75. /* D(I) contains the updated eigenvalues for */
  76. /* 1 <= I <= K. */
  77. /* Q (output) DOUBLE PRECISION array, dimension (LDQ,N) */
  78. /* Initially the first K columns are used as workspace. */
  79. /* On output the columns 1 to K contain */
  80. /* the updated eigenvectors. */
  81. /* LDQ (input) INTEGER */
  82. /* The leading dimension of the array Q. LDQ >= max(1,N). */
  83. /* RHO (input) DOUBLE PRECISION */
  84. /* The value of the parameter in the rank one update equation. */
  85. /* RHO >= 0 required. */
  86. /* DLAMDA (input/output) DOUBLE PRECISION array, dimension (K) */
  87. /* The first K elements of this array contain the old roots */
  88. /* of the deflated updating problem. These are the poles */
  89. /* of the secular equation. May be changed on output by */
  90. /* having lowest order bit set to zero on Cray X-MP, Cray Y-MP, */
  91. /* Cray-2, or Cray C-90, as described above. */
  92. /* Q2 (input) DOUBLE PRECISION array, dimension (LDQ2, N) */
  93. /* The first K columns of this matrix contain the non-deflated */
  94. /* eigenvectors for the split problem. */
  95. /* INDX (input) INTEGER array, dimension (N) */
  96. /* The permutation used to arrange the columns of the deflated */
  97. /* Q matrix into three groups (see DLAED2). */
  98. /* The rows of the eigenvectors found by DLAED4 must be likewise */
  99. /* permuted before the matrix multiply can take place. */
  100. /* CTOT (input) INTEGER array, dimension (4) */
  101. /* A count of the total number of the various types of columns */
  102. /* in Q, as described in INDX. The fourth column type is any */
  103. /* column which has been deflated. */
  104. /* W (input/output) DOUBLE PRECISION array, dimension (K) */
  105. /* The first K elements of this array contain the components */
  106. /* of the deflation-adjusted updating vector. Destroyed on */
  107. /* output. */
  108. /* S (workspace) DOUBLE PRECISION array, dimension (N1 + 1)*K */
  109. /* Will contain the eigenvectors of the repaired matrix which */
  110. /* will be multiplied by the previously accumulated eigenvectors */
  111. /* to update the system. */
  112. /* LDS (input) INTEGER */
  113. /* The leading dimension of S. LDS >= max(1,K). */
  114. /* INFO (output) INTEGER */
  115. /* = 0: successful exit. */
  116. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  117. /* > 0: if INFO = 1, an eigenvalue did not converge */
  118. /* Further Details */
  119. /* =============== */
  120. /* Based on contributions by */
  121. /* Jeff Rutter, Computer Science Division, University of California */
  122. /* at Berkeley, USA */
  123. /* Modified by Francoise Tisseur, University of Tennessee. */
  124. /* ===================================================================== */
  125. /* .. Parameters .. */
  126. /* .. */
  127. /* .. Local Scalars .. */
  128. /* .. */
  129. /* .. External Functions .. */
  130. /* .. */
  131. /* .. External Subroutines .. */
  132. /* .. */
  133. /* .. Intrinsic Functions .. */
  134. /* .. */
  135. /* .. Executable Statements .. */
  136. /* Test the input parameters. */
  137. /* Parameter adjustments */
  138. --d__;
  139. q_dim1 = *ldq;
  140. q_offset = 1 + q_dim1;
  141. q -= q_offset;
  142. --dlamda;
  143. --q2;
  144. --indx;
  145. --ctot;
  146. --w;
  147. --s;
  148. /* Function Body */
  149. *info = 0;
  150. if (*k < 0) {
  151. *info = -1;
  152. } else if (*n < *k) {
  153. *info = -2;
  154. } else if (*ldq < max(1,*n)) {
  155. *info = -6;
  156. }
  157. if (*info != 0) {
  158. i__1 = -(*info);
  159. _starpu_xerbla_("DLAED3", &i__1);
  160. return 0;
  161. }
  162. /* Quick return if possible */
  163. if (*k == 0) {
  164. return 0;
  165. }
  166. /* Modify values DLAMDA(i) to make sure all DLAMDA(i)-DLAMDA(j) can */
  167. /* be computed with high relative accuracy (barring over/underflow). */
  168. /* This is a problem on machines without a guard digit in */
  169. /* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
  170. /* The following code replaces DLAMDA(I) by 2*DLAMDA(I)-DLAMDA(I), */
  171. /* which on any of these machines zeros out the bottommost */
  172. /* bit of DLAMDA(I) if it is 1; this makes the subsequent */
  173. /* subtractions DLAMDA(I)-DLAMDA(J) unproblematic when cancellation */
  174. /* occurs. On binary machines with a guard digit (almost all */
  175. /* machines) it does not change DLAMDA(I) at all. On hexadecimal */
  176. /* and decimal machines with a guard digit, it slightly */
  177. /* changes the bottommost bits of DLAMDA(I). It does not account */
  178. /* for hexadecimal or decimal machines without guard digits */
  179. /* (we know of none). We use a subroutine call to compute */
  180. /* 2*DLAMBDA(I) to prevent optimizing compilers from eliminating */
  181. /* this code. */
  182. i__1 = *k;
  183. for (i__ = 1; i__ <= i__1; ++i__) {
  184. dlamda[i__] = _starpu_dlamc3_(&dlamda[i__], &dlamda[i__]) - dlamda[i__];
  185. /* L10: */
  186. }
  187. i__1 = *k;
  188. for (j = 1; j <= i__1; ++j) {
  189. _starpu_dlaed4_(k, &j, &dlamda[1], &w[1], &q[j * q_dim1 + 1], rho, &d__[j],
  190. info);
  191. /* If the zero finder fails, the computation is terminated. */
  192. if (*info != 0) {
  193. goto L120;
  194. }
  195. /* L20: */
  196. }
  197. if (*k == 1) {
  198. goto L110;
  199. }
  200. if (*k == 2) {
  201. i__1 = *k;
  202. for (j = 1; j <= i__1; ++j) {
  203. w[1] = q[j * q_dim1 + 1];
  204. w[2] = q[j * q_dim1 + 2];
  205. ii = indx[1];
  206. q[j * q_dim1 + 1] = w[ii];
  207. ii = indx[2];
  208. q[j * q_dim1 + 2] = w[ii];
  209. /* L30: */
  210. }
  211. goto L110;
  212. }
  213. /* Compute updated W. */
  214. _starpu_dcopy_(k, &w[1], &c__1, &s[1], &c__1);
  215. /* Initialize W(I) = Q(I,I) */
  216. i__1 = *ldq + 1;
  217. _starpu_dcopy_(k, &q[q_offset], &i__1, &w[1], &c__1);
  218. i__1 = *k;
  219. for (j = 1; j <= i__1; ++j) {
  220. i__2 = j - 1;
  221. for (i__ = 1; i__ <= i__2; ++i__) {
  222. w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
  223. /* L40: */
  224. }
  225. i__2 = *k;
  226. for (i__ = j + 1; i__ <= i__2; ++i__) {
  227. w[i__] *= q[i__ + j * q_dim1] / (dlamda[i__] - dlamda[j]);
  228. /* L50: */
  229. }
  230. /* L60: */
  231. }
  232. i__1 = *k;
  233. for (i__ = 1; i__ <= i__1; ++i__) {
  234. d__1 = sqrt(-w[i__]);
  235. w[i__] = d_sign(&d__1, &s[i__]);
  236. /* L70: */
  237. }
  238. /* Compute eigenvectors of the modified rank-1 modification. */
  239. i__1 = *k;
  240. for (j = 1; j <= i__1; ++j) {
  241. i__2 = *k;
  242. for (i__ = 1; i__ <= i__2; ++i__) {
  243. s[i__] = w[i__] / q[i__ + j * q_dim1];
  244. /* L80: */
  245. }
  246. temp = _starpu_dnrm2_(k, &s[1], &c__1);
  247. i__2 = *k;
  248. for (i__ = 1; i__ <= i__2; ++i__) {
  249. ii = indx[i__];
  250. q[i__ + j * q_dim1] = s[ii] / temp;
  251. /* L90: */
  252. }
  253. /* L100: */
  254. }
  255. /* Compute the updated eigenvectors. */
  256. L110:
  257. n2 = *n - *n1;
  258. n12 = ctot[1] + ctot[2];
  259. n23 = ctot[2] + ctot[3];
  260. _starpu_dlacpy_("A", &n23, k, &q[ctot[1] + 1 + q_dim1], ldq, &s[1], &n23);
  261. iq2 = *n1 * n12 + 1;
  262. if (n23 != 0) {
  263. _starpu_dgemm_("N", "N", &n2, k, &n23, &c_b22, &q2[iq2], &n2, &s[1], &n23, &
  264. c_b23, &q[*n1 + 1 + q_dim1], ldq);
  265. } else {
  266. _starpu_dlaset_("A", &n2, k, &c_b23, &c_b23, &q[*n1 + 1 + q_dim1], ldq);
  267. }
  268. _starpu_dlacpy_("A", &n12, k, &q[q_offset], ldq, &s[1], &n12);
  269. if (n12 != 0) {
  270. _starpu_dgemm_("N", "N", n1, k, &n12, &c_b22, &q2[1], n1, &s[1], &n12, &c_b23,
  271. &q[q_offset], ldq);
  272. } else {
  273. _starpu_dlaset_("A", n1, k, &c_b23, &c_b23, &q[q_dim1 + 1], ldq);
  274. }
  275. L120:
  276. return 0;
  277. /* End of DLAED3 */
  278. } /* _starpu_dlaed3_ */