dsbevd.c 11 KB

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