3 /* Table of constant values */
5 static integer c__1 = 1;
6 static integer c_n1 = -1;
7 static integer c__3 = 3;
8 static integer c__2 = 2;
10 /* Subroutine */ int sorgqr_(integer *m, integer *n, integer *k, real *a,
11 integer *lda, real *tau, real *work, integer *lwork, integer *info)
13 /* System generated locals */
14 integer a_dim1, a_offset, i__1, i__2, i__3;
17 integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
18 extern /* Subroutine */ int sorg2r_(integer *, integer *, integer *, real
19 *, integer *, real *, real *, integer *), slarfb_(char *, char *,
20 char *, char *, integer *, integer *, integer *, real *, integer *
21 , real *, integer *, real *, integer *, real *, integer *), xerbla_(char *, integer *);
22 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
23 integer *, integer *);
24 extern /* Subroutine */ int slarft_(char *, char *, integer *, integer *,
25 real *, integer *, real *, real *, integer *);
26 integer ldwork, lwkopt;
30 /* -- LAPACK routine (version 3.1) -- */
31 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
34 /* .. Scalar Arguments .. */
36 /* .. Array Arguments .. */
42 /* SORGQR generates an M-by-N real matrix Q with orthonormal columns, */
43 /* which is defined as the first N columns of a product of K elementary */
44 /* reflectors of order M */
46 /* Q = H(1) H(2) . . . H(k) */
48 /* as returned by SGEQRF. */
53 /* M (input) INTEGER */
54 /* The number of rows of the matrix Q. M >= 0. */
56 /* N (input) INTEGER */
57 /* The number of columns of the matrix Q. M >= N >= 0. */
59 /* K (input) INTEGER */
60 /* The number of elementary reflectors whose product defines the */
61 /* matrix Q. N >= K >= 0. */
63 /* A (input/output) REAL array, dimension (LDA,N) */
64 /* On entry, the i-th column must contain the vector which */
65 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
66 /* returned by SGEQRF in the first k columns of its array */
68 /* On exit, the M-by-N matrix Q. */
70 /* LDA (input) INTEGER */
71 /* The first dimension of the array A. LDA >= max(1,M). */
73 /* TAU (input) REAL array, dimension (K) */
74 /* TAU(i) must contain the scalar factor of the elementary */
75 /* reflector H(i), as returned by SGEQRF. */
77 /* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
78 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
80 /* LWORK (input) INTEGER */
81 /* The dimension of the array WORK. LWORK >= max(1,N). */
82 /* For optimum performance LWORK >= N*NB, where NB is the */
83 /* optimal blocksize. */
85 /* If LWORK = -1, then a workspace query is assumed; the routine */
86 /* only calculates the optimal size of the WORK array, returns */
87 /* this value as the first entry of the WORK array, and no error */
88 /* message related to LWORK is issued by XERBLA. */
90 /* INFO (output) INTEGER */
91 /* = 0: successful exit */
92 /* < 0: if INFO = -i, the i-th argument has an illegal value */
94 /* ===================================================================== */
96 /* .. Parameters .. */
98 /* .. Local Scalars .. */
100 /* .. External Subroutines .. */
102 /* .. Intrinsic Functions .. */
104 /* .. External Functions .. */
106 /* .. Executable Statements .. */
108 /* Test the input arguments */
110 /* Parameter adjustments */
112 a_offset = 1 + a_dim1;
119 nb = ilaenv_(&c__1, "SORGQR", " ", m, n, k, &c_n1);
120 lwkopt = max(1,*n) * nb;
121 work[1] = (real) lwkopt;
122 lquery = *lwork == -1;
125 } else if (*n < 0 || *n > *m) {
127 } else if (*k < 0 || *k > *n) {
129 } else if (*lda < max(1,*m)) {
131 } else if (*lwork < max(1,*n) && ! lquery) {
136 xerbla_("SORGQR", &i__1);
142 /* Quick return if possible */
152 if (nb > 1 && nb < *k) {
154 /* Determine when to cross over from blocked to unblocked code. */
157 i__1 = 0, i__2 = ilaenv_(&c__3, "SORGQR", " ", m, n, k, &c_n1);
161 /* Determine if workspace is large enough for blocked code. */
167 /* Not enough workspace to use optimal NB: reduce NB and */
168 /* determine the minimum value of NB. */
170 nb = *lwork / ldwork;
172 i__1 = 2, i__2 = ilaenv_(&c__2, "SORGQR", " ", m, n, k, &c_n1);
173 nbmin = max(i__1,i__2);
178 if (nb >= nbmin && nb < *k && nx < *k) {
180 /* Use blocked code after the last block. */
181 /* The first kk columns are handled by the block method. */
183 ki = (*k - nx - 1) / nb * nb;
185 i__1 = *k, i__2 = ki + nb;
188 /* Set A(1:kk,kk+1:n) to zero. */
191 for (j = kk + 1; j <= i__1; ++j) {
193 for (i__ = 1; i__ <= i__2; ++i__) {
194 a[i__ + j * a_dim1] = 0.f;
203 /* Use unblocked code for the last or only block. */
209 sorg2r_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
210 tau[kk + 1], &work[1], &iinfo);
215 /* Use blocked code */
218 for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
220 i__2 = nb, i__3 = *k - i__ + 1;
222 if (i__ + ib <= *n) {
224 /* Form the triangular factor of the block reflector */
225 /* H = H(i) H(i+1) . . . H(i+ib-1) */
228 slarft_("Forward", "Columnwise", &i__2, &ib, &a[i__ + i__ *
229 a_dim1], lda, &tau[i__], &work[1], &ldwork);
231 /* Apply H to A(i:m,i+ib:n) from the left */
234 i__3 = *n - i__ - ib + 1;
235 slarfb_("Left", "No transpose", "Forward", "Columnwise", &
236 i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
237 1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &
238 work[ib + 1], &ldwork);
241 /* Apply H to rows i:m of current block */
244 sorg2r_(&i__2, &ib, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
247 /* Set rows 1:i-1 of current block to zero */
250 for (j = i__; j <= i__2; ++j) {
252 for (l = 1; l <= i__3; ++l) {
253 a[l + j * a_dim1] = 0.f;
262 work[1] = (real) iws;