dspevd.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* dspevd.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. /* Subroutine */ int _starpu_dspevd_(char *jobz, char *uplo, integer *n, doublereal *
  16. ap, doublereal *w, doublereal *z__, integer *ldz, doublereal *work,
  17. integer *lwork, integer *iwork, integer *liwork, integer *info)
  18. {
  19. /* System generated locals */
  20. integer z_dim1, z_offset, i__1;
  21. doublereal d__1;
  22. /* Builtin functions */
  23. double sqrt(doublereal);
  24. /* Local variables */
  25. doublereal eps;
  26. integer inde;
  27. doublereal anrm, rmin, rmax;
  28. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  29. integer *);
  30. doublereal sigma;
  31. extern logical _starpu_lsame_(char *, char *);
  32. integer iinfo, lwmin;
  33. logical wantz;
  34. extern doublereal _starpu_dlamch_(char *);
  35. integer iscale;
  36. extern /* Subroutine */ int _starpu_dstedc_(char *, integer *, doublereal *,
  37. doublereal *, doublereal *, integer *, doublereal *, integer *,
  38. integer *, integer *, integer *);
  39. doublereal safmin;
  40. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  41. doublereal bignum;
  42. extern doublereal _starpu_dlansp_(char *, char *, integer *, doublereal *,
  43. doublereal *);
  44. integer indtau;
  45. extern /* Subroutine */ int _starpu_dsterf_(integer *, doublereal *, doublereal *,
  46. integer *);
  47. integer indwrk, liwmin;
  48. extern /* Subroutine */ int _starpu_dsptrd_(char *, integer *, doublereal *,
  49. doublereal *, doublereal *, doublereal *, integer *),
  50. _starpu_dopmtr_(char *, char *, char *, integer *, integer *, doublereal *
  51. , doublereal *, doublereal *, integer *, doublereal *, integer *);
  52. integer llwork;
  53. doublereal smlnum;
  54. logical lquery;
  55. /* -- LAPACK driver routine (version 3.2) -- */
  56. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  57. /* November 2006 */
  58. /* .. Scalar Arguments .. */
  59. /* .. */
  60. /* .. Array Arguments .. */
  61. /* .. */
  62. /* Purpose */
  63. /* ======= */
  64. /* DSPEVD computes all the eigenvalues and, optionally, eigenvectors */
  65. /* of a real symmetric matrix A in packed storage. If eigenvectors are */
  66. /* desired, it uses a divide and conquer algorithm. */
  67. /* The divide and conquer algorithm makes very mild assumptions about */
  68. /* floating point arithmetic. It will work on machines with a guard */
  69. /* digit in add/subtract, or on those binary machines without guard */
  70. /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
  71. /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */
  72. /* without guard digits, but we know of none. */
  73. /* Arguments */
  74. /* ========= */
  75. /* JOBZ (input) CHARACTER*1 */
  76. /* = 'N': Compute eigenvalues only; */
  77. /* = 'V': Compute eigenvalues and eigenvectors. */
  78. /* UPLO (input) CHARACTER*1 */
  79. /* = 'U': Upper triangle of A is stored; */
  80. /* = 'L': Lower triangle of A is stored. */
  81. /* N (input) INTEGER */
  82. /* The order of the matrix A. N >= 0. */
  83. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  84. /* On entry, the upper or lower triangle of the symmetric matrix */
  85. /* A, packed columnwise in a linear array. The j-th column of A */
  86. /* is stored in the array AP as follows: */
  87. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  88. /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
  89. /* On exit, AP is overwritten by values generated during the */
  90. /* reduction to tridiagonal form. If UPLO = 'U', the diagonal */
  91. /* and first superdiagonal of the tridiagonal matrix T overwrite */
  92. /* the corresponding elements of A, and if UPLO = 'L', the */
  93. /* diagonal and first subdiagonal of T overwrite the */
  94. /* corresponding elements of A. */
  95. /* W (output) DOUBLE PRECISION array, dimension (N) */
  96. /* If INFO = 0, the eigenvalues in ascending order. */
  97. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */
  98. /* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
  99. /* eigenvectors of the matrix A, with the i-th column of Z */
  100. /* holding the eigenvector associated with W(i). */
  101. /* If JOBZ = 'N', then Z is not referenced. */
  102. /* LDZ (input) INTEGER */
  103. /* The leading dimension of the array Z. LDZ >= 1, and if */
  104. /* JOBZ = 'V', LDZ >= max(1,N). */
  105. /* WORK (workspace/output) DOUBLE PRECISION array, */
  106. /* dimension (LWORK) */
  107. /* On exit, if INFO = 0, WORK(1) returns the required LWORK. */
  108. /* LWORK (input) INTEGER */
  109. /* The dimension of the array WORK. */
  110. /* If N <= 1, LWORK must be at least 1. */
  111. /* If JOBZ = 'N' and N > 1, LWORK must be at least 2*N. */
  112. /* If JOBZ = 'V' and N > 1, LWORK must be at least */
  113. /* 1 + 6*N + N**2. */
  114. /* If LWORK = -1, then a workspace query is assumed; the routine */
  115. /* only calculates the required sizes of the WORK and IWORK */
  116. /* arrays, returns these values as the first entries of the WORK */
  117. /* and IWORK arrays, and no error message related to LWORK or */
  118. /* LIWORK is issued by XERBLA. */
  119. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  120. /* On exit, if INFO = 0, IWORK(1) returns the required LIWORK. */
  121. /* LIWORK (input) INTEGER */
  122. /* The dimension of the array IWORK. */
  123. /* If JOBZ = 'N' or N <= 1, LIWORK must be at least 1. */
  124. /* If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N. */
  125. /* If LIWORK = -1, then a workspace query is assumed; the */
  126. /* routine only calculates the required sizes of the WORK and */
  127. /* IWORK arrays, returns these values as the first entries of */
  128. /* the WORK and IWORK arrays, and no error message related to */
  129. /* LWORK or LIWORK is issued by XERBLA. */
  130. /* INFO (output) INTEGER */
  131. /* = 0: successful exit */
  132. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  133. /* > 0: if INFO = i, the algorithm failed to converge; i */
  134. /* off-diagonal elements of an intermediate tridiagonal */
  135. /* form did not converge to zero. */
  136. /* ===================================================================== */
  137. /* .. Parameters .. */
  138. /* .. */
  139. /* .. Local Scalars .. */
  140. /* .. */
  141. /* .. External Functions .. */
  142. /* .. */
  143. /* .. External Subroutines .. */
  144. /* .. */
  145. /* .. Intrinsic Functions .. */
  146. /* .. */
  147. /* .. Executable Statements .. */
  148. /* Test the input parameters. */
  149. /* Parameter adjustments */
  150. --ap;
  151. --w;
  152. z_dim1 = *ldz;
  153. z_offset = 1 + z_dim1;
  154. z__ -= z_offset;
  155. --work;
  156. --iwork;
  157. /* Function Body */
  158. wantz = _starpu_lsame_(jobz, "V");
  159. lquery = *lwork == -1 || *liwork == -1;
  160. *info = 0;
  161. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  162. *info = -1;
  163. } else if (! (_starpu_lsame_(uplo, "U") || _starpu_lsame_(uplo,
  164. "L"))) {
  165. *info = -2;
  166. } else if (*n < 0) {
  167. *info = -3;
  168. } else if (*ldz < 1 || wantz && *ldz < *n) {
  169. *info = -7;
  170. }
  171. if (*info == 0) {
  172. if (*n <= 1) {
  173. liwmin = 1;
  174. lwmin = 1;
  175. } else {
  176. if (wantz) {
  177. liwmin = *n * 5 + 3;
  178. /* Computing 2nd power */
  179. i__1 = *n;
  180. lwmin = *n * 6 + 1 + i__1 * i__1;
  181. } else {
  182. liwmin = 1;
  183. lwmin = *n << 1;
  184. }
  185. }
  186. iwork[1] = liwmin;
  187. work[1] = (doublereal) lwmin;
  188. if (*lwork < lwmin && ! lquery) {
  189. *info = -9;
  190. } else if (*liwork < liwmin && ! lquery) {
  191. *info = -11;
  192. }
  193. }
  194. if (*info != 0) {
  195. i__1 = -(*info);
  196. _starpu_xerbla_("DSPEVD", &i__1);
  197. return 0;
  198. } else if (lquery) {
  199. return 0;
  200. }
  201. /* Quick return if possible */
  202. if (*n == 0) {
  203. return 0;
  204. }
  205. if (*n == 1) {
  206. w[1] = ap[1];
  207. if (wantz) {
  208. z__[z_dim1 + 1] = 1.;
  209. }
  210. return 0;
  211. }
  212. /* Get machine constants. */
  213. safmin = _starpu_dlamch_("Safe minimum");
  214. eps = _starpu_dlamch_("Precision");
  215. smlnum = safmin / eps;
  216. bignum = 1. / smlnum;
  217. rmin = sqrt(smlnum);
  218. rmax = sqrt(bignum);
  219. /* Scale matrix to allowable range, if necessary. */
  220. anrm = _starpu_dlansp_("M", uplo, n, &ap[1], &work[1]);
  221. iscale = 0;
  222. if (anrm > 0. && anrm < rmin) {
  223. iscale = 1;
  224. sigma = rmin / anrm;
  225. } else if (anrm > rmax) {
  226. iscale = 1;
  227. sigma = rmax / anrm;
  228. }
  229. if (iscale == 1) {
  230. i__1 = *n * (*n + 1) / 2;
  231. _starpu_dscal_(&i__1, &sigma, &ap[1], &c__1);
  232. }
  233. /* Call DSPTRD to reduce symmetric packed matrix to tridiagonal form. */
  234. inde = 1;
  235. indtau = inde + *n;
  236. _starpu_dsptrd_(uplo, n, &ap[1], &w[1], &work[inde], &work[indtau], &iinfo);
  237. /* For eigenvalues only, call DSTERF. For eigenvectors, first call */
  238. /* DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the */
  239. /* tridiagonal matrix, then call DOPMTR to multiply it by the */
  240. /* Householder transformations represented in AP. */
  241. if (! wantz) {
  242. _starpu_dsterf_(n, &w[1], &work[inde], info);
  243. } else {
  244. indwrk = indtau + *n;
  245. llwork = *lwork - indwrk + 1;
  246. _starpu_dstedc_("I", n, &w[1], &work[inde], &z__[z_offset], ldz, &work[indwrk]
  247. , &llwork, &iwork[1], liwork, info);
  248. _starpu_dopmtr_("L", uplo, "N", n, n, &ap[1], &work[indtau], &z__[z_offset],
  249. ldz, &work[indwrk], &iinfo);
  250. }
  251. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  252. if (iscale == 1) {
  253. d__1 = 1. / sigma;
  254. _starpu_dscal_(n, &d__1, &w[1], &c__1);
  255. }
  256. work[1] = (doublereal) lwmin;
  257. iwork[1] = liwmin;
  258. return 0;
  259. /* End of DSPEVD */
  260. } /* _starpu_dspevd_ */