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 sorglq_(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 sorgl2_(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 /* SORGLQ generates an M-by-N real matrix Q with orthonormal rows, */
43 /* which is defined as the first M rows of a product of K elementary */
44 /* reflectors of order N */
46 /* Q = H(k) . . . H(2) H(1) */
48 /* as returned by SGELQF. */
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. N >= M. */
59 /* K (input) INTEGER */
60 /* The number of elementary reflectors whose product defines the */
61 /* matrix Q. M >= K >= 0. */
63 /* A (input/output) REAL array, dimension (LDA,N) */
64 /* On entry, the i-th row must contain the vector which defines */
65 /* the elementary reflector H(i), for i = 1,2,...,k, as returned */
66 /* by SGELQF in the first k rows of its array argument A. */
67 /* On exit, the M-by-N matrix Q. */
69 /* LDA (input) INTEGER */
70 /* The first dimension of the array A. LDA >= max(1,M). */
72 /* TAU (input) REAL array, dimension (K) */
73 /* TAU(i) must contain the scalar factor of the elementary */
74 /* reflector H(i), as returned by SGELQF. */
76 /* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
77 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
79 /* LWORK (input) INTEGER */
80 /* The dimension of the array WORK. LWORK >= max(1,M). */
81 /* For optimum performance LWORK >= M*NB, where NB is */
82 /* the optimal blocksize. */
84 /* If LWORK = -1, then a workspace query is assumed; the routine */
85 /* only calculates the optimal size of the WORK array, returns */
86 /* this value as the first entry of the WORK array, and no error */
87 /* message related to LWORK is issued by XERBLA. */
89 /* INFO (output) INTEGER */
90 /* = 0: successful exit */
91 /* < 0: if INFO = -i, the i-th argument has an illegal value */
93 /* ===================================================================== */
95 /* .. Parameters .. */
97 /* .. Local Scalars .. */
99 /* .. External Subroutines .. */
101 /* .. Intrinsic Functions .. */
103 /* .. External Functions .. */
105 /* .. Executable Statements .. */
107 /* Test the input arguments */
109 /* Parameter adjustments */
111 a_offset = 1 + a_dim1;
118 nb = ilaenv_(&c__1, "SORGLQ", " ", m, n, k, &c_n1);
119 lwkopt = max(1,*m) * nb;
120 work[1] = (real) lwkopt;
121 lquery = *lwork == -1;
124 } else if (*n < *m) {
126 } else if (*k < 0 || *k > *m) {
128 } else if (*lda < max(1,*m)) {
130 } else if (*lwork < max(1,*m) && ! lquery) {
135 xerbla_("SORGLQ", &i__1);
141 /* Quick return if possible */
151 if (nb > 1 && nb < *k) {
153 /* Determine when to cross over from blocked to unblocked code. */
156 i__1 = 0, i__2 = ilaenv_(&c__3, "SORGLQ", " ", m, n, k, &c_n1);
160 /* Determine if workspace is large enough for blocked code. */
166 /* Not enough workspace to use optimal NB: reduce NB and */
167 /* determine the minimum value of NB. */
169 nb = *lwork / ldwork;
171 i__1 = 2, i__2 = ilaenv_(&c__2, "SORGLQ", " ", m, n, k, &c_n1);
172 nbmin = max(i__1,i__2);
177 if (nb >= nbmin && nb < *k && nx < *k) {
179 /* Use blocked code after the last block. */
180 /* The first kk rows are handled by the block method. */
182 ki = (*k - nx - 1) / nb * nb;
184 i__1 = *k, i__2 = ki + nb;
187 /* Set A(kk+1:m,1:kk) to zero. */
190 for (j = 1; j <= i__1; ++j) {
192 for (i__ = kk + 1; i__ <= i__2; ++i__) {
193 a[i__ + j * a_dim1] = 0.f;
202 /* Use unblocked code for the last or only block. */
208 sorgl2_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
209 tau[kk + 1], &work[1], &iinfo);
214 /* Use blocked code */
217 for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
219 i__2 = nb, i__3 = *k - i__ + 1;
221 if (i__ + ib <= *m) {
223 /* Form the triangular factor of the block reflector */
224 /* H = H(i) H(i+1) . . . H(i+ib-1) */
227 slarft_("Forward", "Rowwise", &i__2, &ib, &a[i__ + i__ *
228 a_dim1], lda, &tau[i__], &work[1], &ldwork);
230 /* Apply H' to A(i+ib:m,i:n) from the right */
232 i__2 = *m - i__ - ib + 1;
234 slarfb_("Right", "Transpose", "Forward", "Rowwise", &i__2, &
235 i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
236 ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib +
240 /* Apply H' to columns i:n of current block */
243 sorgl2_(&ib, &i__2, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
246 /* Set columns 1:i-1 of current block to zero */
249 for (j = 1; j <= i__2; ++j) {
251 for (l = i__; l <= i__3; ++l) {
252 a[l + j * a_dim1] = 0.f;
261 work[1] = (real) iws;