dsyev.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* dsyev.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_dsyev_(char *jobz, char *uplo, integer *n, doublereal *a,
  19. integer *lda, doublereal *w, doublereal *work, integer *lwork,
  20. integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, i__1, i__2;
  24. doublereal d__1;
  25. /* Builtin functions */
  26. double sqrt(doublereal);
  27. /* Local variables */
  28. integer nb;
  29. doublereal eps;
  30. integer inde;
  31. doublereal anrm;
  32. integer imax;
  33. doublereal rmin, rmax;
  34. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  35. integer *);
  36. doublereal sigma;
  37. extern logical _starpu_lsame_(char *, char *);
  38. integer iinfo;
  39. logical lower, wantz;
  40. extern doublereal _starpu_dlamch_(char *);
  41. integer iscale;
  42. extern /* Subroutine */ int _starpu_dlascl_(char *, integer *, integer *,
  43. doublereal *, doublereal *, integer *, integer *, doublereal *,
  44. integer *, integer *);
  45. doublereal safmin;
  46. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  47. integer *, integer *);
  48. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  49. doublereal bignum;
  50. integer indtau;
  51. extern /* Subroutine */ int _starpu_dsterf_(integer *, doublereal *, doublereal *,
  52. integer *);
  53. extern doublereal _starpu_dlansy_(char *, char *, integer *, doublereal *,
  54. integer *, doublereal *);
  55. integer indwrk;
  56. extern /* Subroutine */ int _starpu_dorgtr_(char *, integer *, doublereal *,
  57. integer *, doublereal *, doublereal *, integer *, integer *), _starpu_dsteqr_(char *, integer *, doublereal *, doublereal *,
  58. doublereal *, integer *, doublereal *, integer *),
  59. _starpu_dsytrd_(char *, integer *, doublereal *, integer *, doublereal *,
  60. doublereal *, doublereal *, doublereal *, integer *, integer *);
  61. integer llwork;
  62. doublereal smlnum;
  63. integer lwkopt;
  64. logical lquery;
  65. /* -- LAPACK driver routine (version 3.2) -- */
  66. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  67. /* November 2006 */
  68. /* .. Scalar Arguments .. */
  69. /* .. */
  70. /* .. Array Arguments .. */
  71. /* .. */
  72. /* Purpose */
  73. /* ======= */
  74. /* DSYEV computes all eigenvalues and, optionally, eigenvectors of a */
  75. /* real symmetric matrix A. */
  76. /* Arguments */
  77. /* ========= */
  78. /* JOBZ (input) CHARACTER*1 */
  79. /* = 'N': Compute eigenvalues only; */
  80. /* = 'V': Compute eigenvalues and eigenvectors. */
  81. /* UPLO (input) CHARACTER*1 */
  82. /* = 'U': Upper triangle of A is stored; */
  83. /* = 'L': Lower triangle of A is stored. */
  84. /* N (input) INTEGER */
  85. /* The order of the matrix A. N >= 0. */
  86. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  87. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  88. /* leading N-by-N upper triangular part of A contains the */
  89. /* upper triangular part of the matrix A. If UPLO = 'L', */
  90. /* the leading N-by-N lower triangular part of A contains */
  91. /* the lower triangular part of the matrix A. */
  92. /* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
  93. /* orthonormal eigenvectors of the matrix A. */
  94. /* If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') */
  95. /* or the upper triangle (if UPLO='U') of A, including the */
  96. /* diagonal, is destroyed. */
  97. /* LDA (input) INTEGER */
  98. /* The leading dimension of the array A. LDA >= max(1,N). */
  99. /* W (output) DOUBLE PRECISION array, dimension (N) */
  100. /* If INFO = 0, the eigenvalues in ascending order. */
  101. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  102. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  103. /* LWORK (input) INTEGER */
  104. /* The length of the array WORK. LWORK >= max(1,3*N-1). */
  105. /* For optimal efficiency, LWORK >= (NB+2)*N, */
  106. /* where NB is the blocksize for DSYTRD returned by ILAENV. */
  107. /* If LWORK = -1, then a workspace query is assumed; the routine */
  108. /* only calculates the optimal size of the WORK array, returns */
  109. /* this value as the first entry of the WORK array, and no error */
  110. /* message related to LWORK is issued by XERBLA. */
  111. /* INFO (output) INTEGER */
  112. /* = 0: successful exit */
  113. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  114. /* > 0: if INFO = i, the algorithm failed to converge; i */
  115. /* off-diagonal elements of an intermediate tridiagonal */
  116. /* form did not converge to zero. */
  117. /* ===================================================================== */
  118. /* .. Parameters .. */
  119. /* .. */
  120. /* .. Local Scalars .. */
  121. /* .. */
  122. /* .. External Functions .. */
  123. /* .. */
  124. /* .. External Subroutines .. */
  125. /* .. */
  126. /* .. Intrinsic Functions .. */
  127. /* .. */
  128. /* .. Executable Statements .. */
  129. /* Test the input parameters. */
  130. /* Parameter adjustments */
  131. a_dim1 = *lda;
  132. a_offset = 1 + a_dim1;
  133. a -= a_offset;
  134. --w;
  135. --work;
  136. /* Function Body */
  137. wantz = _starpu_lsame_(jobz, "V");
  138. lower = _starpu_lsame_(uplo, "L");
  139. lquery = *lwork == -1;
  140. *info = 0;
  141. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  142. *info = -1;
  143. } else if (! (lower || _starpu_lsame_(uplo, "U"))) {
  144. *info = -2;
  145. } else if (*n < 0) {
  146. *info = -3;
  147. } else if (*lda < max(1,*n)) {
  148. *info = -5;
  149. }
  150. if (*info == 0) {
  151. nb = _starpu_ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  152. /* Computing MAX */
  153. i__1 = 1, i__2 = (nb + 2) * *n;
  154. lwkopt = max(i__1,i__2);
  155. work[1] = (doublereal) lwkopt;
  156. /* Computing MAX */
  157. i__1 = 1, i__2 = *n * 3 - 1;
  158. if (*lwork < max(i__1,i__2) && ! lquery) {
  159. *info = -8;
  160. }
  161. }
  162. if (*info != 0) {
  163. i__1 = -(*info);
  164. _starpu_xerbla_("DSYEV ", &i__1);
  165. return 0;
  166. } else if (lquery) {
  167. return 0;
  168. }
  169. /* Quick return if possible */
  170. if (*n == 0) {
  171. return 0;
  172. }
  173. if (*n == 1) {
  174. w[1] = a[a_dim1 + 1];
  175. work[1] = 2.;
  176. if (wantz) {
  177. a[a_dim1 + 1] = 1.;
  178. }
  179. return 0;
  180. }
  181. /* Get machine constants. */
  182. safmin = _starpu_dlamch_("Safe minimum");
  183. eps = _starpu_dlamch_("Precision");
  184. smlnum = safmin / eps;
  185. bignum = 1. / smlnum;
  186. rmin = sqrt(smlnum);
  187. rmax = sqrt(bignum);
  188. /* Scale matrix to allowable range, if necessary. */
  189. anrm = _starpu_dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
  190. iscale = 0;
  191. if (anrm > 0. && anrm < rmin) {
  192. iscale = 1;
  193. sigma = rmin / anrm;
  194. } else if (anrm > rmax) {
  195. iscale = 1;
  196. sigma = rmax / anrm;
  197. }
  198. if (iscale == 1) {
  199. _starpu_dlascl_(uplo, &c__0, &c__0, &c_b17, &sigma, n, n, &a[a_offset], lda,
  200. info);
  201. }
  202. /* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
  203. inde = 1;
  204. indtau = inde + *n;
  205. indwrk = indtau + *n;
  206. llwork = *lwork - indwrk + 1;
  207. _starpu_dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], &
  208. work[indwrk], &llwork, &iinfo);
  209. /* For eigenvalues only, call DSTERF. For eigenvectors, first call */
  210. /* DORGTR to generate the orthogonal matrix, then call DSTEQR. */
  211. if (! wantz) {
  212. _starpu_dsterf_(n, &w[1], &work[inde], info);
  213. } else {
  214. _starpu_dorgtr_(uplo, n, &a[a_offset], lda, &work[indtau], &work[indwrk], &
  215. llwork, &iinfo);
  216. _starpu_dsteqr_(jobz, n, &w[1], &work[inde], &a[a_offset], lda, &work[indtau],
  217. info);
  218. }
  219. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  220. if (iscale == 1) {
  221. if (*info == 0) {
  222. imax = *n;
  223. } else {
  224. imax = *info - 1;
  225. }
  226. d__1 = 1. / sigma;
  227. _starpu_dscal_(&imax, &d__1, &w[1], &c__1);
  228. }
  229. /* Set WORK(1) to optimal workspace size. */
  230. work[1] = (doublereal) lwkopt;
  231. return 0;
  232. /* End of DSYEV */
  233. } /* _starpu_dsyev_ */