dggesx.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /* dggesx.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__0 = 0;
  16. static integer c_n1 = -1;
  17. static doublereal c_b42 = 0.;
  18. static doublereal c_b43 = 1.;
  19. /* Subroutine */ int _starpu_dggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp
  20. selctg, char *sense, integer *n, doublereal *a, integer *lda,
  21. doublereal *b, integer *ldb, integer *sdim, doublereal *alphar,
  22. doublereal *alphai, doublereal *beta, doublereal *vsl, integer *ldvsl,
  23. doublereal *vsr, integer *ldvsr, doublereal *rconde, doublereal *
  24. rcondv, doublereal *work, integer *lwork, integer *iwork, integer *
  25. liwork, logical *bwork, integer *info)
  26. {
  27. /* System generated locals */
  28. integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
  29. vsr_dim1, vsr_offset, i__1, i__2;
  30. doublereal d__1;
  31. /* Builtin functions */
  32. double sqrt(doublereal);
  33. /* Local variables */
  34. integer i__, ip;
  35. doublereal pl, pr, dif[2];
  36. integer ihi, ilo;
  37. doublereal eps;
  38. integer ijob;
  39. doublereal anrm, bnrm;
  40. integer ierr, itau, iwrk, lwrk;
  41. extern logical _starpu_lsame_(char *, char *);
  42. integer ileft, icols;
  43. logical cursl, ilvsl, ilvsr;
  44. integer irows;
  45. extern /* Subroutine */ int _starpu_dlabad_(doublereal *, doublereal *), _starpu_dggbak_(
  46. char *, char *, integer *, integer *, integer *, doublereal *,
  47. doublereal *, integer *, doublereal *, integer *, integer *), _starpu_dggbal_(char *, integer *, doublereal *, integer
  48. *, doublereal *, integer *, integer *, integer *, doublereal *,
  49. doublereal *, doublereal *, integer *);
  50. logical lst2sl;
  51. extern doublereal _starpu_dlamch_(char *), _starpu_dlange_(char *, integer *,
  52. integer *, doublereal *, integer *, doublereal *);
  53. extern /* Subroutine */ int _starpu_dgghrd_(char *, char *, integer *, integer *,
  54. integer *, doublereal *, integer *, doublereal *, integer *,
  55. doublereal *, integer *, doublereal *, integer *, integer *), _starpu_dlascl_(char *, integer *, integer *, doublereal
  56. *, doublereal *, integer *, integer *, doublereal *, integer *,
  57. integer *);
  58. logical ilascl, ilbscl;
  59. extern /* Subroutine */ int _starpu_dgeqrf_(integer *, integer *, doublereal *,
  60. integer *, doublereal *, doublereal *, integer *, integer *),
  61. _starpu_dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  62. doublereal *, integer *);
  63. doublereal safmin;
  64. extern /* Subroutine */ int _starpu_dlaset_(char *, integer *, integer *,
  65. doublereal *, doublereal *, doublereal *, integer *);
  66. doublereal safmax;
  67. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  68. doublereal bignum;
  69. extern /* Subroutine */ int _starpu_dhgeqz_(char *, char *, char *, integer *,
  70. integer *, integer *, doublereal *, integer *, doublereal *,
  71. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  72. integer *, doublereal *, integer *, doublereal *, integer *,
  73. integer *);
  74. integer ijobvl, iright;
  75. extern /* Subroutine */ int _starpu_dtgsen_(integer *, logical *, logical *,
  76. logical *, integer *, doublereal *, integer *, doublereal *,
  77. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  78. integer *, doublereal *, integer *, integer *, doublereal *,
  79. doublereal *, doublereal *, doublereal *, integer *, integer *,
  80. integer *, integer *);
  81. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  82. integer *, integer *);
  83. integer ijobvr;
  84. logical wantsb;
  85. integer liwmin;
  86. logical wantse, lastsl;
  87. doublereal anrmto, bnrmto;
  88. extern /* Subroutine */ int _starpu_dorgqr_(integer *, integer *, integer *,
  89. doublereal *, integer *, doublereal *, doublereal *, integer *,
  90. integer *);
  91. integer minwrk, maxwrk;
  92. logical wantsn;
  93. doublereal smlnum;
  94. extern /* Subroutine */ int _starpu_dormqr_(char *, char *, integer *, integer *,
  95. integer *, doublereal *, integer *, doublereal *, doublereal *,
  96. integer *, doublereal *, integer *, integer *);
  97. logical wantst, lquery, wantsv;
  98. /* -- LAPACK driver routine (version 3.2) -- */
  99. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  100. /* November 2006 */
  101. /* .. Scalar Arguments .. */
  102. /* .. */
  103. /* .. Array Arguments .. */
  104. /* .. */
  105. /* .. Function Arguments .. */
  106. /* .. */
  107. /* Purpose */
  108. /* ======= */
  109. /* DGGESX computes for a pair of N-by-N real nonsymmetric matrices */
  110. /* (A,B), the generalized eigenvalues, the real Schur form (S,T), and, */
  111. /* optionally, the left and/or right matrices of Schur vectors (VSL and */
  112. /* VSR). This gives the generalized Schur factorization */
  113. /* (A,B) = ( (VSL) S (VSR)**T, (VSL) T (VSR)**T ) */
  114. /* Optionally, it also orders the eigenvalues so that a selected cluster */
  115. /* of eigenvalues appears in the leading diagonal blocks of the upper */
  116. /* quasi-triangular matrix S and the upper triangular matrix T; computes */
  117. /* a reciprocal condition number for the average of the selected */
  118. /* eigenvalues (RCONDE); and computes a reciprocal condition number for */
  119. /* the right and left deflating subspaces corresponding to the selected */
  120. /* eigenvalues (RCONDV). The leading columns of VSL and VSR then form */
  121. /* an orthonormal basis for the corresponding left and right eigenspaces */
  122. /* (deflating subspaces). */
  123. /* A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */
  124. /* or a ratio alpha/beta = w, such that A - w*B is singular. It is */
  125. /* usually represented as the pair (alpha,beta), as there is a */
  126. /* reasonable interpretation for beta=0 or for both being zero. */
  127. /* A pair of matrices (S,T) is in generalized real Schur form if T is */
  128. /* upper triangular with non-negative diagonal and S is block upper */
  129. /* triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond */
  130. /* to real generalized eigenvalues, while 2-by-2 blocks of S will be */
  131. /* "standardized" by making the corresponding elements of T have the */
  132. /* form: */
  133. /* [ a 0 ] */
  134. /* [ 0 b ] */
  135. /* and the pair of corresponding 2-by-2 blocks in S and T will have a */
  136. /* complex conjugate pair of generalized eigenvalues. */
  137. /* Arguments */
  138. /* ========= */
  139. /* JOBVSL (input) CHARACTER*1 */
  140. /* = 'N': do not compute the left Schur vectors; */
  141. /* = 'V': compute the left Schur vectors. */
  142. /* JOBVSR (input) CHARACTER*1 */
  143. /* = 'N': do not compute the right Schur vectors; */
  144. /* = 'V': compute the right Schur vectors. */
  145. /* SORT (input) CHARACTER*1 */
  146. /* Specifies whether or not to order the eigenvalues on the */
  147. /* diagonal of the generalized Schur form. */
  148. /* = 'N': Eigenvalues are not ordered; */
  149. /* = 'S': Eigenvalues are ordered (see SELCTG). */
  150. /* SELCTG (external procedure) LOGICAL FUNCTION of three DOUBLE PRECISION arguments */
  151. /* SELCTG must be declared EXTERNAL in the calling subroutine. */
  152. /* If SORT = 'N', SELCTG is not referenced. */
  153. /* If SORT = 'S', SELCTG is used to select eigenvalues to sort */
  154. /* to the top left of the Schur form. */
  155. /* An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if */
  156. /* SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either */
  157. /* one of a complex conjugate pair of eigenvalues is selected, */
  158. /* then both complex eigenvalues are selected. */
  159. /* Note that a selected complex eigenvalue may no longer satisfy */
  160. /* SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) = .TRUE. after ordering, */
  161. /* since ordering may change the value of complex eigenvalues */
  162. /* (especially if the eigenvalue is ill-conditioned), in this */
  163. /* case INFO is set to N+3. */
  164. /* SENSE (input) CHARACTER*1 */
  165. /* Determines which reciprocal condition numbers are computed. */
  166. /* = 'N' : None are computed; */
  167. /* = 'E' : Computed for average of selected eigenvalues only; */
  168. /* = 'V' : Computed for selected deflating subspaces only; */
  169. /* = 'B' : Computed for both. */
  170. /* If SENSE = 'E', 'V', or 'B', SORT must equal 'S'. */
  171. /* N (input) INTEGER */
  172. /* The order of the matrices A, B, VSL, and VSR. N >= 0. */
  173. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  174. /* On entry, the first of the pair of matrices. */
  175. /* On exit, A has been overwritten by its generalized Schur */
  176. /* form S. */
  177. /* LDA (input) INTEGER */
  178. /* The leading dimension of A. LDA >= max(1,N). */
  179. /* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
  180. /* On entry, the second of the pair of matrices. */
  181. /* On exit, B has been overwritten by its generalized Schur */
  182. /* form T. */
  183. /* LDB (input) INTEGER */
  184. /* The leading dimension of B. LDB >= max(1,N). */
  185. /* SDIM (output) INTEGER */
  186. /* If SORT = 'N', SDIM = 0. */
  187. /* If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
  188. /* for which SELCTG is true. (Complex conjugate pairs for which */
  189. /* SELCTG is true for either eigenvalue count as 2.) */
  190. /* ALPHAR (output) DOUBLE PRECISION array, dimension (N) */
  191. /* ALPHAI (output) DOUBLE PRECISION array, dimension (N) */
  192. /* BETA (output) DOUBLE PRECISION array, dimension (N) */
  193. /* On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  194. /* be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i */
  195. /* and BETA(j),j=1,...,N are the diagonals of the complex Schur */
  196. /* form (S,T) that would result if the 2-by-2 diagonal blocks of */
  197. /* the real Schur form of (A,B) were further reduced to */
  198. /* triangular form using 2-by-2 complex unitary transformations. */
  199. /* If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  200. /* positive, then the j-th and (j+1)-st eigenvalues are a */
  201. /* complex conjugate pair, with ALPHAI(j+1) negative. */
  202. /* Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
  203. /* may easily over- or underflow, and BETA(j) may even be zero. */
  204. /* Thus, the user should avoid naively computing the ratio. */
  205. /* However, ALPHAR and ALPHAI will be always less than and */
  206. /* usually comparable with norm(A) in magnitude, and BETA always */
  207. /* less than and usually comparable with norm(B). */
  208. /* VSL (output) DOUBLE PRECISION array, dimension (LDVSL,N) */
  209. /* If JOBVSL = 'V', VSL will contain the left Schur vectors. */
  210. /* Not referenced if JOBVSL = 'N'. */
  211. /* LDVSL (input) INTEGER */
  212. /* The leading dimension of the matrix VSL. LDVSL >=1, and */
  213. /* if JOBVSL = 'V', LDVSL >= N. */
  214. /* VSR (output) DOUBLE PRECISION array, dimension (LDVSR,N) */
  215. /* If JOBVSR = 'V', VSR will contain the right Schur vectors. */
  216. /* Not referenced if JOBVSR = 'N'. */
  217. /* LDVSR (input) INTEGER */
  218. /* The leading dimension of the matrix VSR. LDVSR >= 1, and */
  219. /* if JOBVSR = 'V', LDVSR >= N. */
  220. /* RCONDE (output) DOUBLE PRECISION array, dimension ( 2 ) */
  221. /* If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the */
  222. /* reciprocal condition numbers for the average of the selected */
  223. /* eigenvalues. */
  224. /* Not referenced if SENSE = 'N' or 'V'. */
  225. /* RCONDV (output) DOUBLE PRECISION array, dimension ( 2 ) */
  226. /* If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the */
  227. /* reciprocal condition numbers for the selected deflating */
  228. /* subspaces. */
  229. /* Not referenced if SENSE = 'N' or 'E'. */
  230. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  231. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  232. /* LWORK (input) INTEGER */
  233. /* The dimension of the array WORK. */
  234. /* If N = 0, LWORK >= 1, else if SENSE = 'E', 'V', or 'B', */
  235. /* LWORK >= max( 8*N, 6*N+16, 2*SDIM*(N-SDIM) ), else */
  236. /* LWORK >= max( 8*N, 6*N+16 ). */
  237. /* Note that 2*SDIM*(N-SDIM) <= N*N/2. */
  238. /* Note also that an error is only returned if */
  239. /* LWORK < max( 8*N, 6*N+16), but if SENSE = 'E' or 'V' or 'B' */
  240. /* this may not be large enough. */
  241. /* If LWORK = -1, then a workspace query is assumed; the routine */
  242. /* only calculates the bound on the optimal size of the WORK */
  243. /* array and the minimum size of the IWORK array, returns these */
  244. /* values as the first entries of the WORK and IWORK arrays, and */
  245. /* no error message related to LWORK or LIWORK is issued by */
  246. /* XERBLA. */
  247. /* IWORK (workspace) INTEGER array, dimension (MAX(1,LIWORK)) */
  248. /* On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
  249. /* LIWORK (input) INTEGER */
  250. /* The dimension of the array IWORK. */
  251. /* If SENSE = 'N' or N = 0, LIWORK >= 1, otherwise */
  252. /* LIWORK >= N+6. */
  253. /* If LIWORK = -1, then a workspace query is assumed; the */
  254. /* routine only calculates the bound on the optimal size of the */
  255. /* WORK array and the minimum size of the IWORK array, returns */
  256. /* these values as the first entries of the WORK and IWORK */
  257. /* arrays, and no error message related to LWORK or LIWORK is */
  258. /* issued by XERBLA. */
  259. /* BWORK (workspace) LOGICAL array, dimension (N) */
  260. /* Not referenced if SORT = 'N'. */
  261. /* INFO (output) INTEGER */
  262. /* = 0: successful exit */
  263. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  264. /* = 1,...,N: */
  265. /* The QZ iteration failed. (A,B) are not in Schur */
  266. /* form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
  267. /* be correct for j=INFO+1,...,N. */
  268. /* > N: =N+1: other than QZ iteration failed in DHGEQZ */
  269. /* =N+2: after reordering, roundoff changed values of */
  270. /* some complex eigenvalues so that leading */
  271. /* eigenvalues in the Generalized Schur form no */
  272. /* longer satisfy SELCTG=.TRUE. This could also */
  273. /* be caused due to scaling. */
  274. /* =N+3: reordering failed in DTGSEN. */
  275. /* Further details */
  276. /* =============== */
  277. /* An approximate (asymptotic) bound on the average absolute error of */
  278. /* the selected eigenvalues is */
  279. /* EPS * norm((A, B)) / RCONDE( 1 ). */
  280. /* An approximate (asymptotic) bound on the maximum angular error in */
  281. /* the computed deflating subspaces is */
  282. /* EPS * norm((A, B)) / RCONDV( 2 ). */
  283. /* See LAPACK User's Guide, section 4.11 for more information. */
  284. /* ===================================================================== */
  285. /* .. Parameters .. */
  286. /* .. */
  287. /* .. Local Scalars .. */
  288. /* .. */
  289. /* .. Local Arrays .. */
  290. /* .. */
  291. /* .. External Subroutines .. */
  292. /* .. */
  293. /* .. External Functions .. */
  294. /* .. */
  295. /* .. Intrinsic Functions .. */
  296. /* .. */
  297. /* .. Executable Statements .. */
  298. /* Decode the input arguments */
  299. /* Parameter adjustments */
  300. a_dim1 = *lda;
  301. a_offset = 1 + a_dim1;
  302. a -= a_offset;
  303. b_dim1 = *ldb;
  304. b_offset = 1 + b_dim1;
  305. b -= b_offset;
  306. --alphar;
  307. --alphai;
  308. --beta;
  309. vsl_dim1 = *ldvsl;
  310. vsl_offset = 1 + vsl_dim1;
  311. vsl -= vsl_offset;
  312. vsr_dim1 = *ldvsr;
  313. vsr_offset = 1 + vsr_dim1;
  314. vsr -= vsr_offset;
  315. --rconde;
  316. --rcondv;
  317. --work;
  318. --iwork;
  319. --bwork;
  320. /* Function Body */
  321. if (_starpu_lsame_(jobvsl, "N")) {
  322. ijobvl = 1;
  323. ilvsl = FALSE_;
  324. } else if (_starpu_lsame_(jobvsl, "V")) {
  325. ijobvl = 2;
  326. ilvsl = TRUE_;
  327. } else {
  328. ijobvl = -1;
  329. ilvsl = FALSE_;
  330. }
  331. if (_starpu_lsame_(jobvsr, "N")) {
  332. ijobvr = 1;
  333. ilvsr = FALSE_;
  334. } else if (_starpu_lsame_(jobvsr, "V")) {
  335. ijobvr = 2;
  336. ilvsr = TRUE_;
  337. } else {
  338. ijobvr = -1;
  339. ilvsr = FALSE_;
  340. }
  341. wantst = _starpu_lsame_(sort, "S");
  342. wantsn = _starpu_lsame_(sense, "N");
  343. wantse = _starpu_lsame_(sense, "E");
  344. wantsv = _starpu_lsame_(sense, "V");
  345. wantsb = _starpu_lsame_(sense, "B");
  346. lquery = *lwork == -1 || *liwork == -1;
  347. if (wantsn) {
  348. ijob = 0;
  349. } else if (wantse) {
  350. ijob = 1;
  351. } else if (wantsv) {
  352. ijob = 2;
  353. } else if (wantsb) {
  354. ijob = 4;
  355. }
  356. /* Test the input arguments */
  357. *info = 0;
  358. if (ijobvl <= 0) {
  359. *info = -1;
  360. } else if (ijobvr <= 0) {
  361. *info = -2;
  362. } else if (! wantst && ! _starpu_lsame_(sort, "N")) {
  363. *info = -3;
  364. } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
  365. wantsn) {
  366. *info = -5;
  367. } else if (*n < 0) {
  368. *info = -6;
  369. } else if (*lda < max(1,*n)) {
  370. *info = -8;
  371. } else if (*ldb < max(1,*n)) {
  372. *info = -10;
  373. } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
  374. *info = -16;
  375. } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
  376. *info = -18;
  377. }
  378. /* Compute workspace */
  379. /* (Note: Comments in the code beginning "Workspace:" describe the */
  380. /* minimal amount of workspace needed at that point in the code, */
  381. /* as well as the preferred amount for good performance. */
  382. /* NB refers to the optimal block size for the immediately */
  383. /* following subroutine, as returned by ILAENV.) */
  384. if (*info == 0) {
  385. if (*n > 0) {
  386. /* Computing MAX */
  387. i__1 = *n << 3, i__2 = *n * 6 + 16;
  388. minwrk = max(i__1,i__2);
  389. maxwrk = minwrk - *n + *n * _starpu_ilaenv_(&c__1, "DGEQRF", " ", n, &
  390. c__1, n, &c__0);
  391. /* Computing MAX */
  392. i__1 = maxwrk, i__2 = minwrk - *n + *n * _starpu_ilaenv_(&c__1, "DORMQR",
  393. " ", n, &c__1, n, &c_n1);
  394. maxwrk = max(i__1,i__2);
  395. if (ilvsl) {
  396. /* Computing MAX */
  397. i__1 = maxwrk, i__2 = minwrk - *n + *n * _starpu_ilaenv_(&c__1, "DOR"
  398. "GQR", " ", n, &c__1, n, &c_n1);
  399. maxwrk = max(i__1,i__2);
  400. }
  401. lwrk = maxwrk;
  402. if (ijob >= 1) {
  403. /* Computing MAX */
  404. i__1 = lwrk, i__2 = *n * *n / 2;
  405. lwrk = max(i__1,i__2);
  406. }
  407. } else {
  408. minwrk = 1;
  409. maxwrk = 1;
  410. lwrk = 1;
  411. }
  412. work[1] = (doublereal) lwrk;
  413. if (wantsn || *n == 0) {
  414. liwmin = 1;
  415. } else {
  416. liwmin = *n + 6;
  417. }
  418. iwork[1] = liwmin;
  419. if (*lwork < minwrk && ! lquery) {
  420. *info = -22;
  421. } else if (*liwork < liwmin && ! lquery) {
  422. *info = -24;
  423. }
  424. }
  425. if (*info != 0) {
  426. i__1 = -(*info);
  427. _starpu_xerbla_("DGGESX", &i__1);
  428. return 0;
  429. } else if (lquery) {
  430. return 0;
  431. }
  432. /* Quick return if possible */
  433. if (*n == 0) {
  434. *sdim = 0;
  435. return 0;
  436. }
  437. /* Get machine constants */
  438. eps = _starpu_dlamch_("P");
  439. safmin = _starpu_dlamch_("S");
  440. safmax = 1. / safmin;
  441. _starpu_dlabad_(&safmin, &safmax);
  442. smlnum = sqrt(safmin) / eps;
  443. bignum = 1. / smlnum;
  444. /* Scale A if max element outside range [SMLNUM,BIGNUM] */
  445. anrm = _starpu_dlange_("M", n, n, &a[a_offset], lda, &work[1]);
  446. ilascl = FALSE_;
  447. if (anrm > 0. && anrm < smlnum) {
  448. anrmto = smlnum;
  449. ilascl = TRUE_;
  450. } else if (anrm > bignum) {
  451. anrmto = bignum;
  452. ilascl = TRUE_;
  453. }
  454. if (ilascl) {
  455. _starpu_dlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  456. ierr);
  457. }
  458. /* Scale B if max element outside range [SMLNUM,BIGNUM] */
  459. bnrm = _starpu_dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
  460. ilbscl = FALSE_;
  461. if (bnrm > 0. && bnrm < smlnum) {
  462. bnrmto = smlnum;
  463. ilbscl = TRUE_;
  464. } else if (bnrm > bignum) {
  465. bnrmto = bignum;
  466. ilbscl = TRUE_;
  467. }
  468. if (ilbscl) {
  469. _starpu_dlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  470. ierr);
  471. }
  472. /* Permute the matrix to make it more nearly triangular */
  473. /* (Workspace: need 6*N + 2*N for permutation parameters) */
  474. ileft = 1;
  475. iright = *n + 1;
  476. iwrk = iright + *n;
  477. _starpu_dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  478. ileft], &work[iright], &work[iwrk], &ierr);
  479. /* Reduce B to triangular form (QR decomposition of B) */
  480. /* (Workspace: need N, prefer N*NB) */
  481. irows = ihi + 1 - ilo;
  482. icols = *n + 1 - ilo;
  483. itau = iwrk;
  484. iwrk = itau + irows;
  485. i__1 = *lwork + 1 - iwrk;
  486. _starpu_dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  487. iwrk], &i__1, &ierr);
  488. /* Apply the orthogonal transformation to matrix A */
  489. /* (Workspace: need N, prefer N*NB) */
  490. i__1 = *lwork + 1 - iwrk;
  491. _starpu_dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  492. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
  493. ierr);
  494. /* Initialize VSL */
  495. /* (Workspace: need N, prefer N*NB) */
  496. if (ilvsl) {
  497. _starpu_dlaset_("Full", n, n, &c_b42, &c_b43, &vsl[vsl_offset], ldvsl);
  498. if (irows > 1) {
  499. i__1 = irows - 1;
  500. i__2 = irows - 1;
  501. _starpu_dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
  502. ilo + 1 + ilo * vsl_dim1], ldvsl);
  503. }
  504. i__1 = *lwork + 1 - iwrk;
  505. _starpu_dorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
  506. work[itau], &work[iwrk], &i__1, &ierr);
  507. }
  508. /* Initialize VSR */
  509. if (ilvsr) {
  510. _starpu_dlaset_("Full", n, n, &c_b42, &c_b43, &vsr[vsr_offset], ldvsr);
  511. }
  512. /* Reduce to generalized Hessenberg form */
  513. /* (Workspace: none needed) */
  514. _starpu_dgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  515. ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
  516. *sdim = 0;
  517. /* Perform QZ algorithm, computing Schur vectors if desired */
  518. /* (Workspace: need N) */
  519. iwrk = itau;
  520. i__1 = *lwork + 1 - iwrk;
  521. _starpu_dhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  522. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
  523. , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &ierr);
  524. if (ierr != 0) {
  525. if (ierr > 0 && ierr <= *n) {
  526. *info = ierr;
  527. } else if (ierr > *n && ierr <= *n << 1) {
  528. *info = ierr - *n;
  529. } else {
  530. *info = *n + 1;
  531. }
  532. goto L60;
  533. }
  534. /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */
  535. /* condition number(s) */
  536. /* (Workspace: If IJOB >= 1, need MAX( 8*(N+1), 2*SDIM*(N-SDIM) ) */
  537. /* otherwise, need 8*(N+1) ) */
  538. if (wantst) {
  539. /* Undo scaling on eigenvalues before SELCTGing */
  540. if (ilascl) {
  541. _starpu_dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1],
  542. n, &ierr);
  543. _starpu_dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1],
  544. n, &ierr);
  545. }
  546. if (ilbscl) {
  547. _starpu_dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
  548. &ierr);
  549. }
  550. /* Select eigenvalues */
  551. i__1 = *n;
  552. for (i__ = 1; i__ <= i__1; ++i__) {
  553. bwork[i__] = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
  554. /* L10: */
  555. }
  556. /* Reorder eigenvalues, transform Generalized Schur vectors, and */
  557. /* compute reciprocal condition numbers */
  558. i__1 = *lwork - iwrk + 1;
  559. _starpu_dtgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
  560. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[
  561. vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pl, &pr,
  562. dif, &work[iwrk], &i__1, &iwork[1], liwork, &ierr);
  563. if (ijob >= 1) {
  564. /* Computing MAX */
  565. i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
  566. maxwrk = max(i__1,i__2);
  567. }
  568. if (ierr == -22) {
  569. /* not enough real workspace */
  570. *info = -22;
  571. } else {
  572. if (ijob == 1 || ijob == 4) {
  573. rconde[1] = pl;
  574. rconde[2] = pr;
  575. }
  576. if (ijob == 2 || ijob == 4) {
  577. rcondv[1] = dif[0];
  578. rcondv[2] = dif[1];
  579. }
  580. if (ierr == 1) {
  581. *info = *n + 3;
  582. }
  583. }
  584. }
  585. /* Apply permutation to VSL and VSR */
  586. /* (Workspace: none needed) */
  587. if (ilvsl) {
  588. _starpu_dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
  589. vsl_offset], ldvsl, &ierr);
  590. }
  591. if (ilvsr) {
  592. _starpu_dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
  593. vsr_offset], ldvsr, &ierr);
  594. }
  595. /* Check if unscaling would cause over/underflow, if so, rescale */
  596. /* (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of */
  597. /* B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) */
  598. if (ilascl) {
  599. i__1 = *n;
  600. for (i__ = 1; i__ <= i__1; ++i__) {
  601. if (alphai[i__] != 0.) {
  602. if (alphar[i__] / safmax > anrmto / anrm || safmin / alphar[
  603. i__] > anrm / anrmto) {
  604. work[1] = (d__1 = a[i__ + i__ * a_dim1] / alphar[i__],
  605. abs(d__1));
  606. beta[i__] *= work[1];
  607. alphar[i__] *= work[1];
  608. alphai[i__] *= work[1];
  609. } else if (alphai[i__] / safmax > anrmto / anrm || safmin /
  610. alphai[i__] > anrm / anrmto) {
  611. work[1] = (d__1 = a[i__ + (i__ + 1) * a_dim1] / alphai[
  612. i__], abs(d__1));
  613. beta[i__] *= work[1];
  614. alphar[i__] *= work[1];
  615. alphai[i__] *= work[1];
  616. }
  617. }
  618. /* L20: */
  619. }
  620. }
  621. if (ilbscl) {
  622. i__1 = *n;
  623. for (i__ = 1; i__ <= i__1; ++i__) {
  624. if (alphai[i__] != 0.) {
  625. if (beta[i__] / safmax > bnrmto / bnrm || safmin / beta[i__]
  626. > bnrm / bnrmto) {
  627. work[1] = (d__1 = b[i__ + i__ * b_dim1] / beta[i__], abs(
  628. d__1));
  629. beta[i__] *= work[1];
  630. alphar[i__] *= work[1];
  631. alphai[i__] *= work[1];
  632. }
  633. }
  634. /* L30: */
  635. }
  636. }
  637. /* Undo scaling */
  638. if (ilascl) {
  639. _starpu_dlascl_("H", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
  640. ierr);
  641. _starpu_dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  642. ierr);
  643. _starpu_dlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  644. ierr);
  645. }
  646. if (ilbscl) {
  647. _starpu_dlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
  648. ierr);
  649. _starpu_dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  650. ierr);
  651. }
  652. if (wantst) {
  653. /* Check if reordering is correct */
  654. lastsl = TRUE_;
  655. lst2sl = TRUE_;
  656. *sdim = 0;
  657. ip = 0;
  658. i__1 = *n;
  659. for (i__ = 1; i__ <= i__1; ++i__) {
  660. cursl = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
  661. if (alphai[i__] == 0.) {
  662. if (cursl) {
  663. ++(*sdim);
  664. }
  665. ip = 0;
  666. if (cursl && ! lastsl) {
  667. *info = *n + 2;
  668. }
  669. } else {
  670. if (ip == 1) {
  671. /* Last eigenvalue of conjugate pair */
  672. cursl = cursl || lastsl;
  673. lastsl = cursl;
  674. if (cursl) {
  675. *sdim += 2;
  676. }
  677. ip = -1;
  678. if (cursl && ! lst2sl) {
  679. *info = *n + 2;
  680. }
  681. } else {
  682. /* First eigenvalue of conjugate pair */
  683. ip = 1;
  684. }
  685. }
  686. lst2sl = lastsl;
  687. lastsl = cursl;
  688. /* L50: */
  689. }
  690. }
  691. L60:
  692. work[1] = (doublereal) maxwrk;
  693. iwork[1] = liwmin;
  694. return 0;
  695. /* End of DGGESX */
  696. } /* _starpu_dggesx_ */