dgeqrf.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* dgeqrf.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_dgeqrf_(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, nx, iws, nbmin, iinfo;
  25. extern /* Subroutine */ int _starpu_dgeqr2_(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. /* DGEQRF computes a QR factorization of a real M-by-N matrix A: */
  45. /* A = Q * R. */
  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, the elements on and above the diagonal of the array */
  55. /* contain the min(M,N)-by-N upper trapezoidal matrix R (R is */
  56. /* upper triangular if m >= n); the elements below the diagonal, */
  57. /* with the array TAU, represent the orthogonal matrix Q as a */
  58. /* product of min(m,n) elementary reflectors (see Further */
  59. /* Details). */
  60. /* LDA (input) INTEGER */
  61. /* The leading dimension of the array A. LDA >= max(1,M). */
  62. /* TAU (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  63. /* The scalar factors of the elementary reflectors (see Further */
  64. /* Details). */
  65. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  66. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  67. /* LWORK (input) INTEGER */
  68. /* The dimension of the array WORK. LWORK >= max(1,N). */
  69. /* For optimum performance LWORK >= N*NB, where NB is */
  70. /* the optimal blocksize. */
  71. /* If LWORK = -1, then a workspace query is assumed; the routine */
  72. /* only calculates the optimal size of the WORK array, returns */
  73. /* this value as the first entry of the WORK array, and no error */
  74. /* message related to LWORK is issued by XERBLA. */
  75. /* INFO (output) INTEGER */
  76. /* = 0: successful exit */
  77. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  78. /* Further Details */
  79. /* =============== */
  80. /* The matrix Q is represented as a product of elementary reflectors */
  81. /* Q = H(1) H(2) . . . H(k), where k = min(m,n). */
  82. /* Each H(i) has the form */
  83. /* H(i) = I - tau * v * v' */
  84. /* where tau is a real scalar, and v is a real vector with */
  85. /* v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), */
  86. /* and tau in TAU(i). */
  87. /* ===================================================================== */
  88. /* .. Local Scalars .. */
  89. /* .. */
  90. /* .. External Subroutines .. */
  91. /* .. */
  92. /* .. Intrinsic Functions .. */
  93. /* .. */
  94. /* .. External Functions .. */
  95. /* .. */
  96. /* .. Executable Statements .. */
  97. /* Test the input arguments */
  98. /* Parameter adjustments */
  99. a_dim1 = *lda;
  100. a_offset = 1 + a_dim1;
  101. a -= a_offset;
  102. --tau;
  103. --work;
  104. /* Function Body */
  105. *info = 0;
  106. nb = _starpu_ilaenv_(&c__1, "DGEQRF", " ", m, n, &c_n1, &c_n1);
  107. lwkopt = *n * nb;
  108. work[1] = (doublereal) lwkopt;
  109. lquery = *lwork == -1;
  110. if (*m < 0) {
  111. *info = -1;
  112. } else if (*n < 0) {
  113. *info = -2;
  114. } else if (*lda < max(1,*m)) {
  115. *info = -4;
  116. } else if (*lwork < max(1,*n) && ! lquery) {
  117. *info = -7;
  118. }
  119. if (*info != 0) {
  120. i__1 = -(*info);
  121. _starpu_xerbla_("DGEQRF", &i__1);
  122. return 0;
  123. } else if (lquery) {
  124. return 0;
  125. }
  126. /* Quick return if possible */
  127. k = min(*m,*n);
  128. if (k == 0) {
  129. work[1] = 1.;
  130. return 0;
  131. }
  132. nbmin = 2;
  133. nx = 0;
  134. iws = *n;
  135. if (nb > 1 && nb < k) {
  136. /* Determine when to cross over from blocked to unblocked code. */
  137. /* Computing MAX */
  138. i__1 = 0, i__2 = _starpu_ilaenv_(&c__3, "DGEQRF", " ", m, n, &c_n1, &c_n1);
  139. nx = max(i__1,i__2);
  140. if (nx < k) {
  141. /* Determine if workspace is large enough for blocked code. */
  142. ldwork = *n;
  143. iws = ldwork * nb;
  144. if (*lwork < iws) {
  145. /* Not enough workspace to use optimal NB: reduce NB and */
  146. /* determine the minimum value of NB. */
  147. nb = *lwork / ldwork;
  148. /* Computing MAX */
  149. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DGEQRF", " ", m, n, &c_n1, &
  150. c_n1);
  151. nbmin = max(i__1,i__2);
  152. }
  153. }
  154. }
  155. if (nb >= nbmin && nb < k && nx < k) {
  156. /* Use blocked code initially */
  157. i__1 = k - nx;
  158. i__2 = nb;
  159. for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
  160. /* Computing MIN */
  161. i__3 = k - i__ + 1;
  162. ib = min(i__3,nb);
  163. /* Compute the QR factorization of the current block */
  164. /* A(i:m,i:i+ib-1) */
  165. i__3 = *m - i__ + 1;
  166. _starpu_dgeqr2_(&i__3, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
  167. 1], &iinfo);
  168. if (i__ + ib <= *n) {
  169. /* Form the triangular factor of the block reflector */
  170. /* H = H(i) H(i+1) . . . H(i+ib-1) */
  171. i__3 = *m - i__ + 1;
  172. _starpu_dlarft_("Forward", "Columnwise", &i__3, &ib, &a[i__ + i__ *
  173. a_dim1], lda, &tau[i__], &work[1], &ldwork);
  174. /* Apply H' to A(i:m,i+ib:n) from the left */
  175. i__3 = *m - i__ + 1;
  176. i__4 = *n - i__ - ib + 1;
  177. _starpu_dlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__3, &
  178. i__4, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
  179. ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &work[ib
  180. + 1], &ldwork);
  181. }
  182. /* L10: */
  183. }
  184. } else {
  185. i__ = 1;
  186. }
  187. /* Use unblocked code to factor the last or only block. */
  188. if (i__ <= k) {
  189. i__2 = *m - i__ + 1;
  190. i__1 = *n - i__ + 1;
  191. _starpu_dgeqr2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
  192. , &iinfo);
  193. }
  194. work[1] = (doublereal) iws;
  195. return 0;
  196. /* End of DGEQRF */
  197. } /* _starpu_dgeqrf_ */