dsygvd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* dsygvd.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. /* Subroutine */ int _starpu_dsygvd_(integer *itype, char *jobz, char *uplo, integer *
  16. n, doublereal *a, integer *lda, doublereal *b, integer *ldb,
  17. doublereal *w, doublereal *work, integer *lwork, integer *iwork,
  18. integer *liwork, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, b_dim1, b_offset, i__1;
  22. doublereal d__1, d__2;
  23. /* Local variables */
  24. integer lopt;
  25. extern logical _starpu_lsame_(char *, char *);
  26. extern /* Subroutine */ int _starpu_dtrmm_(char *, char *, char *, char *,
  27. integer *, integer *, doublereal *, doublereal *, integer *,
  28. doublereal *, integer *);
  29. integer lwmin;
  30. char trans[1];
  31. integer liopt;
  32. extern /* Subroutine */ int _starpu_dtrsm_(char *, char *, char *, char *,
  33. integer *, integer *, doublereal *, doublereal *, integer *,
  34. doublereal *, integer *);
  35. logical upper, wantz;
  36. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *), _starpu_dpotrf_(
  37. char *, integer *, doublereal *, integer *, integer *);
  38. integer liwmin;
  39. extern /* Subroutine */ int _starpu_dsyevd_(char *, char *, integer *, doublereal
  40. *, integer *, doublereal *, doublereal *, integer *, integer *,
  41. integer *, integer *), _starpu_dsygst_(integer *, char *,
  42. integer *, doublereal *, integer *, doublereal *, integer *,
  43. integer *);
  44. logical lquery;
  45. /* -- LAPACK driver routine (version 3.2) -- */
  46. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  47. /* November 2006 */
  48. /* .. Scalar Arguments .. */
  49. /* .. */
  50. /* .. Array Arguments .. */
  51. /* .. */
  52. /* Purpose */
  53. /* ======= */
  54. /* DSYGVD computes all the eigenvalues, and optionally, the eigenvectors */
  55. /* of a real generalized symmetric-definite eigenproblem, of the form */
  56. /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and */
  57. /* B are assumed to be symmetric and B is also positive definite. */
  58. /* If eigenvectors are desired, it uses a divide and conquer algorithm. */
  59. /* The divide and conquer algorithm makes very mild assumptions about */
  60. /* floating point arithmetic. It will work on machines with a guard */
  61. /* digit in add/subtract, or on those binary machines without guard */
  62. /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
  63. /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */
  64. /* without guard digits, but we know of none. */
  65. /* Arguments */
  66. /* ========= */
  67. /* ITYPE (input) INTEGER */
  68. /* Specifies the problem type to be solved: */
  69. /* = 1: A*x = (lambda)*B*x */
  70. /* = 2: A*B*x = (lambda)*x */
  71. /* = 3: B*A*x = (lambda)*x */
  72. /* JOBZ (input) CHARACTER*1 */
  73. /* = 'N': Compute eigenvalues only; */
  74. /* = 'V': Compute eigenvalues and eigenvectors. */
  75. /* UPLO (input) CHARACTER*1 */
  76. /* = 'U': Upper triangles of A and B are stored; */
  77. /* = 'L': Lower triangles of A and B are stored. */
  78. /* N (input) INTEGER */
  79. /* The order of the matrices A and B. N >= 0. */
  80. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  81. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  82. /* leading N-by-N upper triangular part of A contains the */
  83. /* upper triangular part of the matrix A. If UPLO = 'L', */
  84. /* the leading N-by-N lower triangular part of A contains */
  85. /* the lower triangular part of the matrix A. */
  86. /* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
  87. /* matrix Z of eigenvectors. The eigenvectors are normalized */
  88. /* as follows: */
  89. /* if ITYPE = 1 or 2, Z**T*B*Z = I; */
  90. /* if ITYPE = 3, Z**T*inv(B)*Z = I. */
  91. /* If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */
  92. /* or the lower triangle (if UPLO='L') of A, including the */
  93. /* diagonal, is destroyed. */
  94. /* LDA (input) INTEGER */
  95. /* The leading dimension of the array A. LDA >= max(1,N). */
  96. /* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
  97. /* On entry, the symmetric matrix B. If UPLO = 'U', the */
  98. /* leading N-by-N upper triangular part of B contains the */
  99. /* upper triangular part of the matrix B. If UPLO = 'L', */
  100. /* the leading N-by-N lower triangular part of B contains */
  101. /* the lower triangular part of the matrix B. */
  102. /* On exit, if INFO <= N, the part of B containing the matrix is */
  103. /* overwritten by the triangular factor U or L from the Cholesky */
  104. /* factorization B = U**T*U or B = L*L**T. */
  105. /* LDB (input) INTEGER */
  106. /* The leading dimension of the array B. LDB >= max(1,N). */
  107. /* W (output) DOUBLE PRECISION array, dimension (N) */
  108. /* If INFO = 0, the eigenvalues in ascending order. */
  109. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  110. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  111. /* LWORK (input) INTEGER */
  112. /* The dimension of the array WORK. */
  113. /* If N <= 1, LWORK >= 1. */
  114. /* If JOBZ = 'N' and N > 1, LWORK >= 2*N+1. */
  115. /* If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2. */
  116. /* If LWORK = -1, then a workspace query is assumed; the routine */
  117. /* only calculates the optimal sizes of the WORK and IWORK */
  118. /* arrays, returns these values as the first entries of the WORK */
  119. /* and IWORK arrays, and no error message related to LWORK or */
  120. /* LIWORK is issued by XERBLA. */
  121. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  122. /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  123. /* LIWORK (input) INTEGER */
  124. /* The dimension of the array IWORK. */
  125. /* If N <= 1, LIWORK >= 1. */
  126. /* If JOBZ = 'N' and N > 1, LIWORK >= 1. */
  127. /* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */
  128. /* If LIWORK = -1, then a workspace query is assumed; the */
  129. /* routine only calculates the optimal sizes of the WORK and */
  130. /* IWORK arrays, returns these values as the first entries of */
  131. /* the WORK and IWORK arrays, and no error message related to */
  132. /* LWORK or LIWORK is issued by XERBLA. */
  133. /* INFO (output) INTEGER */
  134. /* = 0: successful exit */
  135. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  136. /* > 0: DPOTRF or DSYEVD returned an error code: */
  137. /* <= N: if INFO = i and JOBZ = 'N', then the algorithm */
  138. /* failed to converge; i off-diagonal elements of an */
  139. /* intermediate tridiagonal form did not converge to */
  140. /* zero; */
  141. /* if INFO = i and JOBZ = 'V', then the algorithm */
  142. /* failed to compute an eigenvalue while working on */
  143. /* the submatrix lying in rows and columns INFO/(N+1) */
  144. /* through mod(INFO,N+1); */
  145. /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */
  146. /* minor of order i of 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. /* Modified so that no backsubstitution is performed if DSYEVD fails to */
  154. /* converge (NEIG in old code could be greater than N causing out of */
  155. /* bounds reference to A - reported by Ralf Meyer). Also corrected the */
  156. /* description of INFO and the test on ITYPE. Sven, 16 Feb 05. */
  157. /* ===================================================================== */
  158. /* .. Parameters .. */
  159. /* .. */
  160. /* .. Local Scalars .. */
  161. /* .. */
  162. /* .. External Functions .. */
  163. /* .. */
  164. /* .. External Subroutines .. */
  165. /* .. */
  166. /* .. Intrinsic Functions .. */
  167. /* .. */
  168. /* .. Executable Statements .. */
  169. /* Test the input parameters. */
  170. /* Parameter adjustments */
  171. a_dim1 = *lda;
  172. a_offset = 1 + a_dim1;
  173. a -= a_offset;
  174. b_dim1 = *ldb;
  175. b_offset = 1 + b_dim1;
  176. b -= b_offset;
  177. --w;
  178. --work;
  179. --iwork;
  180. /* Function Body */
  181. wantz = _starpu_lsame_(jobz, "V");
  182. upper = _starpu_lsame_(uplo, "U");
  183. lquery = *lwork == -1 || *liwork == -1;
  184. *info = 0;
  185. if (*n <= 1) {
  186. liwmin = 1;
  187. lwmin = 1;
  188. } else if (wantz) {
  189. liwmin = *n * 5 + 3;
  190. /* Computing 2nd power */
  191. i__1 = *n;
  192. lwmin = *n * 6 + 1 + (i__1 * i__1 << 1);
  193. } else {
  194. liwmin = 1;
  195. lwmin = (*n << 1) + 1;
  196. }
  197. lopt = lwmin;
  198. liopt = liwmin;
  199. if (*itype < 1 || *itype > 3) {
  200. *info = -1;
  201. } else if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  202. *info = -2;
  203. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  204. *info = -3;
  205. } else if (*n < 0) {
  206. *info = -4;
  207. } else if (*lda < max(1,*n)) {
  208. *info = -6;
  209. } else if (*ldb < max(1,*n)) {
  210. *info = -8;
  211. }
  212. if (*info == 0) {
  213. work[1] = (doublereal) lopt;
  214. iwork[1] = liopt;
  215. if (*lwork < lwmin && ! lquery) {
  216. *info = -11;
  217. } else if (*liwork < liwmin && ! lquery) {
  218. *info = -13;
  219. }
  220. }
  221. if (*info != 0) {
  222. i__1 = -(*info);
  223. _starpu_xerbla_("DSYGVD", &i__1);
  224. return 0;
  225. } else if (lquery) {
  226. return 0;
  227. }
  228. /* Quick return if possible */
  229. if (*n == 0) {
  230. return 0;
  231. }
  232. /* Form a Cholesky factorization of B. */
  233. _starpu_dpotrf_(uplo, n, &b[b_offset], ldb, info);
  234. if (*info != 0) {
  235. *info = *n + *info;
  236. return 0;
  237. }
  238. /* Transform problem to standard eigenvalue problem and solve. */
  239. _starpu_dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
  240. _starpu_dsyevd_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, &iwork[
  241. 1], liwork, info);
  242. /* Computing MAX */
  243. d__1 = (doublereal) lopt;
  244. lopt = (integer) max(d__1,work[1]);
  245. /* Computing MAX */
  246. d__1 = (doublereal) liopt, d__2 = (doublereal) iwork[1];
  247. liopt = (integer) max(d__1,d__2);
  248. if (wantz && *info == 0) {
  249. /* Backtransform eigenvectors to the original problem. */
  250. if (*itype == 1 || *itype == 2) {
  251. /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
  252. /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
  253. if (upper) {
  254. *(unsigned char *)trans = 'N';
  255. } else {
  256. *(unsigned char *)trans = 'T';
  257. }
  258. _starpu_dtrsm_("Left", uplo, trans, "Non-unit", n, n, &c_b11, &b[b_offset]
  259. , ldb, &a[a_offset], lda);
  260. } else if (*itype == 3) {
  261. /* For B*A*x=(lambda)*x; */
  262. /* backtransform eigenvectors: x = L*y or U'*y */
  263. if (upper) {
  264. *(unsigned char *)trans = 'T';
  265. } else {
  266. *(unsigned char *)trans = 'N';
  267. }
  268. _starpu_dtrmm_("Left", uplo, trans, "Non-unit", n, n, &c_b11, &b[b_offset]
  269. , ldb, &a[a_offset], lda);
  270. }
  271. }
  272. work[1] = (doublereal) lopt;
  273. iwork[1] = liopt;
  274. return 0;
  275. /* End of DSYGVD */
  276. } /* _starpu_dsygvd_ */