294 SUBROUTINE stgsyl( TRANS, IJOB, M, N, A, LDA, B, LDB, C, LDC,
296 $ LDD, E, LDE, F, LDF, SCALE, DIF, WORK, LWORK,
305 INTEGER IJOB, INFO, LDA, LDB, LDC, LDD, LDE, LDF,
311 REAL A( LDA, * ), B( LDB, * ), C( LDC, * ),
312 $ D( LDD, * ), E( LDE, * ), F( LDF, * ),
322 PARAMETER ( ZERO = 0.0e+0, one = 1.0e+0 )
325 LOGICAL LQUERY, NOTRAN
326 INTEGER I, IE, IFUNC, IROUND, IS, ISOLVE, J, JE, JS, K,
327 $ LINFO, LWMIN, MB, NB, P, PPQQ, PQ, Q
328 REAL DSCALE, DSUM, SCALE2, SCALOC
334 EXTERNAL lsame, ilaenv, sroundup_lwork
341 INTRINSIC max, real, sqrt
348 notran = lsame( trans,
'N' )
349 lquery = ( lwork.EQ.-1 )
351 IF( .NOT.notran .AND. .NOT.lsame( trans,
'T' ) )
THEN
353 ELSE IF( notran )
THEN
354 IF( ( ijob.LT.0 ) .OR. ( ijob.GT.4 ) )
THEN
361 ELSE IF( n.LE.0 )
THEN
363 ELSE IF( lda.LT.max( 1, m ) )
THEN
365 ELSE IF( ldb.LT.max( 1, n ) )
THEN
367 ELSE IF( ldc.LT.max( 1, m ) )
THEN
369 ELSE IF( ldd.LT.max( 1, m ) )
THEN
371 ELSE IF( lde.LT.max( 1, n ) )
THEN
373 ELSE IF( ldf.LT.max( 1, m ) )
THEN
380 IF( ijob.EQ.1 .OR. ijob.EQ.2 )
THEN
381 lwmin = max( 1, 2*m*n )
388 work( 1 ) = sroundup_lwork(lwmin)
390 IF( lwork.LT.lwmin .AND. .NOT.lquery )
THEN
396 CALL xerbla(
'STGSYL', -info )
398 ELSE IF( lquery )
THEN
404 IF( m.EQ.0 .OR. n.EQ.0 )
THEN
416 mb = ilaenv( 2,
'STGSYL', trans, m, n, -1, -1 )
417 nb = ilaenv( 5,
'STGSYL', trans, m, n, -1, -1 )
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
431 IF( ( mb.LE.1 .AND. nb.LE.1 ) .OR. ( mb.GE.m .AND. nb.GE.n ) )
434 DO 30 iround = 1, isolve
441 CALL stgsy2( trans, ifunc, m, n, a, lda, b, ldb, c, ldc,
443 $ ldd, e, lde, f, ldf, scale, dsum, dscale,
445 IF( dscale.NE.zero )
THEN
446 IF( ijob.EQ.1 .OR. ijob.EQ.3 )
THEN
447 dif = sqrt( real( 2*m*n ) ) / ( dscale*sqrt( dsum ) )
449 dif = sqrt( real( pq ) ) / ( dscale*sqrt( dsum ) )
453 IF( isolve.EQ.2 .AND. iround.EQ.1 )
THEN
458 CALL slacpy(
'F', m, n, c, ldc, work, m )
459 CALL slacpy(
'F', m, n, f, ldf, work( m*n+1 ), m )
460 CALL slaset(
'F', m, n, zero, zero, c, ldc )
461 CALL slaset(
'F', m, n, zero, zero, f, ldf )
462 ELSE IF( isolve.EQ.2 .AND. iround.EQ.2 )
THEN
463 CALL slacpy(
'F', m, n, work, m, c, ldc )
464 CALL slacpy(
'F', m, n, work( m*n+1 ), m, f, ldf )
484 IF( a( i, i-1 ).NE.zero )
490 IF( iwork( p ).EQ.iwork( p+1 ) )
505 IF( b( j, j-1 ).NE.zero )
511 IF( iwork( q ).EQ.iwork( q+1 ) )
516 DO 150 iround = 1, isolve
529 je = iwork( j+1 ) - 1
533 ie = iwork( i+1 ) - 1
536 CALL stgsy2( trans, ifunc, mb, nb, a( is, is ),
538 $ b( js, js ), ldb, c( is, js ), ldc,
539 $ d( is, is ), ldd, e( js, js ), lde,
540 $ f( is, js ), ldf, scaloc, dsum, dscale,
541 $ iwork( q+2 ), ppqq, linfo )
546 IF( scaloc.NE.one )
THEN
548 CALL sscal( m, scaloc, c( 1, k ), 1 )
549 CALL sscal( m, scaloc, f( 1, k ), 1 )
552 CALL sscal( is-1, scaloc, c( 1, k ), 1 )
553 CALL sscal( is-1, scaloc, f( 1, k ), 1 )
556 CALL sscal( m-ie, scaloc, c( ie+1, k ), 1 )
557 CALL sscal( m-ie, scaloc, f( ie+1, k ), 1 )
560 CALL sscal( m, scaloc, c( 1, k ), 1 )
561 CALL sscal( m, scaloc, f( 1, k ), 1 )
570 CALL sgemm(
'N',
'N', is-1, nb, mb, -one,
571 $ a( 1, is ), lda, c( is, js ), ldc, one,
573 CALL sgemm(
'N',
'N', is-1, nb, mb, -one,
574 $ d( 1, is ), ldd, c( is, js ), ldc, one,
578 CALL sgemm(
'N',
'N', mb, n-je, nb, one,
579 $ f( is, js ), ldf, b( js, je+1 ), ldb,
580 $ one, c( is, je+1 ), ldc )
581 CALL sgemm(
'N',
'N', mb, n-je, nb, one,
582 $ f( is, js ), ldf, e( js, je+1 ), lde,
583 $ one, f( is, je+1 ), ldf )
587 IF( dscale.NE.zero )
THEN
588 IF( ijob.EQ.1 .OR. ijob.EQ.3 )
THEN
589 dif = sqrt( real( 2*m*n ) ) / ( dscale*sqrt( dsum ) )
591 dif = sqrt( real( pq ) ) / ( dscale*sqrt( dsum ) )
594 IF( isolve.EQ.2 .AND. iround.EQ.1 )
THEN
599 CALL slacpy(
'F', m, n, c, ldc, work, m )
600 CALL slacpy(
'F', m, n, f, ldf, work( m*n+1 ), m )
601 CALL slaset(
'F', m, n, zero, zero, c, ldc )
602 CALL slaset(
'F', m, n, zero, zero, f, ldf )
603 ELSE IF( isolve.EQ.2 .AND. iround.EQ.2 )
THEN
604 CALL slacpy(
'F', m, n, work, m, c, ldc )
605 CALL slacpy(
'F', m, n, work( m*n+1 ), m, f, ldf )
620 ie = iwork( i+1 ) - 1
622 DO 200 j = q, p + 2, -1
624 je = iwork( j+1 ) - 1
626 CALL stgsy2( trans, ifunc, mb, nb, a( is, is ), lda,
627 $ b( js, js ), ldb, c( is, js ), ldc,
628 $ d( is, is ), ldd, e( js, js ), lde,
629 $ f( is, js ), ldf, scaloc, dsum, dscale,
630 $ iwork( q+2 ), ppqq, linfo )
633 IF( scaloc.NE.one )
THEN
635 CALL sscal( m, scaloc, c( 1, k ), 1 )
636 CALL sscal( m, scaloc, f( 1, k ), 1 )
639 CALL sscal( is-1, scaloc, c( 1, k ), 1 )
640 CALL sscal( is-1, scaloc, f( 1, k ), 1 )
643 CALL sscal( m-ie, scaloc, c( ie+1, k ), 1 )
644 CALL sscal( m-ie, scaloc, f( ie+1, k ), 1 )
647 CALL sscal( m, scaloc, c( 1, k ), 1 )
648 CALL sscal( m, scaloc, f( 1, k ), 1 )
656 CALL sgemm(
'N',
'T', mb, js-1, nb, one, c( is,
658 $ ldc, b( 1, js ), ldb, one, f( is, 1 ),
660 CALL sgemm(
'N',
'T', mb, js-1, nb, one, f( is,
662 $ ldf, e( 1, js ), lde, one, f( is, 1 ),
666 CALL sgemm(
'T',
'N', m-ie, nb, mb, -one,
667 $ a( is, ie+1 ), lda, c( is, js ), ldc, one,
668 $ c( ie+1, js ), ldc )
669 CALL sgemm(
'T',
'N', m-ie, nb, mb, -one,
670 $ d( is, ie+1 ), ldd, f( is, js ), ldf, one,
671 $ c( ie+1, js ), ldc )
678 work( 1 ) = sroundup_lwork(lwmin)