dsytrd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /* dsytrd.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 integer c_n1 = -1;
  16. static integer c__3 = 3;
  17. static integer c__2 = 2;
  18. static doublereal c_b22 = -1.;
  19. static doublereal c_b23 = 1.;
  20. /* Subroutine */ int _starpu_dsytrd_(char *uplo, integer *n, doublereal *a, integer *
  21. lda, doublereal *d__, doublereal *e, doublereal *tau, doublereal *
  22. work, integer *lwork, integer *info)
  23. {
  24. /* System generated locals */
  25. integer a_dim1, a_offset, i__1, i__2, i__3;
  26. /* Local variables */
  27. integer i__, j, nb, kk, nx, iws;
  28. extern logical _starpu_lsame_(char *, char *);
  29. integer nbmin, iinfo;
  30. logical upper;
  31. extern /* Subroutine */ int _starpu_dsytd2_(char *, integer *, doublereal *,
  32. integer *, doublereal *, doublereal *, doublereal *, integer *), _starpu_dsyr2k_(char *, char *, integer *, integer *, doublereal
  33. *, doublereal *, integer *, doublereal *, integer *, doublereal *,
  34. doublereal *, integer *), _starpu_dlatrd_(char *,
  35. integer *, integer *, doublereal *, integer *, doublereal *,
  36. doublereal *, doublereal *, integer *), _starpu_xerbla_(char *,
  37. integer *);
  38. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  39. integer *, integer *);
  40. integer ldwork, lwkopt;
  41. logical lquery;
  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. /* DSYTRD reduces a real symmetric matrix A to real symmetric */
  52. /* tridiagonal form T by an orthogonal similarity transformation: */
  53. /* Q**T * A * Q = T. */
  54. /* Arguments */
  55. /* ========= */
  56. /* UPLO (input) CHARACTER*1 */
  57. /* = 'U': Upper triangle of A is stored; */
  58. /* = 'L': Lower triangle of A is stored. */
  59. /* N (input) INTEGER */
  60. /* The order of the matrix A. N >= 0. */
  61. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  62. /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  63. /* N-by-N upper triangular part of A contains the upper */
  64. /* triangular part of the matrix A, and the strictly lower */
  65. /* triangular part of A is not referenced. If UPLO = 'L', the */
  66. /* leading N-by-N lower triangular part of A contains the lower */
  67. /* triangular part of the matrix A, and the strictly upper */
  68. /* triangular part of A is not referenced. */
  69. /* On exit, if UPLO = 'U', the diagonal and first superdiagonal */
  70. /* of A are overwritten by the corresponding elements of the */
  71. /* tridiagonal matrix T, and the elements above the first */
  72. /* superdiagonal, with the array TAU, represent the orthogonal */
  73. /* matrix Q as a product of elementary reflectors; if UPLO */
  74. /* = 'L', the diagonal and first subdiagonal of A are over- */
  75. /* written by the corresponding elements of the tridiagonal */
  76. /* matrix T, and the elements below the first subdiagonal, with */
  77. /* the array TAU, represent the orthogonal matrix Q as a product */
  78. /* of elementary reflectors. See Further Details. */
  79. /* LDA (input) INTEGER */
  80. /* The leading dimension of the array A. LDA >= max(1,N). */
  81. /* D (output) DOUBLE PRECISION array, dimension (N) */
  82. /* The diagonal elements of the tridiagonal matrix T: */
  83. /* D(i) = A(i,i). */
  84. /* E (output) DOUBLE PRECISION array, dimension (N-1) */
  85. /* The off-diagonal elements of the tridiagonal matrix T: */
  86. /* E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
  87. /* TAU (output) DOUBLE PRECISION array, dimension (N-1) */
  88. /* The scalar factors of the elementary reflectors (see Further */
  89. /* Details). */
  90. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  91. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  92. /* LWORK (input) INTEGER */
  93. /* The dimension of the array WORK. LWORK >= 1. */
  94. /* For optimum performance LWORK >= N*NB, where NB is the */
  95. /* optimal blocksize. */
  96. /* If LWORK = -1, then a workspace query is assumed; the routine */
  97. /* only calculates the optimal size of the WORK array, returns */
  98. /* this value as the first entry of the WORK array, and no error */
  99. /* message related to LWORK is issued by XERBLA. */
  100. /* INFO (output) INTEGER */
  101. /* = 0: successful exit */
  102. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  103. /* Further Details */
  104. /* =============== */
  105. /* If UPLO = 'U', the matrix Q is represented as a product of elementary */
  106. /* reflectors */
  107. /* Q = H(n-1) . . . H(2) H(1). */
  108. /* Each H(i) has the form */
  109. /* H(i) = I - tau * v * v' */
  110. /* where tau is a real scalar, and v is a real vector with */
  111. /* v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in */
  112. /* A(1:i-1,i+1), and tau in TAU(i). */
  113. /* If UPLO = 'L', the matrix Q is represented as a product of elementary */
  114. /* reflectors */
  115. /* Q = H(1) H(2) . . . H(n-1). */
  116. /* Each H(i) has the form */
  117. /* H(i) = I - tau * v * v' */
  118. /* where tau is a real scalar, and v is a real vector with */
  119. /* v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i), */
  120. /* and tau in TAU(i). */
  121. /* The contents of A on exit are illustrated by the following examples */
  122. /* with n = 5: */
  123. /* if UPLO = 'U': if UPLO = 'L': */
  124. /* ( d e v2 v3 v4 ) ( d ) */
  125. /* ( d e v3 v4 ) ( e d ) */
  126. /* ( d e v4 ) ( v1 e d ) */
  127. /* ( d e ) ( v1 v2 e d ) */
  128. /* ( d ) ( v1 v2 v3 e d ) */
  129. /* where d and e denote diagonal and off-diagonal elements of T, and vi */
  130. /* denotes an element of the vector defining H(i). */
  131. /* ===================================================================== */
  132. /* .. Parameters .. */
  133. /* .. */
  134. /* .. Local Scalars .. */
  135. /* .. */
  136. /* .. External Subroutines .. */
  137. /* .. */
  138. /* .. Intrinsic Functions .. */
  139. /* .. */
  140. /* .. External Functions .. */
  141. /* .. */
  142. /* .. Executable Statements .. */
  143. /* Test the input parameters */
  144. /* Parameter adjustments */
  145. a_dim1 = *lda;
  146. a_offset = 1 + a_dim1;
  147. a -= a_offset;
  148. --d__;
  149. --e;
  150. --tau;
  151. --work;
  152. /* Function Body */
  153. *info = 0;
  154. upper = _starpu_lsame_(uplo, "U");
  155. lquery = *lwork == -1;
  156. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  157. *info = -1;
  158. } else if (*n < 0) {
  159. *info = -2;
  160. } else if (*lda < max(1,*n)) {
  161. *info = -4;
  162. } else if (*lwork < 1 && ! lquery) {
  163. *info = -9;
  164. }
  165. if (*info == 0) {
  166. /* Determine the block size. */
  167. nb = _starpu_ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  168. lwkopt = *n * nb;
  169. work[1] = (doublereal) lwkopt;
  170. }
  171. if (*info != 0) {
  172. i__1 = -(*info);
  173. _starpu_xerbla_("DSYTRD", &i__1);
  174. return 0;
  175. } else if (lquery) {
  176. return 0;
  177. }
  178. /* Quick return if possible */
  179. if (*n == 0) {
  180. work[1] = 1.;
  181. return 0;
  182. }
  183. nx = *n;
  184. iws = 1;
  185. if (nb > 1 && nb < *n) {
  186. /* Determine when to cross over from blocked to unblocked code */
  187. /* (last block is always handled by unblocked code). */
  188. /* Computing MAX */
  189. i__1 = nb, i__2 = _starpu_ilaenv_(&c__3, "DSYTRD", uplo, n, &c_n1, &c_n1, &
  190. c_n1);
  191. nx = max(i__1,i__2);
  192. if (nx < *n) {
  193. /* Determine if workspace is large enough for blocked code. */
  194. ldwork = *n;
  195. iws = ldwork * nb;
  196. if (*lwork < iws) {
  197. /* Not enough workspace to use optimal NB: determine the */
  198. /* minimum value of NB, and reduce NB or force use of */
  199. /* unblocked code by setting NX = N. */
  200. /* Computing MAX */
  201. i__1 = *lwork / ldwork;
  202. nb = max(i__1,1);
  203. nbmin = _starpu_ilaenv_(&c__2, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  204. if (nb < nbmin) {
  205. nx = *n;
  206. }
  207. }
  208. } else {
  209. nx = *n;
  210. }
  211. } else {
  212. nb = 1;
  213. }
  214. if (upper) {
  215. /* Reduce the upper triangle of A. */
  216. /* Columns 1:kk are handled by the unblocked method. */
  217. kk = *n - (*n - nx + nb - 1) / nb * nb;
  218. i__1 = kk + 1;
  219. i__2 = -nb;
  220. for (i__ = *n - nb + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
  221. i__2) {
  222. /* Reduce columns i:i+nb-1 to tridiagonal form and form the */
  223. /* matrix W which is needed to update the unreduced part of */
  224. /* the matrix */
  225. i__3 = i__ + nb - 1;
  226. _starpu_dlatrd_(uplo, &i__3, &nb, &a[a_offset], lda, &e[1], &tau[1], &
  227. work[1], &ldwork);
  228. /* Update the unreduced submatrix A(1:i-1,1:i-1), using an */
  229. /* update of the form: A := A - V*W' - W*V' */
  230. i__3 = i__ - 1;
  231. _starpu_dsyr2k_(uplo, "No transpose", &i__3, &nb, &c_b22, &a[i__ * a_dim1
  232. + 1], lda, &work[1], &ldwork, &c_b23, &a[a_offset], lda);
  233. /* Copy superdiagonal elements back into A, and diagonal */
  234. /* elements into D */
  235. i__3 = i__ + nb - 1;
  236. for (j = i__; j <= i__3; ++j) {
  237. a[j - 1 + j * a_dim1] = e[j - 1];
  238. d__[j] = a[j + j * a_dim1];
  239. /* L10: */
  240. }
  241. /* L20: */
  242. }
  243. /* Use unblocked code to reduce the last or only block */
  244. _starpu_dsytd2_(uplo, &kk, &a[a_offset], lda, &d__[1], &e[1], &tau[1], &iinfo);
  245. } else {
  246. /* Reduce the lower triangle of A */
  247. i__2 = *n - nx;
  248. i__1 = nb;
  249. for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
  250. /* Reduce columns i:i+nb-1 to tridiagonal form and form the */
  251. /* matrix W which is needed to update the unreduced part of */
  252. /* the matrix */
  253. i__3 = *n - i__ + 1;
  254. _starpu_dlatrd_(uplo, &i__3, &nb, &a[i__ + i__ * a_dim1], lda, &e[i__], &
  255. tau[i__], &work[1], &ldwork);
  256. /* Update the unreduced submatrix A(i+ib:n,i+ib:n), using */
  257. /* an update of the form: A := A - V*W' - W*V' */
  258. i__3 = *n - i__ - nb + 1;
  259. _starpu_dsyr2k_(uplo, "No transpose", &i__3, &nb, &c_b22, &a[i__ + nb +
  260. i__ * a_dim1], lda, &work[nb + 1], &ldwork, &c_b23, &a[
  261. i__ + nb + (i__ + nb) * a_dim1], lda);
  262. /* Copy subdiagonal elements back into A, and diagonal */
  263. /* elements into D */
  264. i__3 = i__ + nb - 1;
  265. for (j = i__; j <= i__3; ++j) {
  266. a[j + 1 + j * a_dim1] = e[j];
  267. d__[j] = a[j + j * a_dim1];
  268. /* L30: */
  269. }
  270. /* L40: */
  271. }
  272. /* Use unblocked code to reduce the last or only block */
  273. i__1 = *n - i__ + 1;
  274. _starpu_dsytd2_(uplo, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__],
  275. &tau[i__], &iinfo);
  276. }
  277. work[1] = (doublereal) lwkopt;
  278. return 0;
  279. /* End of DSYTRD */
  280. } /* _starpu_dsytrd_ */