dsyevd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /* dsyevd.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__0 = 0;
  17. static doublereal c_b17 = 1.;
  18. /* Subroutine */ int _starpu_dsyevd_(char *jobz, char *uplo, integer *n, doublereal *
  19. a, integer *lda, doublereal *w, doublereal *work, integer *lwork,
  20. integer *iwork, integer *liwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, i__1, i__2, i__3;
  24. doublereal d__1;
  25. /* Builtin functions */
  26. double sqrt(doublereal);
  27. /* Local variables */
  28. doublereal eps;
  29. integer inde;
  30. doublereal anrm, rmin, rmax;
  31. integer lopt;
  32. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  33. integer *);
  34. doublereal sigma;
  35. extern logical _starpu_lsame_(char *, char *);
  36. integer iinfo, lwmin, liopt;
  37. logical lower, wantz;
  38. integer indwk2, llwrk2;
  39. extern doublereal _starpu_dlamch_(char *);
  40. integer iscale;
  41. extern /* Subroutine */ int _starpu_dlascl_(char *, integer *, integer *,
  42. doublereal *, doublereal *, integer *, integer *, doublereal *,
  43. integer *, integer *), _starpu_dstedc_(char *, integer *,
  44. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  45. integer *, integer *, integer *, integer *), _starpu_dlacpy_(
  46. char *, integer *, integer *, doublereal *, integer *, doublereal
  47. *, integer *);
  48. doublereal safmin;
  49. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  50. integer *, integer *);
  51. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  52. doublereal bignum;
  53. integer indtau;
  54. extern /* Subroutine */ int _starpu_dsterf_(integer *, doublereal *, doublereal *,
  55. integer *);
  56. extern doublereal _starpu_dlansy_(char *, char *, integer *, doublereal *,
  57. integer *, doublereal *);
  58. integer indwrk, liwmin;
  59. extern /* Subroutine */ int _starpu_dormtr_(char *, char *, char *, integer *,
  60. integer *, doublereal *, integer *, doublereal *, doublereal *,
  61. integer *, doublereal *, integer *, integer *), _starpu_dsytrd_(char *, integer *, doublereal *, integer *,
  62. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  63. integer *);
  64. integer llwork;
  65. doublereal smlnum;
  66. logical lquery;
  67. /* -- LAPACK driver routine (version 3.2) -- */
  68. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  69. /* November 2006 */
  70. /* .. Scalar Arguments .. */
  71. /* .. */
  72. /* .. Array Arguments .. */
  73. /* .. */
  74. /* Purpose */
  75. /* ======= */
  76. /* DSYEVD computes all eigenvalues and, optionally, eigenvectors of a */
  77. /* real symmetric matrix A. If eigenvectors are desired, it uses a */
  78. /* divide and conquer algorithm. */
  79. /* The divide and conquer algorithm makes very mild assumptions about */
  80. /* floating point arithmetic. It will work on machines with a guard */
  81. /* digit in add/subtract, or on those binary machines without guard */
  82. /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
  83. /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */
  84. /* without guard digits, but we know of none. */
  85. /* Because of large use of BLAS of level 3, DSYEVD needs N**2 more */
  86. /* workspace than DSYEVX. */
  87. /* Arguments */
  88. /* ========= */
  89. /* JOBZ (input) CHARACTER*1 */
  90. /* = 'N': Compute eigenvalues only; */
  91. /* = 'V': Compute eigenvalues and eigenvectors. */
  92. /* UPLO (input) CHARACTER*1 */
  93. /* = 'U': Upper triangle of A is stored; */
  94. /* = 'L': Lower triangle of A is stored. */
  95. /* N (input) INTEGER */
  96. /* The order of the matrix A. N >= 0. */
  97. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  98. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  99. /* leading N-by-N upper triangular part of A contains the */
  100. /* upper triangular part of the matrix A. If UPLO = 'L', */
  101. /* the leading N-by-N lower triangular part of A contains */
  102. /* the lower triangular part of the matrix A. */
  103. /* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
  104. /* orthonormal eigenvectors of the matrix A. */
  105. /* If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') */
  106. /* or the upper triangle (if UPLO='U') of A, including the */
  107. /* diagonal, is destroyed. */
  108. /* LDA (input) INTEGER */
  109. /* The leading dimension of the array A. LDA >= max(1,N). */
  110. /* W (output) DOUBLE PRECISION array, dimension (N) */
  111. /* If INFO = 0, the eigenvalues in ascending order. */
  112. /* WORK (workspace/output) DOUBLE PRECISION array, */
  113. /* dimension (LWORK) */
  114. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  115. /* LWORK (input) INTEGER */
  116. /* The dimension of the array WORK. */
  117. /* If N <= 1, LWORK must be at least 1. */
  118. /* If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1. */
  119. /* If JOBZ = 'V' and N > 1, LWORK must be at least */
  120. /* 1 + 6*N + 2*N**2. */
  121. /* If LWORK = -1, then a workspace query is assumed; the routine */
  122. /* only calculates the optimal sizes of the WORK and IWORK */
  123. /* arrays, returns these values as the first entries of the WORK */
  124. /* and IWORK arrays, and no error message related to LWORK or */
  125. /* LIWORK is issued by XERBLA. */
  126. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  127. /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  128. /* LIWORK (input) INTEGER */
  129. /* The dimension of the array IWORK. */
  130. /* If N <= 1, LIWORK must be at least 1. */
  131. /* If JOBZ = 'N' and N > 1, LIWORK must be at least 1. */
  132. /* If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N. */
  133. /* If LIWORK = -1, then a workspace query is assumed; the */
  134. /* routine only calculates the optimal sizes of the WORK and */
  135. /* IWORK arrays, returns these values as the first entries of */
  136. /* the WORK and IWORK arrays, and no error message related to */
  137. /* LWORK or LIWORK is issued by XERBLA. */
  138. /* INFO (output) INTEGER */
  139. /* = 0: successful exit */
  140. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  141. /* > 0: if INFO = i and JOBZ = 'N', then the algorithm failed */
  142. /* to converge; i off-diagonal elements of an intermediate */
  143. /* tridiagonal form did not converge to zero; */
  144. /* if INFO = i and JOBZ = 'V', then the algorithm failed */
  145. /* to compute an eigenvalue while working on the submatrix */
  146. /* lying in rows and columns INFO/(N+1) through */
  147. /* mod(INFO,N+1). */
  148. /* Further Details */
  149. /* =============== */
  150. /* Based on contributions by */
  151. /* Jeff Rutter, Computer Science Division, University of California */
  152. /* at Berkeley, USA */
  153. /* Modified by Francoise Tisseur, University of Tennessee. */
  154. /* Modified description of INFO. Sven, 16 Feb 05. */
  155. /* ===================================================================== */
  156. /* .. Parameters .. */
  157. /* .. */
  158. /* .. Local Scalars .. */
  159. /* .. */
  160. /* .. External Functions .. */
  161. /* .. */
  162. /* .. External Subroutines .. */
  163. /* .. */
  164. /* .. Intrinsic Functions .. */
  165. /* .. */
  166. /* .. Executable Statements .. */
  167. /* Test the input parameters. */
  168. /* Parameter adjustments */
  169. a_dim1 = *lda;
  170. a_offset = 1 + a_dim1;
  171. a -= a_offset;
  172. --w;
  173. --work;
  174. --iwork;
  175. /* Function Body */
  176. wantz = _starpu_lsame_(jobz, "V");
  177. lower = _starpu_lsame_(uplo, "L");
  178. lquery = *lwork == -1 || *liwork == -1;
  179. *info = 0;
  180. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  181. *info = -1;
  182. } else if (! (lower || _starpu_lsame_(uplo, "U"))) {
  183. *info = -2;
  184. } else if (*n < 0) {
  185. *info = -3;
  186. } else if (*lda < max(1,*n)) {
  187. *info = -5;
  188. }
  189. if (*info == 0) {
  190. if (*n <= 1) {
  191. liwmin = 1;
  192. lwmin = 1;
  193. lopt = lwmin;
  194. liopt = liwmin;
  195. } else {
  196. if (wantz) {
  197. liwmin = *n * 5 + 3;
  198. /* Computing 2nd power */
  199. i__1 = *n;
  200. lwmin = *n * 6 + 1 + (i__1 * i__1 << 1);
  201. } else {
  202. liwmin = 1;
  203. lwmin = (*n << 1) + 1;
  204. }
  205. /* Computing MAX */
  206. i__1 = lwmin, i__2 = (*n << 1) + _starpu_ilaenv_(&c__1, "DSYTRD", uplo, n,
  207. &c_n1, &c_n1, &c_n1);
  208. lopt = max(i__1,i__2);
  209. liopt = liwmin;
  210. }
  211. work[1] = (doublereal) lopt;
  212. iwork[1] = liopt;
  213. if (*lwork < lwmin && ! lquery) {
  214. *info = -8;
  215. } else if (*liwork < liwmin && ! lquery) {
  216. *info = -10;
  217. }
  218. }
  219. if (*info != 0) {
  220. i__1 = -(*info);
  221. _starpu_xerbla_("DSYEVD", &i__1);
  222. return 0;
  223. } else if (lquery) {
  224. return 0;
  225. }
  226. /* Quick return if possible */
  227. if (*n == 0) {
  228. return 0;
  229. }
  230. if (*n == 1) {
  231. w[1] = a[a_dim1 + 1];
  232. if (wantz) {
  233. a[a_dim1 + 1] = 1.;
  234. }
  235. return 0;
  236. }
  237. /* Get machine constants. */
  238. safmin = _starpu_dlamch_("Safe minimum");
  239. eps = _starpu_dlamch_("Precision");
  240. smlnum = safmin / eps;
  241. bignum = 1. / smlnum;
  242. rmin = sqrt(smlnum);
  243. rmax = sqrt(bignum);
  244. /* Scale matrix to allowable range, if necessary. */
  245. anrm = _starpu_dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
  246. iscale = 0;
  247. if (anrm > 0. && anrm < rmin) {
  248. iscale = 1;
  249. sigma = rmin / anrm;
  250. } else if (anrm > rmax) {
  251. iscale = 1;
  252. sigma = rmax / anrm;
  253. }
  254. if (iscale == 1) {
  255. _starpu_dlascl_(uplo, &c__0, &c__0, &c_b17, &sigma, n, n, &a[a_offset], lda,
  256. info);
  257. }
  258. /* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
  259. inde = 1;
  260. indtau = inde + *n;
  261. indwrk = indtau + *n;
  262. llwork = *lwork - indwrk + 1;
  263. indwk2 = indwrk + *n * *n;
  264. llwrk2 = *lwork - indwk2 + 1;
  265. _starpu_dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], &
  266. work[indwrk], &llwork, &iinfo);
  267. lopt = (integer) ((*n << 1) + work[indwrk]);
  268. /* For eigenvalues only, call DSTERF. For eigenvectors, first call */
  269. /* DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the */
  270. /* tridiagonal matrix, then call DORMTR to multiply it by the */
  271. /* Householder transformations stored in A. */
  272. if (! wantz) {
  273. _starpu_dsterf_(n, &w[1], &work[inde], info);
  274. } else {
  275. _starpu_dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], &
  276. llwrk2, &iwork[1], liwork, info);
  277. _starpu_dormtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[
  278. indwrk], n, &work[indwk2], &llwrk2, &iinfo);
  279. _starpu_dlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda);
  280. /* Computing MAX */
  281. /* Computing 2nd power */
  282. i__3 = *n;
  283. i__1 = lopt, i__2 = *n * 6 + 1 + (i__3 * i__3 << 1);
  284. lopt = max(i__1,i__2);
  285. }
  286. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  287. if (iscale == 1) {
  288. d__1 = 1. / sigma;
  289. _starpu_dscal_(n, &d__1, &w[1], &c__1);
  290. }
  291. work[1] = (doublereal) lopt;
  292. iwork[1] = liopt;
  293. return 0;
  294. /* End of DSYEVD */
  295. } /* _starpu_dsyevd_ */