LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zgedmd.f90
Go to the documentation of this file.
1
2!
3! =========== DOCUMENTATION ===========
4!
5! Definition:
6! ===========
7!
8! SUBROUTINE ZGEDMD( JOBS, JOBZ, JOBR, JOBF, WHTSVD, &
9! M, N, X, LDX, Y, LDY, NRNK, TOL, &
10! K, EIGS, Z, LDZ, RES, B, LDB, &
11! W, LDW, S, LDS, ZWORK, LZWORK, &
12! RWORK, LRWORK, IWORK, LIWORK, INFO )
13!......
14! USE iso_fortran_env
15! IMPLICIT NONE
16! INTEGER, PARAMETER :: WP = real64
17!
18!......
19! Scalar arguments
20! CHARACTER, INTENT(IN) :: JOBS, JOBZ, JOBR, JOBF
21! INTEGER, INTENT(IN) :: WHTSVD, M, N, LDX, LDY, &
22! NRNK, LDZ, LDB, LDW, LDS, &
23! LIWORK, LRWORK, LZWORK
24! INTEGER, INTENT(OUT) :: K, INFO
25! REAL(KIND=WP), INTENT(IN) :: TOL
26! Array arguments
27! COMPLEX(KIND=WP), INTENT(INOUT) :: X(LDX,*), Y(LDY,*)
28! COMPLEX(KIND=WP), INTENT(OUT) :: Z(LDZ,*), B(LDB,*), &
29! W(LDW,*), S(LDS,*)
30! COMPLEX(KIND=WP), INTENT(OUT) :: EIGS(*)
31! COMPLEX(KIND=WP), INTENT(OUT) :: ZWORK(*)
32! REAL(KIND=WP), INTENT(OUT) :: RES(*)
33! REAL(KIND=WP), INTENT(OUT) :: RWORK(*)
34! INTEGER, INTENT(OUT) :: IWORK(*)
35!
36!............................................................
38! =============
53!............................................................
55! ================
71!......................................................................
73! ================================
93!......................................................................
95! ==============================
100!............................................................
101! Arguments
102! =========
103!
122!.....
139!.....
150!.....
164!.....
188!.....
194!.....
201!.....
213!.....
217!.....
229!.....
235!.....
260!.....
267!.....
277!.....
285!.....
298!.....
304!.....
313!.....
326!.....
332!.....
344!.....
350!.....
359!.....
365!.....
378!.....
399!.....
415!.....
438!.....
448!.....
462!.....
483!
484! Authors:
485! ========
486!
488!
490!
491!.............................................................
492!.............................................................
493 SUBROUTINE zgedmd( JOBS, JOBZ, JOBR, JOBF, WHTSVD, &
494 M, N, X, LDX, Y, LDY, NRNK, TOL, &
495 K, EIGS, Z, LDZ, RES, B, LDB, &
496 W, LDW, S, LDS, ZWORK, LZWORK, &
497 RWORK, LRWORK, IWORK, LIWORK, INFO )
498!
499! -- LAPACK driver routine --
500!
501! -- LAPACK is a software package provided by University of --
502! -- Tennessee, University of California Berkeley, University of --
503! -- Colorado Denver and NAG Ltd.. --
504!
505!.....
506 USE iso_fortran_env
507 IMPLICIT NONE
508 INTEGER, PARAMETER :: WP = real64
509!
510! Scalar arguments
511! ~~~~~~~~~~~~~~~~
512 CHARACTER, INTENT(IN) :: JOBS, JOBZ, JOBR, JOBF
513 INTEGER, INTENT(IN) :: WHTSVD, M, N, LDX, LDY, &
514 NRNK, LDZ, LDB, LDW, LDS, &
515 LIWORK, LRWORK, LZWORK
516 INTEGER, INTENT(OUT) :: K, INFO
517 REAL(KIND=wp), INTENT(IN) :: tol
518!
519! Array arguments
520! ~~~~~~~~~~~~~~~
521 COMPLEX(KIND=WP), INTENT(INOUT) :: X(LDX,*), Y(LDY,*)
522 COMPLEX(KIND=WP), INTENT(OUT) :: Z(LDZ,*), B(LDB,*), &
523 W(LDW,*), S(LDS,*)
524 COMPLEX(KIND=WP), INTENT(OUT) :: EIGS(*)
525 COMPLEX(KIND=WP), INTENT(OUT) :: ZWORK(*)
526 REAL(KIND=wp), INTENT(OUT) :: res(*)
527 REAL(KIND=wp), INTENT(OUT) :: rwork(*)
528 INTEGER, INTENT(OUT) :: IWORK(*)
529!
530! Parameters
531! ~~~~~~~~~~
532 REAL(KIND=wp), PARAMETER :: one = 1.0_wp
533 REAL(KIND=wp), PARAMETER :: zero = 0.0_wp
534 COMPLEX(KIND=WP), PARAMETER :: ZONE = ( 1.0_wp, 0.0_wp )
535 COMPLEX(KIND=WP), PARAMETER :: ZZERO = ( 0.0_wp, 0.0_wp )
536!
537! Local scalars
538! ~~~~~~~~~~~~~
539 REAL(KIND=wp) :: ofl, rootsc, scale, small, &
540 ssum, xscl1, xscl2
541 INTEGER :: i, j, IMINWR, INFO1, INFO2, &
542 LWRKEV, LWRSDD, LWRSVD, LWRSVJ, &
543 lwrsvq, mlwork, mwrkev, mwrsdd, &
544 mwrsvd, mwrsvj, mwrsvq, numrnk, &
545 olwork, mlrwrk
546 LOGICAL :: BADXY, LQUERY, SCCOLX, SCCOLY, &
547 wntex, wntref, wntres, wntvec
548 CHARACTER :: JOBZL, T_OR_N
549 CHARACTER :: JSVOPT
550!
551! Local arrays
552! ~~~~~~~~~~~~
553 REAL(KIND=wp) :: rdummy(2)
554!
555! External functions (BLAS and LAPACK)
556! ~~~~~~~~~~~~~~~~~
557 REAL(KIND=wp) zlange, dlamch, dznrm2
558 EXTERNAL zlange, dlamch, dznrm2, izamax
559 INTEGER IZAMAX
560 LOGICAL DISNAN, LSAME
561 EXTERNAL disnan, lsame
562!
563! External subroutines (BLAS and LAPACK)
564! ~~~~~~~~~~~~~~~~~~~~
565 EXTERNAL zaxpy, zgemm, zdscal
566 EXTERNAL zgeev, zgejsv, zgesdd, zgesvd, zgesvdq, &
568!
569! Intrinsic functions
570! ~~~~~~~~~~~~~~~~~~~
571 INTRINSIC dble, int, max, sqrt
572!............................................................
573!
574! Test the input arguments
575!
576 wntres = lsame(jobr,'R')
577 sccolx = lsame(jobs,'S') .OR. lsame(jobs,'C')
578 sccoly = lsame(jobs,'Y')
579 wntvec = lsame(jobz,'V')
580 wntref = lsame(jobf,'R')
581 wntex = lsame(jobf,'E')
582 info = 0
583 lquery = ( ( lzwork == -1 ) .OR. ( liwork == -1 ) &
584 .OR. ( lrwork == -1 ) )
585!
586 IF ( .NOT. (sccolx .OR. sccoly .OR. &
587 lsame(jobs,'N')) ) THEN
588 info = -1
589 ELSE IF ( .NOT. (wntvec .OR. lsame(jobz,'N') &
590 .OR. lsame(jobz,'F')) ) THEN
591 info = -2
592 ELSE IF ( .NOT. (wntres .OR. lsame(jobr,'N')) .OR. &
593 ( wntres .AND. (.NOT.wntvec) ) ) THEN
594 info = -3
595 ELSE IF ( .NOT. (wntref .OR. wntex .OR. &
596 lsame(jobf,'N') ) ) THEN
597 info = -4
598 ELSE IF ( .NOT.((whtsvd == 1) .OR. (whtsvd == 2) .OR. &
599 (whtsvd == 3) .OR. (whtsvd == 4) )) THEN
600 info = -5
601 ELSE IF ( m < 0 ) THEN
602 info = -6
603 ELSE IF ( ( n < 0 ) .OR. ( n > m ) ) THEN
604 info = -7
605 ELSE IF ( ldx < m ) THEN
606 info = -9
607 ELSE IF ( ldy < m ) THEN
608 info = -11
609 ELSE IF ( .NOT. (( nrnk == -2).OR.(nrnk == -1).OR. &
610 ((nrnk >= 1).AND.(nrnk <=n ))) ) THEN
611 info = -12
612 ELSE IF ( ( tol < zero ) .OR. ( tol >= one ) ) THEN
613 info = -13
614 ELSE IF ( ldz < m ) THEN
615 info = -17
616 ELSE IF ( (wntref .OR. wntex ) .AND. ( ldb < m ) ) THEN
617 info = -20
618 ELSE IF ( ldw < n ) THEN
619 info = -22
620 ELSE IF ( lds < n ) THEN
621 info = -24
622 END IF
623!
624 IF ( info == 0 ) THEN
625 ! Compute the minimal and the optimal workspace
626 ! requirements. Simulate running the code and
627 ! determine minimal and optimal sizes of the
628 ! workspace at any moment of the run.
629 IF ( n == 0 ) THEN
630 ! Quick return. All output except K is void.
631 ! INFO=1 signals the void input.
632 ! In case of a workspace query, the default
633 ! minimal workspace lengths are returned.
634 IF ( lquery ) THEN
635 iwork(1) = 1
636 rwork(1) = 1
637 zwork(1) = 2
638 zwork(2) = 2
639 ELSE
640 k = 0
641 END IF
642 info = 1
643 RETURN
644 END IF
645
646 iminwr = 1
647 mlrwrk = max(1,n)
648 mlwork = 2
649 olwork = 2
650 SELECT CASE ( whtsvd )
651 CASE (1)
652 ! The following is specified as the minimal
653 ! length of WORK in the definition of ZGESVD:
654 ! MWRSVD = MAX(1,2*MIN(M,N)+MAX(M,N))
655 mwrsvd = max(1,2*min(m,n)+max(m,n))
656 mlwork = max(mlwork,mwrsvd)
657 mlrwrk = max(mlrwrk,n + 5*min(m,n))
658 IF ( lquery ) THEN
659 CALL zgesvd( 'O', 'S', m, n, x, ldx, rwork, &
660 b, ldb, w, ldw, zwork, -1, rdummy, info1 )
661 lwrsvd = int( zwork(1) )
662 olwork = max(olwork,lwrsvd)
663 END IF
664 CASE (2)
665 ! The following is specified as the minimal
666 ! length of WORK in the definition of ZGESDD:
667 ! MWRSDD = 2*min(M,N)*min(M,N)+2*min(M,N)+max(M,N).
668 ! RWORK length: 5*MIN(M,N)*MIN(M,N)+7*MIN(M,N)
669 ! In LAPACK 3.10.1 RWORK is defined differently.
670 ! Below we take max over the two versions.
671 ! IMINWR = 8*MIN(M,N)
672 mwrsdd = 2*min(m,n)*min(m,n)+2*min(m,n)+max(m,n)
673 mlwork = max(mlwork,mwrsdd)
674 iminwr = 8*min(m,n)
675 mlrwrk = max( mlrwrk, n + &
676 max( 5*min(m,n)*min(m,n)+7*min(m,n), &
677 5*min(m,n)*min(m,n)+5*min(m,n), &
678 2*max(m,n)*min(m,n)+ &
679 2*min(m,n)*min(m,n)+min(m,n) ) )
680 IF ( lquery ) THEN
681 CALL zgesdd( 'O', m, n, x, ldx, rwork, b,ldb,&
682 w, ldw, zwork, -1, rdummy, iwork, info1 )
683 lwrsdd = max( mwrsdd,int( zwork(1) ))
684 ! Possible bug in ZGESDD optimal workspace size.
685 olwork = max(olwork,lwrsdd)
686 END IF
687 CASE (3)
688 CALL zgesvdq( 'H', 'P', 'N', 'R', 'R', m, n, &
689 x, ldx, rwork, z, ldz, w, ldw, numrnk, &
690 iwork, -1, zwork, -1, rdummy, -1, info1 )
691 iminwr = iwork(1)
692 mwrsvq = int(zwork(2))
693 mlwork = max(mlwork,mwrsvq)
694 mlrwrk = max(mlrwrk,n + int(rdummy(1)))
695 IF ( lquery ) THEN
696 lwrsvq = int(zwork(1))
697 olwork = max(olwork,lwrsvq)
698 END IF
699 CASE (4)
700 jsvopt = 'J'
701 CALL zgejsv( 'F', 'U', jsvopt, 'R', 'N', 'P', m, &
702 n, x, ldx, rwork, z, ldz, w, ldw, &
703 zwork, -1, rdummy, -1, iwork, info1 )
704 iminwr = iwork(1)
705 mwrsvj = int(zwork(2))
706 mlwork = max(mlwork,mwrsvj)
707 mlrwrk = max(mlrwrk,n + max(7,int(rdummy(1))))
708 IF ( lquery ) THEN
709 lwrsvj = int(zwork(1))
710 olwork = max(olwork,lwrsvj)
711 END IF
712 END SELECT
713 IF ( wntvec .OR. wntex .OR. lsame(jobz,'F') ) THEN
714 jobzl = 'V'
715 ELSE
716 jobzl = 'N'
717 END IF
718 ! Workspace calculation to the ZGEEV call
719 mwrkev = max( 1, 2*n )
720 mlwork = max(mlwork,mwrkev)
721 mlrwrk = max(mlrwrk,n+2*n)
722 IF ( lquery ) THEN
723 CALL zgeev( 'N', jobzl, n, s, lds, eigs, &
724 w, ldw, w, ldw, zwork, -1, rwork, info1 )
725 lwrkev = int(zwork(1))
726 olwork = max( olwork, lwrkev )
727 END IF
728!
729 IF ( liwork < iminwr .AND. (.NOT.lquery) ) info = -30
730 IF ( lrwork < mlrwrk .AND. (.NOT.lquery) ) info = -28
731 IF ( lzwork < mlwork .AND. (.NOT.lquery) ) info = -26
732
733 END IF
734!
735 IF( info /= 0 ) THEN
736 CALL xerbla( 'ZGEDMD', -info )
737 RETURN
738 ELSE IF ( lquery ) THEN
739! Return minimal and optimal workspace sizes
740 iwork(1) = iminwr
741 rwork(1) = mlrwrk
742 zwork(1) = mlwork
743 zwork(2) = olwork
744 RETURN
745 END IF
746!............................................................
747!
748 ofl = dlamch('O')
749 small = dlamch('S')
750 badxy = .false.
751!
752! <1> Optional scaling of the snapshots (columns of X, Y)
753! ==========================================================
754 IF ( sccolx ) THEN
755 ! The columns of X will be normalized.
756 ! To prevent overflows, the column norms of X are
757 ! carefully computed using ZLASSQ.
758 k = 0
759 DO i = 1, n
760 !WORK(i) = DZNRM2( M, X(1,i), 1 )
761 scale = zero
762 CALL zlassq( m, x(1,i), 1, scale, ssum )
763 IF ( disnan(scale) .OR. disnan(ssum) ) THEN
764 k = 0
765 info = -8
766 CALL xerbla('ZGEDMD',-info)
767 END IF
768 IF ( (scale /= zero) .AND. (ssum /= zero) ) THEN
769 rootsc = sqrt(ssum)
770 IF ( scale .GE. (ofl / rootsc) ) THEN
771! Norm of X(:,i) overflows. First, X(:,i)
772! is scaled by
773! ( ONE / ROOTSC ) / SCALE = 1/||X(:,i)||_2.
774! Next, the norm of X(:,i) is stored without
775! overflow as RWORK(i) = - SCALE * (ROOTSC/M),
776! the minus sign indicating the 1/M factor.
777! Scaling is performed without overflow, and
778! underflow may occur in the smallest entries
779! of X(:,i). The relative backward and forward
780! errors are small in the ell_2 norm.
781 CALL zlascl( 'G', 0, 0, scale, one/rootsc, &
782 m, 1, x(1,i), ldx, info2 )
783 rwork(i) = - scale * ( rootsc / dble(m) )
784 ELSE
785! X(:,i) will be scaled to unit 2-norm
786 rwork(i) = scale * rootsc
787 CALL zlascl( 'G',0, 0, rwork(i), one, m, 1, &
788 x(1,i), ldx, info2 ) ! LAPACK CALL
789! X(1:M,i) = (ONE/RWORK(i)) * X(1:M,i) ! INTRINSIC
790 END IF
791 ELSE
792 rwork(i) = zero
793 k = k + 1
794 END IF
795 END DO
796 IF ( k == n ) THEN
797 ! All columns of X are zero. Return error code -8.
798 ! (the 8th input variable had an illegal value)
799 k = 0
800 info = -8
801 CALL xerbla('ZGEDMD',-info)
802 RETURN
803 END IF
804 DO i = 1, n
805! Now, apply the same scaling to the columns of Y.
806 IF ( rwork(i) > zero ) THEN
807 CALL zdscal( m, one/rwork(i), y(1,i), 1 ) ! BLAS CALL
808! Y(1:M,i) = (ONE/RWORK(i)) * Y(1:M,i) ! INTRINSIC
809 ELSE IF ( rwork(i) < zero ) THEN
810 CALL zlascl( 'G', 0, 0, -rwork(i), &
811 one/dble(m), m, 1, y(1,i), ldy, info2 ) ! LAPACK CALL
812 ELSE IF ( abs(y(izamax(m, y(1,i),1),i )) &
813 /= zero ) THEN
814! X(:,i) is zero vector. For consistency,
815! Y(:,i) should also be zero. If Y(:,i) is not
816! zero, then the data might be inconsistent or
817! corrupted. If JOBS == 'C', Y(:,i) is set to
818! zero and a warning flag is raised.
819! The computation continues but the
820! situation will be reported in the output.
821 badxy = .true.
822 IF ( lsame(jobs,'C')) &
823 CALL zdscal( m, zero, y(1,i), 1 ) ! BLAS CALL
824 END IF
825 END DO
826 END IF
827 !
828 IF ( sccoly ) THEN
829 ! The columns of Y will be normalized.
830 ! To prevent overflows, the column norms of Y are
831 ! carefully computed using ZLASSQ.
832 DO i = 1, n
833 !RWORK(i) = DZNRM2( M, Y(1,i), 1 )
834 scale = zero
835 CALL zlassq( m, y(1,i), 1, scale, ssum )
836 IF ( disnan(scale) .OR. disnan(ssum) ) THEN
837 k = 0
838 info = -10
839 CALL xerbla('ZGEDMD',-info)
840 END IF
841 IF ( scale /= zero .AND. (ssum /= zero) ) THEN
842 rootsc = sqrt(ssum)
843 IF ( scale .GE. (ofl / rootsc) ) THEN
844! Norm of Y(:,i) overflows. First, Y(:,i)
845! is scaled by
846! ( ONE / ROOTSC ) / SCALE = 1/||Y(:,i)||_2.
847! Next, the norm of Y(:,i) is stored without
848! overflow as RWORK(i) = - SCALE * (ROOTSC/M),
849! the minus sign indicating the 1/M factor.
850! Scaling is performed without overflow, and
851! underflow may occur in the smallest entries
852! of Y(:,i). The relative backward and forward
853! errors are small in the ell_2 norm.
854 CALL zlascl( 'G', 0, 0, scale, one/rootsc, &
855 m, 1, y(1,i), ldy, info2 )
856 rwork(i) = - scale * ( rootsc / dble(m) )
857 ELSE
858! Y(:,i) will be scaled to unit 2-norm
859 rwork(i) = scale * rootsc
860 CALL zlascl( 'G',0, 0, rwork(i), one, m, 1, &
861 y(1,i), ldy, info2 ) ! LAPACK CALL
862! Y(1:M,i) = (ONE/RWORK(i)) * Y(1:M,i) ! INTRINSIC
863 END IF
864 ELSE
865 rwork(i) = zero
866 END IF
867 END DO
868 DO i = 1, n
869! Now, apply the same scaling to the columns of X.
870 IF ( rwork(i) > zero ) THEN
871 CALL zdscal( m, one/rwork(i), x(1,i), 1 ) ! BLAS CALL
872! X(1:M,i) = (ONE/RWORK(i)) * X(1:M,i) ! INTRINSIC
873 ELSE IF ( rwork(i) < zero ) THEN
874 CALL zlascl( 'G', 0, 0, -rwork(i), &
875 one/dble(m), m, 1, x(1,i), ldx, info2 ) ! LAPACK CALL
876 ELSE IF ( abs(x(izamax(m, x(1,i),1),i )) &
877 /= zero ) THEN
878! Y(:,i) is zero vector. If X(:,i) is not
879! zero, then a warning flag is raised.
880! The computation continues but the
881! situation will be reported in the output.
882 badxy = .true.
883 END IF
884 END DO
885 END IF
886!
887! <2> SVD of the data snapshot matrix X.
888! =====================================
889! The left singular vectors are stored in the array X.
890! The right singular vectors are in the array W.
891! The array W will later on contain the eigenvectors
892! of a Rayleigh quotient.
893 numrnk = n
894 SELECT CASE ( whtsvd )
895 CASE (1)
896 CALL zgesvd( 'O', 'S', m, n, x, ldx, rwork, b, &
897 ldb, w, ldw, zwork, lzwork, rwork(n+1), info1 ) ! LAPACK CALL
898 t_or_n = 'C'
899 CASE (2)
900 CALL zgesdd( 'O', m, n, x, ldx, rwork, b, ldb, w, &
901 ldw, zwork, lzwork, rwork(n+1), iwork, info1 ) ! LAPACK CALL
902 t_or_n = 'C'
903 CASE (3)
904 CALL zgesvdq( 'H', 'P', 'N', 'R', 'R', m, n, &
905 x, ldx, rwork, z, ldz, w, ldw, &
906 numrnk, iwork, liwork, zwork, &
907 lzwork, rwork(n+1), lrwork-n, info1) ! LAPACK CALL
908 CALL zlacpy( 'A', m, numrnk, z, ldz, x, ldx ) ! LAPACK CALL
909 t_or_n = 'C'
910 CASE (4)
911 CALL zgejsv( 'F', 'U', jsvopt, 'R', 'N', 'P', m, &
912 n, x, ldx, rwork, z, ldz, w, ldw, &
913 zwork, lzwork, rwork(n+1), lrwork-n, iwork, info1 ) ! LAPACK CALL
914 CALL zlacpy( 'A', m, n, z, ldz, x, ldx ) ! LAPACK CALL
915 t_or_n = 'N'
916 xscl1 = rwork(n+1)
917 xscl2 = rwork(n+2)
918 IF ( xscl1 /= xscl2 ) THEN
919 ! This is an exceptional situation. If the
920 ! data matrices are not scaled and the
921 ! largest singular value of X overflows.
922 ! In that case ZGEJSV can return the SVD
923 ! in scaled form. The scaling factor can be used
924 ! to rescale the data (X and Y).
925 CALL zlascl( 'G', 0, 0, xscl1, xscl2, m, n, y, ldy, info2 )
926 END IF
927 END SELECT
928!
929 IF ( info1 > 0 ) THEN
930 ! The SVD selected subroutine did not converge.
931 ! Return with an error code.
932 info = 2
933 RETURN
934 END IF
935!
936 IF ( rwork(1) == zero ) THEN
937 ! The largest computed singular value of (scaled)
938 ! X is zero. Return error code -8
939 ! (the 8th input variable had an illegal value).
940 k = 0
941 info = -8
942 CALL xerbla('ZGEDMD',-info)
943 RETURN
944 END IF
945!
946
947 ! snapshots matrix X. This depends on the
948 ! parameters NRNK and TOL.
949
950 SELECT CASE ( nrnk )
951 CASE ( -1 )
952 k = 1
953 DO i = 2, numrnk
954 IF ( ( rwork(i) <= rwork(1)*tol ) .OR. &
955 ( rwork(i) <= small ) ) EXIT
956 k = k + 1
957 END DO
958 CASE ( -2 )
959 k = 1
960 DO i = 1, numrnk-1
961 IF ( ( rwork(i+1) <= rwork(i)*tol ) .OR. &
962 ( rwork(i) <= small ) ) EXIT
963 k = k + 1
964 END DO
965 CASE DEFAULT
966 k = 1
967 DO i = 2, nrnk
968 IF ( rwork(i) <= small ) EXIT
969 k = k + 1
970 END DO
971 END SELECT
972 ! Now, U = X(1:M,1:K) is the SVD/POD basis for the
973 ! snapshot data in the input matrix X.
974
975
976 ! Depending on the requested outputs, the computation
977 ! is organized to compute additional auxiliary
978 ! matrices (for the residuals and refinements).
979 !
980 ! In all formulas below, we need V_k*Sigma_k^(-1)
981 ! where either V_k is in W(1:N,1:K), or V_k^H is in
982 ! W(1:K,1:N). Here Sigma_k=diag(WORK(1:K)).
983 IF ( lsame(t_or_n, 'N') ) THEN
984 DO i = 1, k
985 CALL zdscal( n, one/rwork(i), w(1,i), 1 ) ! BLAS CALL
986 ! W(1:N,i) = (ONE/RWORK(i)) * W(1:N,i) ! INTRINSIC
987 END DO
988 ELSE
989 ! This non-unit stride access is due to the fact
990 ! that ZGESVD, ZGESVDQ and ZGESDD return the
991 ! adjoint matrix of the right singular vectors.
992 !DO i = 1, K
993 ! CALL ZDSCAL( N, ONE/RWORK(i), W(i,1), LDW ) ! BLAS CALL
994 ! ! W(i,1:N) = (ONE/RWORK(i)) * W(i,1:N) ! INTRINSIC
995 !END DO
996 DO i = 1, k
997 rwork(n+i) = one/rwork(i)
998 END DO
999 DO j = 1, n
1000 DO i = 1, k
1001 w(i,j) = cmplx(rwork(n+i),zero,kind=wp)*w(i,j)
1002 END DO
1003 END DO
1004 END IF
1005!
1006 IF ( wntref ) THEN
1007 !
1008 ! Need A*U(:,1:K)=Y*V_k*inv(diag(WORK(1:K)))
1009 ! for computing the refined Ritz vectors
1010 ! (optionally, outside ZGEDMD).
1011 CALL zgemm( 'N', t_or_n, m, k, n, zone, y, ldy, w, &
1012 ldw, zzero, z, ldz ) ! BLAS CALL
1013 ! Z(1:M,1:K)=MATMUL(Y(1:M,1:N),TRANSPOSE(CONJG(W(1:K,1:N)))) ! INTRINSIC, for T_OR_N=='C'
1014 ! Z(1:M,1:K)=MATMUL(Y(1:M,1:N),W(1:N,1:K)) ! INTRINSIC, for T_OR_N=='N'
1015 !
1016 ! At this point Z contains
1017 ! A * U(:,1:K) = Y * V_k * Sigma_k^(-1), and
1018 ! this is needed for computing the residuals.
1019 ! This matrix is returned in the array B and
1020 ! it can be used to compute refined Ritz vectors.
1021 CALL zlacpy( 'A', m, k, z, ldz, b, ldb ) ! BLAS CALL
1022 ! B(1:M,1:K) = Z(1:M,1:K) ! INTRINSIC
1023
1024 CALL zgemm( 'C', 'N', k, k, m, zone, x, ldx, z, &
1025 ldz, zzero, s, lds ) ! BLAS CALL
1026 ! S(1:K,1:K) = MATMUL(TRANSPOSE(CONJG(X(1:M,1:K))),Z(1:M,1:K)) ! INTRINSIC
1027 ! At this point S = U^H * A * U is the Rayleigh quotient.
1028 ELSE
1029 ! A * U(:,1:K) is not explicitly needed and the
1030 ! computation is organized differently. The Rayleigh
1031 ! quotient is computed more efficiently.
1032 CALL zgemm( 'C', 'N', k, n, m, zone, x, ldx, y, ldy, &
1033 zzero, z, ldz ) ! BLAS CALL
1034 ! Z(1:K,1:N) = MATMUL( TRANSPOSE(CONJG(X(1:M,1:K))), Y(1:M,1:N) ) ! INTRINSIC
1035 !
1036 CALL zgemm( 'N', t_or_n, k, k, n, zone, z, ldz, w, &
1037 ldw, zzero, s, lds ) ! BLAS CALL
1038 ! S(1:K,1:K) = MATMUL(Z(1:K,1:N),TRANSPOSE(CONJG(W(1:K,1:N)))) ! INTRINSIC, for T_OR_N=='T'
1039 ! S(1:K,1:K) = MATMUL(Z(1:K,1:N),(W(1:N,1:K))) ! INTRINSIC, for T_OR_N=='N'
1040 ! At this point S = U^H * A * U is the Rayleigh quotient.
1041 ! If the residuals are requested, save scaled V_k into Z.
1042 ! Recall that V_k or V_k^H is stored in W.
1043 IF ( wntres .OR. wntex ) THEN
1044 IF ( lsame(t_or_n, 'N') ) THEN
1045 CALL zlacpy( 'A', n, k, w, ldw, z, ldz )
1046 ELSE
1047 CALL zlacpy( 'A', k, n, w, ldw, z, ldz )
1048 END IF
1049 END IF
1050 END IF
1051!
1052
1053 ! right eigenvectors of the Rayleigh quotient.
1054 !
1055 CALL zgeev( 'N', jobzl, k, s, lds, eigs, w, ldw, &
1056 w, ldw, zwork, lzwork, rwork(n+1), info1 ) ! LAPACK CALL
1057 !
1058 ! W(1:K,1:K) contains the eigenvectors of the Rayleigh
1059 ! quotient. See the description of Z.
1060 ! Also, see the description of ZGEEV.
1061 IF ( info1 > 0 ) THEN
1062 ! ZGEEV failed to compute the eigenvalues and
1063 ! eigenvectors of the Rayleigh quotient.
1064 info = 3
1065 RETURN
1066 END IF
1067!
1068 ! <6> Compute the eigenvectors (if requested) and,
1069 ! the residuals (if requested).
1070 !
1071 IF ( wntvec .OR. wntex ) THEN
1072 IF ( wntres ) THEN
1073 IF ( wntref ) THEN
1074 ! Here, if the refinement is requested, we have
1075 ! A*U(:,1:K) already computed and stored in Z.
1076 ! For the residuals, need Y = A * U(:,1;K) * W.
1077 CALL zgemm( 'N', 'N', m, k, k, zone, z, ldz, w, &
1078 ldw, zzero, y, ldy ) ! BLAS CALL
1079 ! Y(1:M,1:K) = Z(1:M,1:K) * W(1:K,1:K) ! INTRINSIC
1080 ! This frees Z; Y contains A * U(:,1:K) * W.
1081 ELSE
1082 ! Compute S = V_k * Sigma_k^(-1) * W, where
1083 ! V_k * Sigma_k^(-1) (or its adjoint) is stored in Z
1084 CALL zgemm( t_or_n, 'N', n, k, k, zone, z, ldz, &
1085 w, ldw, zzero, s, lds )
1086 ! Then, compute Z = Y * S =
1087 ! = Y * V_k * Sigma_k^(-1) * W(1:K,1:K) =
1088 ! = A * U(:,1:K) * W(1:K,1:K)
1089 CALL zgemm( 'N', 'N', m, k, n, zone, y, ldy, s, &
1090 lds, zzero, z, ldz )
1091 ! Save a copy of Z into Y and free Z for holding
1092 ! the Ritz vectors.
1093 CALL zlacpy( 'A', m, k, z, ldz, y, ldy )
1094 IF ( wntex ) CALL zlacpy( 'A', m, k, z, ldz, b, ldb )
1095 END IF
1096 ELSE IF ( wntex ) THEN
1097 ! Compute S = V_k * Sigma_k^(-1) * W, where
1098 ! V_k * Sigma_k^(-1) is stored in Z
1099 CALL zgemm( t_or_n, 'N', n, k, k, zone, z, ldz, &
1100 w, ldw, zzero, s, lds )
1101 ! Then, compute Z = Y * S =
1102 ! = Y * V_k * Sigma_k^(-1) * W(1:K,1:K) =
1103 ! = A * U(:,1:K) * W(1:K,1:K)
1104 CALL zgemm( 'N', 'N', m, k, n, zone, y, ldy, s, &
1105 lds, zzero, b, ldb )
1106 ! The above call replaces the following two calls
1107 ! that were used in the developing-testing phase.
1108 ! CALL ZGEMM( 'N', 'N', M, K, N, ZONE, Y, LDY, S, &
1109 ! LDS, ZZERO, Z, LDZ)
1110 ! Save a copy of Z into B and free Z for holding
1111 ! the Ritz vectors.
1112 ! CALL ZLACPY( 'A', M, K, Z, LDZ, B, LDB )
1113 END IF
1114!
1115 ! Compute the Ritz vectors
1116 IF ( wntvec ) CALL zgemm( 'N', 'N', m, k, k, zone, x, ldx, w, ldw, &
1117 zzero, z, ldz ) ! BLAS CALL
1118 ! Z(1:M,1:K) = MATMUL(X(1:M,1:K), W(1:K,1:K)) ! INTRINSIC
1119!
1120 IF ( wntres ) THEN
1121 DO i = 1, k
1122 CALL zaxpy( m, -eigs(i), z(1,i), 1, y(1,i), 1 ) ! BLAS CALL
1123 ! Y(1:M,i) = Y(1:M,i) - EIGS(i) * Z(1:M,i) ! INTRINSIC
1124 res(i) = dznrm2( m, y(1,i), 1 ) ! BLAS CALL
1125 END DO
1126 END IF
1127 END IF
1128!
1129 IF ( whtsvd == 4 ) THEN
1130 rwork(n+1) = xscl1
1131 rwork(n+2) = xscl2
1132 END IF
1133!
1134! Successful exit.
1135 IF ( .NOT. badxy ) THEN
1136 info = 0
1137 ELSE
1138 ! A warning on possible data inconsistency.
1139 ! This should be a rare event.
1140 info = 4
1141 END IF
1142!............................................................
1143 RETURN
1144! ......
1145 END SUBROUTINE zgedmd
1146
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine zaxpy(n, za, zx, incx, zy, incy)
ZAXPY
Definition zaxpy.f:88
subroutine zgedmd(jobs, jobz, jobr, jobf, whtsvd, m, n, x, ldx, y, ldy, nrnk, tol, k, eigs, z, ldz, res, b, ldb, w, ldw, s, lds, zwork, lzwork, rwork, lrwork, iwork, liwork, info)
ZGEDMD computes the Dynamic Mode Decomposition (DMD) for a pair of data snapshot matrices.
Definition zgedmd.f90:498
subroutine zgeev(jobvl, jobvr, n, a, lda, w, vl, ldvl, vr, ldvr, work, lwork, rwork, info)
ZGEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices
Definition zgeev.f:180
subroutine zgejsv(joba, jobu, jobv, jobr, jobt, jobp, m, n, a, lda, sva, u, ldu, v, ldv, cwork, lwork, rwork, lrwork, iwork, info)
ZGEJSV
Definition zgejsv.f:569
subroutine zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMM
Definition zgemm.f:188
subroutine zgesdd(jobz, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, iwork, info)
ZGESDD
Definition zgesdd.f:221
subroutine zgesvd(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, info)
ZGESVD computes the singular value decomposition (SVD) for GE matrices
Definition zgesvd.f:214
subroutine zgesvdq(joba, jobp, jobr, jobu, jobv, m, n, a, lda, s, u, ldu, v, ldv, numrank, iwork, liwork, cwork, lcwork, rwork, lrwork, info)
ZGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE...
Definition zgesvdq.f:413
integer function izamax(n, zx, incx)
IZAMAX
Definition izamax.f:71
subroutine zlacpy(uplo, m, n, a, lda, b, ldb)
ZLACPY copies all or part of one two-dimensional array to another.
Definition zlacpy.f:103
double precision function dlamch(cmach)
DLAMCH
Definition dlamch.f:69
double precision function zlange(norm, m, n, a, lda, work)
ZLANGE returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value ...
Definition zlange.f:115
subroutine zlascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
ZLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition zlascl.f:143
subroutine zlassq(n, x, incx, scale, sumsq)
ZLASSQ updates a sum of squares represented in scaled form.
Definition zlassq.f90:124
real(wp) function dznrm2(n, x, incx)
DZNRM2
Definition dznrm2.f90:90
subroutine zdscal(n, da, zx, incx)
ZDSCAL
Definition zdscal.f:78