LAPACK 3.3.1
Linear Algebra PACKage
|
00001 SUBROUTINE DGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO ) 00002 * 00003 * -- LAPACK routine (version 3.3.1) -- 00004 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00005 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00006 * -- April 2009 -- 00007 * 00008 * .. Scalar Arguments .. 00009 INTEGER IHI, ILO, INFO, LDA, LWORK, N 00010 * .. 00011 * .. Array Arguments .. 00012 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) 00013 * .. 00014 * 00015 * Purpose 00016 * ======= 00017 * 00018 * DGEHRD reduces a real general matrix A to upper Hessenberg form H by 00019 * an orthogonal similarity transformation: Q**T * A * Q = H . 00020 * 00021 * Arguments 00022 * ========= 00023 * 00024 * N (input) INTEGER 00025 * The order of the matrix A. N >= 0. 00026 * 00027 * ILO (input) INTEGER 00028 * IHI (input) INTEGER 00029 * It is assumed that A is already upper triangular in rows 00030 * and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally 00031 * set by a previous call to DGEBAL; otherwise they should be 00032 * set to 1 and N respectively. See Further Details. 00033 * 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. 00034 * 00035 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N) 00036 * On entry, the N-by-N general matrix to be reduced. 00037 * On exit, the upper triangle and the first subdiagonal of A 00038 * are overwritten with the upper Hessenberg matrix H, and the 00039 * elements below the first subdiagonal, with the array TAU, 00040 * represent the orthogonal matrix Q as a product of elementary 00041 * reflectors. See Further Details. 00042 * 00043 * LDA (input) INTEGER 00044 * The leading dimension of the array A. LDA >= max(1,N). 00045 * 00046 * TAU (output) DOUBLE PRECISION array, dimension (N-1) 00047 * The scalar factors of the elementary reflectors (see Further 00048 * Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to 00049 * zero. 00050 * 00051 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) 00052 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. 00053 * 00054 * LWORK (input) INTEGER 00055 * The length of the array WORK. LWORK >= max(1,N). 00056 * For optimum performance LWORK >= N*NB, where NB is the 00057 * optimal blocksize. 00058 * 00059 * If LWORK = -1, then a workspace query is assumed; the routine 00060 * only calculates the optimal size of the WORK array, returns 00061 * this value as the first entry of the WORK array, and no error 00062 * message related to LWORK is issued by XERBLA. 00063 * 00064 * INFO (output) INTEGER 00065 * = 0: successful exit 00066 * < 0: if INFO = -i, the i-th argument had an illegal value. 00067 * 00068 * Further Details 00069 * =============== 00070 * 00071 * The matrix Q is represented as a product of (ihi-ilo) elementary 00072 * reflectors 00073 * 00074 * Q = H(ilo) H(ilo+1) . . . H(ihi-1). 00075 * 00076 * Each H(i) has the form 00077 * 00078 * H(i) = I - tau * v * v**T 00079 * 00080 * where tau is a real scalar, and v is a real vector with 00081 * v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on 00082 * exit in A(i+2:ihi,i), and tau in TAU(i). 00083 * 00084 * The contents of A are illustrated by the following example, with 00085 * n = 7, ilo = 2 and ihi = 6: 00086 * 00087 * on entry, on exit, 00088 * 00089 * ( a a a a a a a ) ( a a h h h h a ) 00090 * ( a a a a a a ) ( a h h h h a ) 00091 * ( a a a a a a ) ( h h h h h h ) 00092 * ( a a a a a a ) ( v2 h h h h h ) 00093 * ( a a a a a a ) ( v2 v3 h h h h ) 00094 * ( a a a a a a ) ( v2 v3 v4 h h h ) 00095 * ( a ) ( a ) 00096 * 00097 * where a denotes an element of the original matrix A, h denotes a 00098 * modified element of the upper Hessenberg matrix H, and vi denotes an 00099 * element of the vector defining H(i). 00100 * 00101 * This file is a slight modification of LAPACK-3.0's DGEHRD 00102 * subroutine incorporating improvements proposed by Quintana-Orti and 00103 * Van de Geijn (2006). (See DLAHR2.) 00104 * 00105 * ===================================================================== 00106 * 00107 * .. Parameters .. 00108 INTEGER NBMAX, LDT 00109 PARAMETER ( NBMAX = 64, LDT = NBMAX+1 ) 00110 DOUBLE PRECISION ZERO, ONE 00111 PARAMETER ( ZERO = 0.0D+0, 00112 $ ONE = 1.0D+0 ) 00113 * .. 00114 * .. Local Scalars .. 00115 LOGICAL LQUERY 00116 INTEGER I, IB, IINFO, IWS, J, LDWORK, LWKOPT, NB, 00117 $ NBMIN, NH, NX 00118 DOUBLE PRECISION EI 00119 * .. 00120 * .. Local Arrays .. 00121 DOUBLE PRECISION T( LDT, NBMAX ) 00122 * .. 00123 * .. External Subroutines .. 00124 EXTERNAL DAXPY, DGEHD2, DGEMM, DLAHR2, DLARFB, DTRMM, 00125 $ XERBLA 00126 * .. 00127 * .. Intrinsic Functions .. 00128 INTRINSIC MAX, MIN 00129 * .. 00130 * .. External Functions .. 00131 INTEGER ILAENV 00132 EXTERNAL ILAENV 00133 * .. 00134 * .. Executable Statements .. 00135 * 00136 * Test the input parameters 00137 * 00138 INFO = 0 00139 NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) ) 00140 LWKOPT = N*NB 00141 WORK( 1 ) = LWKOPT 00142 LQUERY = ( LWORK.EQ.-1 ) 00143 IF( N.LT.0 ) THEN 00144 INFO = -1 00145 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN 00146 INFO = -2 00147 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN 00148 INFO = -3 00149 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN 00150 INFO = -5 00151 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN 00152 INFO = -8 00153 END IF 00154 IF( INFO.NE.0 ) THEN 00155 CALL XERBLA( 'DGEHRD', -INFO ) 00156 RETURN 00157 ELSE IF( LQUERY ) THEN 00158 RETURN 00159 END IF 00160 * 00161 * Set elements 1:ILO-1 and IHI:N-1 of TAU to zero 00162 * 00163 DO 10 I = 1, ILO - 1 00164 TAU( I ) = ZERO 00165 10 CONTINUE 00166 DO 20 I = MAX( 1, IHI ), N - 1 00167 TAU( I ) = ZERO 00168 20 CONTINUE 00169 * 00170 * Quick return if possible 00171 * 00172 NH = IHI - ILO + 1 00173 IF( NH.LE.1 ) THEN 00174 WORK( 1 ) = 1 00175 RETURN 00176 END IF 00177 * 00178 * Determine the block size 00179 * 00180 NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) ) 00181 NBMIN = 2 00182 IWS = 1 00183 IF( NB.GT.1 .AND. NB.LT.NH ) THEN 00184 * 00185 * Determine when to cross over from blocked to unblocked code 00186 * (last block is always handled by unblocked code) 00187 * 00188 NX = MAX( NB, ILAENV( 3, 'DGEHRD', ' ', N, ILO, IHI, -1 ) ) 00189 IF( NX.LT.NH ) THEN 00190 * 00191 * Determine if workspace is large enough for blocked code 00192 * 00193 IWS = N*NB 00194 IF( LWORK.LT.IWS ) THEN 00195 * 00196 * Not enough workspace to use optimal NB: determine the 00197 * minimum value of NB, and reduce NB or force use of 00198 * unblocked code 00199 * 00200 NBMIN = MAX( 2, ILAENV( 2, 'DGEHRD', ' ', N, ILO, IHI, 00201 $ -1 ) ) 00202 IF( LWORK.GE.N*NBMIN ) THEN 00203 NB = LWORK / N 00204 ELSE 00205 NB = 1 00206 END IF 00207 END IF 00208 END IF 00209 END IF 00210 LDWORK = N 00211 * 00212 IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN 00213 * 00214 * Use unblocked code below 00215 * 00216 I = ILO 00217 * 00218 ELSE 00219 * 00220 * Use blocked code 00221 * 00222 DO 40 I = ILO, IHI - 1 - NX, NB 00223 IB = MIN( NB, IHI-I ) 00224 * 00225 * Reduce columns i:i+ib-1 to Hessenberg form, returning the 00226 * matrices V and T of the block reflector H = I - V*T*V**T 00227 * which performs the reduction, and also the matrix Y = A*V*T 00228 * 00229 CALL DLAHR2( IHI, I, IB, A( 1, I ), LDA, TAU( I ), T, LDT, 00230 $ WORK, LDWORK ) 00231 * 00232 * Apply the block reflector H to A(1:ihi,i+ib:ihi) from the 00233 * right, computing A := A - Y * V**T. V(i+ib,ib-1) must be set 00234 * to 1 00235 * 00236 EI = A( I+IB, I+IB-1 ) 00237 A( I+IB, I+IB-1 ) = ONE 00238 CALL DGEMM( 'No transpose', 'Transpose', 00239 $ IHI, IHI-I-IB+1, 00240 $ IB, -ONE, WORK, LDWORK, A( I+IB, I ), LDA, ONE, 00241 $ A( 1, I+IB ), LDA ) 00242 A( I+IB, I+IB-1 ) = EI 00243 * 00244 * Apply the block reflector H to A(1:i,i+1:i+ib-1) from the 00245 * right 00246 * 00247 CALL DTRMM( 'Right', 'Lower', 'Transpose', 00248 $ 'Unit', I, IB-1, 00249 $ ONE, A( I+1, I ), LDA, WORK, LDWORK ) 00250 DO 30 J = 0, IB-2 00251 CALL DAXPY( I, -ONE, WORK( LDWORK*J+1 ), 1, 00252 $ A( 1, I+J+1 ), 1 ) 00253 30 CONTINUE 00254 * 00255 * Apply the block reflector H to A(i+1:ihi,i+ib:n) from the 00256 * left 00257 * 00258 CALL DLARFB( 'Left', 'Transpose', 'Forward', 00259 $ 'Columnwise', 00260 $ IHI-I, N-I-IB+1, IB, A( I+1, I ), LDA, T, LDT, 00261 $ A( I+1, I+IB ), LDA, WORK, LDWORK ) 00262 40 CONTINUE 00263 END IF 00264 * 00265 * Use unblocked code to reduce the rest of the matrix 00266 * 00267 CALL DGEHD2( N, I, IHI, A, LDA, TAU, WORK, IINFO ) 00268 WORK( 1 ) = IWS 00269 * 00270 RETURN 00271 * 00272 * End of DGEHRD 00273 * 00274 END