3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGEQP3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqp3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqp3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqp3.f">
21 * SUBROUTINE CGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, RWORK,
24 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, LWORK, M, N
27 * .. Array Arguments ..
30 * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
39 *> CGEQP3 computes a QR factorization with column pivoting of a
40 *> matrix A: A*P = Q*R using Level 3 BLAS.
49 *> The number of rows of the matrix A. M >= 0.
55 *> The number of columns of the matrix A. N >= 0.
60 *> A is COMPLEX array, dimension (LDA,N)
61 *> On entry, the M-by-N matrix A.
62 *> On exit, the upper triangle of the array contains the
63 *> min(M,N)-by-N upper trapezoidal matrix R; the elements below
64 *> the diagonal, together with the array TAU, represent the
65 *> unitary matrix Q as a product of min(M,N) elementary
72 *> The leading dimension of the array A. LDA >= max(1,M).
75 *> \param[in,out] JPVT
77 *> JPVT is INTEGER array, dimension (N)
78 *> On entry, if JPVT(J).ne.0, the J-th column of A is permuted
79 *> to the front of A*P (a leading column); if JPVT(J)=0,
80 *> the J-th column of A is a free column.
81 *> On exit, if JPVT(J)=K, then the J-th column of A*P was the
82 *> the K-th column of A.
87 *> TAU is COMPLEX array, dimension (min(M,N))
88 *> The scalar factors of the elementary reflectors.
93 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
94 *> On exit, if INFO=0, WORK(1) returns the optimal LWORK.
100 *> The dimension of the array WORK. LWORK >= N+1.
101 *> For optimal performance LWORK >= ( N+1 )*NB, where NB
102 *> is the optimal blocksize.
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.
112 *> RWORK is REAL array, dimension (2*N)
118 *> = 0: successful exit.
119 *> < 0: if INFO = -i, the i-th argument had an illegal value.
125 *> \author Univ. of Tennessee
126 *> \author Univ. of California Berkeley
127 *> \author Univ. of Colorado Denver
130 *> \date November 2015
132 *> \ingroup complexGEcomputational
134 *> \par Further Details:
135 * =====================
139 *> The matrix Q is represented as a product of elementary reflectors
141 *> Q = H(1) H(2) . . . H(k), where k = min(m,n).
143 *> Each H(i) has the form
145 *> H(i) = I - tau * v * v**H
147 *> where tau is a complex scalar, and v is a real/complex vector
148 *> with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in
149 *> A(i+1:m,i), and tau in TAU(i).
152 *> \par Contributors:
155 *> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
156 *> X. Sun, Computer Science Dept., Duke University, USA
158 * =====================================================================
159 SUBROUTINE CGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, RWORK,
162 * -- LAPACK computational routine (version 3.6.0) --
163 * -- LAPACK is a software package provided by Univ. of Tennessee, --
164 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
167 * .. Scalar Arguments ..
168 INTEGER INFO, LDA, LWORK, M, N
170 * .. Array Arguments ..
173 COMPLEX A( LDA, * ), TAU( * ), WORK( * )
176 * =====================================================================
179 INTEGER INB, INBMIN, IXOVER
180 PARAMETER ( INB = 1, INBMIN = 2, IXOVER = 3 )
182 * .. Local Scalars ..
184 INTEGER FJB, IWS, J, JB, LWKOPT, MINMN, MINWS, NA, NB,
185 $ NBMIN, NFXD, NX, SM, SMINMN, SN, TOPBMN
187 * .. External Subroutines ..
188 EXTERNAL CGEQRF, CLAQP2, CLAQPS, CSWAP, CUNMQR, XERBLA
190 * .. External Functions ..
193 EXTERNAL ILAENV, SCNRM2
195 * .. Intrinsic Functions ..
196 INTRINSIC INT, MAX, MIN
198 * .. Executable Statements ..
200 * Test input arguments
201 * ====================
204 LQUERY = ( LWORK.EQ.-1 )
207 ELSE IF( N.LT.0 ) THEN
209 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
215 IF( MINMN.EQ.0 ) THEN
220 NB = ILAENV( INB, 'CGEQRF', ' ', M, N, -1, -1 )
221 LWKOPT = ( N + 1 )*NB
223 WORK( 1 ) = CMPLX( LWKOPT )
225 IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
231 CALL XERBLA( 'CGEQP3', -INFO )
233 ELSE IF( LQUERY ) THEN
237 * Move initial columns up front.
241 IF( JPVT( J ).NE.0 ) THEN
243 CALL CSWAP( M, A( 1, J ), 1, A( 1, NFXD ), 1 )
244 JPVT( J ) = JPVT( NFXD )
256 * Factorize fixed columns
257 * =======================
259 * Compute the QR factorization of fixed columns and update
264 *CC CALL CGEQR2( M, NA, A, LDA, TAU, WORK, INFO )
265 CALL CGEQRF( M, NA, A, LDA, TAU, WORK, LWORK, INFO )
266 IWS = MAX( IWS, INT( WORK( 1 ) ) )
268 *CC CALL CUNM2R( 'Left', 'Conjugate Transpose', M, N-NA,
269 *CC $ NA, A, LDA, TAU, A( 1, NA+1 ), LDA, WORK,
271 CALL CUNMQR( 'Left', 'Conjugate Transpose', M, N-NA, NA, A,
272 $ LDA, TAU, A( 1, NA+1 ), LDA, WORK, LWORK,
274 IWS = MAX( IWS, INT( WORK( 1 ) ) )
278 * Factorize free columns
279 * ======================
281 IF( NFXD.LT.MINMN ) THEN
285 SMINMN = MINMN - NFXD
287 * Determine the block size.
289 NB = ILAENV( INB, 'CGEQRF', ' ', SM, SN, -1, -1 )
293 IF( ( NB.GT.1 ) .AND. ( NB.LT.SMINMN ) ) THEN
295 * Determine when to cross over from blocked to unblocked code.
297 NX = MAX( 0, ILAENV( IXOVER, 'CGEQRF', ' ', SM, SN, -1,
301 IF( NX.LT.SMINMN ) THEN
303 * Determine if workspace is large enough for blocked code.
306 IWS = MAX( IWS, MINWS )
307 IF( LWORK.LT.MINWS ) THEN
309 * Not enough workspace to use optimal NB: Reduce NB and
310 * determine the minimum value of NB.
312 NB = LWORK / ( SN+1 )
313 NBMIN = MAX( 2, ILAENV( INBMIN, 'CGEQRF', ' ', SM, SN,
321 * Initialize partial column norms. The first N elements of work
322 * store the exact column norms.
324 DO 20 J = NFXD + 1, N
325 RWORK( J ) = SCNRM2( SM, A( NFXD+1, J ), 1 )
326 RWORK( N+J ) = RWORK( J )
329 IF( ( NB.GE.NBMIN ) .AND. ( NB.LT.SMINMN ) .AND.
330 $ ( NX.LT.SMINMN ) ) THEN
332 * Use blocked code initially.
336 * Compute factorization: while loop.
341 IF( J.LE.TOPBMN ) THEN
342 JB = MIN( NB, TOPBMN-J+1 )
344 * Factorize JB columns among columns J:N.
346 CALL CLAQPS( M, N-J+1, J-1, JB, FJB, A( 1, J ), LDA,
347 $ JPVT( J ), TAU( J ), RWORK( J ),
348 $ RWORK( N+J ), WORK( 1 ), WORK( JB+1 ),
358 * Use unblocked code to factor the last or only block.
362 $ CALL CLAQP2( M, N-J+1, J-1, A( 1, J ), LDA, JPVT( J ),
363 $ TAU( J ), RWORK( J ), RWORK( N+J ), WORK( 1 ) )
367 WORK( 1 ) = CMPLX( LWKOPT )