dlaed7.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /* dlaed7.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__2 = 2;
  15. static integer c__1 = 1;
  16. static doublereal c_b10 = 1.;
  17. static doublereal c_b11 = 0.;
  18. static integer c_n1 = -1;
  19. /* Subroutine */ int _starpu_dlaed7_(integer *icompq, integer *n, integer *qsiz,
  20. integer *tlvls, integer *curlvl, integer *curpbm, doublereal *d__,
  21. doublereal *q, integer *ldq, integer *indxq, doublereal *rho, integer
  22. *cutpnt, doublereal *qstore, integer *qptr, integer *prmptr, integer *
  23. perm, integer *givptr, integer *givcol, doublereal *givnum,
  24. doublereal *work, integer *iwork, integer *info)
  25. {
  26. /* System generated locals */
  27. integer q_dim1, q_offset, i__1, i__2;
  28. /* Builtin functions */
  29. integer pow_ii(integer *, integer *);
  30. /* Local variables */
  31. integer i__, k, n1, n2, is, iw, iz, iq2, ptr, ldq2, indx, curr;
  32. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  33. integer *, doublereal *, doublereal *, integer *, doublereal *,
  34. integer *, doublereal *, doublereal *, integer *);
  35. integer indxc, indxp;
  36. extern /* Subroutine */ int _starpu_dlaed8_(integer *, integer *, integer *,
  37. integer *, doublereal *, doublereal *, integer *, integer *,
  38. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  39. integer *, doublereal *, integer *, integer *, integer *,
  40. doublereal *, integer *, integer *, integer *), _starpu_dlaed9_(integer *,
  41. integer *, integer *, integer *, doublereal *, doublereal *,
  42. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  43. integer *, integer *), _starpu_dlaeda_(integer *, integer *, integer *,
  44. integer *, integer *, integer *, integer *, integer *, doublereal
  45. *, doublereal *, integer *, doublereal *, doublereal *, integer *)
  46. ;
  47. integer idlmda;
  48. extern /* Subroutine */ int _starpu_dlamrg_(integer *, integer *, doublereal *,
  49. integer *, integer *, integer *), _starpu_xerbla_(char *, integer *);
  50. integer coltyp;
  51. /* -- LAPACK routine (version 3.2) -- */
  52. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  53. /* November 2006 */
  54. /* .. Scalar Arguments .. */
  55. /* .. */
  56. /* .. Array Arguments .. */
  57. /* .. */
  58. /* Purpose */
  59. /* ======= */
  60. /* DLAED7 computes the updated eigensystem of a diagonal */
  61. /* matrix after modification by a rank-one symmetric matrix. This */
  62. /* routine is used only for the eigenproblem which requires all */
  63. /* eigenvalues and optionally eigenvectors of a dense symmetric matrix */
  64. /* that has been reduced to tridiagonal form. DLAED1 handles */
  65. /* the case in which all eigenvalues and eigenvectors of a symmetric */
  66. /* tridiagonal matrix are desired. */
  67. /* T = Q(in) ( D(in) + RHO * Z*Z' ) Q'(in) = Q(out) * D(out) * Q'(out) */
  68. /* where Z = Q'u, u is a vector of length N with ones in the */
  69. /* CUTPNT and CUTPNT + 1 th elements and zeros elsewhere. */
  70. /* The eigenvectors of the original matrix are stored in Q, and the */
  71. /* eigenvalues are in D. The algorithm consists of three stages: */
  72. /* The first stage consists of deflating the size of the problem */
  73. /* when there are multiple eigenvalues or if there is a zero in */
  74. /* the Z vector. For each such occurence the dimension of the */
  75. /* secular equation problem is reduced by one. This stage is */
  76. /* performed by the routine DLAED8. */
  77. /* The second stage consists of calculating the updated */
  78. /* eigenvalues. This is done by finding the roots of the secular */
  79. /* equation via the routine DLAED4 (as called by DLAED9). */
  80. /* This routine also calculates the eigenvectors of the current */
  81. /* problem. */
  82. /* The final stage consists of computing the updated eigenvectors */
  83. /* directly using the updated eigenvalues. The eigenvectors for */
  84. /* the current problem are multiplied with the eigenvectors from */
  85. /* the overall problem. */
  86. /* Arguments */
  87. /* ========= */
  88. /* ICOMPQ (input) INTEGER */
  89. /* = 0: Compute eigenvalues only. */
  90. /* = 1: Compute eigenvectors of original dense symmetric matrix */
  91. /* also. On entry, Q contains the orthogonal matrix used */
  92. /* to reduce the original matrix to tridiagonal form. */
  93. /* N (input) INTEGER */
  94. /* The dimension of the symmetric tridiagonal matrix. N >= 0. */
  95. /* QSIZ (input) INTEGER */
  96. /* The dimension of the orthogonal matrix used to reduce */
  97. /* the full matrix to tridiagonal form. QSIZ >= N if ICOMPQ = 1. */
  98. /* TLVLS (input) INTEGER */
  99. /* The total number of merging levels in the overall divide and */
  100. /* conquer tree. */
  101. /* CURLVL (input) INTEGER */
  102. /* The current level in the overall merge routine, */
  103. /* 0 <= CURLVL <= TLVLS. */
  104. /* CURPBM (input) INTEGER */
  105. /* The current problem in the current level in the overall */
  106. /* merge routine (counting from upper left to lower right). */
  107. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  108. /* On entry, the eigenvalues of the rank-1-perturbed matrix. */
  109. /* On exit, the eigenvalues of the repaired matrix. */
  110. /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N) */
  111. /* On entry, the eigenvectors of the rank-1-perturbed matrix. */
  112. /* On exit, the eigenvectors of the repaired tridiagonal matrix. */
  113. /* LDQ (input) INTEGER */
  114. /* The leading dimension of the array Q. LDQ >= max(1,N). */
  115. /* INDXQ (output) INTEGER array, dimension (N) */
  116. /* The permutation which will reintegrate the subproblem just */
  117. /* solved back into sorted order, i.e., D( INDXQ( I = 1, N ) ) */
  118. /* will be in ascending order. */
  119. /* RHO (input) DOUBLE PRECISION */
  120. /* The subdiagonal element used to create the rank-1 */
  121. /* modification. */
  122. /* CUTPNT (input) INTEGER */
  123. /* Contains the location of the last eigenvalue in the leading */
  124. /* sub-matrix. min(1,N) <= CUTPNT <= N. */
  125. /* QSTORE (input/output) DOUBLE PRECISION array, dimension (N**2+1) */
  126. /* Stores eigenvectors of submatrices encountered during */
  127. /* divide and conquer, packed together. QPTR points to */
  128. /* beginning of the submatrices. */
  129. /* QPTR (input/output) INTEGER array, dimension (N+2) */
  130. /* List of indices pointing to beginning of submatrices stored */
  131. /* in QSTORE. The submatrices are numbered starting at the */
  132. /* bottom left of the divide and conquer tree, from left to */
  133. /* right and bottom to top. */
  134. /* PRMPTR (input) INTEGER array, dimension (N lg N) */
  135. /* Contains a list of pointers which indicate where in PERM a */
  136. /* level's permutation is stored. PRMPTR(i+1) - PRMPTR(i) */
  137. /* indicates the size of the permutation and also the size of */
  138. /* the full, non-deflated problem. */
  139. /* PERM (input) INTEGER array, dimension (N lg N) */
  140. /* Contains the permutations (from deflation and sorting) to be */
  141. /* applied to each eigenblock. */
  142. /* GIVPTR (input) INTEGER array, dimension (N lg N) */
  143. /* Contains a list of pointers which indicate where in GIVCOL a */
  144. /* level's Givens rotations are stored. GIVPTR(i+1) - GIVPTR(i) */
  145. /* indicates the number of Givens rotations. */
  146. /* GIVCOL (input) INTEGER array, dimension (2, N lg N) */
  147. /* Each pair of numbers indicates a pair of columns to take place */
  148. /* in a Givens rotation. */
  149. /* GIVNUM (input) DOUBLE PRECISION array, dimension (2, N lg N) */
  150. /* Each number indicates the S value to be used in the */
  151. /* corresponding Givens rotation. */
  152. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N+QSIZ*N) */
  153. /* IWORK (workspace) INTEGER array, dimension (4*N) */
  154. /* INFO (output) INTEGER */
  155. /* = 0: successful exit. */
  156. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  157. /* > 0: if INFO = 1, an eigenvalue did not converge */
  158. /* Further Details */
  159. /* =============== */
  160. /* Based on contributions by */
  161. /* Jeff Rutter, Computer Science Division, University of California */
  162. /* at Berkeley, USA */
  163. /* ===================================================================== */
  164. /* .. Parameters .. */
  165. /* .. */
  166. /* .. Local Scalars .. */
  167. /* .. */
  168. /* .. External Subroutines .. */
  169. /* .. */
  170. /* .. Intrinsic Functions .. */
  171. /* .. */
  172. /* .. Executable Statements .. */
  173. /* Test the input parameters. */
  174. /* Parameter adjustments */
  175. --d__;
  176. q_dim1 = *ldq;
  177. q_offset = 1 + q_dim1;
  178. q -= q_offset;
  179. --indxq;
  180. --qstore;
  181. --qptr;
  182. --prmptr;
  183. --perm;
  184. --givptr;
  185. givcol -= 3;
  186. givnum -= 3;
  187. --work;
  188. --iwork;
  189. /* Function Body */
  190. *info = 0;
  191. if (*icompq < 0 || *icompq > 1) {
  192. *info = -1;
  193. } else if (*n < 0) {
  194. *info = -2;
  195. } else if (*icompq == 1 && *qsiz < *n) {
  196. *info = -4;
  197. } else if (*ldq < max(1,*n)) {
  198. *info = -9;
  199. } else if (min(1,*n) > *cutpnt || *n < *cutpnt) {
  200. *info = -12;
  201. }
  202. if (*info != 0) {
  203. i__1 = -(*info);
  204. _starpu_xerbla_("DLAED7", &i__1);
  205. return 0;
  206. }
  207. /* Quick return if possible */
  208. if (*n == 0) {
  209. return 0;
  210. }
  211. /* The following values are for bookkeeping purposes only. They are */
  212. /* integer pointers which indicate the portion of the workspace */
  213. /* used by a particular array in DLAED8 and DLAED9. */
  214. if (*icompq == 1) {
  215. ldq2 = *qsiz;
  216. } else {
  217. ldq2 = *n;
  218. }
  219. iz = 1;
  220. idlmda = iz + *n;
  221. iw = idlmda + *n;
  222. iq2 = iw + *n;
  223. is = iq2 + *n * ldq2;
  224. indx = 1;
  225. indxc = indx + *n;
  226. coltyp = indxc + *n;
  227. indxp = coltyp + *n;
  228. /* Form the z-vector which consists of the last row of Q_1 and the */
  229. /* first row of Q_2. */
  230. ptr = pow_ii(&c__2, tlvls) + 1;
  231. i__1 = *curlvl - 1;
  232. for (i__ = 1; i__ <= i__1; ++i__) {
  233. i__2 = *tlvls - i__;
  234. ptr += pow_ii(&c__2, &i__2);
  235. /* L10: */
  236. }
  237. curr = ptr + *curpbm;
  238. _starpu_dlaeda_(n, tlvls, curlvl, curpbm, &prmptr[1], &perm[1], &givptr[1], &
  239. givcol[3], &givnum[3], &qstore[1], &qptr[1], &work[iz], &work[iz
  240. + *n], info);
  241. /* When solving the final problem, we no longer need the stored data, */
  242. /* so we will overwrite the data from this level onto the previously */
  243. /* used storage space. */
  244. if (*curlvl == *tlvls) {
  245. qptr[curr] = 1;
  246. prmptr[curr] = 1;
  247. givptr[curr] = 1;
  248. }
  249. /* Sort and Deflate eigenvalues. */
  250. _starpu_dlaed8_(icompq, &k, n, qsiz, &d__[1], &q[q_offset], ldq, &indxq[1], rho,
  251. cutpnt, &work[iz], &work[idlmda], &work[iq2], &ldq2, &work[iw], &
  252. perm[prmptr[curr]], &givptr[curr + 1], &givcol[(givptr[curr] << 1)
  253. + 1], &givnum[(givptr[curr] << 1) + 1], &iwork[indxp], &iwork[
  254. indx], info);
  255. prmptr[curr + 1] = prmptr[curr] + *n;
  256. givptr[curr + 1] += givptr[curr];
  257. /* Solve Secular Equation. */
  258. if (k != 0) {
  259. _starpu_dlaed9_(&k, &c__1, &k, n, &d__[1], &work[is], &k, rho, &work[idlmda],
  260. &work[iw], &qstore[qptr[curr]], &k, info);
  261. if (*info != 0) {
  262. goto L30;
  263. }
  264. if (*icompq == 1) {
  265. _starpu_dgemm_("N", "N", qsiz, &k, &k, &c_b10, &work[iq2], &ldq2, &qstore[
  266. qptr[curr]], &k, &c_b11, &q[q_offset], ldq);
  267. }
  268. /* Computing 2nd power */
  269. i__1 = k;
  270. qptr[curr + 1] = qptr[curr] + i__1 * i__1;
  271. /* Prepare the INDXQ sorting permutation. */
  272. n1 = k;
  273. n2 = *n - k;
  274. _starpu_dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &indxq[1]);
  275. } else {
  276. qptr[curr + 1] = qptr[curr];
  277. i__1 = *n;
  278. for (i__ = 1; i__ <= i__1; ++i__) {
  279. indxq[i__] = i__;
  280. /* L20: */
  281. }
  282. }
  283. L30:
  284. return 0;
  285. /* End of DLAED7 */
  286. } /* _starpu_dlaed7_ */