Lots of trailing whitespaces in the files of Syd. Cleaning this. No big deal.
[platform/upstream/lapack.git] / SRC / slamswlq.f
1 *
2 *  Definition:
3 *  ===========
4 *
5 *      SUBROUTINE SLAMSWLQ( SIDE, TRANS, M, N, K, MB, NB, A, LDA, T,
6 *     $                LDT, C, LDC, WORK, LWORK, INFO )
7 *
8 *
9 *     .. Scalar Arguments ..
10 *      CHARACTER         SIDE, TRANS
11 *      INTEGER           INFO, LDA, M, N, K, MB, NB, LDT, LWORK, LDC
12 *     ..
13 *     .. Array Arguments ..
14 *      DOUBLE        A( LDA, * ), WORK( * ), C(LDC, * ),
15 *     $                  T( LDT, * )
16 *> \par Purpose:
17 *  =============
18 *>
19 *> \verbatim
20 *>
21 *>    DLAMQRTS overwrites the general real M-by-N matrix C with
22 *>
23 *>
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 of blocked
28 *>    elementary reflectors computed by short wide LQ
29 *>    factorization (DLASWLQ)
30 *> \endverbatim
31 *
32 *  Arguments:
33 *  ==========
34 *
35 *> \param[in] SIDE
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.
39 *>
40 *> \param[in] TRANS
41 *>          TRANS is CHARACTER*1
42 *>          = 'N':  No transpose, apply Q;
43 *>          = 'T':  Transpose, apply Q**T.
44 *> \param[in] M
45 *> \verbatim
46 *>          M is INTEGER
47 *>          The number of rows of the matrix A.  M >=0.
48 *> \endverbatim
49 *>
50 *> \param[in] N
51 *> \verbatim
52 *>          N is INTEGER
53 *>          The number of columns of the matrix C. N >= M.
54 *> \endverbatim
55 *>
56 *> \param[in] K
57 *> \verbatim
58 *>          K is INTEGER
59 *>          The number of elementary reflectors whose product defines
60 *>          the matrix Q.
61 *>          M >= K >= 0;
62 *>
63 *> \endverbatim
64 *> \param[in] MB
65 *> \verbatim
66 *>          MB is INTEGER
67 *>          The row block size to be used in the blocked QR.
68 *>          M >= MB >= 1
69 *> \endverbatim
70 *>
71 *> \param[in] NB
72 *> \verbatim
73 *>          NB is INTEGER
74 *>          The column block size to be used in the blocked QR.
75 *>          NB > M.
76 *> \endverbatim
77 *>
78 *> \param[in] NB
79 *> \verbatim
80 *>          NB is INTEGER
81 *>          The block size to be used in the blocked QR.
82 *>                MB > M.
83 *>
84 *> \endverbatim
85 *>
86 *> \param[in,out] A
87 *> \verbatim
88 *>          A is REAL array, dimension (LDA,K)
89 *>          The i-th row must contain the vector which defines the blocked
90 *>          elementary reflector H(i), for i = 1,2,...,k, as returned by
91 *>          DLASWLQ in the first k rows of its array argument A.
92 *> \endverbatim
93 *>
94 *> \param[in] LDA
95 *> \verbatim
96 *>          LDA is INTEGER
97 *>          The leading dimension of the array A.
98 *>          If SIDE = 'L', LDA >= max(1,M);
99 *>          if SIDE = 'R', LDA >= max(1,N).
100 *> \endverbatim
101 *>
102 *> \param[in] T
103 *> \verbatim
104 *>          T is REAL array, dimension
105 *>          ( M * Number of blocks(CEIL(N-K/NB-K)),
106 *>          The blocked upper triangular block reflectors stored in compact form
107 *>          as a sequence of upper triangular blocks.  See below
108 *>          for further details.
109 *> \endverbatim
110 *>
111 *> \param[in] LDT
112 *> \verbatim
113 *>          LDT is INTEGER
114 *>          The leading dimension of the array T.  LDT >= MB.
115 *> \endverbatim
116 *>
117 *> \param[in,out] C
118 *>          C is REAL array, dimension (LDC,N)
119 *>          On entry, the M-by-N matrix C.
120 *>          On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
121 *> \param[in] LDC
122 *>          LDC is INTEGER
123 *>          The leading dimension of the array C. LDC >= max(1,M).
124 *>
125 *> \param[out] WORK
126 *> \verbatim
127 *>         (workspace) REAL array, dimension (MAX(1,LWORK))
128 *>
129 *> \endverbatim
130 *> \param[in] LWORK
131 *> \verbatim
132 *>          LWORK is INTEGER
133 *>          The dimension of the array WORK.
134 *>          If SIDE = 'L', LWORK >= max(1,NB) * MB;
135 *>          if SIDE = 'R', LWORK >= max(1,M) * MB.
136 *>          If LWORK = -1, then a workspace query is assumed; the routine
137 *>          only calculates the optimal size of the WORK array, returns
138 *>          this value as the first entry of the WORK array, and no error
139 *>          message related to LWORK is issued by XERBLA.
140 *>
141 *> \endverbatim
142 *> \param[out] INFO
143 *> \verbatim
144 *>          INFO is INTEGER
145 *>          = 0:  successful exit
146 *>          < 0:  if INFO = -i, the i-th argument had an illegal value
147 *> \endverbatim
148 *
149 *  Authors:
150 *  ========
151 *
152 *> \author Univ. of Tennessee
153 *> \author Univ. of California Berkeley
154 *> \author Univ. of Colorado Denver
155 *> \author NAG Ltd.
156 *
157 *> \par Further Details:
158 *  =====================
159 *>
160 *> \verbatim
161 *> Short-Wide LQ (SWLQ) performs LQ by a sequence of orthogonal transformations,
162 *> representing Q as a product of other orthogonal matrices
163 *>   Q = Q(1) * Q(2) * . . . * Q(k)
164 *> where each Q(i) zeros out upper diagonal entries of a block of NB rows of A:
165 *>   Q(1) zeros out the upper diagonal entries of rows 1:NB of A
166 *>   Q(2) zeros out the bottom MB-N rows of rows [1:M,NB+1:2*NB-M] of A
167 *>   Q(3) zeros out the bottom MB-N rows of rows [1:M,2*NB-M+1:3*NB-2*M] of A
168 *>   . . .
169 *>
170 *> Q(1) is computed by GELQT, which represents Q(1) by Householder vectors
171 *> stored under the diagonal of rows 1:MB of A, and by upper triangular
172 *> block reflectors, stored in array T(1:LDT,1:N).
173 *> For more information see Further Details in GELQT.
174 *>
175 *> Q(i) for i>1 is computed by TPLQT, which represents Q(i) by Householder vectors
176 *> stored in columns [(i-1)*(NB-M)+M+1:i*(NB-M)+M] of A, and by upper triangular
177 *> block reflectors, stored in array T(1:LDT,(i-1)*M+1:i*M).
178 *> The last Q(k) may use fewer rows.
179 *> For more information see Further Details in TPQRT.
180 *>
181 *> For more details of the overall algorithm, see the description of
182 *> Sequential TSQR in Section 2.2 of [1].
183 *>
184 *> [1] “Communication-Optimal Parallel and Sequential QR and LU Factorizations,”
185 *>     J. Demmel, L. Grigori, M. Hoemmen, J. Langou,
186 *>     SIAM J. Sci. Comput, vol. 34, no. 1, 2012
187 *> \endverbatim
188 *>
189 *  =====================================================================
190       SUBROUTINE SLAMSWLQ( SIDE, TRANS, M, N, K, MB, NB, A, LDA, T,
191      $    LDT, C, LDC, WORK, LWORK, INFO )
192 *
193 *  -- LAPACK computational routine (version 3.5.0) --
194 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
195 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
196 *     November 2013
197 *
198 *     .. Scalar Arguments ..
199       CHARACTER         SIDE, TRANS
200       INTEGER           INFO, LDA, M, N, K, MB, NB, LDT, LWORK, LDC
201 *     ..
202 *     .. Array Arguments ..
203       REAL              A( LDA, * ), WORK( * ), C(LDC, * ),
204      $      T( LDT, * )
205 *     ..
206 *
207 * =====================================================================
208 *
209 *     ..
210 *     .. Local Scalars ..
211       LOGICAL    LEFT, RIGHT, TRAN, NOTRAN, LQUERY
212       INTEGER    I, II, KK, LW, CTR
213 *     ..
214 *     .. External Functions ..
215       LOGICAL            LSAME
216       EXTERNAL           LSAME
217 *     .. External Subroutines ..
218       EXTERNAL           STPMLQT, SGEMLQT, XERBLA
219 *     ..
220 *     .. Executable Statements ..
221 *
222 *     Test the input arguments
223 *
224       LQUERY  = LWORK.LT.0
225       NOTRAN  = LSAME( TRANS, 'N' )
226       TRAN    = LSAME( TRANS, 'T' )
227       LEFT    = LSAME( SIDE, 'L' )
228       RIGHT   = LSAME( SIDE, 'R' )
229       IF (LEFT) THEN
230         LW = N * MB
231       ELSE
232         LW = M * MB
233       END IF
234 *
235       INFO = 0
236       IF( .NOT.LEFT .AND. .NOT.RIGHT ) THEN
237          INFO = -1
238       ELSE IF( .NOT.TRAN .AND. .NOT.NOTRAN ) THEN
239          INFO = -2
240       ELSE IF( M.LT.0 ) THEN
241         INFO = -3
242       ELSE IF( N.LT.0 ) THEN
243         INFO = -4
244       ELSE IF( K.LT.0 ) THEN
245         INFO = -5
246       ELSE IF( LDA.LT.MAX( 1, K ) ) THEN
247         INFO = -9
248       ELSE IF( LDT.LT.MAX( 1, MB) ) THEN
249         INFO = -11
250       ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
251          INFO = -13
252       ELSE IF(( LWORK.LT.MAX(1,LW)).AND.(.NOT.LQUERY)) THEN
253         INFO = -15
254       END IF
255 *
256       IF( INFO.NE.0 ) THEN
257         CALL XERBLA( 'SLAMSWLQ', -INFO )
258         WORK(1) = LW
259         RETURN
260       ELSE IF (LQUERY) THEN
261         WORK(1) = LW
262         RETURN
263       END IF
264 *
265 *     Quick return if possible
266 *
267       IF( MIN(M,N,K).EQ.0 ) THEN
268         RETURN
269       END IF
270 *
271       IF((NB.LE.K).OR.(NB.GE.MAX(M,N,K))) THEN
272         CALL DGEMLQT( SIDE, TRANS, M, N, K, MB, A, LDA,
273      $        T, LDT, C, LDC, WORK, INFO)
274         RETURN
275       END IF
276 *
277       IF(LEFT.AND.TRAN) THEN
278 *
279 *         Multiply Q to the last block of C
280 *
281           KK = MOD((M-K),(NB-K))
282           CTR = (M-K)/(NB-K)
283 *
284           IF (KK.GT.0) THEN
285             II=M-KK+1
286             CALL STPMLQT('L','T',KK , N, K, 0, MB, A(1,II), LDA,
287      $        T(1,CTR*K+1), LDT, C(1,1), LDC,
288      $        C(II,1), LDC, WORK, INFO )
289           ELSE
290             II=M+1
291           END IF
292 *
293           DO I=II-(NB-K),NB+1,-(NB-K)
294 *
295 *         Multiply Q to the current block of C (1:M,I:I+NB)
296 *
297             CTR = CTR - 1
298             CALL STPMLQT('L','T',NB-K , N, K, 0,MB, A(1,I), LDA,
299      $          T(1,CTR*K+1),LDT, C(1,1), LDC,
300      $          C(I,1), LDC, WORK, INFO )
301           END DO
302 *
303 *         Multiply Q to the first block of C (1:M,1:NB)
304 *
305           CALL SGEMLQT('L','T',NB , N, K, MB, A(1,1), LDA, T
306      $              ,LDT ,C(1,1), LDC, WORK, INFO )
307 *
308       ELSE IF (LEFT.AND.NOTRAN) THEN
309 *
310 *         Multiply Q to the first block of C
311 *
312          KK = MOD((M-K),(NB-K))
313          II=M-KK+1
314          CTR = 1
315          CALL SGEMLQT('L','N',NB , N, K, MB, A(1,1), LDA, T
316      $              ,LDT ,C(1,1), LDC, WORK, INFO )
317 *
318          DO I=NB+1,II-NB+K,(NB-K)
319 *
320 *         Multiply Q to the current block of C (I:I+NB,1:N)
321 *
322           CALL STPMLQT('L','N',NB-K , N, K, 0,MB, A(1,I), LDA,
323      $         T(1,CTR * K+1), LDT, C(1,1), LDC,
324      $         C(I,1), LDC, WORK, INFO )
325           CTR = CTR + 1
326 *
327          END DO
328          IF(II.LE.M) THEN
329 *
330 *         Multiply Q to the last block of C
331 *
332           CALL STPMLQT('L','N',KK , N, K, 0, MB, A(1,II), LDA,
333      $        T(1,CTR*K+1), LDT, C(1,1), LDC,
334      $        C(II,1), LDC, WORK, INFO )
335 *
336          END IF
337 *
338       ELSE IF(RIGHT.AND.NOTRAN) THEN
339 *
340 *         Multiply Q to the last block of C
341 *
342           KK = MOD((N-K),(NB-K))
343           CTR = (N-K)/(NB-K)
344           IF (KK.GT.0) THEN
345             II=N-KK+1
346             CALL STPMLQT('R','N',M , KK, K, 0, MB, A(1, II), LDA,
347      $        T(1,CTR*K+1), LDT, C(1,1), LDC,
348      $        C(1,II), LDC, WORK, INFO )
349           ELSE
350             II=N+1
351           END IF
352 *
353           DO I=II-(NB-K),NB+1,-(NB-K)
354 *
355 *         Multiply Q to the current block of C (1:M,I:I+MB)
356 *
357              CTR = CTR - 1
358              CALL STPMLQT('R','N', M, NB-K, K, 0, MB, A(1, I), LDA,
359      $            T(1,CTR*K+1), LDT, C(1,1), LDC,
360      $            C(1,I), LDC, WORK, INFO )
361
362           END DO
363 *
364 *         Multiply Q to the first block of C (1:M,1:MB)
365 *
366           CALL SGEMLQT('R','N',M , NB, K, MB, A(1,1), LDA, T
367      $            ,LDT ,C(1,1), LDC, WORK, INFO )
368 *
369       ELSE IF (RIGHT.AND.TRAN) THEN
370 *
371 *       Multiply Q to the first block of C
372 *
373          KK = MOD((N-K),(NB-K))
374          II=N-KK+1
375          CTR = 1
376          CALL SGEMLQT('R','T',M , NB, K, MB, A(1,1), LDA, T
377      $            ,LDT ,C(1,1), LDC, WORK, INFO )
378 *
379          DO I=NB+1,II-NB+K,(NB-K)
380 *
381 *         Multiply Q to the current block of C (1:M,I:I+MB)
382 *
383           CALL STPMLQT('R','T',M , NB-K, K, 0,MB, A(1,I), LDA,
384      $       T(1, CTR*K+1), LDT, C(1,1), LDC,
385      $       C(1,I), LDC, WORK, INFO )
386           CTR = CTR + 1
387 *
388          END DO
389          IF(II.LE.N) THEN
390 *
391 *       Multiply Q to the last block of C
392 *
393           CALL STPMLQT('R','T',M , KK, K, 0,MB, A(1,II), LDA,
394      $      T(1,CTR*K+1),LDT, C(1,1), LDC,
395      $      C(1,II), LDC, WORK, INFO )
396 *
397          END IF
398 *
399       END IF
400 *
401       WORK(1) = LW
402       RETURN
403 *
404 *     End of SLAMSWLQ
405 *
406       END