dtgexc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /* dtgexc.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__2 = 2;
  16. /* Subroutine */ int _starpu_dtgexc_(logical *wantq, logical *wantz, integer *n,
  17. doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
  18. q, integer *ldq, doublereal *z__, integer *ldz, integer *ifst,
  19. integer *ilst, doublereal *work, integer *lwork, integer *info)
  20. {
  21. /* System generated locals */
  22. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  23. z_offset, i__1;
  24. /* Local variables */
  25. integer nbf, nbl, here, lwmin;
  26. extern /* Subroutine */ int _starpu_dtgex2_(logical *, logical *, integer *,
  27. doublereal *, integer *, doublereal *, integer *, doublereal *,
  28. integer *, doublereal *, integer *, integer *, integer *, integer
  29. *, doublereal *, integer *, integer *), _starpu_xerbla_(char *, integer *);
  30. integer nbnext;
  31. logical lquery;
  32. /* -- LAPACK routine (version 3.2) -- */
  33. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  34. /* November 2006 */
  35. /* .. Scalar Arguments .. */
  36. /* .. */
  37. /* .. Array Arguments .. */
  38. /* .. */
  39. /* Purpose */
  40. /* ======= */
  41. /* DTGEXC reorders the generalized real Schur decomposition of a real */
  42. /* matrix pair (A,B) using an orthogonal equivalence transformation */
  43. /* (A, B) = Q * (A, B) * Z', */
  44. /* so that the diagonal block of (A, B) with row index IFST is moved */
  45. /* to row ILST. */
  46. /* (A, B) must be in generalized real Schur canonical form (as returned */
  47. /* by DGGES), i.e. A is block upper triangular with 1-by-1 and 2-by-2 */
  48. /* diagonal blocks. B is upper triangular. */
  49. /* Optionally, the matrices Q and Z of generalized Schur vectors are */
  50. /* updated. */
  51. /* Q(in) * A(in) * Z(in)' = Q(out) * A(out) * Z(out)' */
  52. /* Q(in) * B(in) * Z(in)' = Q(out) * B(out) * Z(out)' */
  53. /* Arguments */
  54. /* ========= */
  55. /* WANTQ (input) LOGICAL */
  56. /* .TRUE. : update the left transformation matrix Q; */
  57. /* .FALSE.: do not update Q. */
  58. /* WANTZ (input) LOGICAL */
  59. /* .TRUE. : update the right transformation matrix Z; */
  60. /* .FALSE.: do not update Z. */
  61. /* N (input) INTEGER */
  62. /* The order of the matrices A and B. N >= 0. */
  63. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  64. /* On entry, the matrix A in generalized real Schur canonical */
  65. /* form. */
  66. /* On exit, the updated matrix A, again in generalized */
  67. /* real Schur canonical form. */
  68. /* LDA (input) INTEGER */
  69. /* The leading dimension of the array A. LDA >= max(1,N). */
  70. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,N) */
  71. /* On entry, the matrix B in generalized real Schur canonical */
  72. /* form (A,B). */
  73. /* On exit, the updated matrix B, again in generalized */
  74. /* real Schur canonical form (A,B). */
  75. /* LDB (input) INTEGER */
  76. /* The leading dimension of the array B. LDB >= max(1,N). */
  77. /* Q (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */
  78. /* On entry, if WANTQ = .TRUE., the orthogonal matrix Q. */
  79. /* On exit, the updated matrix Q. */
  80. /* If WANTQ = .FALSE., Q is not referenced. */
  81. /* LDQ (input) INTEGER */
  82. /* The leading dimension of the array Q. LDQ >= 1. */
  83. /* If WANTQ = .TRUE., LDQ >= N. */
  84. /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */
  85. /* On entry, if WANTZ = .TRUE., the orthogonal matrix Z. */
  86. /* On exit, the updated matrix Z. */
  87. /* If WANTZ = .FALSE., Z is not referenced. */
  88. /* LDZ (input) INTEGER */
  89. /* The leading dimension of the array Z. LDZ >= 1. */
  90. /* If WANTZ = .TRUE., LDZ >= N. */
  91. /* IFST (input/output) INTEGER */
  92. /* ILST (input/output) INTEGER */
  93. /* Specify the reordering of the diagonal blocks of (A, B). */
  94. /* The block with row index IFST is moved to row ILST, by a */
  95. /* sequence of swapping between adjacent blocks. */
  96. /* On exit, if IFST pointed on entry to the second row of */
  97. /* a 2-by-2 block, it is changed to point to the first row; */
  98. /* ILST always points to the first row of the block in its */
  99. /* final position (which may differ from its input value by */
  100. /* +1 or -1). 1 <= IFST, ILST <= N. */
  101. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  102. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  103. /* LWORK (input) INTEGER */
  104. /* The dimension of the array WORK. */
  105. /* LWORK >= 1 when N <= 1, otherwise LWORK >= 4*N + 16. */
  106. /* If LWORK = -1, then a workspace query is assumed; the routine */
  107. /* only calculates the optimal size of the WORK array, returns */
  108. /* this value as the first entry of the WORK array, and no error */
  109. /* message related to LWORK is issued by XERBLA. */
  110. /* INFO (output) INTEGER */
  111. /* =0: successful exit. */
  112. /* <0: if INFO = -i, the i-th argument had an illegal value. */
  113. /* =1: The transformed matrix pair (A, B) would be too far */
  114. /* from generalized Schur form; the problem is ill- */
  115. /* conditioned. (A, B) may have been partially reordered, */
  116. /* and ILST points to the first row of the current */
  117. /* position of the block being moved. */
  118. /* Further Details */
  119. /* =============== */
  120. /* Based on contributions by */
  121. /* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  122. /* Umea University, S-901 87 Umea, Sweden. */
  123. /* [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
  124. /* Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
  125. /* M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
  126. /* Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
  127. /* ===================================================================== */
  128. /* .. Parameters .. */
  129. /* .. */
  130. /* .. Local Scalars .. */
  131. /* .. */
  132. /* .. External Subroutines .. */
  133. /* .. */
  134. /* .. Intrinsic Functions .. */
  135. /* .. */
  136. /* .. Executable Statements .. */
  137. /* Decode and test input arguments. */
  138. /* Parameter adjustments */
  139. a_dim1 = *lda;
  140. a_offset = 1 + a_dim1;
  141. a -= a_offset;
  142. b_dim1 = *ldb;
  143. b_offset = 1 + b_dim1;
  144. b -= b_offset;
  145. q_dim1 = *ldq;
  146. q_offset = 1 + q_dim1;
  147. q -= q_offset;
  148. z_dim1 = *ldz;
  149. z_offset = 1 + z_dim1;
  150. z__ -= z_offset;
  151. --work;
  152. /* Function Body */
  153. *info = 0;
  154. lquery = *lwork == -1;
  155. if (*n < 0) {
  156. *info = -3;
  157. } else if (*lda < max(1,*n)) {
  158. *info = -5;
  159. } else if (*ldb < max(1,*n)) {
  160. *info = -7;
  161. } else if (*ldq < 1 || *wantq && *ldq < max(1,*n)) {
  162. *info = -9;
  163. } else if (*ldz < 1 || *wantz && *ldz < max(1,*n)) {
  164. *info = -11;
  165. } else if (*ifst < 1 || *ifst > *n) {
  166. *info = -12;
  167. } else if (*ilst < 1 || *ilst > *n) {
  168. *info = -13;
  169. }
  170. if (*info == 0) {
  171. if (*n <= 1) {
  172. lwmin = 1;
  173. } else {
  174. lwmin = (*n << 2) + 16;
  175. }
  176. work[1] = (doublereal) lwmin;
  177. if (*lwork < lwmin && ! lquery) {
  178. *info = -15;
  179. }
  180. }
  181. if (*info != 0) {
  182. i__1 = -(*info);
  183. _starpu_xerbla_("DTGEXC", &i__1);
  184. return 0;
  185. } else if (lquery) {
  186. return 0;
  187. }
  188. /* Quick return if possible */
  189. if (*n <= 1) {
  190. return 0;
  191. }
  192. /* Determine the first row of the specified block and find out */
  193. /* if it is 1-by-1 or 2-by-2. */
  194. if (*ifst > 1) {
  195. if (a[*ifst + (*ifst - 1) * a_dim1] != 0.) {
  196. --(*ifst);
  197. }
  198. }
  199. nbf = 1;
  200. if (*ifst < *n) {
  201. if (a[*ifst + 1 + *ifst * a_dim1] != 0.) {
  202. nbf = 2;
  203. }
  204. }
  205. /* Determine the first row of the final block */
  206. /* and find out if it is 1-by-1 or 2-by-2. */
  207. if (*ilst > 1) {
  208. if (a[*ilst + (*ilst - 1) * a_dim1] != 0.) {
  209. --(*ilst);
  210. }
  211. }
  212. nbl = 1;
  213. if (*ilst < *n) {
  214. if (a[*ilst + 1 + *ilst * a_dim1] != 0.) {
  215. nbl = 2;
  216. }
  217. }
  218. if (*ifst == *ilst) {
  219. return 0;
  220. }
  221. if (*ifst < *ilst) {
  222. /* Update ILST. */
  223. if (nbf == 2 && nbl == 1) {
  224. --(*ilst);
  225. }
  226. if (nbf == 1 && nbl == 2) {
  227. ++(*ilst);
  228. }
  229. here = *ifst;
  230. L10:
  231. /* Swap with next one below. */
  232. if (nbf == 1 || nbf == 2) {
  233. /* Current block either 1-by-1 or 2-by-2. */
  234. nbnext = 1;
  235. if (here + nbf + 1 <= *n) {
  236. if (a[here + nbf + 1 + (here + nbf) * a_dim1] != 0.) {
  237. nbnext = 2;
  238. }
  239. }
  240. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb, &q[
  241. q_offset], ldq, &z__[z_offset], ldz, &here, &nbf, &nbnext,
  242. &work[1], lwork, info);
  243. if (*info != 0) {
  244. *ilst = here;
  245. return 0;
  246. }
  247. here += nbnext;
  248. /* Test if 2-by-2 block breaks into two 1-by-1 blocks. */
  249. if (nbf == 2) {
  250. if (a[here + 1 + here * a_dim1] == 0.) {
  251. nbf = 3;
  252. }
  253. }
  254. } else {
  255. /* Current block consists of two 1-by-1 blocks, each of which */
  256. /* must be swapped individually. */
  257. nbnext = 1;
  258. if (here + 3 <= *n) {
  259. if (a[here + 3 + (here + 2) * a_dim1] != 0.) {
  260. nbnext = 2;
  261. }
  262. }
  263. i__1 = here + 1;
  264. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb, &q[
  265. q_offset], ldq, &z__[z_offset], ldz, &i__1, &c__1, &
  266. nbnext, &work[1], lwork, info);
  267. if (*info != 0) {
  268. *ilst = here;
  269. return 0;
  270. }
  271. if (nbnext == 1) {
  272. /* Swap two 1-by-1 blocks. */
  273. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb,
  274. &q[q_offset], ldq, &z__[z_offset], ldz, &here, &c__1,
  275. &c__1, &work[1], lwork, info);
  276. if (*info != 0) {
  277. *ilst = here;
  278. return 0;
  279. }
  280. ++here;
  281. } else {
  282. /* Recompute NBNEXT in case of 2-by-2 split. */
  283. if (a[here + 2 + (here + 1) * a_dim1] == 0.) {
  284. nbnext = 1;
  285. }
  286. if (nbnext == 2) {
  287. /* 2-by-2 block did not split. */
  288. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  289. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &
  290. here, &c__1, &nbnext, &work[1], lwork, info);
  291. if (*info != 0) {
  292. *ilst = here;
  293. return 0;
  294. }
  295. here += 2;
  296. } else {
  297. /* 2-by-2 block did split. */
  298. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  299. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &
  300. here, &c__1, &c__1, &work[1], lwork, info);
  301. if (*info != 0) {
  302. *ilst = here;
  303. return 0;
  304. }
  305. ++here;
  306. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  307. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &
  308. here, &c__1, &c__1, &work[1], lwork, info);
  309. if (*info != 0) {
  310. *ilst = here;
  311. return 0;
  312. }
  313. ++here;
  314. }
  315. }
  316. }
  317. if (here < *ilst) {
  318. goto L10;
  319. }
  320. } else {
  321. here = *ifst;
  322. L20:
  323. /* Swap with next one below. */
  324. if (nbf == 1 || nbf == 2) {
  325. /* Current block either 1-by-1 or 2-by-2. */
  326. nbnext = 1;
  327. if (here >= 3) {
  328. if (a[here - 1 + (here - 2) * a_dim1] != 0.) {
  329. nbnext = 2;
  330. }
  331. }
  332. i__1 = here - nbnext;
  333. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb, &q[
  334. q_offset], ldq, &z__[z_offset], ldz, &i__1, &nbnext, &nbf,
  335. &work[1], lwork, info);
  336. if (*info != 0) {
  337. *ilst = here;
  338. return 0;
  339. }
  340. here -= nbnext;
  341. /* Test if 2-by-2 block breaks into two 1-by-1 blocks. */
  342. if (nbf == 2) {
  343. if (a[here + 1 + here * a_dim1] == 0.) {
  344. nbf = 3;
  345. }
  346. }
  347. } else {
  348. /* Current block consists of two 1-by-1 blocks, each of which */
  349. /* must be swapped individually. */
  350. nbnext = 1;
  351. if (here >= 3) {
  352. if (a[here - 1 + (here - 2) * a_dim1] != 0.) {
  353. nbnext = 2;
  354. }
  355. }
  356. i__1 = here - nbnext;
  357. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb, &q[
  358. q_offset], ldq, &z__[z_offset], ldz, &i__1, &nbnext, &
  359. c__1, &work[1], lwork, info);
  360. if (*info != 0) {
  361. *ilst = here;
  362. return 0;
  363. }
  364. if (nbnext == 1) {
  365. /* Swap two 1-by-1 blocks. */
  366. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb,
  367. &q[q_offset], ldq, &z__[z_offset], ldz, &here, &
  368. nbnext, &c__1, &work[1], lwork, info);
  369. if (*info != 0) {
  370. *ilst = here;
  371. return 0;
  372. }
  373. --here;
  374. } else {
  375. /* Recompute NBNEXT in case of 2-by-2 split. */
  376. if (a[here + (here - 1) * a_dim1] == 0.) {
  377. nbnext = 1;
  378. }
  379. if (nbnext == 2) {
  380. /* 2-by-2 block did not split. */
  381. i__1 = here - 1;
  382. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  383. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &
  384. i__1, &c__2, &c__1, &work[1], lwork, info);
  385. if (*info != 0) {
  386. *ilst = here;
  387. return 0;
  388. }
  389. here += -2;
  390. } else {
  391. /* 2-by-2 block did split. */
  392. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  393. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &
  394. here, &c__1, &c__1, &work[1], lwork, info);
  395. if (*info != 0) {
  396. *ilst = here;
  397. return 0;
  398. }
  399. --here;
  400. _starpu_dtgex2_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  401. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &
  402. here, &c__1, &c__1, &work[1], lwork, info);
  403. if (*info != 0) {
  404. *ilst = here;
  405. return 0;
  406. }
  407. --here;
  408. }
  409. }
  410. }
  411. if (here > *ilst) {
  412. goto L20;
  413. }
  414. }
  415. *ilst = here;
  416. work[1] = (doublereal) lwmin;
  417. return 0;
  418. /* End of DTGEXC */
  419. } /* _starpu_dtgexc_ */