dsygvx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /* dsygvx.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_b19 = 1.;
  17. /* Subroutine */ int _starpu_dsygvx_(integer *itype, char *jobz, char *range, char *
  18. uplo, integer *n, doublereal *a, integer *lda, doublereal *b, integer
  19. *ldb, doublereal *vl, doublereal *vu, integer *il, integer *iu,
  20. doublereal *abstol, integer *m, doublereal *w, doublereal *z__,
  21. integer *ldz, doublereal *work, integer *lwork, integer *iwork,
  22. integer *ifail, integer *info)
  23. {
  24. /* System generated locals */
  25. integer a_dim1, a_offset, b_dim1, b_offset, z_dim1, z_offset, i__1, i__2;
  26. /* Local variables */
  27. integer nb;
  28. extern logical _starpu_lsame_(char *, char *);
  29. extern /* Subroutine */ int _starpu_dtrmm_(char *, char *, char *, char *,
  30. integer *, integer *, doublereal *, doublereal *, integer *,
  31. doublereal *, integer *);
  32. char trans[1];
  33. extern /* Subroutine */ int _starpu_dtrsm_(char *, char *, char *, char *,
  34. integer *, integer *, doublereal *, doublereal *, integer *,
  35. doublereal *, integer *);
  36. logical upper, wantz, alleig, indeig, valeig;
  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. extern /* Subroutine */ int _starpu_dsyevx_(char *, char *, char *, integer *,
  48. doublereal *, integer *, doublereal *, doublereal *, integer *,
  49. integer *, doublereal *, integer *, doublereal *, doublereal *,
  50. integer *, doublereal *, integer *, integer *, integer *, integer
  51. *);
  52. /* -- LAPACK driver routine (version 3.2) -- */
  53. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  54. /* November 2006 */
  55. /* .. Scalar Arguments .. */
  56. /* .. */
  57. /* .. Array Arguments .. */
  58. /* .. */
  59. /* Purpose */
  60. /* ======= */
  61. /* DSYGVX computes selected eigenvalues, and optionally, eigenvectors */
  62. /* of a real generalized symmetric-definite eigenproblem, of the form */
  63. /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A */
  64. /* and B are assumed to be symmetric and B is also positive definite. */
  65. /* Eigenvalues and eigenvectors can be selected by specifying either a */
  66. /* range of values or a range of indices for the desired eigenvalues. */
  67. /* Arguments */
  68. /* ========= */
  69. /* ITYPE (input) INTEGER */
  70. /* Specifies the problem type to be solved: */
  71. /* = 1: A*x = (lambda)*B*x */
  72. /* = 2: A*B*x = (lambda)*x */
  73. /* = 3: B*A*x = (lambda)*x */
  74. /* JOBZ (input) CHARACTER*1 */
  75. /* = 'N': Compute eigenvalues only; */
  76. /* = 'V': Compute eigenvalues and eigenvectors. */
  77. /* RANGE (input) CHARACTER*1 */
  78. /* = 'A': all eigenvalues will be found. */
  79. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  80. /* will be found. */
  81. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  82. /* UPLO (input) CHARACTER*1 */
  83. /* = 'U': Upper triangle of A and B are stored; */
  84. /* = 'L': Lower triangle of A and B are stored. */
  85. /* N (input) INTEGER */
  86. /* The order of the matrix pencil (A,B). N >= 0. */
  87. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  88. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  89. /* leading N-by-N upper triangular part of A contains the */
  90. /* upper triangular part of the matrix A. If UPLO = 'L', */
  91. /* the leading N-by-N lower triangular part of A contains */
  92. /* the lower triangular part of the matrix A. */
  93. /* On exit, the lower triangle (if UPLO='L') or the upper */
  94. /* triangle (if UPLO='U') of A, including the diagonal, is */
  95. /* destroyed. */
  96. /* LDA (input) INTEGER */
  97. /* The leading dimension of the array A. LDA >= max(1,N). */
  98. /* B (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  99. /* On entry, the symmetric matrix B. If UPLO = 'U', the */
  100. /* leading N-by-N upper triangular part of B contains the */
  101. /* upper triangular part of the matrix B. If UPLO = 'L', */
  102. /* the leading N-by-N lower triangular part of B contains */
  103. /* the lower triangular part of the matrix B. */
  104. /* On exit, if INFO <= N, the part of B containing the matrix is */
  105. /* overwritten by the triangular factor U or L from the Cholesky */
  106. /* factorization B = U**T*U or B = L*L**T. */
  107. /* LDB (input) INTEGER */
  108. /* The leading dimension of the array B. LDB >= max(1,N). */
  109. /* VL (input) DOUBLE PRECISION */
  110. /* VU (input) DOUBLE PRECISION */
  111. /* If RANGE='V', the lower and upper bounds of the interval to */
  112. /* be searched for eigenvalues. VL < VU. */
  113. /* Not referenced if RANGE = 'A' or 'I'. */
  114. /* IL (input) INTEGER */
  115. /* IU (input) INTEGER */
  116. /* If RANGE='I', the indices (in ascending order) of the */
  117. /* smallest and largest eigenvalues to be returned. */
  118. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  119. /* Not referenced if RANGE = 'A' or 'V'. */
  120. /* ABSTOL (input) DOUBLE PRECISION */
  121. /* The absolute error tolerance for the eigenvalues. */
  122. /* An approximate eigenvalue is accepted as converged */
  123. /* when it is determined to lie in an interval [a,b] */
  124. /* of width less than or equal to */
  125. /* ABSTOL + EPS * max( |a|,|b| ) , */
  126. /* where EPS is the machine precision. If ABSTOL is less than */
  127. /* or equal to zero, then EPS*|T| will be used in its place, */
  128. /* where |T| is the 1-norm of the tridiagonal matrix obtained */
  129. /* by reducing A to tridiagonal form. */
  130. /* Eigenvalues will be computed most accurately when ABSTOL is */
  131. /* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
  132. /* If this routine returns with INFO>0, indicating that some */
  133. /* eigenvectors did not converge, try setting ABSTOL to */
  134. /* 2*DLAMCH('S'). */
  135. /* M (output) INTEGER */
  136. /* The total number of eigenvalues found. 0 <= M <= N. */
  137. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  138. /* W (output) DOUBLE PRECISION array, dimension (N) */
  139. /* On normal exit, the first M elements contain the selected */
  140. /* eigenvalues in ascending order. */
  141. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */
  142. /* If JOBZ = 'N', then Z is not referenced. */
  143. /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  144. /* contain the orthonormal eigenvectors of the matrix A */
  145. /* corresponding to the selected eigenvalues, with the i-th */
  146. /* column of Z holding the eigenvector associated with W(i). */
  147. /* The eigenvectors are normalized as follows: */
  148. /* if ITYPE = 1 or 2, Z**T*B*Z = I; */
  149. /* if ITYPE = 3, Z**T*inv(B)*Z = I. */
  150. /* If an eigenvector fails to converge, then that column of Z */
  151. /* contains the latest approximation to the eigenvector, and the */
  152. /* index of the eigenvector is returned in IFAIL. */
  153. /* Note: the user must ensure that at least max(1,M) columns are */
  154. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  155. /* is not known in advance and an upper bound must be used. */
  156. /* LDZ (input) INTEGER */
  157. /* The leading dimension of the array Z. LDZ >= 1, and if */
  158. /* JOBZ = 'V', LDZ >= max(1,N). */
  159. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  160. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  161. /* LWORK (input) INTEGER */
  162. /* The length of the array WORK. LWORK >= max(1,8*N). */
  163. /* For optimal efficiency, LWORK >= (NB+3)*N, */
  164. /* where NB is the blocksize for DSYTRD returned by ILAENV. */
  165. /* If LWORK = -1, then a workspace query is assumed; the routine */
  166. /* only calculates the optimal size of the WORK array, returns */
  167. /* this value as the first entry of the WORK array, and no error */
  168. /* message related to LWORK is issued by XERBLA. */
  169. /* IWORK (workspace) INTEGER array, dimension (5*N) */
  170. /* IFAIL (output) INTEGER array, dimension (N) */
  171. /* If JOBZ = 'V', then if INFO = 0, the first M elements of */
  172. /* IFAIL are zero. If INFO > 0, then IFAIL contains the */
  173. /* indices of the eigenvectors that failed to converge. */
  174. /* If JOBZ = 'N', then IFAIL is not referenced. */
  175. /* INFO (output) INTEGER */
  176. /* = 0: successful exit */
  177. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  178. /* > 0: DPOTRF or DSYEVX returned an error code: */
  179. /* <= N: if INFO = i, DSYEVX failed to converge; */
  180. /* i eigenvectors failed to converge. Their indices */
  181. /* are stored in array IFAIL. */
  182. /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */
  183. /* minor of order i of B is not positive definite. */
  184. /* The factorization of B could not be completed and */
  185. /* no eigenvalues or eigenvectors were computed. */
  186. /* Further Details */
  187. /* =============== */
  188. /* Based on contributions by */
  189. /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
  190. /* ===================================================================== */
  191. /* .. Parameters .. */
  192. /* .. */
  193. /* .. Local Scalars .. */
  194. /* .. */
  195. /* .. External Functions .. */
  196. /* .. */
  197. /* .. External Subroutines .. */
  198. /* .. */
  199. /* .. Intrinsic Functions .. */
  200. /* .. */
  201. /* .. Executable Statements .. */
  202. /* Test the input parameters. */
  203. /* Parameter adjustments */
  204. a_dim1 = *lda;
  205. a_offset = 1 + a_dim1;
  206. a -= a_offset;
  207. b_dim1 = *ldb;
  208. b_offset = 1 + b_dim1;
  209. b -= b_offset;
  210. --w;
  211. z_dim1 = *ldz;
  212. z_offset = 1 + z_dim1;
  213. z__ -= z_offset;
  214. --work;
  215. --iwork;
  216. --ifail;
  217. /* Function Body */
  218. upper = _starpu_lsame_(uplo, "U");
  219. wantz = _starpu_lsame_(jobz, "V");
  220. alleig = _starpu_lsame_(range, "A");
  221. valeig = _starpu_lsame_(range, "V");
  222. indeig = _starpu_lsame_(range, "I");
  223. lquery = *lwork == -1;
  224. *info = 0;
  225. if (*itype < 1 || *itype > 3) {
  226. *info = -1;
  227. } else if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  228. *info = -2;
  229. } else if (! (alleig || valeig || indeig)) {
  230. *info = -3;
  231. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  232. *info = -4;
  233. } else if (*n < 0) {
  234. *info = -5;
  235. } else if (*lda < max(1,*n)) {
  236. *info = -7;
  237. } else if (*ldb < max(1,*n)) {
  238. *info = -9;
  239. } else {
  240. if (valeig) {
  241. if (*n > 0 && *vu <= *vl) {
  242. *info = -11;
  243. }
  244. } else if (indeig) {
  245. if (*il < 1 || *il > max(1,*n)) {
  246. *info = -12;
  247. } else if (*iu < min(*n,*il) || *iu > *n) {
  248. *info = -13;
  249. }
  250. }
  251. }
  252. if (*info == 0) {
  253. if (*ldz < 1 || wantz && *ldz < *n) {
  254. *info = -18;
  255. }
  256. }
  257. if (*info == 0) {
  258. /* Computing MAX */
  259. i__1 = 1, i__2 = *n << 3;
  260. lwkmin = max(i__1,i__2);
  261. nb = _starpu_ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  262. /* Computing MAX */
  263. i__1 = lwkmin, i__2 = (nb + 3) * *n;
  264. lwkopt = max(i__1,i__2);
  265. work[1] = (doublereal) lwkopt;
  266. if (*lwork < lwkmin && ! lquery) {
  267. *info = -20;
  268. }
  269. }
  270. if (*info != 0) {
  271. i__1 = -(*info);
  272. _starpu_xerbla_("DSYGVX", &i__1);
  273. return 0;
  274. } else if (lquery) {
  275. return 0;
  276. }
  277. /* Quick return if possible */
  278. *m = 0;
  279. if (*n == 0) {
  280. return 0;
  281. }
  282. /* Form a Cholesky factorization of B. */
  283. _starpu_dpotrf_(uplo, n, &b[b_offset], ldb, info);
  284. if (*info != 0) {
  285. *info = *n + *info;
  286. return 0;
  287. }
  288. /* Transform problem to standard eigenvalue problem and solve. */
  289. _starpu_dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
  290. _starpu_dsyevx_(jobz, range, uplo, n, &a[a_offset], lda, vl, vu, il, iu, abstol,
  291. m, &w[1], &z__[z_offset], ldz, &work[1], lwork, &iwork[1], &ifail[
  292. 1], info);
  293. if (wantz) {
  294. /* Backtransform eigenvectors to the original problem. */
  295. if (*info > 0) {
  296. *m = *info - 1;
  297. }
  298. if (*itype == 1 || *itype == 2) {
  299. /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
  300. /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
  301. if (upper) {
  302. *(unsigned char *)trans = 'N';
  303. } else {
  304. *(unsigned char *)trans = 'T';
  305. }
  306. _starpu_dtrsm_("Left", uplo, trans, "Non-unit", n, m, &c_b19, &b[b_offset]
  307. , ldb, &z__[z_offset], ldz);
  308. } else if (*itype == 3) {
  309. /* For B*A*x=(lambda)*x; */
  310. /* backtransform eigenvectors: x = L*y or U'*y */
  311. if (upper) {
  312. *(unsigned char *)trans = 'T';
  313. } else {
  314. *(unsigned char *)trans = 'N';
  315. }
  316. _starpu_dtrmm_("Left", uplo, trans, "Non-unit", n, m, &c_b19, &b[b_offset]
  317. , ldb, &z__[z_offset], ldz);
  318. }
  319. }
  320. /* Set WORK(1) to optimal workspace size. */
  321. work[1] = (doublereal) lwkopt;
  322. return 0;
  323. /* End of DSYGVX */
  324. } /* _starpu_dsygvx_ */