1 SUBROUTINE DORGQR( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
3 ! -- LAPACK routine (version 3.1) --
4 ! Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
7 ! .. Scalar Arguments ..
8 INTEGER INFO, K, LDA, LWORK, M, N
10 ! .. Array Arguments ..
11 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
17 ! DORGQR generates an M-by-N real matrix Q with orthonormal columns,
18 ! which is defined as the first N columns of a product of K elementary
19 ! reflectors of order M
21 ! Q = H(1) H(2) . . . H(k)
23 ! as returned by DGEQRF.
29 ! The number of rows of the matrix Q. M >= 0.
32 ! The number of columns of the matrix Q. M >= N >= 0.
35 ! The number of elementary reflectors whose product defines the
36 ! matrix Q. N >= K >= 0.
38 ! A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
39 ! On entry, the i-th column must contain the vector which
40 ! defines the elementary reflector H(i), for i = 1,2,...,k, as
41 ! returned by DGEQRF in the first k columns of its array
43 ! On exit, the M-by-N matrix Q.
46 ! The first dimension of the array A. LDA >= max(1,M).
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 DGEQRF.
52 ! WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
53 ! On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
55 ! LWORK (input) INTEGER
56 ! The dimension of the array WORK. LWORK >= max(1,N).
57 ! For optimum performance LWORK >= N*NB, where NB is the
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.
65 ! INFO (output) INTEGER
66 ! = 0: successful exit
67 ! < 0: if INFO = -i, the i-th argument has an illegal value
69 ! =====================================================================
73 PARAMETER ( ZERO = 0.0D+0 )
77 INTEGER I, IB, IINFO, IWS, J, KI, KK, L, LDWORK, &
80 ! .. External Subroutines ..
81 ! EXTERNAL DLARFB, DLARFT, DORG2R, XERBLA
83 ! .. Intrinsic Functions ..
86 ! .. External Functions ..
90 ! .. Executable Statements ..
92 ! Test the input arguments
95 NB = ILAENV( 1, 'DORGQR', ' ', M, N, K, -1 )
96 LWKOPT = MAX( 1, N )*NB
98 LQUERY = ( LWORK.EQ.-1 )
101 ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
103 ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
105 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
107 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
111 CALL XERBLA( 'DORGQR', -INFO )
113 ELSE IF( LQUERY ) THEN
117 ! Quick return if possible
127 IF( NB.GT.1 .AND. NB.LT.K ) THEN
129 ! Determine when to cross over from blocked to unblocked code.
131 NX = MAX( 0, ILAENV( 3, 'DORGQR', ' ', M, N, K, -1 ) )
134 ! Determine if workspace is large enough for blocked code.
138 IF( LWORK.LT.IWS ) THEN
140 ! Not enough workspace to use optimal NB: reduce NB and
141 ! determine the minimum value of NB.
144 NBMIN = MAX( 2, ILAENV( 2, 'DORGQR', ' ', M, N, K, -1 ) )
149 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
151 ! Use blocked code after the last block.
152 ! The first kk columns are handled by the block method.
154 KI = ( ( K-NX-1 ) / NB )*NB
157 ! Set A(1:kk,kk+1:n) to zero.
168 ! Use unblocked code for the last or only block.
171 CALL DORG2R( M-KK, N-KK, K-KK, A( KK+1, KK+1 ), LDA, &
172 TAU( KK+1 ), WORK, IINFO )
178 DO 50 I = KI + 1, 1, -NB
179 IB = MIN( NB, K-I+1 )
182 ! Form the triangular factor of the block reflector
183 ! H = H(i) H(i+1) . . . H(i+ib-1)
185 CALL DLARFT( 'Forward', 'Columnwise', M-I+1, IB, &
186 A( I, I ), LDA, TAU( I ), WORK, LDWORK )
188 ! Apply H to A(i:m,i+ib:n) from the left
190 CALL DLARFB( 'Left', 'No transpose', 'Forward', &
191 'Columnwise', M-I+1, N-I-IB+1, IB, &
192 A( I, I ), LDA, WORK, LDWORK, A( I, I+IB ), &
193 LDA, WORK( IB+1 ), LDWORK )
196 ! Apply H to rows i:m of current block
198 CALL DORG2R( M-I+1, IB, IB, A( I, I ), LDA, TAU( I ), WORK, &
201 ! Set rows 1:i-1 of current block to zero
203 DO 40 J = I, I + IB - 1
216 END SUBROUTINE DORGQR