dstevd.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* dstevd.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_dstevd_(char *jobz, integer *n, doublereal *d__,
  16. doublereal *e, 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, rmin, rmax, tnrm;
  26. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  27. integer *);
  28. doublereal sigma;
  29. extern logical _starpu_lsame_(char *, char *);
  30. integer lwmin;
  31. logical wantz;
  32. extern doublereal _starpu_dlamch_(char *);
  33. integer iscale;
  34. extern /* Subroutine */ int _starpu_dstedc_(char *, integer *, doublereal *,
  35. doublereal *, doublereal *, integer *, doublereal *, integer *,
  36. integer *, integer *, integer *);
  37. doublereal safmin;
  38. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  39. doublereal bignum;
  40. extern doublereal _starpu_dlanst_(char *, integer *, doublereal *, doublereal *);
  41. extern /* Subroutine */ int _starpu_dsterf_(integer *, doublereal *, doublereal *,
  42. integer *);
  43. integer liwmin;
  44. doublereal smlnum;
  45. logical lquery;
  46. /* -- LAPACK driver routine (version 3.2) -- */
  47. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  48. /* November 2006 */
  49. /* .. Scalar Arguments .. */
  50. /* .. */
  51. /* .. Array Arguments .. */
  52. /* .. */
  53. /* Purpose */
  54. /* ======= */
  55. /* DSTEVD computes all eigenvalues and, optionally, eigenvectors of a */
  56. /* real symmetric tridiagonal matrix. If eigenvectors are desired, it */
  57. /* uses a divide and conquer algorithm. */
  58. /* The divide and conquer algorithm makes very mild assumptions about */
  59. /* floating point arithmetic. It will work on machines with a guard */
  60. /* digit in add/subtract, or on those binary machines without guard */
  61. /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
  62. /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */
  63. /* without guard digits, but we know of none. */
  64. /* Arguments */
  65. /* ========= */
  66. /* JOBZ (input) CHARACTER*1 */
  67. /* = 'N': Compute eigenvalues only; */
  68. /* = 'V': Compute eigenvalues and eigenvectors. */
  69. /* N (input) INTEGER */
  70. /* The order of the matrix. N >= 0. */
  71. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  72. /* On entry, the n diagonal elements of the tridiagonal matrix */
  73. /* A. */
  74. /* On exit, if INFO = 0, the eigenvalues in ascending order. */
  75. /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
  76. /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
  77. /* matrix A, stored in elements 1 to N-1 of E. */
  78. /* On exit, the contents of E are destroyed. */
  79. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */
  80. /* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
  81. /* eigenvectors of the matrix A, with the i-th column of Z */
  82. /* holding the eigenvector associated with D(i). */
  83. /* If JOBZ = 'N', then Z is not referenced. */
  84. /* LDZ (input) INTEGER */
  85. /* The leading dimension of the array Z. LDZ >= 1, and if */
  86. /* JOBZ = 'V', LDZ >= max(1,N). */
  87. /* WORK (workspace/output) DOUBLE PRECISION array, */
  88. /* dimension (LWORK) */
  89. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  90. /* LWORK (input) INTEGER */
  91. /* The dimension of the array WORK. */
  92. /* If JOBZ = 'N' or N <= 1 then LWORK must be at least 1. */
  93. /* If JOBZ = 'V' and N > 1 then LWORK must be at least */
  94. /* ( 1 + 4*N + N**2 ). */
  95. /* If LWORK = -1, then a workspace query is assumed; the routine */
  96. /* only calculates the optimal sizes of the WORK and IWORK */
  97. /* arrays, returns these values as the first entries of the WORK */
  98. /* and IWORK arrays, and no error message related to LWORK or */
  99. /* LIWORK is issued by XERBLA. */
  100. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  101. /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  102. /* LIWORK (input) INTEGER */
  103. /* The dimension of the array IWORK. */
  104. /* If JOBZ = 'N' or N <= 1 then LIWORK must be at least 1. */
  105. /* If JOBZ = 'V' and N > 1 then LIWORK must be at least 3+5*N. */
  106. /* If LIWORK = -1, then a workspace query is assumed; the */
  107. /* routine only calculates the optimal sizes of the WORK and */
  108. /* IWORK arrays, returns these values as the first entries of */
  109. /* the WORK and IWORK arrays, and no error message related to */
  110. /* LWORK or LIWORK 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 E did not converge to zero. */
  116. /* ===================================================================== */
  117. /* .. Parameters .. */
  118. /* .. */
  119. /* .. Local Scalars .. */
  120. /* .. */
  121. /* .. External Functions .. */
  122. /* .. */
  123. /* .. External Subroutines .. */
  124. /* .. */
  125. /* .. Intrinsic Functions .. */
  126. /* .. */
  127. /* .. Executable Statements .. */
  128. /* Test the input parameters. */
  129. /* Parameter adjustments */
  130. --d__;
  131. --e;
  132. z_dim1 = *ldz;
  133. z_offset = 1 + z_dim1;
  134. z__ -= z_offset;
  135. --work;
  136. --iwork;
  137. /* Function Body */
  138. wantz = _starpu_lsame_(jobz, "V");
  139. lquery = *lwork == -1 || *liwork == -1;
  140. *info = 0;
  141. liwmin = 1;
  142. lwmin = 1;
  143. if (*n > 1 && wantz) {
  144. /* Computing 2nd power */
  145. i__1 = *n;
  146. lwmin = (*n << 2) + 1 + i__1 * i__1;
  147. liwmin = *n * 5 + 3;
  148. }
  149. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  150. *info = -1;
  151. } else if (*n < 0) {
  152. *info = -2;
  153. } else if (*ldz < 1 || wantz && *ldz < *n) {
  154. *info = -6;
  155. }
  156. if (*info == 0) {
  157. work[1] = (doublereal) lwmin;
  158. iwork[1] = liwmin;
  159. if (*lwork < lwmin && ! lquery) {
  160. *info = -8;
  161. } else if (*liwork < liwmin && ! lquery) {
  162. *info = -10;
  163. }
  164. }
  165. if (*info != 0) {
  166. i__1 = -(*info);
  167. _starpu_xerbla_("DSTEVD", &i__1);
  168. return 0;
  169. } else if (lquery) {
  170. return 0;
  171. }
  172. /* Quick return if possible */
  173. if (*n == 0) {
  174. return 0;
  175. }
  176. if (*n == 1) {
  177. if (wantz) {
  178. z__[z_dim1 + 1] = 1.;
  179. }
  180. return 0;
  181. }
  182. /* Get machine constants. */
  183. safmin = _starpu_dlamch_("Safe minimum");
  184. eps = _starpu_dlamch_("Precision");
  185. smlnum = safmin / eps;
  186. bignum = 1. / smlnum;
  187. rmin = sqrt(smlnum);
  188. rmax = sqrt(bignum);
  189. /* Scale matrix to allowable range, if necessary. */
  190. iscale = 0;
  191. tnrm = _starpu_dlanst_("M", n, &d__[1], &e[1]);
  192. if (tnrm > 0. && tnrm < rmin) {
  193. iscale = 1;
  194. sigma = rmin / tnrm;
  195. } else if (tnrm > rmax) {
  196. iscale = 1;
  197. sigma = rmax / tnrm;
  198. }
  199. if (iscale == 1) {
  200. _starpu_dscal_(n, &sigma, &d__[1], &c__1);
  201. i__1 = *n - 1;
  202. _starpu_dscal_(&i__1, &sigma, &e[1], &c__1);
  203. }
  204. /* For eigenvalues only, call DSTERF. For eigenvalues and */
  205. /* eigenvectors, call DSTEDC. */
  206. if (! wantz) {
  207. _starpu_dsterf_(n, &d__[1], &e[1], info);
  208. } else {
  209. _starpu_dstedc_("I", n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], lwork,
  210. &iwork[1], liwork, info);
  211. }
  212. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  213. if (iscale == 1) {
  214. d__1 = 1. / sigma;
  215. _starpu_dscal_(n, &d__1, &d__[1], &c__1);
  216. }
  217. work[1] = (doublereal) lwmin;
  218. iwork[1] = liwmin;
  219. return 0;
  220. /* End of DSTEVD */
  221. } /* _starpu_dstevd_ */