1
SUBROUTINE ZGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, RWORK,
4
* -- LAPACK routine (version 3.0) --
5
* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
6
* Courant Institute, Argonne National Lab, and Rice University
9
* .. Scalar Arguments ..
10
INTEGER INFO, LDA, LWORK, M, N
12
* .. Array Arguments ..
14
DOUBLE PRECISION RWORK( * )
15
COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * )
21
* ZGEQP3 computes a QR factorization with column pivoting of a
22
* matrix A: A*P = Q*R using Level 3 BLAS.
28
* The number of rows of the matrix A. M >= 0.
31
* The number of columns of the matrix A. N >= 0.
33
* A (input/output) COMPLEX*16 array, dimension (LDA,N)
34
* On entry, the M-by-N matrix A.
35
* On exit, the upper triangle of the array contains the
36
* min(M,N)-by-N upper trapezoidal matrix R; the elements below
37
* the diagonal, together with the array TAU, represent the
38
* unitary matrix Q as a product of min(M,N) elementary
42
* The leading dimension of the array A. LDA >= max(1,M).
44
* JPVT (input/output) INTEGER array, dimension (N)
45
* On entry, if JPVT(J).ne.0, the J-th column of A is permuted
46
* to the front of A*P (a leading column); if JPVT(J)=0,
47
* the J-th column of A is a free column.
48
* On exit, if JPVT(J)=K, then the J-th column of A*P was the
49
* the K-th column of A.
51
* TAU (output) COMPLEX*16 array, dimension (min(M,N))
52
* The scalar factors of the elementary reflectors.
54
* WORK (workspace/output) COMPLEX*16 array, dimension (LWORK)
55
* On exit, if INFO=0, WORK(1) returns the optimal LWORK.
57
* LWORK (input) INTEGER
58
* The dimension of the array WORK. LWORK >= N+1.
59
* For optimal performance LWORK >= ( N+1 )*NB, where NB
60
* is the optimal blocksize.
62
* If LWORK = -1, then a workspace query is assumed; the routine
63
* only calculates the optimal size of the WORK array, returns
64
* this value as the first entry of the WORK array, and no error
65
* message related to LWORK is issued by XERBLA.
67
* RWORK (workspace) DOUBLE PRECISION array, dimension (2*N)
69
* INFO (output) INTEGER
70
* = 0: successful exit.
71
* < 0: if INFO = -i, the i-th argument had an illegal value.
76
* The matrix Q is represented as a product of elementary reflectors
78
* Q = H(1) H(2) . . . H(k), where k = min(m,n).
80
* Each H(i) has the form
82
* H(i) = I - tau * v * v'
84
* where tau is a real/complex scalar, and v is a real/complex vector
85
* with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in
86
* A(i+1:m,i), and tau in TAU(i).
88
* Based on contributions by
89
* G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
90
* X. Sun, Computer Science Dept., Duke University, USA
92
* =====================================================================
95
INTEGER INB, INBMIN, IXOVER
96
PARAMETER ( INB = 1, INBMIN = 2, IXOVER = 3 )
100
INTEGER FJB, IWS, J, JB, LWKOPT, MINMN, MINWS, NA, NB,
101
$ NBMIN, NFXD, NX, SM, SMINMN, SN, TOPBMN
103
* .. External Subroutines ..
104
EXTERNAL XERBLA, ZGEQRF, ZLAQP2, ZLAQPS, ZSWAP, ZUNMQR
106
* .. External Functions ..
108
DOUBLE PRECISION DZNRM2
109
EXTERNAL ILAENV, DZNRM2
111
* .. Intrinsic Functions ..
112
INTRINSIC INT, MAX, MIN
114
* .. Executable Statements ..
119
* Test input arguments
120
* ====================
123
NB = ILAENV( INB, 'ZGEQRF', ' ', M, N, -1, -1 )
126
LQUERY = ( LWORK.EQ.-1 )
129
ELSE IF( N.LT.0 ) THEN
131
ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
133
ELSE IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
137
CALL XERBLA( 'ZGEQP3', -INFO )
139
ELSE IF( LQUERY ) THEN
143
* Quick return if possible.
145
IF( MINMN.EQ.0 ) THEN
150
* Move initial columns up front.
154
IF( JPVT( J ).NE.0 ) THEN
156
CALL ZSWAP( M, A( 1, J ), 1, A( 1, NFXD ), 1 )
157
JPVT( J ) = JPVT( NFXD )
169
* Factorize fixed columns
170
* =======================
172
* Compute the QR factorization of fixed columns and update
177
*CC CALL ZGEQR2( M, NA, A, LDA, TAU, WORK, INFO )
178
CALL ZGEQRF( M, NA, A, LDA, TAU, WORK, LWORK, INFO )
179
IWS = MAX( IWS, INT( WORK( 1 ) ) )
181
*CC CALL ZUNM2R( 'Left', 'Conjugate Transpose', M, N-NA,
182
*CC $ NA, A, LDA, TAU, A( 1, NA+1 ), LDA, WORK,
184
CALL ZUNMQR( 'Left', 'Conjugate Transpose', M, N-NA, NA, A,
185
$ LDA, TAU, A( 1, NA+1 ), LDA, WORK, LWORK,
187
IWS = MAX( IWS, INT( WORK( 1 ) ) )
191
* Factorize free columns
192
* ======================
194
IF( NFXD.LT.MINMN ) THEN
198
SMINMN = MINMN - NFXD
200
* Determine the block size.
202
NB = ILAENV( INB, 'ZGEQRF', ' ', SM, SN, -1, -1 )
206
IF( ( NB.GT.1 ) .AND. ( NB.LT.SMINMN ) ) THEN
208
* Determine when to cross over from blocked to unblocked code.
210
NX = MAX( 0, ILAENV( IXOVER, 'ZGEQRF', ' ', SM, SN, -1,
214
IF( NX.LT.SMINMN ) THEN
216
* Determine if workspace is large enough for blocked code.
219
IWS = MAX( IWS, MINWS )
220
IF( LWORK.LT.MINWS ) THEN
222
* Not enough workspace to use optimal NB: Reduce NB and
223
* determine the minimum value of NB.
225
NB = LWORK / ( SN+1 )
226
NBMIN = MAX( 2, ILAENV( INBMIN, 'ZGEQRF', ' ', SM, SN,
234
* Initialize partial column norms. The first N elements of work
235
* store the exact column norms.
237
DO 20 J = NFXD + 1, N
238
RWORK( J ) = DZNRM2( SM, A( NFXD+1, J ), 1 )
239
RWORK( N+J ) = RWORK( J )
242
IF( ( NB.GE.NBMIN ) .AND. ( NB.LT.SMINMN ) .AND.
243
$ ( NX.LT.SMINMN ) ) THEN
245
* Use blocked code initially.
249
* Compute factorization: while loop.
254
IF( J.LE.TOPBMN ) THEN
255
JB = MIN( NB, TOPBMN-J+1 )
257
* Factorize JB columns among columns J:N.
259
CALL ZLAQPS( M, N-J+1, J-1, JB, FJB, A( 1, J ), LDA,
260
$ JPVT( J ), TAU( J ), RWORK( J ),
261
$ RWORK( N+J ), WORK( 1 ), WORK( JB+1 ),
271
* Use unblocked code to factor the last or only block.
275
$ CALL ZLAQP2( M, N-J+1, J-1, A( 1, J ), LDA, JPVT( J ),
276
$ TAU( J ), RWORK( J ), RWORK( N+J ), WORK( 1 ) )