300 RECURSIVE SUBROUTINE dlaqz0( WANTS, WANTQ, WANTZ, N, ILO, IHI,
302 $ LDA, B, LDB, ALPHAR, ALPHAI, BETA,
303 $ Q, LDQ, Z, LDZ, WORK, LWORK, REC,
308 CHARACTER,
INTENT( IN ) :: wants, wantq, wantz
309 INTEGER,
INTENT( IN ) :: n, ilo, ihi, lda, ldb, ldq, ldz, lwork,
312 INTEGER,
INTENT( OUT ) :: info
314 DOUBLE PRECISION,
INTENT( INOUT ) :: a( lda, * ), b( ldb, * ),
315 $ q( ldq, * ), z( ldz, * ), alphar( * ),
316 $ alphai( * ), beta( * ), work( * )
319 DOUBLE PRECISION :: zero, one, half
320 PARAMETER( zero = 0.0d0, one = 1.0d0, half = 0.5d0 )
323 DOUBLE PRECISION :: smlnum, ulp, eshift, safmin, safmax, c1, s1,
324 $ temp, swap, bnorm, btol
325 INTEGER :: istart, istop, iiter, maxit, istart2, k, ld, nshifts,
326 $ nblock, nw, nmin, nibble, n_undeflated, n_deflated,
327 $ ns, sweep_info, shiftpos, lworkreq, k2, istartm,
328 $ istopm, iwants, iwantq, iwantz, norm_info, aed_info,
329 $ nwr, nbr, nsr, itemp1, itemp2, rcost, i
330 LOGICAL :: ilschur, ilq, ilz
331 CHARACTER :: jbcmpz*3
337 LOGICAL,
EXTERNAL ::
lsame
338 INTEGER,
EXTERNAL ::
ilaenv
343 IF(
lsame( wants,
'E' ) )
THEN
346 ELSE IF(
lsame( wants,
'S' ) )
THEN
353 IF(
lsame( wantq,
'N' ) )
THEN
356 ELSE IF(
lsame( wantq,
'V' ) )
THEN
359 ELSE IF(
lsame( wantq,
'I' ) )
THEN
366 IF(
lsame( wantz,
'N' ) )
THEN
369 ELSE IF(
lsame( wantz,
'V' ) )
THEN
372 ELSE IF(
lsame( wantz,
'I' ) )
THEN
382 IF( iwants.EQ.0 )
THEN
384 ELSE IF( iwantq.EQ.0 )
THEN
386 ELSE IF( iwantz.EQ.0 )
THEN
388 ELSE IF( n.LT.0 )
THEN
390 ELSE IF( ilo.LT.1 )
THEN
392 ELSE IF( ihi.GT.n .OR. ihi.LT.ilo-1 )
THEN
394 ELSE IF( lda.LT.n )
THEN
396 ELSE IF( ldb.LT.n )
THEN
398 ELSE IF( ldq.LT.1 .OR. ( ilq .AND. ldq.LT.n ) )
THEN
400 ELSE IF( ldz.LT.1 .OR. ( ilz .AND. ldz.LT.n ) )
THEN
404 CALL xerbla(
'DLAQZ0', -info )
412 work( 1 ) = dble( 1 )
419 jbcmpz( 1:1 ) = wants
420 jbcmpz( 2:2 ) = wantq
421 jbcmpz( 3:3 ) = wantz
423 nmin =
ilaenv( 12,
'DLAQZ0', jbcmpz, n, ilo, ihi, lwork )
425 nwr =
ilaenv( 13,
'DLAQZ0', jbcmpz, n, ilo, ihi, lwork )
427 nwr = min( ihi-ilo+1, ( n-1 ) / 3, nwr )
429 nibble =
ilaenv( 14,
'DLAQZ0', jbcmpz, n, ilo, ihi, lwork )
431 nsr =
ilaenv( 15,
'DLAQZ0', jbcmpz, n, ilo, ihi, lwork )
432 nsr = min( nsr, ( n+6 ) / 9, ihi-ilo )
433 nsr = max( 2, nsr-mod( nsr, 2 ) )
435 rcost =
ilaenv( 17,
'DLAQZ0', jbcmpz, n, ilo, ihi, lwork )
436 itemp1 = int( nsr/sqrt( 1+2*nsr/( dble( rcost )/100*n ) ) )
437 itemp1 = ( ( itemp1-1 )/4 )*4+4
440 IF( n .LT. nmin .OR. rec .GE. 2 )
THEN
441 CALL dhgeqz( wants, wantq, wantz, n, ilo, ihi, a, lda, b,
443 $ alphar, alphai, beta, q, ldq, z, ldz, work,
453 nw = max( nwr, nmin )
454 CALL dlaqz3( ilschur, ilq, ilz, n, ilo, ihi, nw, a, lda, b,
456 $ q, ldq, z, ldz, n_undeflated, n_deflated, alphar,
457 $ alphai, beta, work, nw, work, nw, work, -1, rec,
459 itemp1 = int( work( 1 ) )
461 CALL dlaqz4( ilschur, ilq, ilz, n, ilo, ihi, nsr, nbr, alphar,
462 $ alphai, beta, a, lda, b, ldb, q, ldq, z, ldz, work,
463 $ nbr, work, nbr, work, -1, sweep_info )
464 itemp2 = int( work( 1 ) )
466 lworkreq = max( itemp1+2*nw**2, itemp2+2*nbr**2 )
467 IF ( lwork .EQ.-1 )
THEN
468 work( 1 ) = dble( lworkreq )
470 ELSE IF ( lwork .LT. lworkreq )
THEN
474 CALL xerbla(
'DLAQZ0', info )
480 IF( iwantq.EQ.3 )
CALL dlaset(
'FULL', n, n, zero, one, q,
482 IF( iwantz.EQ.3 )
CALL dlaset(
'FULL', n, n, zero, one, z,
486 safmin =
dlamch(
'SAFE MINIMUM' )
488 ulp =
dlamch(
'PRECISION' )
489 smlnum = safmin*( dble( n )/ulp )
491 bnorm =
dlanhs(
'F', ihi-ilo+1, b( ilo, ilo ), ldb, work )
492 btol = max( safmin, ulp*bnorm )
496 maxit = 3*( ihi-ilo+1 )
500 IF( iiter .GE. maxit )
THEN
504 IF ( istart+1 .GE. istop )
THEN
510 IF ( abs( a( istop-1, istop-2 ) ) .LE. max( smlnum,
511 $ ulp*( abs( a( istop-1, istop-1 ) )+abs( a( istop-2,
512 $ istop-2 ) ) ) ) )
THEN
513 a( istop-1, istop-2 ) = zero
517 ELSE IF ( abs( a( istop, istop-1 ) ) .LE. max( smlnum,
518 $ ulp*( abs( a( istop, istop ) )+abs( a( istop-1,
519 $ istop-1 ) ) ) ) )
THEN
520 a( istop, istop-1 ) = zero
526 IF ( abs( a( istart+2, istart+1 ) ) .LE. max( smlnum,
527 $ ulp*( abs( a( istart+1, istart+1 ) )+abs( a( istart+2,
528 $ istart+2 ) ) ) ) )
THEN
529 a( istart+2, istart+1 ) = zero
533 ELSE IF ( abs( a( istart+1, istart ) ) .LE. max( smlnum,
534 $ ulp*( abs( a( istart, istart ) )+abs( a( istart+1,
535 $ istart+1 ) ) ) ) )
THEN
536 a( istart+1, istart ) = zero
542 IF ( istart+1 .GE. istop )
THEN
548 DO k = istop, istart+1, -1
549 IF ( abs( a( k, k-1 ) ) .LE. max( smlnum, ulp*( abs( a( k,
550 $ k ) )+abs( a( k-1, k-1 ) ) ) ) )
THEN
569 DO WHILE ( k.GE.istart2 )
571 IF( abs( b( k, k ) ) .LT. btol )
THEN
575 DO k2 = k, istart2+1, -1
576 CALL dlartg( b( k2-1, k2 ), b( k2-1, k2-1 ), c1,
580 b( k2-1, k2-1 ) = zero
582 CALL drot( k2-2-istartm+1, b( istartm, k2 ), 1,
583 $ b( istartm, k2-1 ), 1, c1, s1 )
584 CALL drot( min( k2+1, istop )-istartm+1,
586 $ k2 ), 1, a( istartm, k2-1 ), 1, c1, s1 )
588 CALL drot( n, z( 1, k2 ), 1, z( 1, k2-1 ), 1,
593 IF( k2.LT.istop )
THEN
594 CALL dlartg( a( k2, k2-1 ), a( k2+1, k2-1 ), c1,
597 a( k2+1, k2-1 ) = zero
599 CALL drot( istopm-k2+1, a( k2, k2 ), lda,
601 $ k2 ), lda, c1, s1 )
602 CALL drot( istopm-k2+1, b( k2, k2 ), ldb,
604 $ k2 ), ldb, c1, s1 )
606 CALL drot( n, q( 1, k2 ), 1, q( 1, k2+1 ), 1,
613 IF( istart2.LT.istop )
THEN
614 CALL dlartg( a( istart2, istart2 ), a( istart2+1,
615 $ istart2 ), c1, s1, temp )
616 a( istart2, istart2 ) = temp
617 a( istart2+1, istart2 ) = zero
619 CALL drot( istopm-( istart2+1 )+1, a( istart2,
620 $ istart2+1 ), lda, a( istart2+1,
621 $ istart2+1 ), lda, c1, s1 )
622 CALL drot( istopm-( istart2+1 )+1, b( istart2,
623 $ istart2+1 ), ldb, b( istart2+1,
624 $ istart2+1 ), ldb, c1, s1 )
626 CALL drot( n, q( 1, istart2 ), 1, q( 1,
627 $ istart2+1 ), 1, c1, s1 )
639 IF ( istart2 .GE. istop )
THEN
650 IF ( istop-istart2+1 .LT. nmin )
THEN
654 IF ( istop-istart+1 .LT. nmin )
THEN
665 CALL dlaqz3( ilschur, ilq, ilz, n, istart2, istop, nw, a,
667 $ b, ldb, q, ldq, z, ldz, n_undeflated, n_deflated,
668 $ alphar, alphai, beta, work, nw, work( nw**2+1 ),
669 $ nw, work( 2*nw**2+1 ), lwork-2*nw**2, rec,
672 IF ( n_deflated > 0 )
THEN
673 istop = istop-n_deflated
678 IF ( 100*n_deflated > nibble*( n_deflated+n_undeflated ) .OR.
679 $ istop-istart2+1 .LT. nmin )
THEN
687 ns = min( nshifts, istop-istart2 )
688 ns = min( ns, n_undeflated )
689 shiftpos = istop-n_undeflated+1
694 DO i = shiftpos, shiftpos+n_undeflated-1, 2
695 IF( alphai( i ).NE.-alphai( i+1 ) )
THEN
698 alphar( i ) = alphar( i+1 )
699 alphar( i+1 ) = alphar( i+2 )
703 alphai( i ) = alphai( i+1 )
704 alphai( i+1 ) = alphai( i+2 )
708 beta( i ) = beta( i+1 )
709 beta( i+1 ) = beta( i+2 )
714 IF ( mod( ld, 6 ) .EQ. 0 )
THEN
718 IF( ( dble( maxit )*safmin )*abs( a( istop,
719 $ istop-1 ) ).LT.abs( a( istop-1, istop-1 ) ) )
THEN
720 eshift = a( istop, istop-1 )/b( istop-1, istop-1 )
722 eshift = eshift+one/( safmin*dble( maxit ) )
724 alphar( shiftpos ) = one
725 alphar( shiftpos+1 ) = zero
726 alphai( shiftpos ) = zero
727 alphai( shiftpos+1 ) = zero
728 beta( shiftpos ) = eshift
729 beta( shiftpos+1 ) = eshift
736 CALL dlaqz4( ilschur, ilq, ilz, n, istart2, istop, ns,
738 $ alphar( shiftpos ), alphai( shiftpos ),
739 $ beta( shiftpos ), a, lda, b, ldb, q, ldq, z, ldz,
740 $ work, nblock, work( nblock**2+1 ), nblock,
741 $ work( 2*nblock**2+1 ), lwork-2*nblock**2,
752 80
CALL dhgeqz( wants, wantq, wantz, n, ilo, ihi, a, lda, b, ldb,
753 $ alphar, alphai, beta, q, ldq, z, ldz, work, lwork,