LAPACK 3.3.0
|
00001 SUBROUTINE DORGRQ( M, N, K, A, LDA, TAU, WORK, LWORK, INFO ) 00002 * 00003 * -- LAPACK routine (version 3.2) -- 00004 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00005 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00006 * November 2006 00007 * 00008 * .. Scalar Arguments .. 00009 INTEGER INFO, K, LDA, LWORK, M, N 00010 * .. 00011 * .. Array Arguments .. 00012 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) 00013 * .. 00014 * 00015 * Purpose 00016 * ======= 00017 * 00018 * DORGRQ generates an M-by-N real matrix Q with orthonormal rows, 00019 * which is defined as the last M rows of a product of K elementary 00020 * reflectors of order N 00021 * 00022 * Q = H(1) H(2) . . . H(k) 00023 * 00024 * as returned by DGERQF. 00025 * 00026 * Arguments 00027 * ========= 00028 * 00029 * M (input) INTEGER 00030 * The number of rows of the matrix Q. M >= 0. 00031 * 00032 * N (input) INTEGER 00033 * The number of columns of the matrix Q. N >= M. 00034 * 00035 * K (input) INTEGER 00036 * The number of elementary reflectors whose product defines the 00037 * matrix Q. M >= K >= 0. 00038 * 00039 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N) 00040 * On entry, the (m-k+i)-th row must contain the vector which 00041 * defines the elementary reflector H(i), for i = 1,2,...,k, as 00042 * returned by DGERQF in the last k rows of its array argument 00043 * A. 00044 * On exit, the M-by-N matrix Q. 00045 * 00046 * LDA (input) INTEGER 00047 * The first dimension of the array A. LDA >= max(1,M). 00048 * 00049 * TAU (input) DOUBLE PRECISION array, dimension (K) 00050 * TAU(i) must contain the scalar factor of the elementary 00051 * reflector H(i), as returned by DGERQF. 00052 * 00053 * WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) 00054 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. 00055 * 00056 * LWORK (input) INTEGER 00057 * The dimension of the array WORK. LWORK >= max(1,M). 00058 * For optimum performance LWORK >= M*NB, where NB is the 00059 * optimal blocksize. 00060 * 00061 * If LWORK = -1, then a workspace query is assumed; the routine 00062 * only calculates the optimal size of the WORK array, returns 00063 * this value as the first entry of the WORK array, and no error 00064 * message related to LWORK is issued by XERBLA. 00065 * 00066 * INFO (output) INTEGER 00067 * = 0: successful exit 00068 * < 0: if INFO = -i, the i-th argument has an illegal value 00069 * 00070 * ===================================================================== 00071 * 00072 * .. Parameters .. 00073 DOUBLE PRECISION ZERO 00074 PARAMETER ( ZERO = 0.0D+0 ) 00075 * .. 00076 * .. Local Scalars .. 00077 LOGICAL LQUERY 00078 INTEGER I, IB, II, IINFO, IWS, J, KK, L, LDWORK, 00079 $ LWKOPT, NB, NBMIN, NX 00080 * .. 00081 * .. External Subroutines .. 00082 EXTERNAL DLARFB, DLARFT, DORGR2, XERBLA 00083 * .. 00084 * .. Intrinsic Functions .. 00085 INTRINSIC MAX, MIN 00086 * .. 00087 * .. External Functions .. 00088 INTEGER ILAENV 00089 EXTERNAL ILAENV 00090 * .. 00091 * .. Executable Statements .. 00092 * 00093 * Test the input arguments 00094 * 00095 INFO = 0 00096 LQUERY = ( LWORK.EQ.-1 ) 00097 IF( M.LT.0 ) THEN 00098 INFO = -1 00099 ELSE IF( N.LT.M ) THEN 00100 INFO = -2 00101 ELSE IF( K.LT.0 .OR. K.GT.M ) THEN 00102 INFO = -3 00103 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN 00104 INFO = -5 00105 END IF 00106 * 00107 IF( INFO.EQ.0 ) THEN 00108 IF( M.LE.0 ) THEN 00109 LWKOPT = 1 00110 ELSE 00111 NB = ILAENV( 1, 'DORGRQ', ' ', M, N, K, -1 ) 00112 LWKOPT = M*NB 00113 END IF 00114 WORK( 1 ) = LWKOPT 00115 * 00116 IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN 00117 INFO = -8 00118 END IF 00119 END IF 00120 * 00121 IF( INFO.NE.0 ) THEN 00122 CALL XERBLA( 'DORGRQ', -INFO ) 00123 RETURN 00124 ELSE IF( LQUERY ) THEN 00125 RETURN 00126 END IF 00127 * 00128 * Quick return if possible 00129 * 00130 IF( M.LE.0 ) THEN 00131 RETURN 00132 END IF 00133 * 00134 NBMIN = 2 00135 NX = 0 00136 IWS = M 00137 IF( NB.GT.1 .AND. NB.LT.K ) THEN 00138 * 00139 * Determine when to cross over from blocked to unblocked code. 00140 * 00141 NX = MAX( 0, ILAENV( 3, 'DORGRQ', ' ', M, N, K, -1 ) ) 00142 IF( NX.LT.K ) THEN 00143 * 00144 * Determine if workspace is large enough for blocked code. 00145 * 00146 LDWORK = M 00147 IWS = LDWORK*NB 00148 IF( LWORK.LT.IWS ) THEN 00149 * 00150 * Not enough workspace to use optimal NB: reduce NB and 00151 * determine the minimum value of NB. 00152 * 00153 NB = LWORK / LDWORK 00154 NBMIN = MAX( 2, ILAENV( 2, 'DORGRQ', ' ', M, N, K, -1 ) ) 00155 END IF 00156 END IF 00157 END IF 00158 * 00159 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN 00160 * 00161 * Use blocked code after the first block. 00162 * The last kk rows are handled by the block method. 00163 * 00164 KK = MIN( K, ( ( K-NX+NB-1 ) / NB )*NB ) 00165 * 00166 * Set A(1:m-kk,n-kk+1:n) to zero. 00167 * 00168 DO 20 J = N - KK + 1, N 00169 DO 10 I = 1, M - KK 00170 A( I, J ) = ZERO 00171 10 CONTINUE 00172 20 CONTINUE 00173 ELSE 00174 KK = 0 00175 END IF 00176 * 00177 * Use unblocked code for the first or only block. 00178 * 00179 CALL DORGR2( M-KK, N-KK, K-KK, A, LDA, TAU, WORK, IINFO ) 00180 * 00181 IF( KK.GT.0 ) THEN 00182 * 00183 * Use blocked code 00184 * 00185 DO 50 I = K - KK + 1, K, NB 00186 IB = MIN( NB, K-I+1 ) 00187 II = M - K + I 00188 IF( II.GT.1 ) THEN 00189 * 00190 * Form the triangular factor of the block reflector 00191 * H = H(i+ib-1) . . . H(i+1) H(i) 00192 * 00193 CALL DLARFT( 'Backward', 'Rowwise', N-K+I+IB-1, IB, 00194 $ A( II, 1 ), LDA, TAU( I ), WORK, LDWORK ) 00195 * 00196 * Apply H' to A(1:m-k+i-1,1:n-k+i+ib-1) from the right 00197 * 00198 CALL DLARFB( 'Right', 'Transpose', 'Backward', 'Rowwise', 00199 $ II-1, N-K+I+IB-1, IB, A( II, 1 ), LDA, WORK, 00200 $ LDWORK, A, LDA, WORK( IB+1 ), LDWORK ) 00201 END IF 00202 * 00203 * Apply H' to columns 1:n-k+i+ib-1 of current block 00204 * 00205 CALL DORGR2( IB, N-K+I+IB-1, IB, A( II, 1 ), LDA, TAU( I ), 00206 $ WORK, IINFO ) 00207 * 00208 * Set columns n-k+i+ib:n of current block to zero 00209 * 00210 DO 40 L = N - K + I + IB, N 00211 DO 30 J = II, II + IB - 1 00212 A( J, L ) = ZERO 00213 30 CONTINUE 00214 40 CONTINUE 00215 50 CONTINUE 00216 END IF 00217 * 00218 WORK( 1 ) = IWS 00219 RETURN 00220 * 00221 * End of DORGRQ 00222 * 00223 END