dgelqf.c 7.2 KB

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