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