dsbgvd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /* dsbgvd.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_b12 = 1.;
  15. static doublereal c_b13 = 0.;
  16. /* Subroutine */ int _starpu_dsbgvd_(char *jobz, char *uplo, integer *n, integer *ka,
  17. integer *kb, doublereal *ab, integer *ldab, doublereal *bb, integer *
  18. ldbb, doublereal *w, doublereal *z__, integer *ldz, doublereal *work,
  19. integer *lwork, integer *iwork, integer *liwork, integer *info)
  20. {
  21. /* System generated locals */
  22. integer ab_dim1, ab_offset, bb_dim1, bb_offset, z_dim1, z_offset, i__1;
  23. /* Local variables */
  24. integer inde;
  25. char vect[1];
  26. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  27. integer *, doublereal *, doublereal *, integer *, doublereal *,
  28. integer *, doublereal *, doublereal *, integer *);
  29. extern logical _starpu_lsame_(char *, char *);
  30. integer iinfo, lwmin;
  31. logical upper, wantz;
  32. integer indwk2, llwrk2;
  33. extern /* Subroutine */ int _starpu_dstedc_(char *, integer *, doublereal *,
  34. doublereal *, doublereal *, integer *, doublereal *, integer *,
  35. integer *, integer *, integer *), _starpu_dlacpy_(char *, integer
  36. *, integer *, doublereal *, integer *, doublereal *, integer *), _starpu_xerbla_(char *, integer *), _starpu_dpbstf_(char *,
  37. integer *, integer *, doublereal *, integer *, integer *),
  38. _starpu_dsbtrd_(char *, char *, integer *, integer *, doublereal *,
  39. integer *, doublereal *, doublereal *, doublereal *, integer *,
  40. doublereal *, integer *), _starpu_dsbgst_(char *, char *,
  41. integer *, integer *, integer *, doublereal *, integer *,
  42. doublereal *, integer *, doublereal *, integer *, doublereal *,
  43. integer *), _starpu_dsterf_(integer *, doublereal *,
  44. doublereal *, integer *);
  45. integer indwrk, liwmin;
  46. logical lquery;
  47. /* -- LAPACK driver routine (version 3.2) -- */
  48. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  49. /* November 2006 */
  50. /* .. Scalar Arguments .. */
  51. /* .. */
  52. /* .. Array Arguments .. */
  53. /* .. */
  54. /* Purpose */
  55. /* ======= */
  56. /* DSBGVD computes all the eigenvalues, and optionally, the eigenvectors */
  57. /* of a real generalized symmetric-definite banded eigenproblem, of the */
  58. /* form A*x=(lambda)*B*x. Here A and B are assumed to be symmetric and */
  59. /* banded, and B is also positive definite. If eigenvectors are */
  60. /* desired, it uses a divide and conquer algorithm. */
  61. /* The divide and conquer algorithm makes very mild assumptions about */
  62. /* floating point arithmetic. It will work on machines with a guard */
  63. /* digit in add/subtract, or on those binary machines without guard */
  64. /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
  65. /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */
  66. /* without guard digits, but we know of none. */
  67. /* Arguments */
  68. /* ========= */
  69. /* JOBZ (input) CHARACTER*1 */
  70. /* = 'N': Compute eigenvalues only; */
  71. /* = 'V': Compute eigenvalues and eigenvectors. */
  72. /* UPLO (input) CHARACTER*1 */
  73. /* = 'U': Upper triangles of A and B are stored; */
  74. /* = 'L': Lower triangles of A and B are stored. */
  75. /* N (input) INTEGER */
  76. /* The order of the matrices A and B. N >= 0. */
  77. /* KA (input) INTEGER */
  78. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  79. /* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */
  80. /* KB (input) INTEGER */
  81. /* The number of superdiagonals of the matrix B if UPLO = 'U', */
  82. /* or the number of subdiagonals if UPLO = 'L'. KB >= 0. */
  83. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */
  84. /* On entry, the upper or lower triangle of the symmetric band */
  85. /* matrix A, stored in the first ka+1 rows of the array. The */
  86. /* j-th column of A is stored in the j-th column of the array AB */
  87. /* as follows: */
  88. /* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */
  89. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */
  90. /* On exit, the contents of AB are destroyed. */
  91. /* LDAB (input) INTEGER */
  92. /* The leading dimension of the array AB. LDAB >= KA+1. */
  93. /* BB (input/output) DOUBLE PRECISION array, dimension (LDBB, N) */
  94. /* On entry, the upper or lower triangle of the symmetric band */
  95. /* matrix B, stored in the first kb+1 rows of the array. The */
  96. /* j-th column of B is stored in the j-th column of the array BB */
  97. /* as follows: */
  98. /* if UPLO = 'U', BB(ka+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */
  99. /* if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). */
  100. /* On exit, the factor S from the split Cholesky factorization */
  101. /* B = S**T*S, as returned by DPBSTF. */
  102. /* LDBB (input) INTEGER */
  103. /* The leading dimension of the array BB. LDBB >= KB+1. */
  104. /* W (output) DOUBLE PRECISION array, dimension (N) */
  105. /* If INFO = 0, the eigenvalues in ascending order. */
  106. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */
  107. /* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
  108. /* eigenvectors, with the i-th column of Z holding the */
  109. /* eigenvector associated with W(i). The eigenvectors are */
  110. /* normalized so Z**T*B*Z = I. */
  111. /* If JOBZ = 'N', then Z is not referenced. */
  112. /* LDZ (input) INTEGER */
  113. /* The leading dimension of the array Z. LDZ >= 1, and if */
  114. /* JOBZ = 'V', LDZ >= max(1,N). */
  115. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  116. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  117. /* LWORK (input) INTEGER */
  118. /* The dimension of the array WORK. */
  119. /* If N <= 1, LWORK >= 1. */
  120. /* If JOBZ = 'N' and N > 1, LWORK >= 3*N. */
  121. /* If JOBZ = 'V' and N > 1, LWORK >= 1 + 5*N + 2*N**2. */
  122. /* If LWORK = -1, then a workspace query is assumed; the routine */
  123. /* only calculates the optimal sizes of the WORK and IWORK */
  124. /* arrays, returns these values as the first entries of the WORK */
  125. /* and IWORK arrays, and no error message related to LWORK or */
  126. /* LIWORK is issued by XERBLA. */
  127. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  128. /* On exit, if LIWORK > 0, IWORK(1) returns the optimal LIWORK. */
  129. /* LIWORK (input) INTEGER */
  130. /* The dimension of the array IWORK. */
  131. /* If JOBZ = 'N' or N <= 1, LIWORK >= 1. */
  132. /* If JOBZ = 'V' and N > 1, LIWORK >= 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 i is: */
  142. /* <= N: the algorithm failed to converge: */
  143. /* i off-diagonal elements of an intermediate */
  144. /* tridiagonal form did not converge to zero; */
  145. /* > N: if INFO = N + i, for 1 <= i <= N, then DPBSTF */
  146. /* returned INFO = i: B is not positive definite. */
  147. /* The factorization of B could not be completed and */
  148. /* no eigenvalues or eigenvectors were computed. */
  149. /* Further Details */
  150. /* =============== */
  151. /* Based on contributions by */
  152. /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
  153. /* ===================================================================== */
  154. /* .. Parameters .. */
  155. /* .. */
  156. /* .. Local Scalars .. */
  157. /* .. */
  158. /* .. External Functions .. */
  159. /* .. */
  160. /* .. External Subroutines .. */
  161. /* .. */
  162. /* .. Executable Statements .. */
  163. /* Test the input parameters. */
  164. /* Parameter adjustments */
  165. ab_dim1 = *ldab;
  166. ab_offset = 1 + ab_dim1;
  167. ab -= ab_offset;
  168. bb_dim1 = *ldbb;
  169. bb_offset = 1 + bb_dim1;
  170. bb -= bb_offset;
  171. --w;
  172. z_dim1 = *ldz;
  173. z_offset = 1 + z_dim1;
  174. z__ -= z_offset;
  175. --work;
  176. --iwork;
  177. /* Function Body */
  178. wantz = _starpu_lsame_(jobz, "V");
  179. upper = _starpu_lsame_(uplo, "U");
  180. lquery = *lwork == -1 || *liwork == -1;
  181. *info = 0;
  182. if (*n <= 1) {
  183. liwmin = 1;
  184. lwmin = 1;
  185. } else if (wantz) {
  186. liwmin = *n * 5 + 3;
  187. /* Computing 2nd power */
  188. i__1 = *n;
  189. lwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
  190. } else {
  191. liwmin = 1;
  192. lwmin = *n << 1;
  193. }
  194. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  195. *info = -1;
  196. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  197. *info = -2;
  198. } else if (*n < 0) {
  199. *info = -3;
  200. } else if (*ka < 0) {
  201. *info = -4;
  202. } else if (*kb < 0 || *kb > *ka) {
  203. *info = -5;
  204. } else if (*ldab < *ka + 1) {
  205. *info = -7;
  206. } else if (*ldbb < *kb + 1) {
  207. *info = -9;
  208. } else if (*ldz < 1 || wantz && *ldz < *n) {
  209. *info = -12;
  210. }
  211. if (*info == 0) {
  212. work[1] = (doublereal) lwmin;
  213. iwork[1] = liwmin;
  214. if (*lwork < lwmin && ! lquery) {
  215. *info = -14;
  216. } else if (*liwork < liwmin && ! lquery) {
  217. *info = -16;
  218. }
  219. }
  220. if (*info != 0) {
  221. i__1 = -(*info);
  222. _starpu_xerbla_("DSBGVD", &i__1);
  223. return 0;
  224. } else if (lquery) {
  225. return 0;
  226. }
  227. /* Quick return if possible */
  228. if (*n == 0) {
  229. return 0;
  230. }
  231. /* Form a split Cholesky factorization of B. */
  232. _starpu_dpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info);
  233. if (*info != 0) {
  234. *info = *n + *info;
  235. return 0;
  236. }
  237. /* Transform problem to standard eigenvalue problem. */
  238. inde = 1;
  239. indwrk = inde + *n;
  240. indwk2 = indwrk + *n * *n;
  241. llwrk2 = *lwork - indwk2 + 1;
  242. _starpu_dsbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb,
  243. &z__[z_offset], ldz, &work[indwrk], &iinfo)
  244. ;
  245. /* Reduce to tridiagonal form. */
  246. if (wantz) {
  247. *(unsigned char *)vect = 'U';
  248. } else {
  249. *(unsigned char *)vect = 'N';
  250. }
  251. _starpu_dsbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[
  252. z_offset], ldz, &work[indwrk], &iinfo);
  253. /* For eigenvalues only, call DSTERF. For eigenvectors, call SSTEDC. */
  254. if (! wantz) {
  255. _starpu_dsterf_(n, &w[1], &work[inde], info);
  256. } else {
  257. _starpu_dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], &
  258. llwrk2, &iwork[1], liwork, info);
  259. _starpu_dgemm_("N", "N", n, n, n, &c_b12, &z__[z_offset], ldz, &work[indwrk],
  260. n, &c_b13, &work[indwk2], n);
  261. _starpu_dlacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz);
  262. }
  263. work[1] = (doublereal) lwmin;
  264. iwork[1] = liwmin;
  265. return 0;
  266. /* End of DSBGVD */
  267. } /* _starpu_dsbgvd_ */