dtgsen.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. /* dtgsen.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. static doublereal c_b28 = 1.;
  17. /* Subroutine */ int _starpu_dtgsen_(integer *ijob, logical *wantq, logical *wantz,
  18. logical *select, integer *n, doublereal *a, integer *lda, doublereal *
  19. b, integer *ldb, doublereal *alphar, doublereal *alphai, doublereal *
  20. beta, doublereal *q, integer *ldq, doublereal *z__, integer *ldz,
  21. integer *m, doublereal *pl, doublereal *pr, doublereal *dif,
  22. doublereal *work, integer *lwork, integer *iwork, integer *liwork,
  23. integer *info)
  24. {
  25. /* System generated locals */
  26. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  27. z_offset, i__1, i__2;
  28. doublereal d__1;
  29. /* Builtin functions */
  30. double sqrt(doublereal), d_sign(doublereal *, doublereal *);
  31. /* Local variables */
  32. integer i__, k, n1, n2, kk, ks, mn2, ijb;
  33. doublereal eps;
  34. integer kase;
  35. logical pair;
  36. integer ierr;
  37. doublereal dsum;
  38. logical swap;
  39. extern /* Subroutine */ int _starpu_dlag2_(doublereal *, integer *, doublereal *,
  40. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  41. doublereal *, doublereal *);
  42. integer isave[3];
  43. logical wantd;
  44. integer lwmin;
  45. logical wantp;
  46. extern /* Subroutine */ int _starpu_dlacn2_(integer *, doublereal *, doublereal *,
  47. integer *, doublereal *, integer *, integer *);
  48. logical wantd1, wantd2;
  49. extern doublereal _starpu_dlamch_(char *);
  50. doublereal dscale, rdscal;
  51. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  52. doublereal *, integer *, doublereal *, integer *),
  53. _starpu_xerbla_(char *, integer *), _starpu_dtgexc_(logical *, logical *,
  54. integer *, doublereal *, integer *, doublereal *, integer *,
  55. doublereal *, integer *, doublereal *, integer *, integer *,
  56. integer *, doublereal *, integer *, integer *), _starpu_dlassq_(integer *,
  57. doublereal *, integer *, doublereal *, doublereal *);
  58. integer liwmin;
  59. extern /* Subroutine */ int _starpu_dtgsyl_(char *, integer *, integer *, integer
  60. *, doublereal *, integer *, doublereal *, integer *, doublereal *,
  61. integer *, doublereal *, integer *, doublereal *, integer *,
  62. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  63. integer *, integer *, integer *);
  64. doublereal smlnum;
  65. logical lquery;
  66. /* -- LAPACK routine (version 3.2) -- */
  67. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  68. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  69. /* January 2007 */
  70. /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
  71. /* .. Scalar Arguments .. */
  72. /* .. */
  73. /* .. Array Arguments .. */
  74. /* .. */
  75. /* Purpose */
  76. /* ======= */
  77. /* DTGSEN reorders the generalized real Schur decomposition of a real */
  78. /* matrix pair (A, B) (in terms of an orthonormal equivalence trans- */
  79. /* formation Q' * (A, B) * Z), so that a selected cluster of eigenvalues */
  80. /* appears in the leading diagonal blocks of the upper quasi-triangular */
  81. /* matrix A and the upper triangular B. The leading columns of Q and */
  82. /* Z form orthonormal bases of the corresponding left and right eigen- */
  83. /* spaces (deflating subspaces). (A, B) must be in generalized real */
  84. /* Schur canonical form (as returned by DGGES), i.e. A is block upper */
  85. /* triangular with 1-by-1 and 2-by-2 diagonal blocks. B is upper */
  86. /* triangular. */
  87. /* DTGSEN also computes the generalized eigenvalues */
  88. /* w(j) = (ALPHAR(j) + i*ALPHAI(j))/BETA(j) */
  89. /* of the reordered matrix pair (A, B). */
  90. /* Optionally, DTGSEN computes the estimates of reciprocal condition */
  91. /* numbers for eigenvalues and eigenspaces. These are Difu[(A11,B11), */
  92. /* (A22,B22)] and Difl[(A11,B11), (A22,B22)], i.e. the separation(s) */
  93. /* between the matrix pairs (A11, B11) and (A22,B22) that correspond to */
  94. /* the selected cluster and the eigenvalues outside the cluster, resp., */
  95. /* and norms of "projections" onto left and right eigenspaces w.r.t. */
  96. /* the selected cluster in the (1,1)-block. */
  97. /* Arguments */
  98. /* ========= */
  99. /* IJOB (input) INTEGER */
  100. /* Specifies whether condition numbers are required for the */
  101. /* cluster of eigenvalues (PL and PR) or the deflating subspaces */
  102. /* (Difu and Difl): */
  103. /* =0: Only reorder w.r.t. SELECT. No extras. */
  104. /* =1: Reciprocal of norms of "projections" onto left and right */
  105. /* eigenspaces w.r.t. the selected cluster (PL and PR). */
  106. /* =2: Upper bounds on Difu and Difl. F-norm-based estimate */
  107. /* (DIF(1:2)). */
  108. /* =3: Estimate of Difu and Difl. 1-norm-based estimate */
  109. /* (DIF(1:2)). */
  110. /* About 5 times as expensive as IJOB = 2. */
  111. /* =4: Compute PL, PR and DIF (i.e. 0, 1 and 2 above): Economic */
  112. /* version to get it all. */
  113. /* =5: Compute PL, PR and DIF (i.e. 0, 1 and 3 above) */
  114. /* WANTQ (input) LOGICAL */
  115. /* .TRUE. : update the left transformation matrix Q; */
  116. /* .FALSE.: do not update Q. */
  117. /* WANTZ (input) LOGICAL */
  118. /* .TRUE. : update the right transformation matrix Z; */
  119. /* .FALSE.: do not update Z. */
  120. /* SELECT (input) LOGICAL array, dimension (N) */
  121. /* SELECT specifies the eigenvalues in the selected cluster. */
  122. /* To select a real eigenvalue w(j), SELECT(j) must be set to */
  123. /* .TRUE.. To select a complex conjugate pair of eigenvalues */
  124. /* w(j) and w(j+1), corresponding to a 2-by-2 diagonal block, */
  125. /* either SELECT(j) or SELECT(j+1) or both must be set to */
  126. /* .TRUE.; a complex conjugate pair of eigenvalues must be */
  127. /* either both included in the cluster or both excluded. */
  128. /* N (input) INTEGER */
  129. /* The order of the matrices A and B. N >= 0. */
  130. /* A (input/output) DOUBLE PRECISION array, dimension(LDA,N) */
  131. /* On entry, the upper quasi-triangular matrix A, with (A, B) in */
  132. /* generalized real Schur canonical form. */
  133. /* On exit, A is overwritten by the reordered matrix A. */
  134. /* LDA (input) INTEGER */
  135. /* The leading dimension of the array A. LDA >= max(1,N). */
  136. /* B (input/output) DOUBLE PRECISION array, dimension(LDB,N) */
  137. /* On entry, the upper triangular matrix B, with (A, B) in */
  138. /* generalized real Schur canonical form. */
  139. /* On exit, B is overwritten by the reordered matrix B. */
  140. /* LDB (input) INTEGER */
  141. /* The leading dimension of the array B. LDB >= max(1,N). */
  142. /* ALPHAR (output) DOUBLE PRECISION array, dimension (N) */
  143. /* ALPHAI (output) DOUBLE PRECISION array, dimension (N) */
  144. /* BETA (output) DOUBLE PRECISION array, dimension (N) */
  145. /* On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  146. /* be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i */
  147. /* and BETA(j),j=1,...,N are the diagonals of the complex Schur */
  148. /* form (S,T) that would result if the 2-by-2 diagonal blocks of */
  149. /* the real generalized Schur form of (A,B) were further reduced */
  150. /* to triangular form using complex unitary transformations. */
  151. /* If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  152. /* positive, then the j-th and (j+1)-st eigenvalues are a */
  153. /* complex conjugate pair, with ALPHAI(j+1) negative. */
  154. /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */
  155. /* On entry, if WANTQ = .TRUE., Q is an N-by-N matrix. */
  156. /* On exit, Q has been postmultiplied by the left orthogonal */
  157. /* transformation matrix which reorder (A, B); The leading M */
  158. /* columns of Q form orthonormal bases for the specified pair of */
  159. /* left eigenspaces (deflating subspaces). */
  160. /* If WANTQ = .FALSE., Q is not referenced. */
  161. /* LDQ (input) INTEGER */
  162. /* The leading dimension of the array Q. LDQ >= 1; */
  163. /* and if WANTQ = .TRUE., LDQ >= N. */
  164. /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */
  165. /* On entry, if WANTZ = .TRUE., Z is an N-by-N matrix. */
  166. /* On exit, Z has been postmultiplied by the left orthogonal */
  167. /* transformation matrix which reorder (A, B); The leading M */
  168. /* columns of Z form orthonormal bases for the specified pair of */
  169. /* left eigenspaces (deflating subspaces). */
  170. /* If WANTZ = .FALSE., Z is not referenced. */
  171. /* LDZ (input) INTEGER */
  172. /* The leading dimension of the array Z. LDZ >= 1; */
  173. /* If WANTZ = .TRUE., LDZ >= N. */
  174. /* M (output) INTEGER */
  175. /* The dimension of the specified pair of left and right eigen- */
  176. /* spaces (deflating subspaces). 0 <= M <= N. */
  177. /* PL (output) DOUBLE PRECISION */
  178. /* PR (output) DOUBLE PRECISION */
  179. /* If IJOB = 1, 4 or 5, PL, PR are lower bounds on the */
  180. /* reciprocal of the norm of "projections" onto left and right */
  181. /* eigenspaces with respect to the selected cluster. */
  182. /* 0 < PL, PR <= 1. */
  183. /* If M = 0 or M = N, PL = PR = 1. */
  184. /* If IJOB = 0, 2 or 3, PL and PR are not referenced. */
  185. /* DIF (output) DOUBLE PRECISION array, dimension (2). */
  186. /* If IJOB >= 2, DIF(1:2) store the estimates of Difu and Difl. */
  187. /* If IJOB = 2 or 4, DIF(1:2) are F-norm-based upper bounds on */
  188. /* Difu and Difl. If IJOB = 3 or 5, DIF(1:2) are 1-norm-based */
  189. /* estimates of Difu and Difl. */
  190. /* If M = 0 or N, DIF(1:2) = F-norm([A, B]). */
  191. /* If IJOB = 0 or 1, DIF is not referenced. */
  192. /* WORK (workspace/output) DOUBLE PRECISION array, */
  193. /* dimension (MAX(1,LWORK)) */
  194. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  195. /* LWORK (input) INTEGER */
  196. /* The dimension of the array WORK. LWORK >= 4*N+16. */
  197. /* If IJOB = 1, 2 or 4, LWORK >= MAX(4*N+16, 2*M*(N-M)). */
  198. /* If IJOB = 3 or 5, LWORK >= MAX(4*N+16, 4*M*(N-M)). */
  199. /* If LWORK = -1, then a workspace query is assumed; the routine */
  200. /* only calculates the optimal size of the WORK array, returns */
  201. /* this value as the first entry of the WORK array, and no error */
  202. /* message related to LWORK is issued by XERBLA. */
  203. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  204. /* IF IJOB = 0, IWORK is not referenced. Otherwise, */
  205. /* on exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  206. /* LIWORK (input) INTEGER */
  207. /* The dimension of the array IWORK. LIWORK >= 1. */
  208. /* If IJOB = 1, 2 or 4, LIWORK >= N+6. */
  209. /* If IJOB = 3 or 5, LIWORK >= MAX(2*M*(N-M), N+6). */
  210. /* If LIWORK = -1, then a workspace query is assumed; the */
  211. /* routine only calculates the optimal size of the IWORK array, */
  212. /* returns this value as the first entry of the IWORK array, and */
  213. /* no error message related to LIWORK is issued by XERBLA. */
  214. /* INFO (output) INTEGER */
  215. /* =0: Successful exit. */
  216. /* <0: If INFO = -i, the i-th argument had an illegal value. */
  217. /* =1: Reordering of (A, B) failed because the transformed */
  218. /* matrix pair (A, B) would be too far from generalized */
  219. /* Schur form; the problem is very ill-conditioned. */
  220. /* (A, B) may have been partially reordered. */
  221. /* If requested, 0 is returned in DIF(*), PL and PR. */
  222. /* Further Details */
  223. /* =============== */
  224. /* DTGSEN first collects the selected eigenvalues by computing */
  225. /* orthogonal U and W that move them to the top left corner of (A, B). */
  226. /* In other words, the selected eigenvalues are the eigenvalues of */
  227. /* (A11, B11) in: */
  228. /* U'*(A, B)*W = (A11 A12) (B11 B12) n1 */
  229. /* ( 0 A22),( 0 B22) n2 */
  230. /* n1 n2 n1 n2 */
  231. /* where N = n1+n2 and U' means the transpose of U. The first n1 columns */
  232. /* of U and W span the specified pair of left and right eigenspaces */
  233. /* (deflating subspaces) of (A, B). */
  234. /* If (A, B) has been obtained from the generalized real Schur */
  235. /* decomposition of a matrix pair (C, D) = Q*(A, B)*Z', then the */
  236. /* reordered generalized real Schur form of (C, D) is given by */
  237. /* (C, D) = (Q*U)*(U'*(A, B)*W)*(Z*W)', */
  238. /* and the first n1 columns of Q*U and Z*W span the corresponding */
  239. /* deflating subspaces of (C, D) (Q and Z store Q*U and Z*W, resp.). */
  240. /* Note that if the selected eigenvalue is sufficiently ill-conditioned, */
  241. /* then its value may differ significantly from its value before */
  242. /* reordering. */
  243. /* The reciprocal condition numbers of the left and right eigenspaces */
  244. /* spanned by the first n1 columns of U and W (or Q*U and Z*W) may */
  245. /* be returned in DIF(1:2), corresponding to Difu and Difl, resp. */
  246. /* The Difu and Difl are defined as: */
  247. /* Difu[(A11, B11), (A22, B22)] = sigma-min( Zu ) */
  248. /* and */
  249. /* Difl[(A11, B11), (A22, B22)] = Difu[(A22, B22), (A11, B11)], */
  250. /* where sigma-min(Zu) is the smallest singular value of the */
  251. /* (2*n1*n2)-by-(2*n1*n2) matrix */
  252. /* Zu = [ kron(In2, A11) -kron(A22', In1) ] */
  253. /* [ kron(In2, B11) -kron(B22', In1) ]. */
  254. /* Here, Inx is the identity matrix of size nx and A22' is the */
  255. /* transpose of A22. kron(X, Y) is the Kronecker product between */
  256. /* the matrices X and Y. */
  257. /* When DIF(2) is small, small changes in (A, B) can cause large changes */
  258. /* in the deflating subspace. An approximate (asymptotic) bound on the */
  259. /* maximum angular error in the computed deflating subspaces is */
  260. /* EPS * norm((A, B)) / DIF(2), */
  261. /* where EPS is the machine precision. */
  262. /* The reciprocal norm of the projectors on the left and right */
  263. /* eigenspaces associated with (A11, B11) may be returned in PL and PR. */
  264. /* They are computed as follows. First we compute L and R so that */
  265. /* P*(A, B)*Q is block diagonal, where */
  266. /* P = ( I -L ) n1 Q = ( I R ) n1 */
  267. /* ( 0 I ) n2 and ( 0 I ) n2 */
  268. /* n1 n2 n1 n2 */
  269. /* and (L, R) is the solution to the generalized Sylvester equation */
  270. /* A11*R - L*A22 = -A12 */
  271. /* B11*R - L*B22 = -B12 */
  272. /* Then PL = (F-norm(L)**2+1)**(-1/2) and PR = (F-norm(R)**2+1)**(-1/2). */
  273. /* An approximate (asymptotic) bound on the average absolute error of */
  274. /* the selected eigenvalues is */
  275. /* EPS * norm((A, B)) / PL. */
  276. /* There are also global error bounds which valid for perturbations up */
  277. /* to a certain restriction: A lower bound (x) on the smallest */
  278. /* F-norm(E,F) for which an eigenvalue of (A11, B11) may move and */
  279. /* coalesce with an eigenvalue of (A22, B22) under perturbation (E,F), */
  280. /* (i.e. (A + E, B + F), is */
  281. /* x = min(Difu,Difl)/((1/(PL*PL)+1/(PR*PR))**(1/2)+2*max(1/PL,1/PR)). */
  282. /* An approximate bound on x can be computed from DIF(1:2), PL and PR. */
  283. /* If y = ( F-norm(E,F) / x) <= 1, the angles between the perturbed */
  284. /* (L', R') and unperturbed (L, R) left and right deflating subspaces */
  285. /* associated with the selected cluster in the (1,1)-blocks can be */
  286. /* bounded as */
  287. /* max-angle(L, L') <= arctan( y * PL / (1 - y * (1 - PL * PL)**(1/2)) */
  288. /* max-angle(R, R') <= arctan( y * PR / (1 - y * (1 - PR * PR)**(1/2)) */
  289. /* See LAPACK User's Guide section 4.11 or the following references */
  290. /* for more information. */
  291. /* Note that if the default method for computing the Frobenius-norm- */
  292. /* based estimate DIF is not wanted (see DLATDF), then the parameter */
  293. /* IDIFJB (see below) should be changed from 3 to 4 (routine DLATDF */
  294. /* (IJOB = 2 will be used)). See DTGSYL for more details. */
  295. /* Based on contributions by */
  296. /* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  297. /* Umea University, S-901 87 Umea, Sweden. */
  298. /* References */
  299. /* ========== */
  300. /* [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
  301. /* Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
  302. /* M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
  303. /* Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
  304. /* [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
  305. /* Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
  306. /* Estimation: Theory, Algorithms and Software, */
  307. /* Report UMINF - 94.04, Department of Computing Science, Umea */
  308. /* University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
  309. /* Note 87. To appear in Numerical Algorithms, 1996. */
  310. /* [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
  311. /* for Solving the Generalized Sylvester Equation and Estimating the */
  312. /* Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
  313. /* Department of Computing Science, Umea University, S-901 87 Umea, */
  314. /* Sweden, December 1993, Revised April 1994, Also as LAPACK Working */
  315. /* Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1, */
  316. /* 1996. */
  317. /* ===================================================================== */
  318. /* .. Parameters .. */
  319. /* .. */
  320. /* .. Local Scalars .. */
  321. /* .. */
  322. /* .. Local Arrays .. */
  323. /* .. */
  324. /* .. External Subroutines .. */
  325. /* .. */
  326. /* .. External Functions .. */
  327. /* .. */
  328. /* .. Intrinsic Functions .. */
  329. /* .. */
  330. /* .. Executable Statements .. */
  331. /* Decode and test the input parameters */
  332. /* Parameter adjustments */
  333. --select;
  334. a_dim1 = *lda;
  335. a_offset = 1 + a_dim1;
  336. a -= a_offset;
  337. b_dim1 = *ldb;
  338. b_offset = 1 + b_dim1;
  339. b -= b_offset;
  340. --alphar;
  341. --alphai;
  342. --beta;
  343. q_dim1 = *ldq;
  344. q_offset = 1 + q_dim1;
  345. q -= q_offset;
  346. z_dim1 = *ldz;
  347. z_offset = 1 + z_dim1;
  348. z__ -= z_offset;
  349. --dif;
  350. --work;
  351. --iwork;
  352. /* Function Body */
  353. *info = 0;
  354. lquery = *lwork == -1 || *liwork == -1;
  355. if (*ijob < 0 || *ijob > 5) {
  356. *info = -1;
  357. } else if (*n < 0) {
  358. *info = -5;
  359. } else if (*lda < max(1,*n)) {
  360. *info = -7;
  361. } else if (*ldb < max(1,*n)) {
  362. *info = -9;
  363. } else if (*ldq < 1 || *wantq && *ldq < *n) {
  364. *info = -14;
  365. } else if (*ldz < 1 || *wantz && *ldz < *n) {
  366. *info = -16;
  367. }
  368. if (*info != 0) {
  369. i__1 = -(*info);
  370. _starpu_xerbla_("DTGSEN", &i__1);
  371. return 0;
  372. }
  373. /* Get machine constants */
  374. eps = _starpu_dlamch_("P");
  375. smlnum = _starpu_dlamch_("S") / eps;
  376. ierr = 0;
  377. wantp = *ijob == 1 || *ijob >= 4;
  378. wantd1 = *ijob == 2 || *ijob == 4;
  379. wantd2 = *ijob == 3 || *ijob == 5;
  380. wantd = wantd1 || wantd2;
  381. /* Set M to the dimension of the specified pair of deflating */
  382. /* subspaces. */
  383. *m = 0;
  384. pair = FALSE_;
  385. i__1 = *n;
  386. for (k = 1; k <= i__1; ++k) {
  387. if (pair) {
  388. pair = FALSE_;
  389. } else {
  390. if (k < *n) {
  391. if (a[k + 1 + k * a_dim1] == 0.) {
  392. if (select[k]) {
  393. ++(*m);
  394. }
  395. } else {
  396. pair = TRUE_;
  397. if (select[k] || select[k + 1]) {
  398. *m += 2;
  399. }
  400. }
  401. } else {
  402. if (select[*n]) {
  403. ++(*m);
  404. }
  405. }
  406. }
  407. /* L10: */
  408. }
  409. if (*ijob == 1 || *ijob == 2 || *ijob == 4) {
  410. /* Computing MAX */
  411. i__1 = 1, i__2 = (*n << 2) + 16, i__1 = max(i__1,i__2), i__2 = (*m <<
  412. 1) * (*n - *m);
  413. lwmin = max(i__1,i__2);
  414. /* Computing MAX */
  415. i__1 = 1, i__2 = *n + 6;
  416. liwmin = max(i__1,i__2);
  417. } else if (*ijob == 3 || *ijob == 5) {
  418. /* Computing MAX */
  419. i__1 = 1, i__2 = (*n << 2) + 16, i__1 = max(i__1,i__2), i__2 = (*m <<
  420. 2) * (*n - *m);
  421. lwmin = max(i__1,i__2);
  422. /* Computing MAX */
  423. i__1 = 1, i__2 = (*m << 1) * (*n - *m), i__1 = max(i__1,i__2), i__2 =
  424. *n + 6;
  425. liwmin = max(i__1,i__2);
  426. } else {
  427. /* Computing MAX */
  428. i__1 = 1, i__2 = (*n << 2) + 16;
  429. lwmin = max(i__1,i__2);
  430. liwmin = 1;
  431. }
  432. work[1] = (doublereal) lwmin;
  433. iwork[1] = liwmin;
  434. if (*lwork < lwmin && ! lquery) {
  435. *info = -22;
  436. } else if (*liwork < liwmin && ! lquery) {
  437. *info = -24;
  438. }
  439. if (*info != 0) {
  440. i__1 = -(*info);
  441. _starpu_xerbla_("DTGSEN", &i__1);
  442. return 0;
  443. } else if (lquery) {
  444. return 0;
  445. }
  446. /* Quick return if possible. */
  447. if (*m == *n || *m == 0) {
  448. if (wantp) {
  449. *pl = 1.;
  450. *pr = 1.;
  451. }
  452. if (wantd) {
  453. dscale = 0.;
  454. dsum = 1.;
  455. i__1 = *n;
  456. for (i__ = 1; i__ <= i__1; ++i__) {
  457. _starpu_dlassq_(n, &a[i__ * a_dim1 + 1], &c__1, &dscale, &dsum);
  458. _starpu_dlassq_(n, &b[i__ * b_dim1 + 1], &c__1, &dscale, &dsum);
  459. /* L20: */
  460. }
  461. dif[1] = dscale * sqrt(dsum);
  462. dif[2] = dif[1];
  463. }
  464. goto L60;
  465. }
  466. /* Collect the selected blocks at the top-left corner of (A, B). */
  467. ks = 0;
  468. pair = FALSE_;
  469. i__1 = *n;
  470. for (k = 1; k <= i__1; ++k) {
  471. if (pair) {
  472. pair = FALSE_;
  473. } else {
  474. swap = select[k];
  475. if (k < *n) {
  476. if (a[k + 1 + k * a_dim1] != 0.) {
  477. pair = TRUE_;
  478. swap = swap || select[k + 1];
  479. }
  480. }
  481. if (swap) {
  482. ++ks;
  483. /* Swap the K-th block to position KS. */
  484. /* Perform the reordering of diagonal blocks in (A, B) */
  485. /* by orthogonal transformation matrices and update */
  486. /* Q and Z accordingly (if requested): */
  487. kk = k;
  488. if (k != ks) {
  489. _starpu_dtgexc_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  490. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &kk,
  491. &ks, &work[1], lwork, &ierr);
  492. }
  493. if (ierr > 0) {
  494. /* Swap is rejected: exit. */
  495. *info = 1;
  496. if (wantp) {
  497. *pl = 0.;
  498. *pr = 0.;
  499. }
  500. if (wantd) {
  501. dif[1] = 0.;
  502. dif[2] = 0.;
  503. }
  504. goto L60;
  505. }
  506. if (pair) {
  507. ++ks;
  508. }
  509. }
  510. }
  511. /* L30: */
  512. }
  513. if (wantp) {
  514. /* Solve generalized Sylvester equation for R and L */
  515. /* and compute PL and PR. */
  516. n1 = *m;
  517. n2 = *n - *m;
  518. i__ = n1 + 1;
  519. ijb = 0;
  520. _starpu_dlacpy_("Full", &n1, &n2, &a[i__ * a_dim1 + 1], lda, &work[1], &n1);
  521. _starpu_dlacpy_("Full", &n1, &n2, &b[i__ * b_dim1 + 1], ldb, &work[n1 * n2 +
  522. 1], &n1);
  523. i__1 = *lwork - (n1 << 1) * n2;
  524. _starpu_dtgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * a_dim1]
  525. , lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + i__ *
  526. b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &dif[1], &
  527. work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &ierr);
  528. /* Estimate the reciprocal of norms of "projections" onto left */
  529. /* and right eigenspaces. */
  530. rdscal = 0.;
  531. dsum = 1.;
  532. i__1 = n1 * n2;
  533. _starpu_dlassq_(&i__1, &work[1], &c__1, &rdscal, &dsum);
  534. *pl = rdscal * sqrt(dsum);
  535. if (*pl == 0.) {
  536. *pl = 1.;
  537. } else {
  538. *pl = dscale / (sqrt(dscale * dscale / *pl + *pl) * sqrt(*pl));
  539. }
  540. rdscal = 0.;
  541. dsum = 1.;
  542. i__1 = n1 * n2;
  543. _starpu_dlassq_(&i__1, &work[n1 * n2 + 1], &c__1, &rdscal, &dsum);
  544. *pr = rdscal * sqrt(dsum);
  545. if (*pr == 0.) {
  546. *pr = 1.;
  547. } else {
  548. *pr = dscale / (sqrt(dscale * dscale / *pr + *pr) * sqrt(*pr));
  549. }
  550. }
  551. if (wantd) {
  552. /* Compute estimates of Difu and Difl. */
  553. if (wantd1) {
  554. n1 = *m;
  555. n2 = *n - *m;
  556. i__ = n1 + 1;
  557. ijb = 3;
  558. /* Frobenius norm-based Difu-estimate. */
  559. i__1 = *lwork - (n1 << 1) * n2;
  560. _starpu_dtgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ *
  561. a_dim1], lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ +
  562. i__ * b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &
  563. dif[1], &work[(n1 << 1) * n2 + 1], &i__1, &iwork[1], &
  564. ierr);
  565. /* Frobenius norm-based Difl-estimate. */
  566. i__1 = *lwork - (n1 << 1) * n2;
  567. _starpu_dtgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, &a[
  568. a_offset], lda, &work[1], &n2, &b[i__ + i__ * b_dim1],
  569. ldb, &b[b_offset], ldb, &work[n1 * n2 + 1], &n2, &dscale,
  570. &dif[2], &work[(n1 << 1) * n2 + 1], &i__1, &iwork[1], &
  571. ierr);
  572. } else {
  573. /* Compute 1-norm-based estimates of Difu and Difl using */
  574. /* reversed communication with DLACN2. In each step a */
  575. /* generalized Sylvester equation or a transposed variant */
  576. /* is solved. */
  577. kase = 0;
  578. n1 = *m;
  579. n2 = *n - *m;
  580. i__ = n1 + 1;
  581. ijb = 0;
  582. mn2 = (n1 << 1) * n2;
  583. /* 1-norm-based estimate of Difu. */
  584. L40:
  585. _starpu_dlacn2_(&mn2, &work[mn2 + 1], &work[1], &iwork[1], &dif[1], &kase,
  586. isave);
  587. if (kase != 0) {
  588. if (kase == 1) {
  589. /* Solve generalized Sylvester equation. */
  590. i__1 = *lwork - (n1 << 1) * n2;
  591. _starpu_dtgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ +
  592. i__ * a_dim1], lda, &work[1], &n1, &b[b_offset],
  593. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  594. 1], &n1, &dscale, &dif[1], &work[(n1 << 1) * n2 +
  595. 1], &i__1, &iwork[1], &ierr);
  596. } else {
  597. /* Solve the transposed variant. */
  598. i__1 = *lwork - (n1 << 1) * n2;
  599. _starpu_dtgsyl_("T", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ +
  600. i__ * a_dim1], lda, &work[1], &n1, &b[b_offset],
  601. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  602. 1], &n1, &dscale, &dif[1], &work[(n1 << 1) * n2 +
  603. 1], &i__1, &iwork[1], &ierr);
  604. }
  605. goto L40;
  606. }
  607. dif[1] = dscale / dif[1];
  608. /* 1-norm-based estimate of Difl. */
  609. L50:
  610. _starpu_dlacn2_(&mn2, &work[mn2 + 1], &work[1], &iwork[1], &dif[2], &kase,
  611. isave);
  612. if (kase != 0) {
  613. if (kase == 1) {
  614. /* Solve generalized Sylvester equation. */
  615. i__1 = *lwork - (n1 << 1) * n2;
  616. _starpu_dtgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda,
  617. &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ *
  618. b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 +
  619. 1], &n2, &dscale, &dif[2], &work[(n1 << 1) * n2 +
  620. 1], &i__1, &iwork[1], &ierr);
  621. } else {
  622. /* Solve the transposed variant. */
  623. i__1 = *lwork - (n1 << 1) * n2;
  624. _starpu_dtgsyl_("T", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda,
  625. &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ *
  626. b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 +
  627. 1], &n2, &dscale, &dif[2], &work[(n1 << 1) * n2 +
  628. 1], &i__1, &iwork[1], &ierr);
  629. }
  630. goto L50;
  631. }
  632. dif[2] = dscale / dif[2];
  633. }
  634. }
  635. L60:
  636. /* Compute generalized eigenvalues of reordered pair (A, B) and */
  637. /* normalize the generalized Schur form. */
  638. pair = FALSE_;
  639. i__1 = *n;
  640. for (k = 1; k <= i__1; ++k) {
  641. if (pair) {
  642. pair = FALSE_;
  643. } else {
  644. if (k < *n) {
  645. if (a[k + 1 + k * a_dim1] != 0.) {
  646. pair = TRUE_;
  647. }
  648. }
  649. if (pair) {
  650. /* Compute the eigenvalue(s) at position K. */
  651. work[1] = a[k + k * a_dim1];
  652. work[2] = a[k + 1 + k * a_dim1];
  653. work[3] = a[k + (k + 1) * a_dim1];
  654. work[4] = a[k + 1 + (k + 1) * a_dim1];
  655. work[5] = b[k + k * b_dim1];
  656. work[6] = b[k + 1 + k * b_dim1];
  657. work[7] = b[k + (k + 1) * b_dim1];
  658. work[8] = b[k + 1 + (k + 1) * b_dim1];
  659. d__1 = smlnum * eps;
  660. _starpu_dlag2_(&work[1], &c__2, &work[5], &c__2, &d__1, &beta[k], &
  661. beta[k + 1], &alphar[k], &alphar[k + 1], &alphai[k]);
  662. alphai[k + 1] = -alphai[k];
  663. } else {
  664. if (d_sign(&c_b28, &b[k + k * b_dim1]) < 0.) {
  665. /* If B(K,K) is negative, make it positive */
  666. i__2 = *n;
  667. for (i__ = 1; i__ <= i__2; ++i__) {
  668. a[k + i__ * a_dim1] = -a[k + i__ * a_dim1];
  669. b[k + i__ * b_dim1] = -b[k + i__ * b_dim1];
  670. if (*wantq) {
  671. q[i__ + k * q_dim1] = -q[i__ + k * q_dim1];
  672. }
  673. /* L70: */
  674. }
  675. }
  676. alphar[k] = a[k + k * a_dim1];
  677. alphai[k] = 0.;
  678. beta[k] = b[k + k * b_dim1];
  679. }
  680. }
  681. /* L80: */
  682. }
  683. work[1] = (doublereal) lwmin;
  684. iwork[1] = liwmin;
  685. return 0;
  686. /* End of DTGSEN */
  687. } /* _starpu_dtgsen_ */