LAPACK  3.10.1 LAPACK: Linear Algebra PACKage
cgeqrf.f
Go to the documentation of this file.
1 *> \brief \b CGEQRF
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqrf.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqrf.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqrf.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CGEQRF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * INTEGER INFO, LDA, LWORK, M, N
25 * ..
26 * .. Array Arguments ..
27 * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
28 * ..
29 *
30 *
31 *> \par Purpose:
32 * =============
33 *>
34 *> \verbatim
35 *>
36 *> CGEQRF computes a QR factorization of a complex M-by-N matrix A:
37 *>
38 *> A = Q * ( R ),
39 *> ( 0 )
40 *>
41 *> where:
42 *>
43 *> Q is a M-by-M orthogonal matrix;
44 *> R is an upper-triangular N-by-N matrix;
45 *> 0 is a (M-N)-by-N zero matrix, if M > N.
46 *>
47 *> \endverbatim
48 *
49 * Arguments:
50 * ==========
51 *
52 *> \param[in] M
53 *> \verbatim
54 *> M is INTEGER
55 *> The number of rows of the matrix A. M >= 0.
56 *> \endverbatim
57 *>
58 *> \param[in] N
59 *> \verbatim
60 *> N is INTEGER
61 *> The number of columns of the matrix A. N >= 0.
62 *> \endverbatim
63 *>
64 *> \param[in,out] A
65 *> \verbatim
66 *> A is COMPLEX array, dimension (LDA,N)
67 *> On entry, the M-by-N matrix A.
68 *> On exit, the elements on and above the diagonal of the array
69 *> contain the min(M,N)-by-N upper trapezoidal matrix R (R is
70 *> upper triangular if m >= n); the elements below the diagonal,
71 *> with the array TAU, represent the unitary matrix Q as a
72 *> product of min(m,n) elementary reflectors (see Further
73 *> 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,M).
80 *> \endverbatim
81 *>
82 *> \param[out] TAU
83 *> \verbatim
84 *> TAU is COMPLEX array, dimension (min(M,N))
85 *> The scalar factors of the elementary reflectors (see Further
86 *> Details).
87 *> \endverbatim
88 *>
89 *> \param[out] WORK
90 *> \verbatim
91 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
92 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
93 *> \endverbatim
94 *>
95 *> \param[in] LWORK
96 *> \verbatim
97 *> LWORK is INTEGER
98 *> The dimension of the array WORK.
99 *> LWORK >= 1, if MIN(M,N) = 0, and LWORK >= N, otherwise.
100 *> For optimum performance LWORK >= N*NB, where NB is
101 *> the 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 *> \ingroup complexGEcomputational
125 *
126 *> \par Further Details:
127 * =====================
128 *>
129 *> \verbatim
130 *>
131 *> The matrix Q is represented as a product of elementary reflectors
132 *>
133 *> Q = H(1) H(2) . . . H(k), where k = min(m,n).
134 *>
135 *> Each H(i) has the form
136 *>
137 *> H(i) = I - tau * v * v**H
138 *>
139 *> where tau is a complex scalar, and v is a complex vector with
140 *> v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
141 *> and tau in TAU(i).
142 *> \endverbatim
143 *>
144 * =====================================================================
145  SUBROUTINE cgeqrf( M, N, A, LDA, TAU, WORK, LWORK, INFO )
146 *
147 * -- LAPACK computational routine --
148 * -- LAPACK is a software package provided by Univ. of Tennessee, --
149 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
150 *
151 * .. Scalar Arguments ..
152  INTEGER INFO, LDA, LWORK, M, N
153 * ..
154 * .. Array Arguments ..
155  COMPLEX A( LDA, * ), TAU( * ), WORK( * )
156 * ..
157 *
158 * =====================================================================
159 *
160 * .. Local Scalars ..
161  LOGICAL LQUERY
162  INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB,
163  \$ NBMIN, NX
164 * ..
165 * .. External Subroutines ..
166  EXTERNAL cgeqr2, clarfb, clarft, xerbla
167 * ..
168 * .. Intrinsic Functions ..
169  INTRINSIC max, min
170 * ..
171 * .. External Functions ..
172  INTEGER ILAENV
173  EXTERNAL ilaenv
174 * ..
175 * .. Executable Statements ..
176 *
177 * Test the input arguments
178 *
179  k = min( m, n )
180  info = 0
181  nb = ilaenv( 1, 'CGEQRF', ' ', m, n, -1, -1 )
182  lquery = ( lwork.EQ.-1 )
183  IF( m.LT.0 ) THEN
184  info = -1
185  ELSE IF( n.LT.0 ) THEN
186  info = -2
187  ELSE IF( lda.LT.max( 1, m ) ) THEN
188  info = -4
189  ELSE IF( .NOT.lquery ) THEN
190  IF( lwork.LE.0 .OR. ( m.GT.0 .AND. lwork.LT.max( 1, n ) ) )
191  \$ info = -7
192  END IF
193  IF( info.NE.0 ) THEN
194  CALL xerbla( 'CGEQRF', -info )
195  RETURN
196  ELSE IF( lquery ) THEN
197  IF( k.EQ.0 ) THEN
198  lwkopt = 1
199  ELSE
200  lwkopt = n*nb
201  END IF
202  work( 1 ) = lwkopt
203  RETURN
204  END IF
205 *
206 * Quick return if possible
207 *
208  IF( k.EQ.0 ) THEN
209  work( 1 ) = 1
210  RETURN
211  END IF
212 *
213  nbmin = 2
214  nx = 0
215  iws = n
216  IF( nb.GT.1 .AND. nb.LT.k ) THEN
217 *
218 * Determine when to cross over from blocked to unblocked code.
219 *
220  nx = max( 0, ilaenv( 3, 'CGEQRF', ' ', m, n, -1, -1 ) )
221  IF( nx.LT.k ) THEN
222 *
223 * Determine if workspace is large enough for blocked code.
224 *
225  ldwork = n
226  iws = ldwork*nb
227  IF( lwork.LT.iws ) THEN
228 *
229 * Not enough workspace to use optimal NB: reduce NB and
230 * determine the minimum value of NB.
231 *
232  nb = lwork / ldwork
233  nbmin = max( 2, ilaenv( 2, 'CGEQRF', ' ', m, n, -1,
234  \$ -1 ) )
235  END IF
236  END IF
237  END IF
238 *
239  IF( nb.GE.nbmin .AND. nb.LT.k .AND. nx.LT.k ) THEN
240 *
241 * Use blocked code initially
242 *
243  DO 10 i = 1, k - nx, nb
244  ib = min( k-i+1, nb )
245 *
246 * Compute the QR factorization of the current block
247 * A(i:m,i:i+ib-1)
248 *
249  CALL cgeqr2( m-i+1, ib, a( i, i ), lda, tau( i ), work,
250  \$ iinfo )
251  IF( i+ib.LE.n ) THEN
252 *
253 * Form the triangular factor of the block reflector
254 * H = H(i) H(i+1) . . . H(i+ib-1)
255 *
256  CALL clarft( 'Forward', 'Columnwise', m-i+1, ib,
257  \$ a( i, i ), lda, tau( i ), work, ldwork )
258 *
259 * Apply H**H to A(i:m,i+ib:n) from the left
260 *
261  CALL clarfb( 'Left', 'Conjugate transpose', 'Forward',
262  \$ 'Columnwise', m-i+1, n-i-ib+1, ib,
263  \$ a( i, i ), lda, work, ldwork, a( i, i+ib ),
264  \$ lda, work( ib+1 ), ldwork )
265  END IF
266  10 CONTINUE
267  ELSE
268  i = 1
269  END IF
270 *
271 * Use unblocked code to factor the last or only block.
272 *
273  IF( i.LE.k )
274  \$ CALL cgeqr2( m-i+1, n-i+1, a( i, i ), lda, tau( i ), work,
275  \$ iinfo )
276 *
277  work( 1 ) = iws
278  RETURN
279 *
280 * End of CGEQRF
281 *
282  END
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:60
subroutine cgeqr2(M, N, A, LDA, TAU, WORK, INFO)
CGEQR2 computes the QR factorization of a general rectangular matrix using an unblocked algorithm.
Definition: cgeqr2.f:130
subroutine cgeqrf(M, N, A, LDA, TAU, WORK, LWORK, INFO)
CGEQRF
Definition: cgeqrf.f:146
subroutine clarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV, T, LDT, C, LDC, WORK, LDWORK)
CLARFB applies a block reflector or its conjugate-transpose to a general rectangular matrix.
Definition: clarfb.f:197
subroutine clarft(DIRECT, STOREV, N, K, V, LDV, TAU, T, LDT)
CLARFT forms the triangular factor T of a block reflector H = I - vtvH
Definition: clarft.f:163