dorgqr.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /* dorgqr.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_dorgqr_(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;
  24. /* Local variables */
  25. integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
  26. extern /* Subroutine */ int _starpu_dorg2r_(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. /* DORGQR generates an M-by-N real matrix Q with orthonormal columns, */
  46. /* which is defined as the first N columns of a product of K elementary */
  47. /* reflectors of order M */
  48. /* Q = H(1) H(2) . . . H(k) */
  49. /* as returned by DGEQRF. */
  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 i-th column must contain the vector which */
  61. /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
  62. /* returned by DGEQRF in the first 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 DGEQRF. */
  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. nb = _starpu_ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1);
  105. lwkopt = max(1,*n) * nb;
  106. work[1] = (doublereal) lwkopt;
  107. lquery = *lwork == -1;
  108. if (*m < 0) {
  109. *info = -1;
  110. } else if (*n < 0 || *n > *m) {
  111. *info = -2;
  112. } else if (*k < 0 || *k > *n) {
  113. *info = -3;
  114. } else if (*lda < max(1,*m)) {
  115. *info = -5;
  116. } else if (*lwork < max(1,*n) && ! lquery) {
  117. *info = -8;
  118. }
  119. if (*info != 0) {
  120. i__1 = -(*info);
  121. _starpu_xerbla_("DORGQR", &i__1);
  122. return 0;
  123. } else if (lquery) {
  124. return 0;
  125. }
  126. /* Quick return if possible */
  127. if (*n <= 0) {
  128. work[1] = 1.;
  129. return 0;
  130. }
  131. nbmin = 2;
  132. nx = 0;
  133. iws = *n;
  134. if (nb > 1 && nb < *k) {
  135. /* Determine when to cross over from blocked to unblocked code. */
  136. /* Computing MAX */
  137. i__1 = 0, i__2 = _starpu_ilaenv_(&c__3, "DORGQR", " ", m, n, k, &c_n1);
  138. nx = max(i__1,i__2);
  139. if (nx < *k) {
  140. /* Determine if workspace is large enough for blocked code. */
  141. ldwork = *n;
  142. iws = ldwork * nb;
  143. if (*lwork < iws) {
  144. /* Not enough workspace to use optimal NB: reduce NB and */
  145. /* determine the minimum value of NB. */
  146. nb = *lwork / ldwork;
  147. /* Computing MAX */
  148. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DORGQR", " ", m, n, k, &c_n1);
  149. nbmin = max(i__1,i__2);
  150. }
  151. }
  152. }
  153. if (nb >= nbmin && nb < *k && nx < *k) {
  154. /* Use blocked code after the last block. */
  155. /* The first kk columns are handled by the block method. */
  156. ki = (*k - nx - 1) / nb * nb;
  157. /* Computing MIN */
  158. i__1 = *k, i__2 = ki + nb;
  159. kk = min(i__1,i__2);
  160. /* Set A(1:kk,kk+1:n) to zero. */
  161. i__1 = *n;
  162. for (j = kk + 1; j <= i__1; ++j) {
  163. i__2 = kk;
  164. for (i__ = 1; i__ <= i__2; ++i__) {
  165. a[i__ + j * a_dim1] = 0.;
  166. /* L10: */
  167. }
  168. /* L20: */
  169. }
  170. } else {
  171. kk = 0;
  172. }
  173. /* Use unblocked code for the last or only block. */
  174. if (kk < *n) {
  175. i__1 = *m - kk;
  176. i__2 = *n - kk;
  177. i__3 = *k - kk;
  178. _starpu_dorg2r_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
  179. tau[kk + 1], &work[1], &iinfo);
  180. }
  181. if (kk > 0) {
  182. /* Use blocked code */
  183. i__1 = -nb;
  184. for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
  185. /* Computing MIN */
  186. i__2 = nb, i__3 = *k - i__ + 1;
  187. ib = min(i__2,i__3);
  188. if (i__ + ib <= *n) {
  189. /* Form the triangular factor of the block reflector */
  190. /* H = H(i) H(i+1) . . . H(i+ib-1) */
  191. i__2 = *m - i__ + 1;
  192. _starpu_dlarft_("Forward", "Columnwise", &i__2, &ib, &a[i__ + i__ *
  193. a_dim1], lda, &tau[i__], &work[1], &ldwork);
  194. /* Apply H to A(i:m,i+ib:n) from the left */
  195. i__2 = *m - i__ + 1;
  196. i__3 = *n - i__ - ib + 1;
  197. _starpu_dlarfb_("Left", "No transpose", "Forward", "Columnwise", &
  198. i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
  199. 1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &
  200. work[ib + 1], &ldwork);
  201. }
  202. /* Apply H to rows i:m of current block */
  203. i__2 = *m - i__ + 1;
  204. _starpu_dorg2r_(&i__2, &ib, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
  205. work[1], &iinfo);
  206. /* Set rows 1:i-1 of current block to zero */
  207. i__2 = i__ + ib - 1;
  208. for (j = i__; j <= i__2; ++j) {
  209. i__3 = i__ - 1;
  210. for (l = 1; l <= i__3; ++l) {
  211. a[l + j * a_dim1] = 0.;
  212. /* L30: */
  213. }
  214. /* L40: */
  215. }
  216. /* L50: */
  217. }
  218. }
  219. work[1] = (doublereal) iws;
  220. return 0;
  221. /* End of DORGQR */
  222. } /* _starpu_dorgqr_ */