LAPACK  3.6.0
LAPACK: Linear Algebra PACKage
sgehrd.f
Go to the documentation of this file.
1 *> \brief \b SGEHRD
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download SGEHRD + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgehrd.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgehrd.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgehrd.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE SGEHRD( 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 * REAL A( LDA, * ), TAU( * ), WORK( * )
28 * ..
29 *
30 *
31 *> \par Purpose:
32 * =============
33 *>
34 *> \verbatim
35 *>
36 *> SGEHRD reduces a real general matrix A to upper Hessenberg form H by
37 *> an orthogonal similarity transformation: Q**T * 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 SGEBAL; 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 REAL 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 orthogonal 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 REAL 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 REAL 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 good performance, LWORK should generally be larger.
101 *>
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.
106 *> \endverbatim
107 *>
108 *> \param[out] INFO
109 *> \verbatim
110 *> INFO is INTEGER
111 *> = 0: successful exit
112 *> < 0: if INFO = -i, the i-th argument had an illegal value.
113 *> \endverbatim
114 *
115 * Authors:
116 * ========
117 *
118 *> \author Univ. of Tennessee
119 *> \author Univ. of California Berkeley
120 *> \author Univ. of Colorado Denver
121 *> \author NAG Ltd.
122 *
123 *> \date November 2015
124 *
125 *> \ingroup realGEcomputational
126 *
127 *> \par Further Details:
128 * =====================
129 *>
130 *> \verbatim
131 *>
132 *> The matrix Q is represented as a product of (ihi-ilo) elementary
133 *> reflectors
134 *>
135 *> Q = H(ilo) H(ilo+1) . . . H(ihi-1).
136 *>
137 *> Each H(i) has the form
138 *>
139 *> H(i) = I - tau * v * v**T
140 *>
141 *> where tau is a real scalar, and v is a real 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).
144 *>
145 *> The contents of A are illustrated by the following example, with
146 *> n = 7, ilo = 2 and ihi = 6:
147 *>
148 *> on entry, on exit,
149 *>
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 )
156 *> ( a ) ( a )
157 *>
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).
161 *>
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.)
165 *> \endverbatim
166 *>
167 * =====================================================================
168  SUBROUTINE sgehrd( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
169 *
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..--
173 * November 2015
174 *
175 * .. Scalar Arguments ..
176  INTEGER IHI, ILO, INFO, LDA, LWORK, N
177 * ..
178 * .. Array Arguments ..
179  REAL A( lda, * ), TAU( * ), WORK( * )
180 * ..
181 *
182 * =====================================================================
183 *
184 * .. Parameters ..
185  INTEGER NBMAX, LDT, TSIZE
186  parameter( nbmax = 64, ldt = nbmax+1,
187  $ tsize = ldt*nbmax )
188  REAL ZERO, ONE
189  parameter( zero = 0.0e+0,
190  $ one = 1.0e+0 )
191 * ..
192 * .. Local Scalars ..
193  LOGICAL LQUERY
194  INTEGER I, IB, IINFO, IWT, J, LDWORK, LWKOPT, NB,
195  $ nbmin, nh, nx
196  REAL EI
197 * ..
198 * .. External Subroutines ..
199  EXTERNAL saxpy, sgehd2, sgemm, slahr2, slarfb, strmm,
200  $ xerbla
201 * ..
202 * .. Intrinsic Functions ..
203  INTRINSIC max, min
204 * ..
205 * .. External Functions ..
206  INTEGER ILAENV
207  EXTERNAL ilaenv
208 * ..
209 * .. Executable Statements ..
210 *
211 * Test the input parameters
212 *
213  info = 0
214  lquery = ( lwork.EQ.-1 )
215  IF( n.LT.0 ) THEN
216  info = -1
217  ELSE IF( ilo.LT.1 .OR. ilo.GT.max( 1, n ) ) THEN
218  info = -2
219  ELSE IF( ihi.LT.min( ilo, n ) .OR. ihi.GT.n ) THEN
220  info = -3
221  ELSE IF( lda.LT.max( 1, n ) ) THEN
222  info = -5
223  ELSE IF( lwork.LT.max( 1, n ) .AND. .NOT.lquery ) THEN
224  info = -8
225  END IF
226 *
227  IF( info.EQ.0 ) THEN
228 *
229 * Compute the workspace requirements
230 *
231  nb = min( nbmax, ilaenv( 1, 'SGEHRD', ' ', n, ilo, ihi, -1 ) )
232  lwkopt = n*nb + tsize
233  work( 1 ) = lwkopt
234  END IF
235 *
236  IF( info.NE.0 ) THEN
237  CALL xerbla( 'SGEHRD', -info )
238  RETURN
239  ELSE IF( lquery ) THEN
240  RETURN
241  END IF
242 *
243 * Set elements 1:ILO-1 and IHI:N-1 of TAU to zero
244 *
245  DO 10 i = 1, ilo - 1
246  tau( i ) = zero
247  10 CONTINUE
248  DO 20 i = max( 1, ihi ), n - 1
249  tau( i ) = zero
250  20 CONTINUE
251 *
252 * Quick return if possible
253 *
254  nh = ihi - ilo + 1
255  IF( nh.LE.1 ) THEN
256  work( 1 ) = 1
257  RETURN
258  END IF
259 *
260 * Determine the block size
261 *
262  nb = min( nbmax, ilaenv( 1, 'SGEHRD', ' ', n, ilo, ihi, -1 ) )
263  nbmin = 2
264  IF( nb.GT.1 .AND. nb.LT.nh ) THEN
265 *
266 * Determine when to cross over from blocked to unblocked code
267 * (last block is always handled by unblocked code)
268 *
269  nx = max( nb, ilaenv( 3, 'SGEHRD', ' ', n, ilo, ihi, -1 ) )
270  IF( nx.LT.nh ) THEN
271 *
272 * Determine if workspace is large enough for blocked code
273 *
274  IF( lwork.LT.n*nb+tsize ) 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, 'SGEHRD', ' ', n, ilo, ihi,
281  $ -1 ) )
282  IF( lwork.GE.(n*nbmin + tsize) ) THEN
283  nb = (lwork-tsize) / 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  iwt = 1 + n*nb
303  DO 40 i = ilo, ihi - 1 - nx, nb
304  ib = min( nb, ihi-i )
305 *
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**T
308 * which performs the reduction, and also the matrix Y = A*V*T
309 *
310  CALL slahr2( ihi, i, ib, a( 1, i ), lda, tau( i ),
311  $ work( iwt ), ldt, work, ldwork )
312 *
313 * Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
314 * right, computing A := A - Y * V**T. V(i+ib,ib-1) must be set
315 * to 1
316 *
317  ei = a( i+ib, i+ib-1 )
318  a( i+ib, i+ib-1 ) = one
319  CALL sgemm( 'No transpose', 'Transpose',
320  $ ihi, ihi-i-ib+1,
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
324 *
325 * Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
326 * right
327 *
328  CALL strmm( 'Right', 'Lower', 'Transpose',
329  $ 'Unit', i, ib-1,
330  $ one, a( i+1, i ), lda, work, ldwork )
331  DO 30 j = 0, ib-2
332  CALL saxpy( i, -one, work( ldwork*j+1 ), 1,
333  $ a( 1, i+j+1 ), 1 )
334  30 CONTINUE
335 *
336 * Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
337 * left
338 *
339  CALL slarfb( 'Left', 'Transpose', 'Forward',
340  $ 'Columnwise',
341  $ ihi-i, n-i-ib+1, ib, a( i+1, i ), lda,
342  $ work( iwt ), ldt, a( i+1, i+ib ), lda,
343  $ work, ldwork )
344  40 CONTINUE
345  END IF
346 *
347 * Use unblocked code to reduce the rest of the matrix
348 *
349  CALL sgehd2( n, i, ihi, a, lda, tau, work, iinfo )
350  work( 1 ) = lwkopt
351 *
352  RETURN
353 *
354 * End of SGEHRD
355 *
356  END
subroutine slahr2(N, K, NB, A, LDA, TAU, T, LDT, Y, LDY)
SLAHR2 reduces the specified number of first columns of a general rectangular matrix A so that elemen...
Definition: slahr2.f:183
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine strmm(SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA, B, LDB)
STRMM
Definition: strmm.f:179
subroutine sgehrd(N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO)
SGEHRD
Definition: sgehrd.f:169
subroutine saxpy(N, SA, SX, INCX, SY, INCY)
SAXPY
Definition: saxpy.f:54
subroutine sgehd2(N, ILO, IHI, A, LDA, TAU, WORK, INFO)
SGEHD2 reduces a general square matrix to upper Hessenberg form using an unblocked algorithm...
Definition: sgehd2.f:151
subroutine sgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
SGEMM
Definition: sgemm.f:189
subroutine slarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV, T, LDT, C, LDC, WORK, LDWORK)
SLARFB applies a block reflector or its transpose to a general rectangular matrix.
Definition: slarfb.f:197