KTH framework for Nek5000 toolboxes; testing version  0.0.1
dorglq.f
Go to the documentation of this file.
1  SUBROUTINE dorglq( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
2 *
3 * -- LAPACK routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * June 30, 1999
7 *
8 * .. Scalar Arguments ..
9  INTEGER INFO, K, LDA, LWORK, M, N
10 * ..
11 * .. Array Arguments ..
12  DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
13 * ..
14 *
15 * Purpose
16 * =======
17 *
18 * DORGLQ generates an M-by-N real matrix Q with orthonormal rows,
19 * which is defined as the first M rows of a product of K elementary
20 * reflectors of order N
21 *
22 * Q = H(k) . . . H(2) H(1)
23 *
24 * as returned by DGELQF.
25 *
26 * Arguments
27 * =========
28 *
29 * M (input) INTEGER
30 * The number of rows of the matrix Q. M >= 0.
31 *
32 * N (input) INTEGER
33 * The number of columns of the matrix Q. N >= M.
34 *
35 * K (input) INTEGER
36 * The number of elementary reflectors whose product defines the
37 * matrix Q. M >= K >= 0.
38 *
39 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
40 * On entry, the i-th row must contain the vector which defines
41 * the elementary reflector H(i), for i = 1,2,...,k, as returned
42 * by DGELQF in the first k rows of its array argument A.
43 * On exit, the M-by-N matrix Q.
44 *
45 * LDA (input) INTEGER
46 * The first dimension of the array A. LDA >= max(1,M).
47 *
48 * TAU (input) DOUBLE PRECISION array, dimension (K)
49 * TAU(i) must contain the scalar factor of the elementary
50 * reflector H(i), as returned by DGELQF.
51 *
52 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
53 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
54 *
55 * LWORK (input) INTEGER
56 * The dimension of the array WORK. LWORK >= max(1,M).
57 * For optimum performance LWORK >= M*NB, where NB is
58 * the optimal blocksize.
59 *
60 * If LWORK = -1, then a workspace query is assumed; the routine
61 * only calculates the optimal size of the WORK array, returns
62 * this value as the first entry of the WORK array, and no error
63 * message related to LWORK is issued by XERBLA.
64 *
65 * INFO (output) INTEGER
66 * = 0: successful exit
67 * < 0: if INFO = -i, the i-th argument has an illegal value
68 *
69 * =====================================================================
70 *
71 * .. Parameters ..
72  DOUBLE PRECISION ZERO
73  parameter( zero = 0.0d+0 )
74 * ..
75 * .. Local Scalars ..
76  LOGICAL LQUERY
77  INTEGER I, IB, IINFO, IWS, J, KI, KK, L, LDWORK,
78  $ LWKOPT, NB, NBMIN, NX
79 * ..
80 * .. External Subroutines ..
81  EXTERNAL dlarfb, dlarft, dorgl2, xerbla
82 * ..
83 * .. Intrinsic Functions ..
84  INTRINSIC max, min
85 * ..
86 * .. External Functions ..
87  INTEGER ILAENV
88  EXTERNAL ilaenv
89 * ..
90 * .. Executable Statements ..
91 *
92 * Test the input arguments
93 *
94  info = 0
95  nb = ilaenv( 1, 'DORGLQ', ' ', m, n, k, -1 )
96  lwkopt = max( 1, m )*nb
97  work( 1 ) = lwkopt
98  lquery = ( lwork.EQ.-1 )
99  IF( m.LT.0 ) THEN
100  info = -1
101  ELSE IF( n.LT.m ) THEN
102  info = -2
103  ELSE IF( k.LT.0 .OR. k.GT.m ) THEN
104  info = -3
105  ELSE IF( lda.LT.max( 1, m ) ) THEN
106  info = -5
107  ELSE IF( lwork.LT.max( 1, m ) .AND. .NOT.lquery ) THEN
108  info = -8
109  END IF
110  IF( info.NE.0 ) THEN
111  CALL xerbla( 'DORGLQ', -info )
112  RETURN
113  ELSE IF( lquery ) THEN
114  RETURN
115  END IF
116 *
117 * Quick return if possible
118 *
119  IF( m.LE.0 ) THEN
120  work( 1 ) = 1
121  RETURN
122  END IF
123 *
124  nbmin = 2
125  nx = 0
126  iws = m
127  IF( nb.GT.1 .AND. nb.LT.k ) THEN
128 *
129 * Determine when to cross over from blocked to unblocked code.
130 *
131  nx = max( 0, ilaenv( 3, 'DORGLQ', ' ', m, n, k, -1 ) )
132  IF( nx.LT.k ) THEN
133 *
134 * Determine if workspace is large enough for blocked code.
135 *
136  ldwork = m
137  iws = ldwork*nb
138  IF( lwork.LT.iws ) THEN
139 *
140 * Not enough workspace to use optimal NB: reduce NB and
141 * determine the minimum value of NB.
142 *
143  nb = lwork / ldwork
144  nbmin = max( 2, ilaenv( 2, 'DORGLQ', ' ', m, n, k, -1 ) )
145  END IF
146  END IF
147  END IF
148 *
149  IF( nb.GE.nbmin .AND. nb.LT.k .AND. nx.LT.k ) THEN
150 *
151 * Use blocked code after the last block.
152 * The first kk rows are handled by the block method.
153 *
154  ki = ( ( k-nx-1 ) / nb )*nb
155  kk = min( k, ki+nb )
156 *
157 * Set A(kk+1:m,1:kk) to zero.
158 *
159  DO 20 j = 1, kk
160  DO 10 i = kk + 1, m
161  a( i, j ) = zero
162  10 CONTINUE
163  20 CONTINUE
164  ELSE
165  kk = 0
166  END IF
167 *
168 * Use unblocked code for the last or only block.
169 *
170  IF( kk.LT.m )
171  $ CALL dorgl2( m-kk, n-kk, k-kk, a( kk+1, kk+1 ), lda,
172  $ tau( kk+1 ), work, iinfo )
173 *
174  IF( kk.GT.0 ) THEN
175 *
176 * Use blocked code
177 *
178  DO 50 i = ki + 1, 1, -nb
179  ib = min( nb, k-i+1 )
180  IF( i+ib.LE.m ) THEN
181 *
182 * Form the triangular factor of the block reflector
183 * H = H(i) H(i+1) . . . H(i+ib-1)
184 *
185  CALL dlarft( 'Forward', 'Rowwise', n-i+1, ib, a( i, i ),
186  $ lda, tau( i ), work, ldwork )
187 *
188 * Apply H' to A(i+ib:m,i:n) from the right
189 *
190  CALL dlarfb( 'Right', 'Transpose', 'Forward', 'Rowwise',
191  $ m-i-ib+1, n-i+1, ib, a( i, i ), lda, work,
192  $ ldwork, a( i+ib, i ), lda, work( ib+1 ),
193  $ ldwork )
194  END IF
195 *
196 * Apply H' to columns i:n of current block
197 *
198  CALL dorgl2( ib, n-i+1, ib, a( i, i ), lda, tau( i ), work,
199  $ iinfo )
200 *
201 * Set columns 1:i-1 of current block to zero
202 *
203  DO 40 j = 1, i - 1
204  DO 30 l = i, i + ib - 1
205  a( l, j ) = zero
206  30 CONTINUE
207  40 CONTINUE
208  50 CONTINUE
209  END IF
210 *
211  work( 1 ) = iws
212  RETURN
213 *
214 * End of DORGLQ
215 *
216  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 dorgl2(M, N, K, A, LDA, TAU, WORK, INFO)
Definition: dorgl2.f:2
subroutine dorglq(M, N, K, A, LDA, TAU, WORK, LWORK, INFO)
Definition: dorglq.f:2
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2