dorgql.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* dorgql.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__1 = 1;
  15. static integer c_n1 = -1;
  16. static integer c__3 = 3;
  17. static integer c__2 = 2;
  18. /* Subroutine */ int _starpu_dorgql_(integer *m, integer *n, integer *k, doublereal *
  19. a, integer *lda, doublereal *tau, doublereal *work, integer *lwork,
  20. integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
  24. /* Local variables */
  25. integer i__, j, l, ib, nb, kk, nx, iws, nbmin, iinfo;
  26. extern /* Subroutine */ int _starpu_dorg2l_(integer *, integer *, integer *,
  27. doublereal *, integer *, doublereal *, doublereal *, integer *),
  28. _starpu_dlarfb_(char *, char *, char *, char *, integer *, integer *,
  29. integer *, doublereal *, integer *, doublereal *, integer *,
  30. doublereal *, integer *, doublereal *, integer *), _starpu_dlarft_(char *, char *, integer *, integer *,
  31. doublereal *, integer *, doublereal *, doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  32. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  33. integer *, integer *);
  34. integer ldwork, lwkopt;
  35. logical lquery;
  36. /* -- LAPACK routine (version 3.2) -- */
  37. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  38. /* November 2006 */
  39. /* .. Scalar Arguments .. */
  40. /* .. */
  41. /* .. Array Arguments .. */
  42. /* .. */
  43. /* Purpose */
  44. /* ======= */
  45. /* DORGQL generates an M-by-N real matrix Q with orthonormal columns, */
  46. /* which is defined as the last N columns of a product of K elementary */
  47. /* reflectors of order M */
  48. /* Q = H(k) . . . H(2) H(1) */
  49. /* as returned by DGEQLF. */
  50. /* Arguments */
  51. /* ========= */
  52. /* M (input) INTEGER */
  53. /* The number of rows of the matrix Q. M >= 0. */
  54. /* N (input) INTEGER */
  55. /* The number of columns of the matrix Q. M >= N >= 0. */
  56. /* K (input) INTEGER */
  57. /* The number of elementary reflectors whose product defines the */
  58. /* matrix Q. N >= K >= 0. */
  59. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  60. /* On entry, the (n-k+i)-th column must contain the vector which */
  61. /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
  62. /* returned by DGEQLF in the last k columns of its array */
  63. /* argument A. */
  64. /* On exit, the M-by-N matrix Q. */
  65. /* LDA (input) INTEGER */
  66. /* The first dimension of the array A. LDA >= max(1,M). */
  67. /* TAU (input) DOUBLE PRECISION array, dimension (K) */
  68. /* TAU(i) must contain the scalar factor of the elementary */
  69. /* reflector H(i), as returned by DGEQLF. */
  70. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  71. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  72. /* LWORK (input) INTEGER */
  73. /* The dimension of the array WORK. LWORK >= max(1,N). */
  74. /* For optimum performance LWORK >= N*NB, where NB is the */
  75. /* optimal blocksize. */
  76. /* If LWORK = -1, then a workspace query is assumed; the routine */
  77. /* only calculates the optimal size of the WORK array, returns */
  78. /* this value as the first entry of the WORK array, and no error */
  79. /* message related to LWORK is issued by XERBLA. */
  80. /* INFO (output) INTEGER */
  81. /* = 0: successful exit */
  82. /* < 0: if INFO = -i, the i-th argument has an illegal value */
  83. /* ===================================================================== */
  84. /* .. Parameters .. */
  85. /* .. */
  86. /* .. Local Scalars .. */
  87. /* .. */
  88. /* .. External Subroutines .. */
  89. /* .. */
  90. /* .. Intrinsic Functions .. */
  91. /* .. */
  92. /* .. External Functions .. */
  93. /* .. */
  94. /* .. Executable Statements .. */
  95. /* Test the input arguments */
  96. /* Parameter adjustments */
  97. a_dim1 = *lda;
  98. a_offset = 1 + a_dim1;
  99. a -= a_offset;
  100. --tau;
  101. --work;
  102. /* Function Body */
  103. *info = 0;
  104. lquery = *lwork == -1;
  105. if (*m < 0) {
  106. *info = -1;
  107. } else if (*n < 0 || *n > *m) {
  108. *info = -2;
  109. } else if (*k < 0 || *k > *n) {
  110. *info = -3;
  111. } else if (*lda < max(1,*m)) {
  112. *info = -5;
  113. }
  114. if (*info == 0) {
  115. if (*n == 0) {
  116. lwkopt = 1;
  117. } else {
  118. nb = _starpu_ilaenv_(&c__1, "DORGQL", " ", m, n, k, &c_n1);
  119. lwkopt = *n * nb;
  120. }
  121. work[1] = (doublereal) lwkopt;
  122. if (*lwork < max(1,*n) && ! lquery) {
  123. *info = -8;
  124. }
  125. }
  126. if (*info != 0) {
  127. i__1 = -(*info);
  128. _starpu_xerbla_("DORGQL", &i__1);
  129. return 0;
  130. } else if (lquery) {
  131. return 0;
  132. }
  133. /* Quick return if possible */
  134. if (*n <= 0) {
  135. return 0;
  136. }
  137. nbmin = 2;
  138. nx = 0;
  139. iws = *n;
  140. if (nb > 1 && nb < *k) {
  141. /* Determine when to cross over from blocked to unblocked code. */
  142. /* Computing MAX */
  143. i__1 = 0, i__2 = _starpu_ilaenv_(&c__3, "DORGQL", " ", m, n, k, &c_n1);
  144. nx = max(i__1,i__2);
  145. if (nx < *k) {
  146. /* Determine if workspace is large enough for blocked code. */
  147. ldwork = *n;
  148. iws = ldwork * nb;
  149. if (*lwork < iws) {
  150. /* Not enough workspace to use optimal NB: reduce NB and */
  151. /* determine the minimum value of NB. */
  152. nb = *lwork / ldwork;
  153. /* Computing MAX */
  154. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DORGQL", " ", m, n, k, &c_n1);
  155. nbmin = max(i__1,i__2);
  156. }
  157. }
  158. }
  159. if (nb >= nbmin && nb < *k && nx < *k) {
  160. /* Use blocked code after the first block. */
  161. /* The last kk columns are handled by the block method. */
  162. /* Computing MIN */
  163. i__1 = *k, i__2 = (*k - nx + nb - 1) / nb * nb;
  164. kk = min(i__1,i__2);
  165. /* Set A(m-kk+1:m,1:n-kk) to zero. */
  166. i__1 = *n - kk;
  167. for (j = 1; j <= i__1; ++j) {
  168. i__2 = *m;
  169. for (i__ = *m - kk + 1; i__ <= i__2; ++i__) {
  170. a[i__ + j * a_dim1] = 0.;
  171. /* L10: */
  172. }
  173. /* L20: */
  174. }
  175. } else {
  176. kk = 0;
  177. }
  178. /* Use unblocked code for the first or only block. */
  179. i__1 = *m - kk;
  180. i__2 = *n - kk;
  181. i__3 = *k - kk;
  182. _starpu_dorg2l_(&i__1, &i__2, &i__3, &a[a_offset], lda, &tau[1], &work[1], &iinfo)
  183. ;
  184. if (kk > 0) {
  185. /* Use blocked code */
  186. i__1 = *k;
  187. i__2 = nb;
  188. for (i__ = *k - kk + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
  189. i__2) {
  190. /* Computing MIN */
  191. i__3 = nb, i__4 = *k - i__ + 1;
  192. ib = min(i__3,i__4);
  193. if (*n - *k + i__ > 1) {
  194. /* Form the triangular factor of the block reflector */
  195. /* H = H(i+ib-1) . . . H(i+1) H(i) */
  196. i__3 = *m - *k + i__ + ib - 1;
  197. _starpu_dlarft_("Backward", "Columnwise", &i__3, &ib, &a[(*n - *k +
  198. i__) * a_dim1 + 1], lda, &tau[i__], &work[1], &ldwork);
  199. /* Apply H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left */
  200. i__3 = *m - *k + i__ + ib - 1;
  201. i__4 = *n - *k + i__ - 1;
  202. _starpu_dlarfb_("Left", "No transpose", "Backward", "Columnwise", &
  203. i__3, &i__4, &ib, &a[(*n - *k + i__) * a_dim1 + 1],
  204. lda, &work[1], &ldwork, &a[a_offset], lda, &work[ib +
  205. 1], &ldwork);
  206. }
  207. /* Apply H to rows 1:m-k+i+ib-1 of current block */
  208. i__3 = *m - *k + i__ + ib - 1;
  209. _starpu_dorg2l_(&i__3, &ib, &ib, &a[(*n - *k + i__) * a_dim1 + 1], lda, &
  210. tau[i__], &work[1], &iinfo);
  211. /* Set rows m-k+i+ib:m of current block to zero */
  212. i__3 = *n - *k + i__ + ib - 1;
  213. for (j = *n - *k + i__; j <= i__3; ++j) {
  214. i__4 = *m;
  215. for (l = *m - *k + i__ + ib; l <= i__4; ++l) {
  216. a[l + j * a_dim1] = 0.;
  217. /* L30: */
  218. }
  219. /* L40: */
  220. }
  221. /* L50: */
  222. }
  223. }
  224. work[1] = (doublereal) iws;
  225. return 0;
  226. /* End of DORGQL */
  227. } /* _starpu_dorgql_ */