3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGEHRD + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgehrd.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgehrd.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgehrd.f">
21 * SUBROUTINE CGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER IHI, ILO, INFO, LDA, LWORK, N
26 * .. Array Arguments ..
27 * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
36 *> CGEHRD reduces a complex general matrix A to upper Hessenberg form H by
37 *> an unitary similarity transformation: Q**H * A * Q = H .
46 *> The order of the matrix A. N >= 0.
58 *> It is assumed that A is already upper triangular in rows
59 *> and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
60 *> set by a previous call to CGEBAL; otherwise they should be
61 *> set to 1 and N respectively. See Further Details.
62 *> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
67 *> A is COMPLEX array, dimension (LDA,N)
68 *> On entry, the N-by-N general matrix to be reduced.
69 *> On exit, the upper triangle and the first subdiagonal of A
70 *> are overwritten with the upper Hessenberg matrix H, and the
71 *> elements below the first subdiagonal, with the array TAU,
72 *> represent the unitary matrix Q as a product of elementary
73 *> reflectors. See Further Details.
79 *> The leading dimension of the array A. LDA >= max(1,N).
84 *> TAU is COMPLEX array, dimension (N-1)
85 *> The scalar factors of the elementary reflectors (see Further
86 *> Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
92 *> WORK is COMPLEX array, dimension (LWORK)
93 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
99 *> The length of the array WORK. LWORK >= max(1,N).
100 *> For good performance, LWORK should generally be larger.
102 *> If LWORK = -1, then a workspace query is assumed; the routine
103 *> only calculates the optimal size of the WORK array, returns
104 *> this value as the first entry of the WORK array, and no error
105 *> message related to LWORK is issued by XERBLA.
111 *> = 0: successful exit
112 *> < 0: if INFO = -i, the i-th argument had an illegal value.
118 *> \author Univ. of Tennessee
119 *> \author Univ. of California Berkeley
120 *> \author Univ. of Colorado Denver
123 *> \date November 2015
125 *> \ingroup complexGEcomputational
127 *> \par Further Details:
128 * =====================
132 *> The matrix Q is represented as a product of (ihi-ilo) elementary
135 *> Q = H(ilo) H(ilo+1) . . . H(ihi-1).
137 *> Each H(i) has the form
139 *> H(i) = I - tau * v * v**H
141 *> where tau is a complex scalar, and v is a complex vector with
142 *> v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
143 *> exit in A(i+2:ihi,i), and tau in TAU(i).
145 *> The contents of A are illustrated by the following example, with
146 *> n = 7, ilo = 2 and ihi = 6:
148 *> on entry, on exit,
150 *> ( a a a a a a a ) ( a a h h h h a )
151 *> ( a a a a a a ) ( a h h h h a )
152 *> ( a a a a a a ) ( h h h h h h )
153 *> ( a a a a a a ) ( v2 h h h h h )
154 *> ( a a a a a a ) ( v2 v3 h h h h )
155 *> ( a a a a a a ) ( v2 v3 v4 h h h )
158 *> where a denotes an element of the original matrix A, h denotes a
159 *> modified element of the upper Hessenberg matrix H, and vi denotes an
160 *> element of the vector defining H(i).
162 *> This file is a slight modification of LAPACK-3.0's DGEHRD
163 *> subroutine incorporating improvements proposed by Quintana-Orti and
164 *> Van de Geijn (2006). (See DLAHR2.)
167 * =====================================================================
168 SUBROUTINE CGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
170 * -- LAPACK computational routine (version 3.6.0) --
171 * -- LAPACK is a software package provided by Univ. of Tennessee, --
172 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
175 * .. Scalar Arguments ..
176 INTEGER IHI, ILO, INFO, LDA, LWORK, N
178 * .. Array Arguments ..
179 COMPLEX A( LDA, * ), TAU( * ), WORK( * )
182 * =====================================================================
185 INTEGER NBMAX, LDT, TSIZE
186 PARAMETER ( NBMAX = 64, LDT = NBMAX+1,
187 $ TSIZE = LDT*NBMAX )
189 PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ),
190 $ ONE = ( 1.0E+0, 0.0E+0 ) )
192 * .. Local Scalars ..
194 INTEGER I, IB, IINFO, IWT, J, LDWORK, LWKOPT, NB,
198 * .. External Subroutines ..
199 EXTERNAL CAXPY, CGEHD2, CGEMM, CLAHR2, CLARFB, CTRMM,
202 * .. Intrinsic Functions ..
205 * .. External Functions ..
209 * .. Executable Statements ..
211 * Test the input parameters
214 LQUERY = ( LWORK.EQ.-1 )
217 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
219 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
221 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
223 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
229 * Compute the workspace requirements
231 NB = MIN( NBMAX, ILAENV( 1, 'CGEHRD', ' ', N, ILO, IHI, -1 ) )
232 LWKOPT = N*NB + TSIZE
237 CALL XERBLA( 'CGEHRD', -INFO )
239 ELSE IF( LQUERY ) THEN
243 * Set elements 1:ILO-1 and IHI:N-1 of TAU to zero
248 DO 20 I = MAX( 1, IHI ), N - 1
252 * Quick return if possible
260 * Determine the block size
262 NB = MIN( NBMAX, ILAENV( 1, 'CGEHRD', ' ', N, ILO, IHI, -1 ) )
264 IF( NB.GT.1 .AND. NB.LT.NH ) THEN
266 * Determine when to cross over from blocked to unblocked code
267 * (last block is always handled by unblocked code)
269 NX = MAX( NB, ILAENV( 3, 'CGEHRD', ' ', N, ILO, IHI, -1 ) )
272 * Determine if workspace is large enough for blocked code
274 IF( LWORK.LT.N*NB+TSIZE ) THEN
276 * Not enough workspace to use optimal NB: determine the
277 * minimum value of NB, and reduce NB or force use of
280 NBMIN = MAX( 2, ILAENV( 2, 'CGEHRD', ' ', N, ILO, IHI,
282 IF( LWORK.GE.(N*NBMIN+TSIZE) ) THEN
283 NB = (LWORK-TSIZE) / N
292 IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN
294 * Use unblocked code below
303 DO 40 I = ILO, IHI - 1 - NX, NB
304 IB = MIN( NB, IHI-I )
306 * Reduce columns i:i+ib-1 to Hessenberg form, returning the
307 * matrices V and T of the block reflector H = I - V*T*V**H
308 * which performs the reduction, and also the matrix Y = A*V*T
310 CALL CLAHR2( IHI, I, IB, A( 1, I ), LDA, TAU( I ),
311 $ WORK( IWT ), LDT, WORK, LDWORK )
313 * Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
314 * right, computing A := A - Y * V**H. V(i+ib,ib-1) must be set
317 EI = A( I+IB, I+IB-1 )
318 A( I+IB, I+IB-1 ) = ONE
319 CALL CGEMM( 'No transpose', 'Conjugate transpose',
321 $ IB, -ONE, WORK, LDWORK, A( I+IB, I ), LDA, ONE,
322 $ A( 1, I+IB ), LDA )
323 A( I+IB, I+IB-1 ) = EI
325 * Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
328 CALL CTRMM( 'Right', 'Lower', 'Conjugate transpose',
330 $ ONE, A( I+1, I ), LDA, WORK, LDWORK )
332 CALL CAXPY( I, -ONE, WORK( LDWORK*J+1 ), 1,
336 * Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
339 CALL CLARFB( 'Left', 'Conjugate transpose', 'Forward',
341 $ IHI-I, N-I-IB+1, IB, A( I+1, I ), LDA,
342 $ WORK( IWT ), LDT, A( I+1, I+IB ), LDA,
347 * Use unblocked code to reduce the rest of the matrix
349 CALL CGEHD2( N, I, IHI, A, LDA, TAU, WORK, IINFO )