LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgehrd.f
Go to the documentation of this file.
1*> \brief \b CGEHRD
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGEHRD + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgehrd.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgehrd.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgehrd.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
20*
21* .. Scalar Arguments ..
22* INTEGER IHI, ILO, INFO, LDA, LWORK, N
23* ..
24* .. Array Arguments ..
25* COMPLEX A( LDA, * ), TAU( * ), WORK( * )
26* ..
27*
28*
29*> \par Purpose:
30* =============
31*>
32*> \verbatim
33*>
34*> CGEHRD reduces a complex general matrix A to upper Hessenberg form H by
35*> an unitary similarity transformation: Q**H * A * Q = H .
36*> \endverbatim
37*
38* Arguments:
39* ==========
40*
41*> \param[in] N
42*> \verbatim
43*> N is INTEGER
44*> The order of the matrix A. N >= 0.
45*> \endverbatim
46*>
47*> \param[in] ILO
48*> \verbatim
49*> ILO is INTEGER
50*> \endverbatim
51*>
52*> \param[in] IHI
53*> \verbatim
54*> IHI is INTEGER
55*>
56*> It is assumed that A is already upper triangular in rows
57*> and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
58*> set by a previous call to CGEBAL; otherwise they should be
59*> set to 1 and N respectively. See Further Details.
60*> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
61*> \endverbatim
62*>
63*> \param[in,out] A
64*> \verbatim
65*> A is COMPLEX array, dimension (LDA,N)
66*> On entry, the N-by-N general matrix to be reduced.
67*> On exit, the upper triangle and the first subdiagonal of A
68*> are overwritten with the upper Hessenberg matrix H, and the
69*> elements below the first subdiagonal, with the array TAU,
70*> represent the unitary matrix Q as a product of elementary
71*> reflectors. See Further Details.
72*> \endverbatim
73*>
74*> \param[in] LDA
75*> \verbatim
76*> LDA is INTEGER
77*> The leading dimension of the array A. LDA >= max(1,N).
78*> \endverbatim
79*>
80*> \param[out] TAU
81*> \verbatim
82*> TAU is COMPLEX array, dimension (N-1)
83*> The scalar factors of the elementary reflectors (see Further
84*> Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
85*> zero.
86*> \endverbatim
87*>
88*> \param[out] WORK
89*> \verbatim
90*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
91*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
92*> \endverbatim
93*>
94*> \param[in] LWORK
95*> \verbatim
96*> LWORK is INTEGER
97*> The length of the array WORK. LWORK >= max(1,N).
98*> For good performance, LWORK should generally be larger.
99*>
100*> If LWORK = -1, then a workspace query is assumed; the routine
101*> only calculates the optimal size of the WORK array, returns
102*> this value as the first entry of the WORK array, and no error
103*> message related to LWORK is issued by XERBLA.
104*> \endverbatim
105*>
106*> \param[out] INFO
107*> \verbatim
108*> INFO is INTEGER
109*> = 0: successful exit
110*> < 0: if INFO = -i, the i-th argument had an illegal value.
111*> \endverbatim
112*
113* Authors:
114* ========
115*
116*> \author Univ. of Tennessee
117*> \author Univ. of California Berkeley
118*> \author Univ. of Colorado Denver
119*> \author NAG Ltd.
120*
121*> \ingroup gehrd
122*
123*> \par Further Details:
124* =====================
125*>
126*> \verbatim
127*>
128*> The matrix Q is represented as a product of (ihi-ilo) elementary
129*> reflectors
130*>
131*> Q = H(ilo) H(ilo+1) . . . H(ihi-1).
132*>
133*> Each H(i) has the form
134*>
135*> H(i) = I - tau * v * v**H
136*>
137*> where tau is a complex scalar, and v is a complex vector with
138*> v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
139*> exit in A(i+2:ihi,i), and tau in TAU(i).
140*>
141*> The contents of A are illustrated by the following example, with
142*> n = 7, ilo = 2 and ihi = 6:
143*>
144*> on entry, on exit,
145*>
146*> ( a a a a a a a ) ( a a h h h h a )
147*> ( a a a a a a ) ( a h h h h a )
148*> ( a a a a a a ) ( h h h h h h )
149*> ( a a a a a a ) ( v2 h h h h h )
150*> ( a a a a a a ) ( v2 v3 h h h h )
151*> ( a a a a a a ) ( v2 v3 v4 h h h )
152*> ( a ) ( a )
153*>
154*> where a denotes an element of the original matrix A, h denotes a
155*> modified element of the upper Hessenberg matrix H, and vi denotes an
156*> element of the vector defining H(i).
157*>
158*> This file is a slight modification of LAPACK-3.0's CGEHRD
159*> subroutine incorporating improvements proposed by Quintana-Orti and
160*> Van de Geijn (2006). (See CLAHR2.)
161*> \endverbatim
162*>
163* =====================================================================
164 SUBROUTINE cgehrd( N, ILO, IHI, A, LDA, TAU, WORK, LWORK,
165 $ INFO )
166*
167* -- LAPACK computational routine --
168* -- LAPACK is a software package provided by Univ. of Tennessee, --
169* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
170*
171* .. Scalar Arguments ..
172 INTEGER IHI, ILO, INFO, LDA, LWORK, N
173* ..
174* .. Array Arguments ..
175 COMPLEX A( LDA, * ), TAU( * ), WORK( * )
176* ..
177*
178* =====================================================================
179*
180* .. Parameters ..
181 INTEGER NBMAX, LDT, TSIZE
182 parameter( nbmax = 64, ldt = nbmax+1,
183 $ tsize = ldt*nbmax )
184 COMPLEX ZERO, ONE
185 parameter( zero = ( 0.0e+0, 0.0e+0 ),
186 $ one = ( 1.0e+0, 0.0e+0 ) )
187* ..
188* .. Local Scalars ..
189 LOGICAL LQUERY
190 INTEGER I, IB, IINFO, IWT, J, LDWORK, LWKOPT, NB,
191 $ nbmin, nh, nx
192 COMPLEX EI
193* ..
194* .. External Subroutines ..
195 EXTERNAL caxpy, cgehd2, cgemm, clahr2, clarfb,
196 $ ctrmm,
197 $ xerbla
198* ..
199* .. Intrinsic Functions ..
200 INTRINSIC max, min
201* ..
202* .. External Functions ..
203 INTEGER ILAENV
204 REAL SROUNDUP_LWORK
205 EXTERNAL ilaenv, sroundup_lwork
206* ..
207* .. Executable Statements ..
208*
209* Test the input parameters
210*
211 info = 0
212 lquery = ( lwork.EQ.-1 )
213 IF( n.LT.0 ) THEN
214 info = -1
215 ELSE IF( ilo.LT.1 .OR. ilo.GT.max( 1, n ) ) THEN
216 info = -2
217 ELSE IF( ihi.LT.min( ilo, n ) .OR. ihi.GT.n ) THEN
218 info = -3
219 ELSE IF( lda.LT.max( 1, n ) ) THEN
220 info = -5
221 ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery ) THEN
222 info = -8
223 END IF
224*
225 nh = ihi - ilo + 1
226 IF( info.EQ.0 ) THEN
227*
228* Compute the workspace requirements
229*
230 IF( nh.LE.1 ) THEN
231 lwkopt = 1
232 ELSE
233 nb = min( nbmax, ilaenv( 1, 'CGEHRD', ' ', n, ilo, ihi,
234 $ -1 ) )
235 lwkopt = n*nb + tsize
236 END IF
237 work( 1 ) = sroundup_lwork( lwkopt )
238 END IF
239*
240 IF( info.NE.0 ) THEN
241 CALL xerbla( 'CGEHRD', -info )
242 RETURN
243 ELSE IF( lquery ) THEN
244 RETURN
245 END IF
246*
247* Set elements 1:ILO-1 and IHI:N-1 of TAU to zero
248*
249 DO 10 i = 1, ilo - 1
250 tau( i ) = zero
251 10 CONTINUE
252 DO 20 i = max( 1, ihi ), n - 1
253 tau( i ) = zero
254 20 CONTINUE
255*
256* Quick return if possible
257*
258 IF( nh.LE.1 ) THEN
259 work( 1 ) = 1
260 RETURN
261 END IF
262*
263* Determine the block size
264*
265 nb = min( nbmax, ilaenv( 1, 'CGEHRD', ' ', n, ilo, ihi, -1 ) )
266 nbmin = 2
267 IF( nb.GT.1 .AND. nb.LT.nh ) THEN
268*
269* Determine when to cross over from blocked to unblocked code
270* (last block is always handled by unblocked code)
271*
272 nx = max( nb, ilaenv( 3, 'CGEHRD', ' ', n, ilo, ihi, -1 ) )
273 IF( nx.LT.nh ) THEN
274*
275* Determine if workspace is large enough for blocked code
276*
277 IF( lwork.LT.lwkopt ) THEN
278*
279* Not enough workspace to use optimal NB: determine the
280* minimum value of NB, and reduce NB or force use of
281* unblocked code
282*
283 nbmin = max( 2, ilaenv( 2, 'CGEHRD', ' ', n, ilo, ihi,
284 $ -1 ) )
285 IF( lwork.GE.(n*nbmin+tsize) ) THEN
286 nb = (lwork-tsize) / n
287 ELSE
288 nb = 1
289 END IF
290 END IF
291 END IF
292 END IF
293 ldwork = n
294*
295 IF( nb.LT.nbmin .OR. nb.GE.nh ) THEN
296*
297* Use unblocked code below
298*
299 i = ilo
300*
301 ELSE
302*
303* Use blocked code
304*
305 iwt = 1 + n*nb
306 DO 40 i = ilo, ihi - 1 - nx, nb
307 ib = min( nb, ihi-i )
308*
309* Reduce columns i:i+ib-1 to Hessenberg form, returning the
310* matrices V and T of the block reflector H = I - V*T*V**H
311* which performs the reduction, and also the matrix Y = A*V*T
312*
313 CALL clahr2( ihi, i, ib, a( 1, i ), lda, tau( i ),
314 $ work( iwt ), ldt, work, ldwork )
315*
316* Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
317* right, computing A := A - Y * V**H. V(i+ib,ib-1) must be set
318* to 1
319*
320 ei = a( i+ib, i+ib-1 )
321 a( i+ib, i+ib-1 ) = one
322 CALL cgemm( 'No transpose', 'Conjugate transpose',
323 $ ihi, ihi-i-ib+1,
324 $ ib, -one, work, ldwork, a( i+ib, i ), lda, one,
325 $ a( 1, i+ib ), lda )
326 a( i+ib, i+ib-1 ) = ei
327*
328* Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
329* right
330*
331 CALL ctrmm( 'Right', 'Lower', 'Conjugate transpose',
332 $ 'Unit', i, ib-1,
333 $ one, a( i+1, i ), lda, work, ldwork )
334 DO 30 j = 0, ib-2
335 CALL caxpy( i, -one, work( ldwork*j+1 ), 1,
336 $ a( 1, i+j+1 ), 1 )
337 30 CONTINUE
338*
339* Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
340* left
341*
342 CALL clarfb( 'Left', 'Conjugate transpose', 'Forward',
343 $ 'Columnwise',
344 $ ihi-i, n-i-ib+1, ib, a( i+1, i ), lda,
345 $ work( iwt ), ldt, a( i+1, i+ib ), lda,
346 $ work, ldwork )
347 40 CONTINUE
348 END IF
349*
350* Use unblocked code to reduce the rest of the matrix
351*
352 CALL cgehd2( n, i, ihi, a, lda, tau, work, iinfo )
353*
354 work( 1 ) = sroundup_lwork( lwkopt )
355*
356 RETURN
357*
358* End of CGEHRD
359*
360 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine caxpy(n, ca, cx, incx, cy, incy)
CAXPY
Definition caxpy.f:88
subroutine cgehd2(n, ilo, ihi, a, lda, tau, work, info)
CGEHD2 reduces a general square matrix to upper Hessenberg form using an unblocked algorithm.
Definition cgehd2.f:147
subroutine cgehrd(n, ilo, ihi, a, lda, tau, work, lwork, info)
CGEHRD
Definition cgehrd.f:166
subroutine cgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
CGEMM
Definition cgemm.f:188
subroutine clahr2(n, k, nb, a, lda, tau, t, ldt, y, ldy)
CLAHR2 reduces the specified number of first columns of a general rectangular matrix A so that elemen...
Definition clahr2.f:179
subroutine clarfb(side, trans, direct, storev, m, n, k, v, ldv, t, ldt, c, ldc, work, ldwork)
CLARFB applies a block reflector or its conjugate-transpose to a general rectangular matrix.
Definition clarfb.f:195
subroutine ctrmm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
CTRMM
Definition ctrmm.f:177