dspgvd.c 11 KB

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