dsygv.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* dsygv.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. static integer c_n1 = -1;
  16. static doublereal c_b16 = 1.;
  17. /* Subroutine */ int _starpu_dsygv_(integer *itype, char *jobz, char *uplo, integer *
  18. n, doublereal *a, integer *lda, doublereal *b, integer *ldb,
  19. doublereal *w, doublereal *work, integer *lwork, integer *info)
  20. {
  21. /* System generated locals */
  22. integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
  23. /* Local variables */
  24. integer nb, neig;
  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. char trans[1];
  30. extern /* Subroutine */ int _starpu_dtrsm_(char *, char *, char *, char *,
  31. integer *, integer *, doublereal *, doublereal *, integer *,
  32. doublereal *, integer *);
  33. logical upper;
  34. extern /* Subroutine */ int _starpu_dsyev_(char *, char *, integer *, doublereal *
  35. , integer *, doublereal *, doublereal *, integer *, integer *);
  36. logical wantz;
  37. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  38. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  39. integer *, integer *);
  40. extern /* Subroutine */ int _starpu_dpotrf_(char *, integer *, doublereal *,
  41. integer *, integer *);
  42. integer lwkmin;
  43. extern /* Subroutine */ int _starpu_dsygst_(integer *, char *, integer *,
  44. doublereal *, integer *, doublereal *, integer *, integer *);
  45. integer lwkopt;
  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. /* DSYGV computes all the eigenvalues, and optionally, the eigenvectors */
  57. /* of a real generalized symmetric-definite eigenproblem, of the form */
  58. /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. */
  59. /* Here A and B are assumed to be symmetric and B is also */
  60. /* positive definite. */
  61. /* Arguments */
  62. /* ========= */
  63. /* ITYPE (input) INTEGER */
  64. /* Specifies the problem type to be solved: */
  65. /* = 1: A*x = (lambda)*B*x */
  66. /* = 2: A*B*x = (lambda)*x */
  67. /* = 3: B*A*x = (lambda)*x */
  68. /* JOBZ (input) CHARACTER*1 */
  69. /* = 'N': Compute eigenvalues only; */
  70. /* = 'V': Compute eigenvalues and eigenvectors. */
  71. /* UPLO (input) CHARACTER*1 */
  72. /* = 'U': Upper triangles of A and B are stored; */
  73. /* = 'L': Lower triangles of A and B are stored. */
  74. /* N (input) INTEGER */
  75. /* The order of the matrices A and B. N >= 0. */
  76. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  77. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  78. /* leading N-by-N upper triangular part of A contains the */
  79. /* upper triangular part of the matrix A. If UPLO = 'L', */
  80. /* the leading N-by-N lower triangular part of A contains */
  81. /* the lower triangular part of the matrix A. */
  82. /* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
  83. /* matrix Z of eigenvectors. The eigenvectors are normalized */
  84. /* as follows: */
  85. /* if ITYPE = 1 or 2, Z**T*B*Z = I; */
  86. /* if ITYPE = 3, Z**T*inv(B)*Z = I. */
  87. /* If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */
  88. /* or the lower triangle (if UPLO='L') of A, including the */
  89. /* diagonal, is destroyed. */
  90. /* LDA (input) INTEGER */
  91. /* The leading dimension of the array A. LDA >= max(1,N). */
  92. /* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
  93. /* On entry, the symmetric positive definite matrix B. */
  94. /* If UPLO = 'U', the leading N-by-N upper triangular part of B */
  95. /* contains the upper triangular part of the matrix B. */
  96. /* If UPLO = 'L', the leading N-by-N lower triangular part of B */
  97. /* contains the lower triangular part of the matrix B. */
  98. /* On exit, if INFO <= N, the part of B containing the matrix is */
  99. /* overwritten by the triangular factor U or L from the Cholesky */
  100. /* factorization B = U**T*U or B = L*L**T. */
  101. /* LDB (input) INTEGER */
  102. /* The leading dimension of the array B. LDB >= max(1,N). */
  103. /* W (output) DOUBLE PRECISION array, dimension (N) */
  104. /* If INFO = 0, the eigenvalues in ascending order. */
  105. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  106. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  107. /* LWORK (input) INTEGER */
  108. /* The length of the array WORK. LWORK >= max(1,3*N-1). */
  109. /* For optimal efficiency, LWORK >= (NB+2)*N, */
  110. /* where NB is the blocksize for DSYTRD returned by ILAENV. */
  111. /* If LWORK = -1, then a workspace query is assumed; the routine */
  112. /* only calculates the optimal size of the WORK array, returns */
  113. /* this value as the first entry of the WORK array, and no error */
  114. /* message related to LWORK is issued by XERBLA. */
  115. /* INFO (output) INTEGER */
  116. /* = 0: successful exit */
  117. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  118. /* > 0: DPOTRF or DSYEV returned an error code: */
  119. /* <= N: if INFO = i, DSYEV failed to converge; */
  120. /* i off-diagonal elements of an intermediate */
  121. /* tridiagonal form did not converge to zero; */
  122. /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */
  123. /* minor of order i of B is not positive definite. */
  124. /* The factorization of B could not be completed and */
  125. /* no eigenvalues or eigenvectors were computed. */
  126. /* ===================================================================== */
  127. /* .. Parameters .. */
  128. /* .. */
  129. /* .. Local Scalars .. */
  130. /* .. */
  131. /* .. External Functions .. */
  132. /* .. */
  133. /* .. External Subroutines .. */
  134. /* .. */
  135. /* .. Intrinsic Functions .. */
  136. /* .. */
  137. /* .. Executable Statements .. */
  138. /* Test the input parameters. */
  139. /* Parameter adjustments */
  140. a_dim1 = *lda;
  141. a_offset = 1 + a_dim1;
  142. a -= a_offset;
  143. b_dim1 = *ldb;
  144. b_offset = 1 + b_dim1;
  145. b -= b_offset;
  146. --w;
  147. --work;
  148. /* Function Body */
  149. wantz = _starpu_lsame_(jobz, "V");
  150. upper = _starpu_lsame_(uplo, "U");
  151. lquery = *lwork == -1;
  152. *info = 0;
  153. if (*itype < 1 || *itype > 3) {
  154. *info = -1;
  155. } else if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  156. *info = -2;
  157. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  158. *info = -3;
  159. } else if (*n < 0) {
  160. *info = -4;
  161. } else if (*lda < max(1,*n)) {
  162. *info = -6;
  163. } else if (*ldb < max(1,*n)) {
  164. *info = -8;
  165. }
  166. if (*info == 0) {
  167. /* Computing MAX */
  168. i__1 = 1, i__2 = *n * 3 - 1;
  169. lwkmin = max(i__1,i__2);
  170. nb = _starpu_ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  171. /* Computing MAX */
  172. i__1 = lwkmin, i__2 = (nb + 2) * *n;
  173. lwkopt = max(i__1,i__2);
  174. work[1] = (doublereal) lwkopt;
  175. if (*lwork < lwkmin && ! lquery) {
  176. *info = -11;
  177. }
  178. }
  179. if (*info != 0) {
  180. i__1 = -(*info);
  181. _starpu_xerbla_("DSYGV ", &i__1);
  182. return 0;
  183. } else if (lquery) {
  184. return 0;
  185. }
  186. /* Quick return if possible */
  187. if (*n == 0) {
  188. return 0;
  189. }
  190. /* Form a Cholesky factorization of B. */
  191. _starpu_dpotrf_(uplo, n, &b[b_offset], ldb, info);
  192. if (*info != 0) {
  193. *info = *n + *info;
  194. return 0;
  195. }
  196. /* Transform problem to standard eigenvalue problem and solve. */
  197. _starpu_dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
  198. _starpu_dsyev_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, info);
  199. if (wantz) {
  200. /* Backtransform eigenvectors to the original problem. */
  201. neig = *n;
  202. if (*info > 0) {
  203. neig = *info - 1;
  204. }
  205. if (*itype == 1 || *itype == 2) {
  206. /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
  207. /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
  208. if (upper) {
  209. *(unsigned char *)trans = 'N';
  210. } else {
  211. *(unsigned char *)trans = 'T';
  212. }
  213. _starpu_dtrsm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[
  214. b_offset], ldb, &a[a_offset], lda);
  215. } else if (*itype == 3) {
  216. /* For B*A*x=(lambda)*x; */
  217. /* backtransform eigenvectors: x = L*y or U'*y */
  218. if (upper) {
  219. *(unsigned char *)trans = 'T';
  220. } else {
  221. *(unsigned char *)trans = 'N';
  222. }
  223. _starpu_dtrmm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[
  224. b_offset], ldb, &a[a_offset], lda);
  225. }
  226. }
  227. work[1] = (doublereal) lwkopt;
  228. return 0;
  229. /* End of DSYGV */
  230. } /* _starpu_dsygv_ */