KTH framework for Nek5000 toolboxes; testing version  0.0.1
dormqr.f
Go to the documentation of this file.
1  SUBROUTINE dormqr( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC,
2  $ WORK, LWORK, INFO )
3 *
4 * -- LAPACK routine (version 3.0) --
5 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
6 * Courant Institute, Argonne National Lab, and Rice University
7 * June 30, 1999
8 *
9 * .. Scalar Arguments ..
10  CHARACTER SIDE, TRANS
11  INTEGER INFO, K, LDA, LDC, LWORK, M, N
12 * ..
13 * .. Array Arguments ..
14  DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * DORMQR overwrites the general real M-by-N matrix C with
21 *
22 * SIDE = 'L' SIDE = 'R'
23 * TRANS = 'N': Q * C C * Q
24 * TRANS = 'T': Q**T * C C * Q**T
25 *
26 * where Q is a real orthogonal matrix defined as the product of k
27 * elementary reflectors
28 *
29 * Q = H(1) H(2) . . . H(k)
30 *
31 * as returned by DGEQRF. Q is of order M if SIDE = 'L' and of order N
32 * if SIDE = 'R'.
33 *
34 * Arguments
35 * =========
36 *
37 * SIDE (input) CHARACTER*1
38 * = 'L': apply Q or Q**T from the Left;
39 * = 'R': apply Q or Q**T from the Right.
40 *
41 * TRANS (input) CHARACTER*1
42 * = 'N': No transpose, apply Q;
43 * = 'T': Transpose, apply Q**T.
44 *
45 * M (input) INTEGER
46 * The number of rows of the matrix C. M >= 0.
47 *
48 * N (input) INTEGER
49 * The number of columns of the matrix C. N >= 0.
50 *
51 * K (input) INTEGER
52 * The number of elementary reflectors whose product defines
53 * the matrix Q.
54 * If SIDE = 'L', M >= K >= 0;
55 * if SIDE = 'R', N >= K >= 0.
56 *
57 * A (input) DOUBLE PRECISION array, dimension (LDA,K)
58 * The i-th column must contain the vector which defines the
59 * elementary reflector H(i), for i = 1,2,...,k, as returned by
60 * DGEQRF in the first k columns of its array argument A.
61 * A is modified by the routine but restored on exit.
62 *
63 * LDA (input) INTEGER
64 * The leading dimension of the array A.
65 * If SIDE = 'L', LDA >= max(1,M);
66 * if SIDE = 'R', LDA >= max(1,N).
67 *
68 * TAU (input) DOUBLE PRECISION array, dimension (K)
69 * TAU(i) must contain the scalar factor of the elementary
70 * reflector H(i), as returned by DGEQRF.
71 *
72 * C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
73 * On entry, the M-by-N matrix C.
74 * On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.
75 *
76 * LDC (input) INTEGER
77 * The leading dimension of the array C. LDC >= max(1,M).
78 *
79 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
80 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
81 *
82 * LWORK (input) INTEGER
83 * The dimension of the array WORK.
84 * If SIDE = 'L', LWORK >= max(1,N);
85 * if SIDE = 'R', LWORK >= max(1,M).
86 * For optimum performance LWORK >= N*NB if SIDE = 'L', and
87 * LWORK >= M*NB if SIDE = 'R', where NB is the optimal
88 * blocksize.
89 *
90 * If LWORK = -1, then a workspace query is assumed; the routine
91 * only calculates the optimal size of the WORK array, returns
92 * this value as the first entry of the WORK array, and no error
93 * message related to LWORK is issued by XERBLA.
94 *
95 * INFO (output) INTEGER
96 * = 0: successful exit
97 * < 0: if INFO = -i, the i-th argument had an illegal value
98 *
99 * =====================================================================
100 *
101 * .. Parameters ..
102  INTEGER NBMAX, LDT
103  parameter( nbmax = 64, ldt = nbmax+1 )
104 * ..
105 * .. Local Scalars ..
106  LOGICAL LEFT, LQUERY, NOTRAN
107  INTEGER I, I1, I2, I3, IB, IC, IINFO, IWS, JC, LDWORK,
108  $ lwkopt, mi, nb, nbmin, ni, nq, nw
109 * ..
110 * .. Local Arrays ..
111  DOUBLE PRECISION T( LDT, NBMAX )
112 * ..
113 * .. External Functions ..
114  LOGICAL LSAME
115  INTEGER ILAENV
116  EXTERNAL lsame, ilaenv
117 * ..
118 * .. External Subroutines ..
119  EXTERNAL dlarfb, dlarft, dorm2r, xerbla
120 * ..
121 * .. Intrinsic Functions ..
122  INTRINSIC max, min
123 * ..
124 * .. Executable Statements ..
125 *
126 * Test the input arguments
127 *
128  info = 0
129  left = lsame( side, 'L' )
130  notran = lsame( trans, 'N' )
131  lquery = ( lwork.EQ.-1 )
132 *
133 * NQ is the order of Q and NW is the minimum dimension of WORK
134 *
135  IF( left ) THEN
136  nq = m
137  nw = n
138  ELSE
139  nq = n
140  nw = m
141  END IF
142  IF( .NOT.left .AND. .NOT.lsame( side, 'R' ) ) THEN
143  info = -1
144  ELSE IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) ) THEN
145  info = -2
146  ELSE IF( m.LT.0 ) THEN
147  info = -3
148  ELSE IF( n.LT.0 ) THEN
149  info = -4
150  ELSE IF( k.LT.0 .OR. k.GT.nq ) THEN
151  info = -5
152  ELSE IF( lda.LT.max( 1, nq ) ) THEN
153  info = -7
154  ELSE IF( ldc.LT.max( 1, m ) ) THEN
155  info = -10
156  ELSE IF( lwork.LT.max( 1, nw ) .AND. .NOT.lquery ) THEN
157  info = -12
158  END IF
159 *
160  IF( info.EQ.0 ) THEN
161 *
162 * Determine the block size. NB may be at most NBMAX, where NBMAX
163 * is used to define the local array T.
164 *
165  nb = min( nbmax, ilaenv( 1, 'DORMQR', side // trans, m, n, k,
166  $ -1 ) )
167  lwkopt = max( 1, nw )*nb
168  work( 1 ) = lwkopt
169  END IF
170 *
171  IF( info.NE.0 ) THEN
172  CALL xerbla( 'DORMQR', -info )
173  RETURN
174  ELSE IF( lquery ) THEN
175  RETURN
176  END IF
177 *
178 * Quick return if possible
179 *
180  IF( m.EQ.0 .OR. n.EQ.0 .OR. k.EQ.0 ) THEN
181  work( 1 ) = 1
182  RETURN
183  END IF
184 *
185  nbmin = 2
186  ldwork = nw
187  IF( nb.GT.1 .AND. nb.LT.k ) THEN
188  iws = nw*nb
189  IF( lwork.LT.iws ) THEN
190  nb = lwork / ldwork
191  nbmin = max( 2, ilaenv( 2, 'DORMQR', side // trans, m, n, k,
192  $ -1 ) )
193  END IF
194  ELSE
195  iws = nw
196  END IF
197 *
198  IF( nb.LT.nbmin .OR. nb.GE.k ) THEN
199 *
200 * Use unblocked code
201 *
202  CALL dorm2r( side, trans, m, n, k, a, lda, tau, c, ldc, work,
203  $ iinfo )
204  ELSE
205 *
206 * Use blocked code
207 *
208  IF( ( left .AND. .NOT.notran ) .OR.
209  $ ( .NOT.left .AND. notran ) ) THEN
210  i1 = 1
211  i2 = k
212  i3 = nb
213  ELSE
214  i1 = ( ( k-1 ) / nb )*nb + 1
215  i2 = 1
216  i3 = -nb
217  END IF
218 *
219  IF( left ) THEN
220  ni = n
221  jc = 1
222  ELSE
223  mi = m
224  ic = 1
225  END IF
226 *
227  DO 10 i = i1, i2, i3
228  ib = min( nb, k-i+1 )
229 *
230 * Form the triangular factor of the block reflector
231 * H = H(i) H(i+1) . . . H(i+ib-1)
232 *
233  CALL dlarft( 'Forward', 'Columnwise', nq-i+1, ib, a( i, i ),
234  $ lda, tau( i ), t, ldt )
235  IF( left ) THEN
236 *
237 * H or H' is applied to C(i:m,1:n)
238 *
239  mi = m - i + 1
240  ic = i
241  ELSE
242 *
243 * H or H' is applied to C(1:m,i:n)
244 *
245  ni = n - i + 1
246  jc = i
247  END IF
248 *
249 * Apply H or H'
250 *
251  CALL dlarfb( side, trans, 'Forward', 'Columnwise', mi, ni,
252  $ ib, a( i, i ), lda, t, ldt, c( ic, jc ), ldc,
253  $ work, ldwork )
254  10 CONTINUE
255  END IF
256  work( 1 ) = lwkopt
257  RETURN
258 *
259 * End of DORMQR
260 *
261  END
subroutine dlarfb(SIDE, TRANS, DIRECT, STOREV, M, N, K, V, LDV, T, LDT, C, LDC, WORK, LDWORK)
Definition: dlarfb.f:3
subroutine dlarft(DIRECT, STOREV, N, K, V, LDV, TAU, T, LDT)
Definition: dlarft.f:2
subroutine dorm2r(SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK, INFO)
Definition: dorm2r.f:3
subroutine dormqr(SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK, LWORK, INFO)
Definition: dormqr.f:3
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2