dsbgvx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /* dsbgvx.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 doublereal c_b25 = 1.;
  16. static doublereal c_b27 = 0.;
  17. /* Subroutine */ int _starpu_dsbgvx_(char *jobz, char *range, char *uplo, integer *n,
  18. integer *ka, integer *kb, doublereal *ab, integer *ldab, doublereal *
  19. bb, integer *ldbb, doublereal *q, integer *ldq, doublereal *vl,
  20. doublereal *vu, integer *il, integer *iu, doublereal *abstol, integer
  21. *m, doublereal *w, doublereal *z__, integer *ldz, doublereal *work,
  22. integer *iwork, integer *ifail, integer *info)
  23. {
  24. /* System generated locals */
  25. integer ab_dim1, ab_offset, bb_dim1, bb_offset, q_dim1, q_offset, z_dim1,
  26. z_offset, i__1, i__2;
  27. /* Local variables */
  28. integer i__, j, jj;
  29. doublereal tmp1;
  30. integer indd, inde;
  31. char vect[1];
  32. logical test;
  33. integer itmp1, indee;
  34. extern logical _starpu_lsame_(char *, char *);
  35. extern /* Subroutine */ int _starpu_dgemv_(char *, integer *, integer *,
  36. doublereal *, doublereal *, integer *, doublereal *, integer *,
  37. doublereal *, doublereal *, integer *);
  38. integer iinfo;
  39. char order[1];
  40. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  41. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  42. *, doublereal *, integer *);
  43. logical upper, wantz, alleig, indeig;
  44. integer indibl;
  45. logical valeig;
  46. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  47. doublereal *, integer *, doublereal *, integer *),
  48. _starpu_xerbla_(char *, integer *), _starpu_dpbstf_(char *, integer *,
  49. integer *, doublereal *, integer *, integer *), _starpu_dsbtrd_(
  50. char *, char *, integer *, integer *, doublereal *, integer *,
  51. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  52. integer *);
  53. integer indisp;
  54. extern /* Subroutine */ int _starpu_dsbgst_(char *, char *, integer *, integer *,
  55. integer *, doublereal *, integer *, doublereal *, integer *,
  56. doublereal *, integer *, doublereal *, integer *),
  57. _starpu_dstein_(integer *, doublereal *, doublereal *, integer *,
  58. doublereal *, integer *, integer *, doublereal *, integer *,
  59. doublereal *, integer *, integer *, integer *);
  60. integer indiwo;
  61. extern /* Subroutine */ int _starpu_dsterf_(integer *, doublereal *, doublereal *,
  62. integer *), _starpu_dstebz_(char *, char *, integer *, doublereal *,
  63. doublereal *, integer *, integer *, doublereal *, doublereal *,
  64. doublereal *, integer *, integer *, doublereal *, integer *,
  65. integer *, doublereal *, integer *, integer *);
  66. integer indwrk;
  67. extern /* Subroutine */ int _starpu_dsteqr_(char *, integer *, doublereal *,
  68. doublereal *, doublereal *, integer *, doublereal *, integer *);
  69. integer nsplit;
  70. /* -- LAPACK driver routine (version 3.2) -- */
  71. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  72. /* November 2006 */
  73. /* .. Scalar Arguments .. */
  74. /* .. */
  75. /* .. Array Arguments .. */
  76. /* .. */
  77. /* Purpose */
  78. /* ======= */
  79. /* DSBGVX computes selected eigenvalues, and optionally, eigenvectors */
  80. /* of a real generalized symmetric-definite banded eigenproblem, of */
  81. /* the form A*x=(lambda)*B*x. Here A and B are assumed to be symmetric */
  82. /* and banded, and B is also positive definite. Eigenvalues and */
  83. /* eigenvectors can be selected by specifying either all eigenvalues, */
  84. /* a range of values or a range of indices for the desired eigenvalues. */
  85. /* Arguments */
  86. /* ========= */
  87. /* JOBZ (input) CHARACTER*1 */
  88. /* = 'N': Compute eigenvalues only; */
  89. /* = 'V': Compute eigenvalues and eigenvectors. */
  90. /* RANGE (input) CHARACTER*1 */
  91. /* = 'A': all eigenvalues will be found. */
  92. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  93. /* will be found. */
  94. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  95. /* UPLO (input) CHARACTER*1 */
  96. /* = 'U': Upper triangles of A and B are stored; */
  97. /* = 'L': Lower triangles of A and B are stored. */
  98. /* N (input) INTEGER */
  99. /* The order of the matrices A and B. N >= 0. */
  100. /* KA (input) INTEGER */
  101. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  102. /* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */
  103. /* KB (input) INTEGER */
  104. /* The number of superdiagonals of the matrix B if UPLO = 'U', */
  105. /* or the number of subdiagonals if UPLO = 'L'. KB >= 0. */
  106. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */
  107. /* On entry, the upper or lower triangle of the symmetric band */
  108. /* matrix A, stored in the first ka+1 rows of the array. The */
  109. /* j-th column of A is stored in the j-th column of the array AB */
  110. /* as follows: */
  111. /* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */
  112. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */
  113. /* On exit, the contents of AB are destroyed. */
  114. /* LDAB (input) INTEGER */
  115. /* The leading dimension of the array AB. LDAB >= KA+1. */
  116. /* BB (input/output) DOUBLE PRECISION array, dimension (LDBB, N) */
  117. /* On entry, the upper or lower triangle of the symmetric band */
  118. /* matrix B, stored in the first kb+1 rows of the array. The */
  119. /* j-th column of B is stored in the j-th column of the array BB */
  120. /* as follows: */
  121. /* if UPLO = 'U', BB(ka+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */
  122. /* if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). */
  123. /* On exit, the factor S from the split Cholesky factorization */
  124. /* B = S**T*S, as returned by DPBSTF. */
  125. /* LDBB (input) INTEGER */
  126. /* The leading dimension of the array BB. LDBB >= KB+1. */
  127. /* Q (output) DOUBLE PRECISION array, dimension (LDQ, N) */
  128. /* If JOBZ = 'V', the n-by-n matrix used in the reduction of */
  129. /* A*x = (lambda)*B*x to standard form, i.e. C*x = (lambda)*x, */
  130. /* and consequently C to tridiagonal form. */
  131. /* If JOBZ = 'N', the array Q is not referenced. */
  132. /* LDQ (input) INTEGER */
  133. /* The leading dimension of the array Q. If JOBZ = 'N', */
  134. /* LDQ >= 1. If JOBZ = 'V', LDQ >= max(1,N). */
  135. /* VL (input) DOUBLE PRECISION */
  136. /* VU (input) DOUBLE PRECISION */
  137. /* If RANGE='V', the lower and upper bounds of the interval to */
  138. /* be searched for eigenvalues. VL < VU. */
  139. /* Not referenced if RANGE = 'A' or 'I'. */
  140. /* IL (input) INTEGER */
  141. /* IU (input) INTEGER */
  142. /* If RANGE='I', the indices (in ascending order) of the */
  143. /* smallest and largest eigenvalues to be returned. */
  144. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  145. /* Not referenced if RANGE = 'A' or 'V'. */
  146. /* ABSTOL (input) DOUBLE PRECISION */
  147. /* The absolute error tolerance for the eigenvalues. */
  148. /* An approximate eigenvalue is accepted as converged */
  149. /* when it is determined to lie in an interval [a,b] */
  150. /* of width less than or equal to */
  151. /* ABSTOL + EPS * max( |a|,|b| ) , */
  152. /* where EPS is the machine precision. If ABSTOL is less than */
  153. /* or equal to zero, then EPS*|T| will be used in its place, */
  154. /* where |T| is the 1-norm of the tridiagonal matrix obtained */
  155. /* by reducing A to tridiagonal form. */
  156. /* Eigenvalues will be computed most accurately when ABSTOL is */
  157. /* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
  158. /* If this routine returns with INFO>0, indicating that some */
  159. /* eigenvectors did not converge, try setting ABSTOL to */
  160. /* 2*DLAMCH('S'). */
  161. /* M (output) INTEGER */
  162. /* The total number of eigenvalues found. 0 <= M <= N. */
  163. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  164. /* W (output) DOUBLE PRECISION array, dimension (N) */
  165. /* If INFO = 0, the eigenvalues in ascending order. */
  166. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */
  167. /* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
  168. /* eigenvectors, with the i-th column of Z holding the */
  169. /* eigenvector associated with W(i). The eigenvectors are */
  170. /* normalized so Z**T*B*Z = I. */
  171. /* If JOBZ = 'N', then Z is not referenced. */
  172. /* LDZ (input) INTEGER */
  173. /* The leading dimension of the array Z. LDZ >= 1, and if */
  174. /* JOBZ = 'V', LDZ >= max(1,N). */
  175. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (7*N) */
  176. /* IWORK (workspace/output) INTEGER array, dimension (5*N) */
  177. /* IFAIL (output) INTEGER array, dimension (M) */
  178. /* If JOBZ = 'V', then if INFO = 0, the first M elements of */
  179. /* IFAIL are zero. If INFO > 0, then IFAIL contains the */
  180. /* indices of the eigenvalues that failed to converge. */
  181. /* If JOBZ = 'N', then IFAIL is not referenced. */
  182. /* INFO (output) INTEGER */
  183. /* = 0 : successful exit */
  184. /* < 0 : if INFO = -i, the i-th argument had an illegal value */
  185. /* <= N: if INFO = i, then i eigenvectors failed to converge. */
  186. /* Their indices are stored in IFAIL. */
  187. /* > N : DPBSTF returned an error code; i.e., */
  188. /* if INFO = N + i, for 1 <= i <= N, then the leading */
  189. /* minor of order i of B is not positive definite. */
  190. /* The factorization of B could not be completed and */
  191. /* no eigenvalues or eigenvectors were computed. */
  192. /* Further Details */
  193. /* =============== */
  194. /* Based on contributions by */
  195. /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
  196. /* ===================================================================== */
  197. /* .. Parameters .. */
  198. /* .. */
  199. /* .. Local Scalars .. */
  200. /* .. */
  201. /* .. External Functions .. */
  202. /* .. */
  203. /* .. External Subroutines .. */
  204. /* .. */
  205. /* .. Intrinsic Functions .. */
  206. /* .. */
  207. /* .. Executable Statements .. */
  208. /* Test the input parameters. */
  209. /* Parameter adjustments */
  210. ab_dim1 = *ldab;
  211. ab_offset = 1 + ab_dim1;
  212. ab -= ab_offset;
  213. bb_dim1 = *ldbb;
  214. bb_offset = 1 + bb_dim1;
  215. bb -= bb_offset;
  216. q_dim1 = *ldq;
  217. q_offset = 1 + q_dim1;
  218. q -= q_offset;
  219. --w;
  220. z_dim1 = *ldz;
  221. z_offset = 1 + z_dim1;
  222. z__ -= z_offset;
  223. --work;
  224. --iwork;
  225. --ifail;
  226. /* Function Body */
  227. wantz = _starpu_lsame_(jobz, "V");
  228. upper = _starpu_lsame_(uplo, "U");
  229. alleig = _starpu_lsame_(range, "A");
  230. valeig = _starpu_lsame_(range, "V");
  231. indeig = _starpu_lsame_(range, "I");
  232. *info = 0;
  233. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  234. *info = -1;
  235. } else if (! (alleig || valeig || indeig)) {
  236. *info = -2;
  237. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  238. *info = -3;
  239. } else if (*n < 0) {
  240. *info = -4;
  241. } else if (*ka < 0) {
  242. *info = -5;
  243. } else if (*kb < 0 || *kb > *ka) {
  244. *info = -6;
  245. } else if (*ldab < *ka + 1) {
  246. *info = -8;
  247. } else if (*ldbb < *kb + 1) {
  248. *info = -10;
  249. } else if (*ldq < 1 || wantz && *ldq < *n) {
  250. *info = -12;
  251. } else {
  252. if (valeig) {
  253. if (*n > 0 && *vu <= *vl) {
  254. *info = -14;
  255. }
  256. } else if (indeig) {
  257. if (*il < 1 || *il > max(1,*n)) {
  258. *info = -15;
  259. } else if (*iu < min(*n,*il) || *iu > *n) {
  260. *info = -16;
  261. }
  262. }
  263. }
  264. if (*info == 0) {
  265. if (*ldz < 1 || wantz && *ldz < *n) {
  266. *info = -21;
  267. }
  268. }
  269. if (*info != 0) {
  270. i__1 = -(*info);
  271. _starpu_xerbla_("DSBGVX", &i__1);
  272. return 0;
  273. }
  274. /* Quick return if possible */
  275. *m = 0;
  276. if (*n == 0) {
  277. return 0;
  278. }
  279. /* Form a split Cholesky factorization of B. */
  280. _starpu_dpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info);
  281. if (*info != 0) {
  282. *info = *n + *info;
  283. return 0;
  284. }
  285. /* Transform problem to standard eigenvalue problem. */
  286. _starpu_dsbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb,
  287. &q[q_offset], ldq, &work[1], &iinfo);
  288. /* Reduce symmetric band matrix to tridiagonal form. */
  289. indd = 1;
  290. inde = indd + *n;
  291. indwrk = inde + *n;
  292. if (wantz) {
  293. *(unsigned char *)vect = 'U';
  294. } else {
  295. *(unsigned char *)vect = 'N';
  296. }
  297. _starpu_dsbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &work[indd], &work[inde],
  298. &q[q_offset], ldq, &work[indwrk], &iinfo);
  299. /* If all eigenvalues are desired and ABSTOL is less than or equal */
  300. /* to zero, then call DSTERF or SSTEQR. If this fails for some */
  301. /* eigenvalue, then try DSTEBZ. */
  302. test = FALSE_;
  303. if (indeig) {
  304. if (*il == 1 && *iu == *n) {
  305. test = TRUE_;
  306. }
  307. }
  308. if ((alleig || test) && *abstol <= 0.) {
  309. _starpu_dcopy_(n, &work[indd], &c__1, &w[1], &c__1);
  310. indee = indwrk + (*n << 1);
  311. i__1 = *n - 1;
  312. _starpu_dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
  313. if (! wantz) {
  314. _starpu_dsterf_(n, &w[1], &work[indee], info);
  315. } else {
  316. _starpu_dlacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz);
  317. _starpu_dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[
  318. indwrk], info);
  319. if (*info == 0) {
  320. i__1 = *n;
  321. for (i__ = 1; i__ <= i__1; ++i__) {
  322. ifail[i__] = 0;
  323. /* L10: */
  324. }
  325. }
  326. }
  327. if (*info == 0) {
  328. *m = *n;
  329. goto L30;
  330. }
  331. *info = 0;
  332. }
  333. /* Otherwise, call DSTEBZ and, if eigenvectors are desired, */
  334. /* call DSTEIN. */
  335. if (wantz) {
  336. *(unsigned char *)order = 'B';
  337. } else {
  338. *(unsigned char *)order = 'E';
  339. }
  340. indibl = 1;
  341. indisp = indibl + *n;
  342. indiwo = indisp + *n;
  343. _starpu_dstebz_(range, order, n, vl, vu, il, iu, abstol, &work[indd], &work[inde],
  344. m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[indwrk],
  345. &iwork[indiwo], info);
  346. if (wantz) {
  347. _starpu_dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[
  348. indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], &
  349. ifail[1], info);
  350. /* Apply transformation matrix used in reduction to tridiagonal */
  351. /* form to eigenvectors returned by DSTEIN. */
  352. i__1 = *m;
  353. for (j = 1; j <= i__1; ++j) {
  354. _starpu_dcopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1);
  355. _starpu_dgemv_("N", n, n, &c_b25, &q[q_offset], ldq, &work[1], &c__1, &
  356. c_b27, &z__[j * z_dim1 + 1], &c__1);
  357. /* L20: */
  358. }
  359. }
  360. L30:
  361. /* If eigenvalues are not in order, then sort them, along with */
  362. /* eigenvectors. */
  363. if (wantz) {
  364. i__1 = *m - 1;
  365. for (j = 1; j <= i__1; ++j) {
  366. i__ = 0;
  367. tmp1 = w[j];
  368. i__2 = *m;
  369. for (jj = j + 1; jj <= i__2; ++jj) {
  370. if (w[jj] < tmp1) {
  371. i__ = jj;
  372. tmp1 = w[jj];
  373. }
  374. /* L40: */
  375. }
  376. if (i__ != 0) {
  377. itmp1 = iwork[indibl + i__ - 1];
  378. w[i__] = w[j];
  379. iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
  380. w[j] = tmp1;
  381. iwork[indibl + j - 1] = itmp1;
  382. _starpu_dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  383. &c__1);
  384. if (*info != 0) {
  385. itmp1 = ifail[i__];
  386. ifail[i__] = ifail[j];
  387. ifail[j] = itmp1;
  388. }
  389. }
  390. /* L50: */
  391. }
  392. }
  393. return 0;
  394. /* End of DSBGVX */
  395. } /* _starpu_dsbgvx_ */