You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stgsyl.f 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. *> \brief \b STGSYL
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download STGSYL + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgsyl.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgsyl.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgsyl.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE STGSYL( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D,
  22. * LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK,
  23. * IWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER TRANS
  27. * INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF,
  28. * $ LWORK, M, N
  29. * REAL DIF, SCALE
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER IWORK( * )
  33. * REAL A( LDA, * ), B( LDB, * ), C( LDC, * ),
  34. * $ D( LDD, * ), E( LDE, * ), F( LDF, * ),
  35. * $ WORK( * )
  36. * ..
  37. *
  38. *
  39. *> \par Purpose:
  40. * =============
  41. *>
  42. *> \verbatim
  43. *>
  44. *> STGSYL solves the generalized Sylvester equation:
  45. *>
  46. *> A * R - L * B = scale * C (1)
  47. *> D * R - L * E = scale * F
  48. *>
  49. *> where R and L are unknown m-by-n matrices, (A, D), (B, E) and
  50. *> (C, F) are given matrix pairs of size m-by-m, n-by-n and m-by-n,
  51. *> respectively, with real entries. (A, D) and (B, E) must be in
  52. *> generalized (real) Schur canonical form, i.e. A, B are upper quasi
  53. *> triangular and D, E are upper triangular.
  54. *>
  55. *> The solution (R, L) overwrites (C, F). 0 <= SCALE <= 1 is an output
  56. *> scaling factor chosen to avoid overflow.
  57. *>
  58. *> In matrix notation (1) is equivalent to solve Zx = scale b, where
  59. *> Z is defined as
  60. *>
  61. *> Z = [ kron(In, A) -kron(B**T, Im) ] (2)
  62. *> [ kron(In, D) -kron(E**T, Im) ].
  63. *>
  64. *> Here Ik is the identity matrix of size k and X**T is the transpose of
  65. *> X. kron(X, Y) is the Kronecker product between the matrices X and Y.
  66. *>
  67. *> If TRANS = 'T', STGSYL solves the transposed system Z**T*y = scale*b,
  68. *> which is equivalent to solve for R and L in
  69. *>
  70. *> A**T * R + D**T * L = scale * C (3)
  71. *> R * B**T + L * E**T = scale * -F
  72. *>
  73. *> This case (TRANS = 'T') is used to compute an one-norm-based estimate
  74. *> of Dif[(A,D), (B,E)], the separation between the matrix pairs (A,D)
  75. *> and (B,E), using SLACON.
  76. *>
  77. *> If IJOB >= 1, STGSYL computes a Frobenius norm-based estimate
  78. *> of Dif[(A,D),(B,E)]. That is, the reciprocal of a lower bound on the
  79. *> reciprocal of the smallest singular value of Z. See [1-2] for more
  80. *> information.
  81. *>
  82. *> This is a level 3 BLAS algorithm.
  83. *> \endverbatim
  84. *
  85. * Arguments:
  86. * ==========
  87. *
  88. *> \param[in] TRANS
  89. *> \verbatim
  90. *> TRANS is CHARACTER*1
  91. *> = 'N': solve the generalized Sylvester equation (1).
  92. *> = 'T': solve the 'transposed' system (3).
  93. *> \endverbatim
  94. *>
  95. *> \param[in] IJOB
  96. *> \verbatim
  97. *> IJOB is INTEGER
  98. *> Specifies what kind of functionality to be performed.
  99. *> = 0: solve (1) only.
  100. *> = 1: The functionality of 0 and 3.
  101. *> = 2: The functionality of 0 and 4.
  102. *> = 3: Only an estimate of Dif[(A,D), (B,E)] is computed.
  103. *> (look ahead strategy IJOB = 1 is used).
  104. *> = 4: Only an estimate of Dif[(A,D), (B,E)] is computed.
  105. *> ( SGECON on sub-systems is used ).
  106. *> Not referenced if TRANS = 'T'.
  107. *> \endverbatim
  108. *>
  109. *> \param[in] M
  110. *> \verbatim
  111. *> M is INTEGER
  112. *> The order of the matrices A and D, and the row dimension of
  113. *> the matrices C, F, R and L.
  114. *> \endverbatim
  115. *>
  116. *> \param[in] N
  117. *> \verbatim
  118. *> N is INTEGER
  119. *> The order of the matrices B and E, and the column dimension
  120. *> of the matrices C, F, R and L.
  121. *> \endverbatim
  122. *>
  123. *> \param[in] A
  124. *> \verbatim
  125. *> A is REAL array, dimension (LDA, M)
  126. *> The upper quasi triangular matrix A.
  127. *> \endverbatim
  128. *>
  129. *> \param[in] LDA
  130. *> \verbatim
  131. *> LDA is INTEGER
  132. *> The leading dimension of the array A. LDA >= max(1, M).
  133. *> \endverbatim
  134. *>
  135. *> \param[in] B
  136. *> \verbatim
  137. *> B is REAL array, dimension (LDB, N)
  138. *> The upper quasi triangular matrix B.
  139. *> \endverbatim
  140. *>
  141. *> \param[in] LDB
  142. *> \verbatim
  143. *> LDB is INTEGER
  144. *> The leading dimension of the array B. LDB >= max(1, N).
  145. *> \endverbatim
  146. *>
  147. *> \param[in,out] C
  148. *> \verbatim
  149. *> C is REAL array, dimension (LDC, N)
  150. *> On entry, C contains the right-hand-side of the first matrix
  151. *> equation in (1) or (3).
  152. *> On exit, if IJOB = 0, 1 or 2, C has been overwritten by
  153. *> the solution R. If IJOB = 3 or 4 and TRANS = 'N', C holds R,
  154. *> the solution achieved during the computation of the
  155. *> Dif-estimate.
  156. *> \endverbatim
  157. *>
  158. *> \param[in] LDC
  159. *> \verbatim
  160. *> LDC is INTEGER
  161. *> The leading dimension of the array C. LDC >= max(1, M).
  162. *> \endverbatim
  163. *>
  164. *> \param[in] D
  165. *> \verbatim
  166. *> D is REAL array, dimension (LDD, M)
  167. *> The upper triangular matrix D.
  168. *> \endverbatim
  169. *>
  170. *> \param[in] LDD
  171. *> \verbatim
  172. *> LDD is INTEGER
  173. *> The leading dimension of the array D. LDD >= max(1, M).
  174. *> \endverbatim
  175. *>
  176. *> \param[in] E
  177. *> \verbatim
  178. *> E is REAL array, dimension (LDE, N)
  179. *> The upper triangular matrix E.
  180. *> \endverbatim
  181. *>
  182. *> \param[in] LDE
  183. *> \verbatim
  184. *> LDE is INTEGER
  185. *> The leading dimension of the array E. LDE >= max(1, N).
  186. *> \endverbatim
  187. *>
  188. *> \param[in,out] F
  189. *> \verbatim
  190. *> F is REAL array, dimension (LDF, N)
  191. *> On entry, F contains the right-hand-side of the second matrix
  192. *> equation in (1) or (3).
  193. *> On exit, if IJOB = 0, 1 or 2, F has been overwritten by
  194. *> the solution L. If IJOB = 3 or 4 and TRANS = 'N', F holds L,
  195. *> the solution achieved during the computation of the
  196. *> Dif-estimate.
  197. *> \endverbatim
  198. *>
  199. *> \param[in] LDF
  200. *> \verbatim
  201. *> LDF is INTEGER
  202. *> The leading dimension of the array F. LDF >= max(1, M).
  203. *> \endverbatim
  204. *>
  205. *> \param[out] DIF
  206. *> \verbatim
  207. *> DIF is REAL
  208. *> On exit DIF is the reciprocal of a lower bound of the
  209. *> reciprocal of the Dif-function, i.e. DIF is an upper bound of
  210. *> Dif[(A,D), (B,E)] = sigma_min(Z), where Z as in (2).
  211. *> IF IJOB = 0 or TRANS = 'T', DIF is not touched.
  212. *> \endverbatim
  213. *>
  214. *> \param[out] SCALE
  215. *> \verbatim
  216. *> SCALE is REAL
  217. *> On exit SCALE is the scaling factor in (1) or (3).
  218. *> If 0 < SCALE < 1, C and F hold the solutions R and L, resp.,
  219. *> to a slightly perturbed system but the input matrices A, B, D
  220. *> and E have not been changed. If SCALE = 0, C and F hold the
  221. *> solutions R and L, respectively, to the homogeneous system
  222. *> with C = F = 0. Normally, SCALE = 1.
  223. *> \endverbatim
  224. *>
  225. *> \param[out] WORK
  226. *> \verbatim
  227. *> WORK is REAL array, dimension (MAX(1,LWORK))
  228. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  229. *> \endverbatim
  230. *>
  231. *> \param[in] LWORK
  232. *> \verbatim
  233. *> LWORK is INTEGER
  234. *> The dimension of the array WORK. LWORK > = 1.
  235. *> If IJOB = 1 or 2 and TRANS = 'N', LWORK >= max(1,2*M*N).
  236. *>
  237. *> If LWORK = -1, then a workspace query is assumed; the routine
  238. *> only calculates the optimal size of the WORK array, returns
  239. *> this value as the first entry of the WORK array, and no error
  240. *> message related to LWORK is issued by XERBLA.
  241. *> \endverbatim
  242. *>
  243. *> \param[out] IWORK
  244. *> \verbatim
  245. *> IWORK is INTEGER array, dimension (M+N+6)
  246. *> \endverbatim
  247. *>
  248. *> \param[out] INFO
  249. *> \verbatim
  250. *> INFO is INTEGER
  251. *> =0: successful exit
  252. *> <0: If INFO = -i, the i-th argument had an illegal value.
  253. *> >0: (A, D) and (B, E) have common or close eigenvalues.
  254. *> \endverbatim
  255. *
  256. * Authors:
  257. * ========
  258. *
  259. *> \author Univ. of Tennessee
  260. *> \author Univ. of California Berkeley
  261. *> \author Univ. of Colorado Denver
  262. *> \author NAG Ltd.
  263. *
  264. *> \ingroup tgsyl
  265. *
  266. *> \par Contributors:
  267. * ==================
  268. *>
  269. *> Bo Kagstrom and Peter Poromaa, Department of Computing Science,
  270. *> Umea University, S-901 87 Umea, Sweden.
  271. *
  272. *> \par References:
  273. * ================
  274. *>
  275. *> \verbatim
  276. *>
  277. *> [1] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software
  278. *> for Solving the Generalized Sylvester Equation and Estimating the
  279. *> Separation between Regular Matrix Pairs, Report UMINF - 93.23,
  280. *> Department of Computing Science, Umea University, S-901 87 Umea,
  281. *> Sweden, December 1993, Revised April 1994, Also as LAPACK Working
  282. *> Note 75. To appear in ACM Trans. on Math. Software, Vol 22,
  283. *> No 1, 1996.
  284. *>
  285. *> [2] B. Kagstrom, A Perturbation Analysis of the Generalized Sylvester
  286. *> Equation (AR - LB, DR - LE ) = (C, F), SIAM J. Matrix Anal.
  287. *> Appl., 15(4):1045-1060, 1994
  288. *>
  289. *> [3] B. Kagstrom and L. Westin, Generalized Schur Methods with
  290. *> Condition Estimators for Solving the Generalized Sylvester
  291. *> Equation, IEEE Transactions on Automatic Control, Vol. 34, No. 7,
  292. *> July 1989, pp 745-751.
  293. *> \endverbatim
  294. *>
  295. * =====================================================================
  296. SUBROUTINE STGSYL( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC, D,
  297. $ LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK,
  298. $ IWORK, INFO )
  299. *
  300. * -- LAPACK computational routine --
  301. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  302. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  303. *
  304. * .. Scalar Arguments ..
  305. CHARACTER TRANS
  306. INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF,
  307. $ LWORK, M, N
  308. REAL DIF, SCALE
  309. * ..
  310. * .. Array Arguments ..
  311. INTEGER IWORK( * )
  312. REAL A( LDA, * ), B( LDB, * ), C( LDC, * ),
  313. $ D( LDD, * ), E( LDE, * ), F( LDF, * ),
  314. $ WORK( * )
  315. * ..
  316. *
  317. * =====================================================================
  318. * Replaced various illegal calls to SCOPY by calls to SLASET.
  319. * Sven Hammarling, 1/5/02.
  320. *
  321. * .. Parameters ..
  322. REAL ZERO, ONE
  323. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  324. * ..
  325. * .. Local Scalars ..
  326. LOGICAL LQUERY, NOTRAN
  327. INTEGER I, IE, IFUNC, IROUND, IS, ISOLVE, J, JE, JS, K,
  328. $ LINFO, LWMIN, MB, NB, P, PPQQ, PQ, Q
  329. REAL DSCALE, DSUM, SCALE2, SCALOC
  330. * ..
  331. * .. External Functions ..
  332. LOGICAL LSAME
  333. INTEGER ILAENV
  334. REAL SROUNDUP_LWORK
  335. EXTERNAL LSAME, ILAENV, SROUNDUP_LWORK
  336. * ..
  337. * .. External Subroutines ..
  338. EXTERNAL SGEMM, SLACPY, SLASET, SSCAL, STGSY2, XERBLA
  339. * ..
  340. * .. Intrinsic Functions ..
  341. INTRINSIC MAX, REAL, SQRT
  342. * ..
  343. * .. Executable Statements ..
  344. *
  345. * Decode and test input parameters
  346. *
  347. INFO = 0
  348. NOTRAN = LSAME( TRANS, 'N' )
  349. LQUERY = ( LWORK.EQ.-1 )
  350. *
  351. IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN
  352. INFO = -1
  353. ELSE IF( NOTRAN ) THEN
  354. IF( ( IJOB.LT.0 ) .OR. ( IJOB.GT.4 ) ) THEN
  355. INFO = -2
  356. END IF
  357. END IF
  358. IF( INFO.EQ.0 ) THEN
  359. IF( M.LE.0 ) THEN
  360. INFO = -3
  361. ELSE IF( N.LE.0 ) THEN
  362. INFO = -4
  363. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  364. INFO = -6
  365. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  366. INFO = -8
  367. ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
  368. INFO = -10
  369. ELSE IF( LDD.LT.MAX( 1, M ) ) THEN
  370. INFO = -12
  371. ELSE IF( LDE.LT.MAX( 1, N ) ) THEN
  372. INFO = -14
  373. ELSE IF( LDF.LT.MAX( 1, M ) ) THEN
  374. INFO = -16
  375. END IF
  376. END IF
  377. *
  378. IF( INFO.EQ.0 ) THEN
  379. IF( NOTRAN ) THEN
  380. IF( IJOB.EQ.1 .OR. IJOB.EQ.2 ) THEN
  381. LWMIN = MAX( 1, 2*M*N )
  382. ELSE
  383. LWMIN = 1
  384. END IF
  385. ELSE
  386. LWMIN = 1
  387. END IF
  388. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  389. *
  390. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  391. INFO = -20
  392. END IF
  393. END IF
  394. *
  395. IF( INFO.NE.0 ) THEN
  396. CALL XERBLA( 'STGSYL', -INFO )
  397. RETURN
  398. ELSE IF( LQUERY ) THEN
  399. RETURN
  400. END IF
  401. *
  402. * Quick return if possible
  403. *
  404. IF( M.EQ.0 .OR. N.EQ.0 ) THEN
  405. SCALE = 1
  406. IF( NOTRAN ) THEN
  407. IF( IJOB.NE.0 ) THEN
  408. DIF = 0
  409. END IF
  410. END IF
  411. RETURN
  412. END IF
  413. *
  414. * Determine optimal block sizes MB and NB
  415. *
  416. MB = ILAENV( 2, 'STGSYL', TRANS, M, N, -1, -1 )
  417. NB = ILAENV( 5, 'STGSYL', TRANS, M, N, -1, -1 )
  418. *
  419. ISOLVE = 1
  420. IFUNC = 0
  421. IF( NOTRAN ) THEN
  422. IF( IJOB.GE.3 ) THEN
  423. IFUNC = IJOB - 2
  424. CALL SLASET( 'F', M, N, ZERO, ZERO, C, LDC )
  425. CALL SLASET( 'F', M, N, ZERO, ZERO, F, LDF )
  426. ELSE IF( IJOB.GE.1 .AND. NOTRAN ) THEN
  427. ISOLVE = 2
  428. END IF
  429. END IF
  430. *
  431. IF( ( MB.LE.1 .AND. NB.LE.1 ) .OR. ( MB.GE.M .AND. NB.GE.N ) )
  432. $ THEN
  433. *
  434. DO 30 IROUND = 1, ISOLVE
  435. *
  436. * Use unblocked Level 2 solver
  437. *
  438. DSCALE = ZERO
  439. DSUM = ONE
  440. PQ = 0
  441. CALL STGSY2( TRANS, IFUNC, M, N, A, LDA, B, LDB, C, LDC, D,
  442. $ LDD, E, LDE, F, LDF, SCALE, DSUM, DSCALE,
  443. $ IWORK, PQ, INFO )
  444. IF( DSCALE.NE.ZERO ) THEN
  445. IF( IJOB.EQ.1 .OR. IJOB.EQ.3 ) THEN
  446. DIF = SQRT( REAL( 2*M*N ) ) / ( DSCALE*SQRT( DSUM ) )
  447. ELSE
  448. DIF = SQRT( REAL( PQ ) ) / ( DSCALE*SQRT( DSUM ) )
  449. END IF
  450. END IF
  451. *
  452. IF( ISOLVE.EQ.2 .AND. IROUND.EQ.1 ) THEN
  453. IF( NOTRAN ) THEN
  454. IFUNC = IJOB
  455. END IF
  456. SCALE2 = SCALE
  457. CALL SLACPY( 'F', M, N, C, LDC, WORK, M )
  458. CALL SLACPY( 'F', M, N, F, LDF, WORK( M*N+1 ), M )
  459. CALL SLASET( 'F', M, N, ZERO, ZERO, C, LDC )
  460. CALL SLASET( 'F', M, N, ZERO, ZERO, F, LDF )
  461. ELSE IF( ISOLVE.EQ.2 .AND. IROUND.EQ.2 ) THEN
  462. CALL SLACPY( 'F', M, N, WORK, M, C, LDC )
  463. CALL SLACPY( 'F', M, N, WORK( M*N+1 ), M, F, LDF )
  464. SCALE = SCALE2
  465. END IF
  466. 30 CONTINUE
  467. *
  468. RETURN
  469. END IF
  470. *
  471. * Determine block structure of A
  472. *
  473. P = 0
  474. I = 1
  475. 40 CONTINUE
  476. IF( I.GT.M )
  477. $ GO TO 50
  478. P = P + 1
  479. IWORK( P ) = I
  480. I = I + MB
  481. IF( I.GE.M )
  482. $ GO TO 50
  483. IF( A( I, I-1 ).NE.ZERO )
  484. $ I = I + 1
  485. GO TO 40
  486. 50 CONTINUE
  487. *
  488. IWORK( P+1 ) = M + 1
  489. IF( IWORK( P ).EQ.IWORK( P+1 ) )
  490. $ P = P - 1
  491. *
  492. * Determine block structure of B
  493. *
  494. Q = P + 1
  495. J = 1
  496. 60 CONTINUE
  497. IF( J.GT.N )
  498. $ GO TO 70
  499. Q = Q + 1
  500. IWORK( Q ) = J
  501. J = J + NB
  502. IF( J.GE.N )
  503. $ GO TO 70
  504. IF( B( J, J-1 ).NE.ZERO )
  505. $ J = J + 1
  506. GO TO 60
  507. 70 CONTINUE
  508. *
  509. IWORK( Q+1 ) = N + 1
  510. IF( IWORK( Q ).EQ.IWORK( Q+1 ) )
  511. $ Q = Q - 1
  512. *
  513. IF( NOTRAN ) THEN
  514. *
  515. DO 150 IROUND = 1, ISOLVE
  516. *
  517. * Solve (I, J)-subsystem
  518. * A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J)
  519. * D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J)
  520. * for I = P, P - 1,..., 1; J = 1, 2,..., Q
  521. *
  522. DSCALE = ZERO
  523. DSUM = ONE
  524. PQ = 0
  525. SCALE = ONE
  526. DO 130 J = P + 2, Q
  527. JS = IWORK( J )
  528. JE = IWORK( J+1 ) - 1
  529. NB = JE - JS + 1
  530. DO 120 I = P, 1, -1
  531. IS = IWORK( I )
  532. IE = IWORK( I+1 ) - 1
  533. MB = IE - IS + 1
  534. PPQQ = 0
  535. CALL STGSY2( TRANS, IFUNC, MB, NB, A( IS, IS ), LDA,
  536. $ B( JS, JS ), LDB, C( IS, JS ), LDC,
  537. $ D( IS, IS ), LDD, E( JS, JS ), LDE,
  538. $ F( IS, JS ), LDF, SCALOC, DSUM, DSCALE,
  539. $ IWORK( Q+2 ), PPQQ, LINFO )
  540. IF( LINFO.GT.0 )
  541. $ INFO = LINFO
  542. *
  543. PQ = PQ + PPQQ
  544. IF( SCALOC.NE.ONE ) THEN
  545. DO 80 K = 1, JS - 1
  546. CALL SSCAL( M, SCALOC, C( 1, K ), 1 )
  547. CALL SSCAL( M, SCALOC, F( 1, K ), 1 )
  548. 80 CONTINUE
  549. DO 90 K = JS, JE
  550. CALL SSCAL( IS-1, SCALOC, C( 1, K ), 1 )
  551. CALL SSCAL( IS-1, SCALOC, F( 1, K ), 1 )
  552. 90 CONTINUE
  553. DO 100 K = JS, JE
  554. CALL SSCAL( M-IE, SCALOC, C( IE+1, K ), 1 )
  555. CALL SSCAL( M-IE, SCALOC, F( IE+1, K ), 1 )
  556. 100 CONTINUE
  557. DO 110 K = JE + 1, N
  558. CALL SSCAL( M, SCALOC, C( 1, K ), 1 )
  559. CALL SSCAL( M, SCALOC, F( 1, K ), 1 )
  560. 110 CONTINUE
  561. SCALE = SCALE*SCALOC
  562. END IF
  563. *
  564. * Substitute R(I, J) and L(I, J) into remaining
  565. * equation.
  566. *
  567. IF( I.GT.1 ) THEN
  568. CALL SGEMM( 'N', 'N', IS-1, NB, MB, -ONE,
  569. $ A( 1, IS ), LDA, C( IS, JS ), LDC, ONE,
  570. $ C( 1, JS ), LDC )
  571. CALL SGEMM( 'N', 'N', IS-1, NB, MB, -ONE,
  572. $ D( 1, IS ), LDD, C( IS, JS ), LDC, ONE,
  573. $ F( 1, JS ), LDF )
  574. END IF
  575. IF( J.LT.Q ) THEN
  576. CALL SGEMM( 'N', 'N', MB, N-JE, NB, ONE,
  577. $ F( IS, JS ), LDF, B( JS, JE+1 ), LDB,
  578. $ ONE, C( IS, JE+1 ), LDC )
  579. CALL SGEMM( 'N', 'N', MB, N-JE, NB, ONE,
  580. $ F( IS, JS ), LDF, E( JS, JE+1 ), LDE,
  581. $ ONE, F( IS, JE+1 ), LDF )
  582. END IF
  583. 120 CONTINUE
  584. 130 CONTINUE
  585. IF( DSCALE.NE.ZERO ) THEN
  586. IF( IJOB.EQ.1 .OR. IJOB.EQ.3 ) THEN
  587. DIF = SQRT( REAL( 2*M*N ) ) / ( DSCALE*SQRT( DSUM ) )
  588. ELSE
  589. DIF = SQRT( REAL( PQ ) ) / ( DSCALE*SQRT( DSUM ) )
  590. END IF
  591. END IF
  592. IF( ISOLVE.EQ.2 .AND. IROUND.EQ.1 ) THEN
  593. IF( NOTRAN ) THEN
  594. IFUNC = IJOB
  595. END IF
  596. SCALE2 = SCALE
  597. CALL SLACPY( 'F', M, N, C, LDC, WORK, M )
  598. CALL SLACPY( 'F', M, N, F, LDF, WORK( M*N+1 ), M )
  599. CALL SLASET( 'F', M, N, ZERO, ZERO, C, LDC )
  600. CALL SLASET( 'F', M, N, ZERO, ZERO, F, LDF )
  601. ELSE IF( ISOLVE.EQ.2 .AND. IROUND.EQ.2 ) THEN
  602. CALL SLACPY( 'F', M, N, WORK, M, C, LDC )
  603. CALL SLACPY( 'F', M, N, WORK( M*N+1 ), M, F, LDF )
  604. SCALE = SCALE2
  605. END IF
  606. 150 CONTINUE
  607. *
  608. ELSE
  609. *
  610. * Solve transposed (I, J)-subsystem
  611. * A(I, I)**T * R(I, J) + D(I, I)**T * L(I, J) = C(I, J)
  612. * R(I, J) * B(J, J)**T + L(I, J) * E(J, J)**T = -F(I, J)
  613. * for I = 1,2,..., P; J = Q, Q-1,..., 1
  614. *
  615. SCALE = ONE
  616. DO 210 I = 1, P
  617. IS = IWORK( I )
  618. IE = IWORK( I+1 ) - 1
  619. MB = IE - IS + 1
  620. DO 200 J = Q, P + 2, -1
  621. JS = IWORK( J )
  622. JE = IWORK( J+1 ) - 1
  623. NB = JE - JS + 1
  624. CALL STGSY2( TRANS, IFUNC, MB, NB, A( IS, IS ), LDA,
  625. $ B( JS, JS ), LDB, C( IS, JS ), LDC,
  626. $ D( IS, IS ), LDD, E( JS, JS ), LDE,
  627. $ F( IS, JS ), LDF, SCALOC, DSUM, DSCALE,
  628. $ IWORK( Q+2 ), PPQQ, LINFO )
  629. IF( LINFO.GT.0 )
  630. $ INFO = LINFO
  631. IF( SCALOC.NE.ONE ) THEN
  632. DO 160 K = 1, JS - 1
  633. CALL SSCAL( M, SCALOC, C( 1, K ), 1 )
  634. CALL SSCAL( M, SCALOC, F( 1, K ), 1 )
  635. 160 CONTINUE
  636. DO 170 K = JS, JE
  637. CALL SSCAL( IS-1, SCALOC, C( 1, K ), 1 )
  638. CALL SSCAL( IS-1, SCALOC, F( 1, K ), 1 )
  639. 170 CONTINUE
  640. DO 180 K = JS, JE
  641. CALL SSCAL( M-IE, SCALOC, C( IE+1, K ), 1 )
  642. CALL SSCAL( M-IE, SCALOC, F( IE+1, K ), 1 )
  643. 180 CONTINUE
  644. DO 190 K = JE + 1, N
  645. CALL SSCAL( M, SCALOC, C( 1, K ), 1 )
  646. CALL SSCAL( M, SCALOC, F( 1, K ), 1 )
  647. 190 CONTINUE
  648. SCALE = SCALE*SCALOC
  649. END IF
  650. *
  651. * Substitute R(I, J) and L(I, J) into remaining equation.
  652. *
  653. IF( J.GT.P+2 ) THEN
  654. CALL SGEMM( 'N', 'T', MB, JS-1, NB, ONE, C( IS, JS ),
  655. $ LDC, B( 1, JS ), LDB, ONE, F( IS, 1 ),
  656. $ LDF )
  657. CALL SGEMM( 'N', 'T', MB, JS-1, NB, ONE, F( IS, JS ),
  658. $ LDF, E( 1, JS ), LDE, ONE, F( IS, 1 ),
  659. $ LDF )
  660. END IF
  661. IF( I.LT.P ) THEN
  662. CALL SGEMM( 'T', 'N', M-IE, NB, MB, -ONE,
  663. $ A( IS, IE+1 ), LDA, C( IS, JS ), LDC, ONE,
  664. $ C( IE+1, JS ), LDC )
  665. CALL SGEMM( 'T', 'N', M-IE, NB, MB, -ONE,
  666. $ D( IS, IE+1 ), LDD, F( IS, JS ), LDF, ONE,
  667. $ C( IE+1, JS ), LDC )
  668. END IF
  669. 200 CONTINUE
  670. 210 CONTINUE
  671. *
  672. END IF
  673. *
  674. WORK( 1 ) = SROUNDUP_LWORK(LWMIN)
  675. *
  676. RETURN
  677. *
  678. * End of STGSYL
  679. *
  680. END