278 RECURSIVE SUBROUTINE zlaqz0( WANTS, WANTQ, WANTZ, N, ILO, IHI,
280 $ LDA, B, LDB, ALPHA, BETA, Q, LDQ, Z,
281 $ LDZ, WORK, LWORK, RWORK, REC,
286 CHARACTER,
INTENT( IN ) :: wants, wantq, wantz
287 INTEGER,
INTENT( IN ) :: n, ilo, ihi, lda, ldb, ldq, ldz, lwork,
289 INTEGER,
INTENT( OUT ) :: info
290 COMPLEX*16,
INTENT( INOUT ) :: a( lda, * ), b( ldb, * ), q( ldq,
291 $ * ), z( ldz, * ), alpha( * ), beta( * ), work( * )
292 DOUBLE PRECISION,
INTENT( OUT ) :: rwork( * )
295 COMPLEX*16 czero, cone
296 parameter( czero = ( 0.0d+0, 0.0d+0 ), cone = ( 1.0d+0,
298 DOUBLE PRECISION :: zero, one, half
299 parameter( zero = 0.0d0, one = 1.0d0, half = 0.5d0 )
302 DOUBLE PRECISION :: smlnum, ulp, safmin, safmax, c1, tempr,
304 COMPLEX*16 :: eshift, s1, temp
305 INTEGER :: istart, istop, iiter, maxit, istart2, k, ld, nshifts,
306 $ nblock, nw, nmin, nibble, n_undeflated, n_deflated,
307 $ ns, sweep_info, shiftpos, lworkreq, k2, istartm,
308 $ istopm, iwants, iwantq, iwantz, norm_info, aed_info,
309 $ nwr, nbr, nsr, itemp1, itemp2, rcost
310 LOGICAL :: ilschur, ilq, ilz
311 CHARACTER :: jbcmpz*3
317 LOGICAL,
EXTERNAL ::
lsame
318 INTEGER,
EXTERNAL ::
ilaenv
323 IF(
lsame( wants,
'E' ) )
THEN
326 ELSE IF(
lsame( wants,
'S' ) )
THEN
333 IF(
lsame( wantq,
'N' ) )
THEN
336 ELSE IF(
lsame( wantq,
'V' ) )
THEN
339 ELSE IF(
lsame( wantq,
'I' ) )
THEN
346 IF(
lsame( wantz,
'N' ) )
THEN
349 ELSE IF(
lsame( wantz,
'V' ) )
THEN
352 ELSE IF(
lsame( wantz,
'I' ) )
THEN
362 IF( iwants.EQ.0 )
THEN
364 ELSE IF( iwantq.EQ.0 )
THEN
366 ELSE IF( iwantz.EQ.0 )
THEN
368 ELSE IF( n.LT.0 )
THEN
370 ELSE IF( ilo.LT.1 )
THEN
372 ELSE IF( ihi.GT.n .OR. ihi.LT.ilo-1 )
THEN
374 ELSE IF( lda.LT.n )
THEN
376 ELSE IF( ldb.LT.n )
THEN
378 ELSE IF( ldq.LT.1 .OR. ( ilq .AND. ldq.LT.n ) )
THEN
380 ELSE IF( ldz.LT.1 .OR. ( ilz .AND. ldz.LT.n ) )
THEN
384 CALL xerbla(
'ZLAQZ0', -info )
392 work( 1 ) = dble( 1 )
399 jbcmpz( 1:1 ) = wants
400 jbcmpz( 2:2 ) = wantq
401 jbcmpz( 3:3 ) = wantz
403 nmin =
ilaenv( 12,
'ZLAQZ0', jbcmpz, n, ilo, ihi, lwork )
405 nwr =
ilaenv( 13,
'ZLAQZ0', jbcmpz, n, ilo, ihi, lwork )
407 nwr = min( ihi-ilo+1, ( n-1 ) / 3, nwr )
409 nibble =
ilaenv( 14,
'ZLAQZ0', jbcmpz, n, ilo, ihi, lwork )
411 nsr =
ilaenv( 15,
'ZLAQZ0', jbcmpz, n, ilo, ihi, lwork )
412 nsr = min( nsr, ( n+6 ) / 9, ihi-ilo )
413 nsr = max( 2, nsr-mod( nsr, 2 ) )
415 rcost =
ilaenv( 17,
'ZLAQZ0', jbcmpz, n, ilo, ihi, lwork )
416 itemp1 = int( nsr/sqrt( 1+2*nsr/( dble( rcost )/100*n ) ) )
417 itemp1 = ( ( itemp1-1 )/4 )*4+4
420 IF( n .LT. nmin .OR. rec .GE. 2 )
THEN
421 CALL zhgeqz( wants, wantq, wantz, n, ilo, ihi, a, lda, b,
423 $ alpha, beta, q, ldq, z, ldz, work, lwork, rwork,
433 nw = max( nwr, nmin )
434 CALL zlaqz2( ilschur, ilq, ilz, n, ilo, ihi, nw, a, lda, b,
436 $ q, ldq, z, ldz, n_undeflated, n_deflated, alpha,
437 $ beta, work, nw, work, nw, work, -1, rwork, rec,
439 itemp1 = int( work( 1 ) )
441 CALL zlaqz3( ilschur, ilq, ilz, n, ilo, ihi, nsr, nbr, alpha,
442 $ beta, a, lda, b, ldb, q, ldq, z, ldz, work, nbr,
443 $ work, nbr, work, -1, sweep_info )
444 itemp2 = int( work( 1 ) )
446 lworkreq = max( itemp1+2*nw**2, itemp2+2*nbr**2 )
447 IF ( lwork .EQ.-1 )
THEN
448 work( 1 ) = dble( lworkreq )
450 ELSE IF ( lwork .LT. lworkreq )
THEN
454 CALL xerbla(
'ZLAQZ0', info )
460 IF( iwantq.EQ.3 )
CALL zlaset(
'FULL', n, n, czero, cone, q,
462 IF( iwantz.EQ.3 )
CALL zlaset(
'FULL', n, n, czero, cone, z,
466 safmin =
dlamch(
'SAFE MINIMUM' )
468 ulp =
dlamch(
'PRECISION' )
469 smlnum = safmin*( dble( n )/ulp )
471 bnorm =
zlanhs(
'F', ihi-ilo+1, b( ilo, ilo ), ldb, rwork )
472 btol = max( safmin, ulp*bnorm )
476 maxit = 30*( ihi-ilo+1 )
480 IF( iiter .GE. maxit )
THEN
484 IF ( istart+1 .GE. istop )
THEN
490 IF ( abs( a( istop, istop-1 ) ) .LE. max( smlnum,
491 $ ulp*( abs( a( istop, istop ) )+abs( a( istop-1,
492 $ istop-1 ) ) ) ) )
THEN
493 a( istop, istop-1 ) = czero
499 IF ( abs( a( istart+1, istart ) ) .LE. max( smlnum,
500 $ ulp*( abs( a( istart, istart ) )+abs( a( istart+1,
501 $ istart+1 ) ) ) ) )
THEN
502 a( istart+1, istart ) = czero
508 IF ( istart+1 .GE. istop )
THEN
514 DO k = istop, istart+1, -1
515 IF ( abs( a( k, k-1 ) ) .LE. max( smlnum, ulp*( abs( a( k,
516 $ k ) )+abs( a( k-1, k-1 ) ) ) ) )
THEN
535 DO WHILE ( k.GE.istart2 )
537 IF( abs( b( k, k ) ) .LT. btol )
THEN
541 DO k2 = k, istart2+1, -1
542 CALL zlartg( b( k2-1, k2 ), b( k2-1, k2-1 ), c1,
546 b( k2-1, k2-1 ) = czero
548 CALL zrot( k2-2-istartm+1, b( istartm, k2 ), 1,
549 $ b( istartm, k2-1 ), 1, c1, s1 )
550 CALL zrot( min( k2+1, istop )-istartm+1,
552 $ k2 ), 1, a( istartm, k2-1 ), 1, c1, s1 )
554 CALL zrot( n, z( 1, k2 ), 1, z( 1, k2-1 ), 1,
559 IF( k2.LT.istop )
THEN
560 CALL zlartg( a( k2, k2-1 ), a( k2+1, k2-1 ), c1,
563 a( k2+1, k2-1 ) = czero
565 CALL zrot( istopm-k2+1, a( k2, k2 ), lda,
567 $ k2 ), lda, c1, s1 )
568 CALL zrot( istopm-k2+1, b( k2, k2 ), ldb,
570 $ k2 ), ldb, c1, s1 )
572 CALL zrot( n, q( 1, k2 ), 1, q( 1, k2+1 ), 1,
579 IF( istart2.LT.istop )
THEN
580 CALL zlartg( a( istart2, istart2 ), a( istart2+1,
581 $ istart2 ), c1, s1, temp )
582 a( istart2, istart2 ) = temp
583 a( istart2+1, istart2 ) = czero
585 CALL zrot( istopm-( istart2+1 )+1, a( istart2,
586 $ istart2+1 ), lda, a( istart2+1,
587 $ istart2+1 ), lda, c1, s1 )
588 CALL zrot( istopm-( istart2+1 )+1, b( istart2,
589 $ istart2+1 ), ldb, b( istart2+1,
590 $ istart2+1 ), ldb, c1, s1 )
592 CALL zrot( n, q( 1, istart2 ), 1, q( 1,
593 $ istart2+1 ), 1, c1, dconjg( s1 ) )
605 IF ( istart2 .GE. istop )
THEN
616 IF ( istop-istart2+1 .LT. nmin )
THEN
620 IF ( istop-istart+1 .LT. nmin )
THEN
631 CALL zlaqz2( ilschur, ilq, ilz, n, istart2, istop, nw, a,
633 $ b, ldb, q, ldq, z, ldz, n_undeflated, n_deflated,
634 $ alpha, beta, work, nw, work( nw**2+1 ), nw,
635 $ work( 2*nw**2+1 ), lwork-2*nw**2, rwork, rec,
638 IF ( n_deflated > 0 )
THEN
639 istop = istop-n_deflated
644 IF ( 100*n_deflated > nibble*( n_deflated+n_undeflated ) .OR.
645 $ istop-istart2+1 .LT. nmin )
THEN
653 ns = min( nshifts, istop-istart2 )
654 ns = min( ns, n_undeflated )
655 shiftpos = istop-n_undeflated+1
657 IF ( mod( ld, 6 ) .EQ. 0 )
THEN
661 IF( ( dble( maxit )*safmin )*abs( a( istop,
662 $ istop-1 ) ).LT.abs( a( istop-1, istop-1 ) ) )
THEN
663 eshift = a( istop, istop-1 )/b( istop-1, istop-1 )
665 eshift = eshift+cone/( safmin*dble( maxit ) )
667 alpha( shiftpos ) = cone
668 beta( shiftpos ) = eshift
675 CALL zlaqz3( ilschur, ilq, ilz, n, istart2, istop, ns,
677 $ alpha( shiftpos ), beta( shiftpos ), a, lda, b,
678 $ ldb, q, ldq, z, ldz, work, nblock, work( nblock**
679 $ 2+1 ), nblock, work( 2*nblock**2+1 ),
680 $ lwork-2*nblock**2, sweep_info )
690 80
CALL zhgeqz( wants, wantq, wantz, n, ilo, ihi, a, lda, b, ldb,
691 $ alpha, beta, q, ldq, z, ldz, work, lwork, rwork,