1
SUBROUTINE ZTZRZF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
3
* -- LAPACK routine (version 3.0) --
4
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5
* Courant Institute, Argonne National Lab, and Rice University
8
* .. Scalar Arguments ..
9
INTEGER INFO, LDA, LWORK, M, N
11
* .. Array Arguments ..
12
COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * )
18
* ZTZRZF reduces the M-by-N ( M<=N ) complex upper trapezoidal matrix A
19
* to upper triangular form by means of unitary transformations.
21
* The upper trapezoidal matrix A is factored as
25
* where Z is an N-by-N unitary matrix and R is an M-by-M upper
32
* The number of rows of the matrix A. M >= 0.
35
* The number of columns of the matrix A. N >= 0.
37
* A (input/output) COMPLEX*16 array, dimension (LDA,N)
38
* On entry, the leading M-by-N upper trapezoidal part of the
39
* array A must contain the matrix to be factorized.
40
* On exit, the leading M-by-M upper triangular part of A
41
* contains the upper triangular matrix R, and elements M+1 to
42
* N of the first M rows of A, with the array TAU, represent the
43
* unitary matrix Z as a product of M elementary reflectors.
46
* The leading dimension of the array A. LDA >= max(1,M).
48
* TAU (output) COMPLEX*16 array, dimension (M)
49
* The scalar factors of the elementary reflectors.
51
* WORK (workspace/output) COMPLEX*16 array, dimension (LWORK)
52
* On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
54
* LWORK (input) INTEGER
55
* The dimension of the array WORK. LWORK >= max(1,M).
56
* For optimum performance LWORK >= M*NB, where NB is
57
* the optimal blocksize.
59
* If LWORK = -1, then a workspace query is assumed; the routine
60
* only calculates the optimal size of the WORK array, returns
61
* this value as the first entry of the WORK array, and no error
62
* message related to LWORK is issued by XERBLA.
64
* INFO (output) INTEGER
65
* = 0: successful exit
66
* < 0: if INFO = -i, the i-th argument had an illegal value
71
* Based on contributions by
72
* A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
74
* The factorization is obtained by Householder's method. The kth
75
* transformation matrix, Z( k ), which is used to introduce zeros into
76
* the ( m - k + 1 )th row of A, is given in the form
83
* T( k ) = I - tau*u( k )*u( k )', u( k ) = ( 1 ),
87
* tau is a scalar and z( k ) is an ( n - m ) element vector.
88
* tau and z( k ) are chosen to annihilate the elements of the kth row
91
* The scalar tau is returned in the kth element of TAU and the vector
92
* u( k ) in the kth row of A, such that the elements of z( k ) are
93
* in a( k, m + 1 ), ..., a( k, n ). The elements of R are returned in
94
* the upper triangular part of A.
98
* Z = Z( 1 ) * Z( 2 ) * ... * Z( m ).
100
* =====================================================================
104
PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )
106
* .. Local Scalars ..
108
INTEGER I, IB, IWS, KI, KK, LDWORK, LWKOPT, M1, MU, NB,
111
* .. External Subroutines ..
112
EXTERNAL XERBLA, ZLARZB, ZLARZT, ZLATRZ
114
* .. Intrinsic Functions ..
117
* .. External Functions ..
121
* .. Executable Statements ..
123
* Test the input arguments
126
LQUERY = ( LWORK.EQ.-1 )
129
ELSE IF( N.LT.M ) THEN
131
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
133
ELSE IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN
139
* Determine the block size.
141
NB = ILAENV( 1, 'ZGERQF', ' ', M, N, -1, -1 )
147
CALL XERBLA( 'ZTZRZF', -INFO )
149
ELSE IF( LQUERY ) THEN
153
* Quick return if possible
158
ELSE IF( M.EQ.N ) THEN
169
IF( NB.GT.1 .AND. NB.LT.M ) THEN
171
* Determine when to cross over from blocked to unblocked code.
173
NX = MAX( 0, ILAENV( 3, 'ZGERQF', ' ', M, N, -1, -1 ) )
176
* Determine if workspace is large enough for blocked code.
180
IF( LWORK.LT.IWS ) THEN
182
* Not enough workspace to use optimal NB: reduce NB and
183
* determine the minimum value of NB.
186
NBMIN = MAX( 2, ILAENV( 2, 'ZGERQF', ' ', M, N, -1,
192
IF( NB.GE.NBMIN .AND. NB.LT.M .AND. NX.LT.M ) THEN
194
* Use blocked code initially.
195
* The last kk rows are handled by the block method.
198
KI = ( ( M-NX-1 ) / NB )*NB
201
DO 20 I = M - KK + KI + 1, M - KK + 1, -NB
202
IB = MIN( M-I+1, NB )
204
* Compute the TZ factorization of the current block
207
CALL ZLATRZ( IB, N-I+1, N-M, A( I, I ), LDA, TAU( I ),
211
* Form the triangular factor of the block reflector
212
* H = H(i+ib-1) . . . H(i+1) H(i)
214
CALL ZLARZT( 'Backward', 'Rowwise', N-M, IB, A( I, M1 ),
215
$ LDA, TAU( I ), WORK, LDWORK )
217
* Apply H to A(1:i-1,i:n) from the right
219
CALL ZLARZB( 'Right', 'No transpose', 'Backward',
220
$ 'Rowwise', I-1, N-I+1, IB, N-M, A( I, M1 ),
221
$ LDA, WORK, LDWORK, A( 1, I ), LDA,
222
$ WORK( IB+1 ), LDWORK )
230
* Use unblocked code to factor the last or only block
233
$ CALL ZLATRZ( MU, N, N-M, A, LDA, TAU, WORK )