5 * SUBROUTINE SLAMTSQR( SIDE, TRANS, M, N, K, MB, NB, A, LDA, T,
6 * $ LDT, C, LDC, WORK, LWORK, INFO )
9 * .. Scalar Arguments ..
10 * CHARACTER SIDE, TRANS
11 * INTEGER INFO, LDA, M, N, K, MB, NB, LDT, LWORK, LDC
13 * .. Array Arguments ..
14 * DOUBLE A( LDA, * ), WORK( * ), C(LDC, * ),
21 *> SLAMTSQR overwrites the general real M-by-N matrix C with
24 *> SIDE = 'L' SIDE = 'R'
25 *> TRANS = 'N': Q * C C * Q
26 *> TRANS = 'T': Q**T * C C * Q**T
27 *> where Q is a real orthogonal matrix defined as the product
28 *> of blocked elementary reflectors computed by tall skinny
29 *> QR factorization (DLATSQR)
36 *> SIDE is CHARACTER*1
37 *> = 'L': apply Q or Q**T from the Left;
38 *> = 'R': apply Q or Q**T from the Right.
41 *> TRANS is CHARACTER*1
42 *> = 'N': No transpose, apply Q;
43 *> = 'T': Transpose, apply Q**T.
47 *> The number of rows of the matrix A. M >=0.
53 *> The number of columns of the matrix C. M >= N >= 0.
59 *> The number of elementary reflectors whose product defines
68 *> The block size to be used in the blocked QR.
69 *> MB > N. (must be the same as DLATSQR)
75 *> The column block size to be used in the blocked QR.
81 *> A is REAL array, dimension (LDA,K)
82 *> The i-th column must contain the vector which defines the
83 *> blockedelementary reflector H(i), for i = 1,2,...,k, as
84 *> returned by DLATSQR in the first k columns of
85 *> its array argument A.
91 *> The leading dimension of the array A.
92 *> If SIDE = 'L', LDA >= max(1,M);
93 *> if SIDE = 'R', LDA >= max(1,N).
98 *> T is REAL array, dimension
99 *> ( N * Number of blocks(CEIL(M-K/MB-K)),
100 *> The blocked upper triangular block reflectors stored in compact form
101 *> as a sequence of upper triangular blocks. See below
102 *> for further details.
108 *> The leading dimension of the array T. LDT >= NB.
112 *> C is REAL array, dimension (LDC,N)
113 *> On entry, the M-by-N matrix C.
114 *> On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
117 *> The leading dimension of the array C. LDC >= max(1,M).
121 *> (workspace) REAL array, dimension (MAX(1,LWORK))
127 *> The dimension of the array WORK.
129 *> If SIDE = 'L', LWORK >= max(1,N)*NB;
130 *> if SIDE = 'R', LWORK >= max(1,MB)*NB.
131 *> If LWORK = -1, then a workspace query is assumed; the routine
132 *> only calculates the optimal size of the WORK array, returns
133 *> this value as the first entry of the WORK array, and no error
134 *> message related to LWORK is issued by XERBLA.
140 *> = 0: successful exit
141 *> < 0: if INFO = -i, the i-th argument had an illegal value
147 *> \author Univ. of Tennessee
148 *> \author Univ. of California Berkeley
149 *> \author Univ. of Colorado Denver
152 *> \par Further Details:
153 * =====================
156 *> Tall-Skinny QR (TSQR) performs QR by a sequence of orthogonal transformations,
157 *> representing Q as a product of other orthogonal matrices
158 *> Q = Q(1) * Q(2) * . . . * Q(k)
159 *> where each Q(i) zeros out subdiagonal entries of a block of MB rows of A:
160 *> Q(1) zeros out the subdiagonal entries of rows 1:MB of A
161 *> Q(2) zeros out the bottom MB-N rows of rows [1:N,MB+1:2*MB-N] of A
162 *> Q(3) zeros out the bottom MB-N rows of rows [1:N,2*MB-N+1:3*MB-2*N] of A
165 *> Q(1) is computed by GEQRT, which represents Q(1) by Householder vectors
166 *> stored under the diagonal of rows 1:MB of A, and by upper triangular
167 *> block reflectors, stored in array T(1:LDT,1:N).
168 *> For more information see Further Details in GEQRT.
170 *> Q(i) for i>1 is computed by TPQRT, which represents Q(i) by Householder vectors
171 *> stored in rows [(i-1)*(MB-N)+N+1:i*(MB-N)+N] of A, and by upper triangular
172 *> block reflectors, stored in array T(1:LDT,(i-1)*N+1:i*N).
173 *> The last Q(k) may use fewer rows.
174 *> For more information see Further Details in TPQRT.
176 *> For more details of the overall algorithm, see the description of
177 *> Sequential TSQR in Section 2.2 of [1].
179 *> [1] “Communication-Optimal Parallel and Sequential QR and LU Factorizations,”
180 *> J. Demmel, L. Grigori, M. Hoemmen, J. Langou,
181 *> SIAM J. Sci. Comput, vol. 34, no. 1, 2012
184 * =====================================================================
185 SUBROUTINE SLAMTSQR( SIDE, TRANS, M, N, K, MB, NB, A, LDA, T,
186 $ LDT, C, LDC, WORK, LWORK, INFO )
188 * -- LAPACK computational routine (version 3.5.0) --
189 * -- LAPACK is a software package provided by Univ. of Tennessee, --
190 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
193 * .. Scalar Arguments ..
194 CHARACTER SIDE, TRANS
195 INTEGER INFO, LDA, M, N, K, MB, NB, LDT, LWORK, LDC
197 * .. Array Arguments ..
198 REAL A( LDA, * ), WORK( * ), C(LDC, * ),
202 * =====================================================================
205 * .. Local Scalars ..
206 LOGICAL LEFT, RIGHT, TRAN, NOTRAN, LQUERY
207 INTEGER I, II, KK, LW, CTR
209 * .. External Functions ..
212 * .. External Subroutines ..
213 EXTERNAL SGEMQRT, STPMQRT, XERBLA
215 * .. Executable Statements ..
217 * Test the input arguments
220 NOTRAN = LSAME( TRANS, 'N' )
221 TRAN = LSAME( TRANS, 'T' )
222 LEFT = LSAME( SIDE, 'L' )
223 RIGHT = LSAME( SIDE, 'R' )
231 IF( .NOT.LEFT .AND. .NOT.RIGHT ) THEN
233 ELSE IF( .NOT.TRAN .AND. .NOT.NOTRAN ) THEN
235 ELSE IF( M.LT.0 ) THEN
237 ELSE IF( N.LT.0 ) THEN
239 ELSE IF( K.LT.0 ) THEN
241 ELSE IF( LDA.LT.MAX( 1, K ) ) THEN
243 ELSE IF( LDT.LT.MAX( 1, NB) ) THEN
245 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
247 ELSE IF(( LWORK.LT.MAX(1,LW)).AND.(.NOT.LQUERY)) THEN
252 * Determine the block size if it is tall skinny or short and wide
259 CALL XERBLA( 'SLAMTSQR', -INFO )
261 ELSE IF (LQUERY) THEN
265 * Quick return if possible
267 IF( MIN(M,N,K).EQ.0 ) THEN
271 IF((MB.LE.K).OR.(MB.GE.MAX(M,N,K))) THEN
272 CALL SGEMQRT( SIDE, TRANS, M, N, K, NB, A, LDA,
273 $ T, LDT, C, LDC, WORK, INFO)
277 IF(LEFT.AND.NOTRAN) THEN
279 * Multiply Q to the last block of C
281 KK = MOD((M-K),(MB-K))
285 CALL STPMQRT('L','N',KK , N, K, 0, NB, A(II,1), LDA,
286 $ T(1,CTR*K+1),LDT , C(1,1), LDC,
287 $ C(II,1), LDC, WORK, INFO )
292 DO I=II-(MB-K),MB+1,-(MB-K)
294 * Multiply Q to the current block of C (I:I+MB,1:N)
297 CALL STPMQRT('L','N',MB-K , N, K, 0,NB, A(I,1), LDA,
298 $ T(1, CTR * K + 1), LDT, C(1,1), LDC,
299 $ C(I,1), LDC, WORK, INFO )
303 * Multiply Q to the first block of C (1:MB,1:N)
305 CALL SGEMQRT('L','N',MB , N, K, NB, A(1,1), LDA, T
306 $ ,LDT ,C(1,1), LDC, WORK, INFO )
308 ELSE IF (LEFT.AND.TRAN) THEN
310 * Multiply Q to the first block of C
312 KK = MOD((M-K),(MB-K))
315 CALL SGEMQRT('L','T',MB , N, K, NB, A(1,1), LDA, T
316 $ ,LDT ,C(1,1), LDC, WORK, INFO )
318 DO I=MB+1,II-MB+K,(MB-K)
320 * Multiply Q to the current block of C (I:I+MB,1:N)
322 CALL STPMQRT('L','T',MB-K , N, K, 0,NB, A(I,1), LDA,
323 $ T(1,CTR * K + 1),LDT, C(1,1), LDC,
324 $ C(I,1), LDC, WORK, INFO )
330 * Multiply Q to the last block of C
332 CALL STPMQRT('L','T',KK , N, K, 0,NB, A(II,1), LDA,
333 $ T(1, CTR * K + 1), LDT, C(1,1), LDC,
334 $ C(II,1), LDC, WORK, INFO )
338 ELSE IF(RIGHT.AND.TRAN) THEN
340 * Multiply Q to the last block of C
342 KK = MOD((N-K),(MB-K))
346 CALL STPMQRT('R','T',M , KK, K, 0, NB, A(II,1), LDA,
347 $ T(1, CTR * K + 1), LDT, C(1,1), LDC,
348 $ C(1,II), LDC, WORK, INFO )
353 DO I=II-(MB-K),MB+1,-(MB-K)
355 * Multiply Q to the current block of C (1:M,I:I+MB)
358 CALL STPMQRT('R','T',M , MB-K, K, 0,NB, A(I,1), LDA,
359 $ T(1, CTR * K + 1), LDT, C(1,1), LDC,
360 $ C(1,I), LDC, WORK, INFO )
363 * Multiply Q to the first block of C (1:M,1:MB)
365 CALL SGEMQRT('R','T',M , MB, K, NB, A(1,1), LDA, T
366 $ ,LDT ,C(1,1), LDC, WORK, INFO )
368 ELSE IF (RIGHT.AND.NOTRAN) THEN
370 * Multiply Q to the first block of C
372 KK = MOD((N-K),(MB-K))
375 CALL SGEMQRT('R','N', M, MB , K, NB, A(1,1), LDA, T
376 $ ,LDT ,C(1,1), LDC, WORK, INFO )
378 DO I=MB+1,II-MB+K,(MB-K)
380 * Multiply Q to the current block of C (1:M,I:I+MB)
382 CALL STPMQRT('R','N', M, MB-K, K, 0,NB, A(I,1), LDA,
383 $ T(1, CTR * K + 1),LDT, C(1,1), LDC,
384 $ C(1,I), LDC, WORK, INFO )
390 * Multiply Q to the last block of C
392 CALL STPMQRT('R','N', M, KK , K, 0,NB, A(II,1), LDA,
393 $ T(1, CTR * K + 1),LDT, C(1,1), LDC,
394 $ C(1,II), LDC, WORK, INFO )