dgerqf.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* dgerqf.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_dgerqf_(integer *m, integer *n, doublereal *a, integer *
  19. lda, doublereal *tau, doublereal *work, integer *lwork, integer *info)
  20. {
  21. /* System generated locals */
  22. integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
  23. /* Local variables */
  24. integer i__, k, ib, nb, ki, kk, mu, nu, nx, iws, nbmin, iinfo;
  25. extern /* Subroutine */ int _starpu_dgerq2_(integer *, integer *, doublereal *,
  26. integer *, doublereal *, doublereal *, integer *), _starpu_dlarfb_(char *,
  27. char *, char *, char *, integer *, integer *, integer *,
  28. doublereal *, integer *, doublereal *, integer *, doublereal *,
  29. integer *, doublereal *, integer *), _starpu_dlarft_(char *, char *, integer *, integer *, doublereal
  30. *, integer *, doublereal *, doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  31. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  32. integer *, integer *);
  33. integer ldwork, lwkopt;
  34. logical lquery;
  35. /* -- LAPACK routine (version 3.2) -- */
  36. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  37. /* November 2006 */
  38. /* .. Scalar Arguments .. */
  39. /* .. */
  40. /* .. Array Arguments .. */
  41. /* .. */
  42. /* Purpose */
  43. /* ======= */
  44. /* DGERQF computes an RQ factorization of a real M-by-N matrix A: */
  45. /* A = R * Q. */
  46. /* Arguments */
  47. /* ========= */
  48. /* M (input) INTEGER */
  49. /* The number of rows of the matrix A. M >= 0. */
  50. /* N (input) INTEGER */
  51. /* The number of columns of the matrix A. N >= 0. */
  52. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  53. /* On entry, the M-by-N matrix A. */
  54. /* On exit, */
  55. /* if m <= n, the upper triangle of the subarray */
  56. /* A(1:m,n-m+1:n) contains the M-by-M upper triangular matrix R; */
  57. /* if m >= n, the elements on and above the (m-n)-th subdiagonal */
  58. /* contain the M-by-N upper trapezoidal matrix R; */
  59. /* the remaining elements, with the array TAU, represent the */
  60. /* orthogonal matrix Q as a product of min(m,n) elementary */
  61. /* reflectors (see Further Details). */
  62. /* LDA (input) INTEGER */
  63. /* The leading dimension of the array A. LDA >= max(1,M). */
  64. /* TAU (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  65. /* The scalar factors of the elementary reflectors (see Further */
  66. /* Details). */
  67. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  68. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  69. /* LWORK (input) INTEGER */
  70. /* The dimension of the array WORK. LWORK >= max(1,M). */
  71. /* For optimum performance LWORK >= M*NB, where NB is */
  72. /* the optimal blocksize. */
  73. /* If LWORK = -1, then a workspace query is assumed; the routine */
  74. /* only calculates the optimal size of the WORK array, returns */
  75. /* this value as the first entry of the WORK array, and no error */
  76. /* message related to LWORK is issued by XERBLA. */
  77. /* INFO (output) INTEGER */
  78. /* = 0: successful exit */
  79. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  80. /* Further Details */
  81. /* =============== */
  82. /* The matrix Q is represented as a product of elementary reflectors */
  83. /* Q = H(1) H(2) . . . H(k), where k = min(m,n). */
  84. /* Each H(i) has the form */
  85. /* H(i) = I - tau * v * v' */
  86. /* where tau is a real scalar, and v is a real vector with */
  87. /* v(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in */
  88. /* A(m-k+i,1:n-k+i-1), and tau in TAU(i). */
  89. /* ===================================================================== */
  90. /* .. Local Scalars .. */
  91. /* .. */
  92. /* .. External Subroutines .. */
  93. /* .. */
  94. /* .. Intrinsic Functions .. */
  95. /* .. */
  96. /* .. External Functions .. */
  97. /* .. */
  98. /* .. Executable Statements .. */
  99. /* Test the input arguments */
  100. /* Parameter adjustments */
  101. a_dim1 = *lda;
  102. a_offset = 1 + a_dim1;
  103. a -= a_offset;
  104. --tau;
  105. --work;
  106. /* Function Body */
  107. *info = 0;
  108. lquery = *lwork == -1;
  109. if (*m < 0) {
  110. *info = -1;
  111. } else if (*n < 0) {
  112. *info = -2;
  113. } else if (*lda < max(1,*m)) {
  114. *info = -4;
  115. }
  116. if (*info == 0) {
  117. k = min(*m,*n);
  118. if (k == 0) {
  119. lwkopt = 1;
  120. } else {
  121. nb = _starpu_ilaenv_(&c__1, "DGERQF", " ", m, n, &c_n1, &c_n1);
  122. lwkopt = *m * nb;
  123. }
  124. work[1] = (doublereal) lwkopt;
  125. if (*lwork < max(1,*m) && ! lquery) {
  126. *info = -7;
  127. }
  128. }
  129. if (*info != 0) {
  130. i__1 = -(*info);
  131. _starpu_xerbla_("DGERQF", &i__1);
  132. return 0;
  133. } else if (lquery) {
  134. return 0;
  135. }
  136. /* Quick return if possible */
  137. if (k == 0) {
  138. return 0;
  139. }
  140. nbmin = 2;
  141. nx = 1;
  142. iws = *m;
  143. if (nb > 1 && nb < k) {
  144. /* Determine when to cross over from blocked to unblocked code. */
  145. /* Computing MAX */
  146. i__1 = 0, i__2 = _starpu_ilaenv_(&c__3, "DGERQF", " ", m, n, &c_n1, &c_n1);
  147. nx = max(i__1,i__2);
  148. if (nx < k) {
  149. /* Determine if workspace is large enough for blocked code. */
  150. ldwork = *m;
  151. iws = ldwork * nb;
  152. if (*lwork < iws) {
  153. /* Not enough workspace to use optimal NB: reduce NB and */
  154. /* determine the minimum value of NB. */
  155. nb = *lwork / ldwork;
  156. /* Computing MAX */
  157. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DGERQF", " ", m, n, &c_n1, &
  158. c_n1);
  159. nbmin = max(i__1,i__2);
  160. }
  161. }
  162. }
  163. if (nb >= nbmin && nb < k && nx < k) {
  164. /* Use blocked code initially. */
  165. /* The last kk rows are handled by the block method. */
  166. ki = (k - nx - 1) / nb * nb;
  167. /* Computing MIN */
  168. i__1 = k, i__2 = ki + nb;
  169. kk = min(i__1,i__2);
  170. i__1 = k - kk + 1;
  171. i__2 = -nb;
  172. for (i__ = k - kk + ki + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__
  173. += i__2) {
  174. /* Computing MIN */
  175. i__3 = k - i__ + 1;
  176. ib = min(i__3,nb);
  177. /* Compute the RQ factorization of the current block */
  178. /* A(m-k+i:m-k+i+ib-1,1:n-k+i+ib-1) */
  179. i__3 = *n - k + i__ + ib - 1;
  180. _starpu_dgerq2_(&ib, &i__3, &a[*m - k + i__ + a_dim1], lda, &tau[i__], &
  181. work[1], &iinfo);
  182. if (*m - k + i__ > 1) {
  183. /* Form the triangular factor of the block reflector */
  184. /* H = H(i+ib-1) . . . H(i+1) H(i) */
  185. i__3 = *n - k + i__ + ib - 1;
  186. _starpu_dlarft_("Backward", "Rowwise", &i__3, &ib, &a[*m - k + i__ +
  187. a_dim1], lda, &tau[i__], &work[1], &ldwork);
  188. /* Apply H to A(1:m-k+i-1,1:n-k+i+ib-1) from the right */
  189. i__3 = *m - k + i__ - 1;
  190. i__4 = *n - k + i__ + ib - 1;
  191. _starpu_dlarfb_("Right", "No transpose", "Backward", "Rowwise", &i__3,
  192. &i__4, &ib, &a[*m - k + i__ + a_dim1], lda, &work[1],
  193. &ldwork, &a[a_offset], lda, &work[ib + 1], &ldwork);
  194. }
  195. /* L10: */
  196. }
  197. mu = *m - k + i__ + nb - 1;
  198. nu = *n - k + i__ + nb - 1;
  199. } else {
  200. mu = *m;
  201. nu = *n;
  202. }
  203. /* Use unblocked code to factor the last or only block */
  204. if (mu > 0 && nu > 0) {
  205. _starpu_dgerq2_(&mu, &nu, &a[a_offset], lda, &tau[1], &work[1], &iinfo);
  206. }
  207. work[1] = (doublereal) iws;
  208. return 0;
  209. /* End of DGERQF */
  210. } /* _starpu_dgerqf_ */