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