5 * SUBROUTINE ZGEQR( M, N, A, LDA, WORK1, LWORK1, WORK2, LWORK2,
8 * .. Scalar Arguments ..
9 * INTEGER INFO, LDA, M, N, LWORK1, LWORK2
11 * .. Array Arguments ..
12 * COMPLEX*16 A( LDA, * ), WORK1( * ), WORK2( * )
21 *> ZGEQR computes a QR factorization of an M-by-N matrix A,
22 *> using ZLATSQR when A is tall and skinny
23 *> (M sufficiently greater than N), and otherwise ZGEQRT:
33 *> The number of rows of the matrix A. M >= 0.
39 *> The number of columns of the matrix A. N >= 0.
44 *> A is COMPLEX*16 array, dimension (LDA,N)
45 *> On entry, the M-by-N matrix A.
46 *> On exit, the elements on and above the diagonal of the array
47 *> contain the min(M,N)-by-N upper trapezoidal matrix R
48 *> (R is upper triangular if M >= N);
49 *> the elements below the diagonal represent Q (see Further Details).
55 *> The leading dimension of the array A. LDA >= max(1,M).
60 *> WORK1 is COMPLEX*16 array, dimension (MAX(1,LWORK1))
61 *> WORK1 contains part of the data structure used to store Q.
62 *> WORK1(1): algorithm type = 1, to indicate output from
64 *> WORK1(2): optimum size of WORK1
65 *> WORK1(3): minimum size of WORK1
66 *> WORK1(4): row block size
67 *> WORK1(5): column block size
68 *> WORK1(6:LWORK1): data structure needed for Q, computed by
75 *> The dimension of the array WORK1.
76 *> If LWORK1 = -1, then a query is assumed. In this case the
77 *> routine calculates the optimal size of WORK1 and
78 *> returns this value in WORK1(2), and calculates the minimum
79 *> size of WORK1 and returns this value in WORK1(3).
80 *> No error message related to LWORK1 is issued by XERBLA when
86 *> (workspace) COMPLEX*16 array, dimension (MAX(1,LWORK2))
92 *> The dimension of the array WORK2.
93 *> If LWORK2 = -1, then a query is assumed. In this case the
94 *> routine calculates the optimal size of WORK2 and
95 *> returns this value in WORK2(1), and calculates the minimum
96 *> size of WORK2 and returns this value in WORK2(2).
97 *> No error message related to LWORK2 is issued by XERBLA when
104 *> = 0: successful exit
105 *> < 0: if INFO = -i, the i-th argument had an illegal value
111 *> \author Univ. of Tennessee
112 *> \author Univ. of California Berkeley
113 *> \author Univ. of Colorado Denver
116 *> \par Further Details:
117 * =====================
120 *> Depending on the matrix dimensions M and N, and row and column
121 *> block sizes MB and NB returned by ILAENV, GEQR will use either
122 *> LATSQR (if the matrix is tall-and-skinny) or GEQRT to compute
123 *> the QR decomposition.
124 *> The output of LATSQR or GEQRT representing Q is stored in A and in
125 *> array WORK1(6:LWORK1) for later use.
126 *> WORK1(2:5) contains the matrix dimensions M,N and block sizes MB,NB
127 *> which are needed to interpret A and WORK1(6:LWORK1) for later use.
128 *> WORK1(1)=1 indicates that the code needed to take WORK1(2:5) and
129 *> decide whether LATSQR or GEQRT was used is the same as used below in
130 *> GEQR. For a detailed description of A and WORK1(6:LWORK1), see
131 *> Further Details in LATSQR or GEQRT.
134 * =====================================================================
135 SUBROUTINE ZGEQR( M, N, A, LDA, WORK1, LWORK1, WORK2, LWORK2,
138 * -- LAPACK computational routine (version 3.5.0) --
139 * -- LAPACK is a software package provided by Univ. of Tennessee, --
140 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd. --
143 * .. Scalar Arguments ..
144 INTEGER INFO, LDA, M, N, LWORK1, LWORK2
146 * .. Array Arguments ..
147 COMPLEX*16 A( LDA, * ), WORK1( * ), WORK2( * )
150 * =====================================================================
153 * .. Local Scalars ..
154 LOGICAL LQUERY, LMINWS
155 INTEGER MB, NB, I, II, KK, MINLW1, NBLCKS
157 * .. EXTERNAL FUNCTIONS ..
160 * .. EXTERNAL SUBROUTINES ..
161 EXTERNAL ZLATSQR, ZGEQRT, XERBLA
162 * .. INTRINSIC FUNCTIONS ..
163 INTRINSIC MAX, MIN, MOD
165 * .. EXTERNAL FUNCTIONS ..
169 * .. EXECUTABLE STATEMENTS ..
171 * TEST THE INPUT ARGUMENTS
175 LQUERY = ( LWORK1.EQ.-1 .OR. LWORK2.EQ.-1 )
177 * Determine the block size
179 IF ( MIN(M,N).GT.0 ) THEN
180 MB = ILAENV( 1, 'ZGEQR ', ' ', M, N, 1, -1)
181 NB = ILAENV( 1, 'ZGEQR ', ' ', M, N, 2, -1)
186 IF( MB.GT.M.OR.MB.LE.N) MB = M
187 IF( NB.GT.MIN(M,N).OR.NB.LT.1) NB = 1
189 IF ((MB.GT.N).AND.(M.GT.N)) THEN
190 IF(MOD(M-N, MB-N).EQ.0) THEN
191 NBLCKS = (M-N)/(MB-N)
193 NBLCKS = (M-N)/(MB-N) + 1
199 * Determine if the workspace size satisfies minimum size
202 IF((LWORK1.LT.MAX(1, NB*N*NBLCKS+5)
203 $ .OR.(LWORK2.LT.NB*N)).AND.(LWORK2.GE.N).AND.(LWORK1.GT.N+5)
204 $ .AND.(.NOT.LQUERY)) THEN
205 IF (LWORK1.LT.MAX(1, NB * N * NBLCKS+5)) THEN
209 IF (LWORK1.LT.MAX(1, N * NBLCKS+5)) THEN
213 IF (LWORK2.LT.NB*N) THEN
221 ELSE IF( N.LT.0 ) THEN
223 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
225 ELSE IF( LWORK1.LT.MAX( 1, NB * N * NBLCKS + 5 )
226 $ .AND.(.NOT.LQUERY).AND.(.NOT.LMINWS)) THEN
228 ELSE IF( (LWORK2.LT.MAX(1,N*NB)).AND.(.NOT.LQUERY)
229 $ .AND.(.NOT.LMINWS)) THEN
235 WORK1(2) = NB * N * NBLCKS + 5
243 CALL XERBLA( 'ZGEQR', -INFO )
245 ELSE IF (LQUERY) THEN
249 * Quick return if possible
251 IF( MIN(M,N).EQ.0 ) THEN
255 * The QR Decomposition
257 IF((M.LE.N).OR.(MB.LE.N).OR.(MB.GE.M)) THEN
258 CALL ZGEQRT( M, N, NB, A, LDA, WORK1(6), NB, WORK2, INFO)
260 CALL ZLATSQR( M, N, MB, NB, A, LDA, WORK1(6), NB, WORK2,