dtzrzf.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* dtzrzf.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_dtzrzf_(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, i__5;
  23. /* Local variables */
  24. integer i__, m1, ib, nb, ki, kk, mu, nx, iws, nbmin;
  25. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *), _starpu_dlarzb_(
  26. char *, char *, char *, char *, integer *, integer *, integer *,
  27. integer *, doublereal *, integer *, doublereal *, integer *,
  28. doublereal *, integer *, doublereal *, integer *);
  29. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  30. integer *, integer *);
  31. extern /* Subroutine */ int _starpu_dlarzt_(char *, char *, integer *, integer *,
  32. doublereal *, integer *, doublereal *, doublereal *, integer *), _starpu_dlatrz_(integer *, integer *, integer *,
  33. doublereal *, integer *, doublereal *, doublereal *);
  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. /* DTZRZF reduces the M-by-N ( M<=N ) real upper trapezoidal matrix A */
  46. /* to upper triangular form by means of orthogonal transformations. */
  47. /* The upper trapezoidal matrix A is factored as */
  48. /* A = ( R 0 ) * Z, */
  49. /* where Z is an N-by-N orthogonal matrix and R is an M-by-M upper */
  50. /* triangular matrix. */
  51. /* Arguments */
  52. /* ========= */
  53. /* M (input) INTEGER */
  54. /* The number of rows of the matrix A. M >= 0. */
  55. /* N (input) INTEGER */
  56. /* The number of columns of the matrix A. N >= M. */
  57. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  58. /* On entry, the leading M-by-N upper trapezoidal part of the */
  59. /* array A must contain the matrix to be factorized. */
  60. /* On exit, the leading M-by-M upper triangular part of A */
  61. /* contains the upper triangular matrix R, and elements M+1 to */
  62. /* N of the first M rows of A, with the array TAU, represent the */
  63. /* orthogonal matrix Z as a product of M elementary reflectors. */
  64. /* LDA (input) INTEGER */
  65. /* The leading dimension of the array A. LDA >= max(1,M). */
  66. /* TAU (output) DOUBLE PRECISION array, dimension (M) */
  67. /* The scalar factors of the elementary reflectors. */
  68. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  69. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  70. /* LWORK (input) INTEGER */
  71. /* The dimension of the array WORK. LWORK >= max(1,M). */
  72. /* For optimum performance LWORK >= M*NB, where NB is */
  73. /* the optimal blocksize. */
  74. /* If LWORK = -1, then a workspace query is assumed; the routine */
  75. /* only calculates the optimal size of the WORK array, returns */
  76. /* this value as the first entry of the WORK array, and no error */
  77. /* message related to LWORK is issued by XERBLA. */
  78. /* INFO (output) INTEGER */
  79. /* = 0: successful exit */
  80. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  81. /* Further Details */
  82. /* =============== */
  83. /* Based on contributions by */
  84. /* A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
  85. /* The factorization is obtained by Householder's method. The kth */
  86. /* transformation matrix, Z( k ), which is used to introduce zeros into */
  87. /* the ( m - k + 1 )th row of A, is given in the form */
  88. /* Z( k ) = ( I 0 ), */
  89. /* ( 0 T( k ) ) */
  90. /* where */
  91. /* T( k ) = I - tau*u( k )*u( k )', u( k ) = ( 1 ), */
  92. /* ( 0 ) */
  93. /* ( z( k ) ) */
  94. /* tau is a scalar and z( k ) is an ( n - m ) element vector. */
  95. /* tau and z( k ) are chosen to annihilate the elements of the kth row */
  96. /* of X. */
  97. /* The scalar tau is returned in the kth element of TAU and the vector */
  98. /* u( k ) in the kth row of A, such that the elements of z( k ) are */
  99. /* in a( k, m + 1 ), ..., a( k, n ). The elements of R are returned in */
  100. /* the upper triangular part of A. */
  101. /* Z is given by */
  102. /* Z = Z( 1 ) * Z( 2 ) * ... * Z( m ). */
  103. /* ===================================================================== */
  104. /* .. Parameters .. */
  105. /* .. */
  106. /* .. Local Scalars .. */
  107. /* .. */
  108. /* .. External Subroutines .. */
  109. /* .. */
  110. /* .. Intrinsic Functions .. */
  111. /* .. */
  112. /* .. External Functions .. */
  113. /* .. */
  114. /* .. Executable Statements .. */
  115. /* Test the input arguments */
  116. /* Parameter adjustments */
  117. a_dim1 = *lda;
  118. a_offset = 1 + a_dim1;
  119. a -= a_offset;
  120. --tau;
  121. --work;
  122. /* Function Body */
  123. *info = 0;
  124. lquery = *lwork == -1;
  125. if (*m < 0) {
  126. *info = -1;
  127. } else if (*n < *m) {
  128. *info = -2;
  129. } else if (*lda < max(1,*m)) {
  130. *info = -4;
  131. }
  132. if (*info == 0) {
  133. if (*m == 0 || *m == *n) {
  134. lwkopt = 1;
  135. } else {
  136. /* Determine the block size. */
  137. nb = _starpu_ilaenv_(&c__1, "DGERQF", " ", m, n, &c_n1, &c_n1);
  138. lwkopt = *m * nb;
  139. }
  140. work[1] = (doublereal) lwkopt;
  141. if (*lwork < max(1,*m) && ! lquery) {
  142. *info = -7;
  143. }
  144. }
  145. if (*info != 0) {
  146. i__1 = -(*info);
  147. _starpu_xerbla_("DTZRZF", &i__1);
  148. return 0;
  149. } else if (lquery) {
  150. return 0;
  151. }
  152. /* Quick return if possible */
  153. if (*m == 0) {
  154. return 0;
  155. } else if (*m == *n) {
  156. i__1 = *n;
  157. for (i__ = 1; i__ <= i__1; ++i__) {
  158. tau[i__] = 0.;
  159. /* L10: */
  160. }
  161. return 0;
  162. }
  163. nbmin = 2;
  164. nx = 1;
  165. iws = *m;
  166. if (nb > 1 && nb < *m) {
  167. /* Determine when to cross over from blocked to unblocked code. */
  168. /* Computing MAX */
  169. i__1 = 0, i__2 = _starpu_ilaenv_(&c__3, "DGERQF", " ", m, n, &c_n1, &c_n1);
  170. nx = max(i__1,i__2);
  171. if (nx < *m) {
  172. /* Determine if workspace is large enough for blocked code. */
  173. ldwork = *m;
  174. iws = ldwork * nb;
  175. if (*lwork < iws) {
  176. /* Not enough workspace to use optimal NB: reduce NB and */
  177. /* determine the minimum value of NB. */
  178. nb = *lwork / ldwork;
  179. /* Computing MAX */
  180. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DGERQF", " ", m, n, &c_n1, &
  181. c_n1);
  182. nbmin = max(i__1,i__2);
  183. }
  184. }
  185. }
  186. if (nb >= nbmin && nb < *m && nx < *m) {
  187. /* Use blocked code initially. */
  188. /* The last kk rows are handled by the block method. */
  189. /* Computing MIN */
  190. i__1 = *m + 1;
  191. m1 = min(i__1,*n);
  192. ki = (*m - nx - 1) / nb * nb;
  193. /* Computing MIN */
  194. i__1 = *m, i__2 = ki + nb;
  195. kk = min(i__1,i__2);
  196. i__1 = *m - kk + 1;
  197. i__2 = -nb;
  198. for (i__ = *m - kk + ki + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1;
  199. i__ += i__2) {
  200. /* Computing MIN */
  201. i__3 = *m - i__ + 1;
  202. ib = min(i__3,nb);
  203. /* Compute the TZ factorization of the current block */
  204. /* A(i:i+ib-1,i:n) */
  205. i__3 = *n - i__ + 1;
  206. i__4 = *n - *m;
  207. _starpu_dlatrz_(&ib, &i__3, &i__4, &a[i__ + i__ * a_dim1], lda, &tau[i__],
  208. &work[1]);
  209. if (i__ > 1) {
  210. /* Form the triangular factor of the block reflector */
  211. /* H = H(i+ib-1) . . . H(i+1) H(i) */
  212. i__3 = *n - *m;
  213. _starpu_dlarzt_("Backward", "Rowwise", &i__3, &ib, &a[i__ + m1 *
  214. a_dim1], lda, &tau[i__], &work[1], &ldwork);
  215. /* Apply H to A(1:i-1,i:n) from the right */
  216. i__3 = i__ - 1;
  217. i__4 = *n - i__ + 1;
  218. i__5 = *n - *m;
  219. _starpu_dlarzb_("Right", "No transpose", "Backward", "Rowwise", &i__3,
  220. &i__4, &ib, &i__5, &a[i__ + m1 * a_dim1], lda, &work[
  221. 1], &ldwork, &a[i__ * a_dim1 + 1], lda, &work[ib + 1],
  222. &ldwork)
  223. ;
  224. }
  225. /* L20: */
  226. }
  227. mu = i__ + nb - 1;
  228. } else {
  229. mu = *m;
  230. }
  231. /* Use unblocked code to factor the last or only block */
  232. if (mu > 0) {
  233. i__2 = *n - *m;
  234. _starpu_dlatrz_(&mu, n, &i__2, &a[a_offset], lda, &tau[1], &work[1]);
  235. }
  236. work[1] = (doublereal) lwkopt;
  237. return 0;
  238. /* End of DTZRZF */
  239. } /* _starpu_dtzrzf_ */