LAPACK 3.3.1
Linear Algebra PACKage

zhpevd.f

Go to the documentation of this file.
00001       SUBROUTINE ZHPEVD( JOBZ, UPLO, N, AP, W, Z, LDZ, WORK, LWORK,
00002      $                   RWORK, LRWORK, IWORK, LIWORK, INFO )
00003 *
00004 *  -- LAPACK driver routine (version 3.2) --
00005 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00006 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00007 *     November 2006
00008 *
00009 *     .. Scalar Arguments ..
00010       CHARACTER          JOBZ, UPLO
00011       INTEGER            INFO, LDZ, LIWORK, LRWORK, LWORK, N
00012 *     ..
00013 *     .. Array Arguments ..
00014       INTEGER            IWORK( * )
00015       DOUBLE PRECISION   RWORK( * ), W( * )
00016       COMPLEX*16         AP( * ), WORK( * ), Z( LDZ, * )
00017 *     ..
00018 *
00019 *  Purpose
00020 *  =======
00021 *
00022 *  ZHPEVD computes all the eigenvalues and, optionally, eigenvectors of
00023 *  a complex Hermitian matrix A in packed storage.  If eigenvectors are
00024 *  desired, it uses a divide and conquer algorithm.
00025 *
00026 *  The divide and conquer algorithm makes very mild assumptions about
00027 *  floating point arithmetic. It will work on machines with a guard
00028 *  digit in add/subtract, or on those binary machines without guard
00029 *  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
00030 *  Cray-2. It could conceivably fail on hexadecimal or decimal machines
00031 *  without guard digits, but we know of none.
00032 *
00033 *  Arguments
00034 *  =========
00035 *
00036 *  JOBZ    (input) CHARACTER*1
00037 *          = 'N':  Compute eigenvalues only;
00038 *          = 'V':  Compute eigenvalues and eigenvectors.
00039 *
00040 *  UPLO    (input) CHARACTER*1
00041 *          = 'U':  Upper triangle of A is stored;
00042 *          = 'L':  Lower triangle of A is stored.
00043 *
00044 *  N       (input) INTEGER
00045 *          The order of the matrix A.  N >= 0.
00046 *
00047 *  AP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
00048 *          On entry, the upper or lower triangle of the Hermitian matrix
00049 *          A, packed columnwise in a linear array.  The j-th column of A
00050 *          is stored in the array AP as follows:
00051 *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
00052 *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
00053 *
00054 *          On exit, AP is overwritten by values generated during the
00055 *          reduction to tridiagonal form.  If UPLO = 'U', the diagonal
00056 *          and first superdiagonal of the tridiagonal matrix T overwrite
00057 *          the corresponding elements of A, and if UPLO = 'L', the
00058 *          diagonal and first subdiagonal of T overwrite the
00059 *          corresponding elements of A.
00060 *
00061 *  W       (output) DOUBLE PRECISION array, dimension (N)
00062 *          If INFO = 0, the eigenvalues in ascending order.
00063 *
00064 *  Z       (output) COMPLEX*16 array, dimension (LDZ, N)
00065 *          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal
00066 *          eigenvectors of the matrix A, with the i-th column of Z
00067 *          holding the eigenvector associated with W(i).
00068 *          If JOBZ = 'N', then Z is not referenced.
00069 *
00070 *  LDZ     (input) INTEGER
00071 *          The leading dimension of the array Z.  LDZ >= 1, and if
00072 *          JOBZ = 'V', LDZ >= max(1,N).
00073 *
00074 *  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
00075 *          On exit, if INFO = 0, WORK(1) returns the required LWORK.
00076 *
00077 *  LWORK   (input) INTEGER
00078 *          The dimension of array WORK.
00079 *          If N <= 1,               LWORK must be at least 1.
00080 *          If JOBZ = 'N' and N > 1, LWORK must be at least N.
00081 *          If JOBZ = 'V' and N > 1, LWORK must be at least 2*N.
00082 *
00083 *          If LWORK = -1, then a workspace query is assumed; the routine
00084 *          only calculates the required sizes of the WORK, RWORK and
00085 *          IWORK arrays, returns these values as the first entries of
00086 *          the WORK, RWORK and IWORK arrays, and no error message
00087 *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
00088 *
00089 *  RWORK   (workspace/output) DOUBLE PRECISION array,
00090 *                                         dimension (LRWORK)
00091 *          On exit, if INFO = 0, RWORK(1) returns the required LRWORK.
00092 *
00093 *  LRWORK  (input) INTEGER
00094 *          The dimension of array RWORK.
00095 *          If N <= 1,               LRWORK must be at least 1.
00096 *          If JOBZ = 'N' and N > 1, LRWORK must be at least N.
00097 *          If JOBZ = 'V' and N > 1, LRWORK must be at least
00098 *                    1 + 5*N + 2*N**2.
00099 *
00100 *          If LRWORK = -1, then a workspace query is assumed; the
00101 *          routine only calculates the required sizes of the WORK, RWORK
00102 *          and IWORK arrays, returns these values as the first entries
00103 *          of the WORK, RWORK and IWORK arrays, and no error message
00104 *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
00105 *
00106 *  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
00107 *          On exit, if INFO = 0, IWORK(1) returns the required LIWORK.
00108 *
00109 *  LIWORK  (input) INTEGER
00110 *          The dimension of array IWORK.
00111 *          If JOBZ  = 'N' or N <= 1, LIWORK must be at least 1.
00112 *          If JOBZ  = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
00113 *
00114 *          If LIWORK = -1, then a workspace query is assumed; the
00115 *          routine only calculates the required sizes of the WORK, RWORK
00116 *          and IWORK arrays, returns these values as the first entries
00117 *          of the WORK, RWORK and IWORK arrays, and no error message
00118 *          related to LWORK or LRWORK or LIWORK is issued by XERBLA.
00119 *
00120 *  INFO    (output) INTEGER
00121 *          = 0:  successful exit
00122 *          < 0:  if INFO = -i, the i-th argument had an illegal value.
00123 *          > 0:  if INFO = i, the algorithm failed to converge; i
00124 *                off-diagonal elements of an intermediate tridiagonal
00125 *                form did not converge to zero.
00126 *
00127 *  =====================================================================
00128 *
00129 *     .. Parameters ..
00130       DOUBLE PRECISION   ZERO, ONE
00131       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00132       COMPLEX*16         CONE
00133       PARAMETER          ( CONE = ( 1.0D+0, 0.0D+0 ) )
00134 *     ..
00135 *     .. Local Scalars ..
00136       LOGICAL            LQUERY, WANTZ
00137       INTEGER            IINFO, IMAX, INDE, INDRWK, INDTAU, INDWRK,
00138      $                   ISCALE, LIWMIN, LLRWK, LLWRK, LRWMIN, LWMIN
00139       DOUBLE PRECISION   ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
00140      $                   SMLNUM
00141 *     ..
00142 *     .. External Functions ..
00143       LOGICAL            LSAME
00144       DOUBLE PRECISION   DLAMCH, ZLANHP
00145       EXTERNAL           LSAME, DLAMCH, ZLANHP
00146 *     ..
00147 *     .. External Subroutines ..
00148       EXTERNAL           DSCAL, DSTERF, XERBLA, ZDSCAL, ZHPTRD, ZSTEDC,
00149      $                   ZUPMTR
00150 *     ..
00151 *     .. Intrinsic Functions ..
00152       INTRINSIC          SQRT
00153 *     ..
00154 *     .. Executable Statements ..
00155 *
00156 *     Test the input parameters.
00157 *
00158       WANTZ = LSAME( JOBZ, 'V' )
00159       LQUERY = ( LWORK.EQ.-1 .OR. LRWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
00160 *
00161       INFO = 0
00162       IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
00163          INFO = -1
00164       ELSE IF( .NOT.( LSAME( UPLO, 'L' ) .OR. LSAME( UPLO, 'U' ) ) )
00165      $          THEN
00166          INFO = -2
00167       ELSE IF( N.LT.0 ) THEN
00168          INFO = -3
00169       ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
00170          INFO = -7
00171       END IF
00172 *
00173       IF( INFO.EQ.0 ) THEN
00174          IF( N.LE.1 ) THEN
00175             LWMIN = 1
00176             LIWMIN = 1
00177             LRWMIN = 1
00178          ELSE
00179             IF( WANTZ ) THEN
00180                LWMIN = 2*N
00181                LRWMIN = 1 + 5*N + 2*N**2
00182                LIWMIN = 3 + 5*N
00183             ELSE
00184                LWMIN = N
00185                LRWMIN = N
00186                LIWMIN = 1
00187             END IF
00188          END IF
00189          WORK( 1 ) = LWMIN
00190          RWORK( 1 ) = LRWMIN
00191          IWORK( 1 ) = LIWMIN
00192 *
00193          IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
00194             INFO = -9
00195          ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
00196             INFO = -11
00197          ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
00198             INFO = -13
00199          END IF
00200       END IF
00201 *
00202       IF( INFO.NE.0 ) THEN
00203          CALL XERBLA( 'ZHPEVD', -INFO )
00204          RETURN
00205       ELSE IF( LQUERY ) THEN
00206          RETURN
00207       END IF
00208 *
00209 *     Quick return if possible
00210 *
00211       IF( N.EQ.0 )
00212      $   RETURN
00213 *
00214       IF( N.EQ.1 ) THEN
00215          W( 1 ) = AP( 1 )
00216          IF( WANTZ )
00217      $      Z( 1, 1 ) = CONE
00218          RETURN
00219       END IF
00220 *
00221 *     Get machine constants.
00222 *
00223       SAFMIN = DLAMCH( 'Safe minimum' )
00224       EPS = DLAMCH( 'Precision' )
00225       SMLNUM = SAFMIN / EPS
00226       BIGNUM = ONE / SMLNUM
00227       RMIN = SQRT( SMLNUM )
00228       RMAX = SQRT( BIGNUM )
00229 *
00230 *     Scale matrix to allowable range, if necessary.
00231 *
00232       ANRM = ZLANHP( 'M', UPLO, N, AP, RWORK )
00233       ISCALE = 0
00234       IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
00235          ISCALE = 1
00236          SIGMA = RMIN / ANRM
00237       ELSE IF( ANRM.GT.RMAX ) THEN
00238          ISCALE = 1
00239          SIGMA = RMAX / ANRM
00240       END IF
00241       IF( ISCALE.EQ.1 ) THEN
00242          CALL ZDSCAL( ( N*( N+1 ) ) / 2, SIGMA, AP, 1 )
00243       END IF
00244 *
00245 *     Call ZHPTRD to reduce Hermitian packed matrix to tridiagonal form.
00246 *
00247       INDE = 1
00248       INDTAU = 1
00249       INDRWK = INDE + N
00250       INDWRK = INDTAU + N
00251       LLWRK = LWORK - INDWRK + 1
00252       LLRWK = LRWORK - INDRWK + 1
00253       CALL ZHPTRD( UPLO, N, AP, W, RWORK( INDE ), WORK( INDTAU ),
00254      $             IINFO )
00255 *
00256 *     For eigenvalues only, call DSTERF.  For eigenvectors, first call
00257 *     ZUPGTR to generate the orthogonal matrix, then call ZSTEDC.
00258 *
00259       IF( .NOT.WANTZ ) THEN
00260          CALL DSTERF( N, W, RWORK( INDE ), INFO )
00261       ELSE
00262          CALL ZSTEDC( 'I', N, W, RWORK( INDE ), Z, LDZ, WORK( INDWRK ),
00263      $                LLWRK, RWORK( INDRWK ), LLRWK, IWORK, LIWORK,
00264      $                INFO )
00265          CALL ZUPMTR( 'L', UPLO, 'N', N, N, AP, WORK( INDTAU ), Z, LDZ,
00266      $                WORK( INDWRK ), IINFO )
00267       END IF
00268 *
00269 *     If matrix was scaled, then rescale eigenvalues appropriately.
00270 *
00271       IF( ISCALE.EQ.1 ) THEN
00272          IF( INFO.EQ.0 ) THEN
00273             IMAX = N
00274          ELSE
00275             IMAX = INFO - 1
00276          END IF
00277          CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
00278       END IF
00279 *
00280       WORK( 1 ) = LWMIN
00281       RWORK( 1 ) = LRWMIN
00282       IWORK( 1 ) = LIWMIN
00283       RETURN
00284 *
00285 *     End of ZHPEVD
00286 *
00287       END
 All Files Functions