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