dgebrd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /* dgebrd.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. static doublereal c_b21 = -1.;
  19. static doublereal c_b22 = 1.;
  20. /* Subroutine */ int _starpu_dgebrd_(integer *m, integer *n, doublereal *a, integer *
  21. lda, doublereal *d__, doublereal *e, doublereal *tauq, doublereal *
  22. taup, doublereal *work, integer *lwork, integer *info)
  23. {
  24. /* System generated locals */
  25. integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
  26. /* Local variables */
  27. integer i__, j, nb, nx;
  28. doublereal ws;
  29. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  30. integer *, doublereal *, doublereal *, integer *, doublereal *,
  31. integer *, doublereal *, doublereal *, integer *);
  32. integer nbmin, iinfo, minmn;
  33. extern /* Subroutine */ int _starpu_dgebd2_(integer *, integer *, doublereal *,
  34. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  35. doublereal *, integer *), _starpu_dlabrd_(integer *, integer *, integer *
  36. , doublereal *, integer *, doublereal *, doublereal *, doublereal
  37. *, doublereal *, doublereal *, integer *, doublereal *, integer *)
  38. , _starpu_xerbla_(char *, integer *);
  39. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  40. integer *, integer *);
  41. integer ldwrkx, ldwrky, lwkopt;
  42. logical lquery;
  43. /* -- LAPACK routine (version 3.2) -- */
  44. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  45. /* November 2006 */
  46. /* .. Scalar Arguments .. */
  47. /* .. */
  48. /* .. Array Arguments .. */
  49. /* .. */
  50. /* Purpose */
  51. /* ======= */
  52. /* DGEBRD reduces a general real M-by-N matrix A to upper or lower */
  53. /* bidiagonal form B by an orthogonal transformation: Q**T * A * P = B. */
  54. /* If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal. */
  55. /* Arguments */
  56. /* ========= */
  57. /* M (input) INTEGER */
  58. /* The number of rows in the matrix A. M >= 0. */
  59. /* N (input) INTEGER */
  60. /* The number of columns in the matrix A. N >= 0. */
  61. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  62. /* On entry, the M-by-N general matrix to be reduced. */
  63. /* On exit, */
  64. /* if m >= n, the diagonal and the first superdiagonal are */
  65. /* overwritten with the upper bidiagonal matrix B; the */
  66. /* elements below the diagonal, with the array TAUQ, represent */
  67. /* the orthogonal matrix Q as a product of elementary */
  68. /* reflectors, and the elements above the first superdiagonal, */
  69. /* with the array TAUP, represent the orthogonal matrix P as */
  70. /* a product of elementary reflectors; */
  71. /* if m < n, the diagonal and the first subdiagonal are */
  72. /* overwritten with the lower bidiagonal matrix B; the */
  73. /* elements below the first subdiagonal, with the array TAUQ, */
  74. /* represent the orthogonal matrix Q as a product of */
  75. /* elementary reflectors, and the elements above the diagonal, */
  76. /* with the array TAUP, represent the orthogonal matrix P as */
  77. /* a product of elementary reflectors. */
  78. /* See Further Details. */
  79. /* LDA (input) INTEGER */
  80. /* The leading dimension of the array A. LDA >= max(1,M). */
  81. /* D (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  82. /* The diagonal elements of the bidiagonal matrix B: */
  83. /* D(i) = A(i,i). */
  84. /* E (output) DOUBLE PRECISION array, dimension (min(M,N)-1) */
  85. /* The off-diagonal elements of the bidiagonal matrix B: */
  86. /* if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1; */
  87. /* if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1. */
  88. /* TAUQ (output) DOUBLE PRECISION array dimension (min(M,N)) */
  89. /* The scalar factors of the elementary reflectors which */
  90. /* represent the orthogonal matrix Q. See Further Details. */
  91. /* TAUP (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  92. /* The scalar factors of the elementary reflectors which */
  93. /* represent the orthogonal matrix P. See Further Details. */
  94. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  95. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  96. /* LWORK (input) INTEGER */
  97. /* The length of the array WORK. LWORK >= max(1,M,N). */
  98. /* For optimum performance LWORK >= (M+N)*NB, where NB */
  99. /* is the optimal blocksize. */
  100. /* If LWORK = -1, then a workspace query is assumed; the routine */
  101. /* only calculates the optimal size of the WORK array, returns */
  102. /* this value as the first entry of the WORK array, and no error */
  103. /* message related to LWORK is issued by XERBLA. */
  104. /* INFO (output) INTEGER */
  105. /* = 0: successful exit */
  106. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  107. /* Further Details */
  108. /* =============== */
  109. /* The matrices Q and P are represented as products of elementary */
  110. /* reflectors: */
  111. /* If m >= n, */
  112. /* Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1) */
  113. /* Each H(i) and G(i) has the form: */
  114. /* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u' */
  115. /* where tauq and taup are real scalars, and v and u are real vectors; */
  116. /* v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i); */
  117. /* u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n); */
  118. /* tauq is stored in TAUQ(i) and taup in TAUP(i). */
  119. /* If m < n, */
  120. /* Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m) */
  121. /* Each H(i) and G(i) has the form: */
  122. /* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u' */
  123. /* where tauq and taup are real scalars, and v and u are real vectors; */
  124. /* v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i); */
  125. /* u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n); */
  126. /* tauq is stored in TAUQ(i) and taup in TAUP(i). */
  127. /* The contents of A on exit are illustrated by the following examples: */
  128. /* m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n): */
  129. /* ( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 ) */
  130. /* ( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 ) */
  131. /* ( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 ) */
  132. /* ( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 ) */
  133. /* ( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 ) */
  134. /* ( v1 v2 v3 v4 v5 ) */
  135. /* where d and e denote diagonal and off-diagonal elements of B, vi */
  136. /* denotes an element of the vector defining H(i), and ui an element of */
  137. /* the vector defining G(i). */
  138. /* ===================================================================== */
  139. /* .. Parameters .. */
  140. /* .. */
  141. /* .. Local Scalars .. */
  142. /* .. */
  143. /* .. External Subroutines .. */
  144. /* .. */
  145. /* .. Intrinsic Functions .. */
  146. /* .. */
  147. /* .. External Functions .. */
  148. /* .. */
  149. /* .. Executable Statements .. */
  150. /* Test the input parameters */
  151. /* Parameter adjustments */
  152. a_dim1 = *lda;
  153. a_offset = 1 + a_dim1;
  154. a -= a_offset;
  155. --d__;
  156. --e;
  157. --tauq;
  158. --taup;
  159. --work;
  160. /* Function Body */
  161. *info = 0;
  162. /* Computing MAX */
  163. i__1 = 1, i__2 = _starpu_ilaenv_(&c__1, "DGEBRD", " ", m, n, &c_n1, &c_n1);
  164. nb = max(i__1,i__2);
  165. lwkopt = (*m + *n) * nb;
  166. work[1] = (doublereal) lwkopt;
  167. lquery = *lwork == -1;
  168. if (*m < 0) {
  169. *info = -1;
  170. } else if (*n < 0) {
  171. *info = -2;
  172. } else if (*lda < max(1,*m)) {
  173. *info = -4;
  174. } else /* if(complicated condition) */ {
  175. /* Computing MAX */
  176. i__1 = max(1,*m);
  177. if (*lwork < max(i__1,*n) && ! lquery) {
  178. *info = -10;
  179. }
  180. }
  181. if (*info < 0) {
  182. i__1 = -(*info);
  183. _starpu_xerbla_("DGEBRD", &i__1);
  184. return 0;
  185. } else if (lquery) {
  186. return 0;
  187. }
  188. /* Quick return if possible */
  189. minmn = min(*m,*n);
  190. if (minmn == 0) {
  191. work[1] = 1.;
  192. return 0;
  193. }
  194. ws = (doublereal) max(*m,*n);
  195. ldwrkx = *m;
  196. ldwrky = *n;
  197. if (nb > 1 && nb < minmn) {
  198. /* Set the crossover point NX. */
  199. /* Computing MAX */
  200. i__1 = nb, i__2 = _starpu_ilaenv_(&c__3, "DGEBRD", " ", m, n, &c_n1, &c_n1);
  201. nx = max(i__1,i__2);
  202. /* Determine when to switch from blocked to unblocked code. */
  203. if (nx < minmn) {
  204. ws = (doublereal) ((*m + *n) * nb);
  205. if ((doublereal) (*lwork) < ws) {
  206. /* Not enough work space for the optimal NB, consider using */
  207. /* a smaller block size. */
  208. nbmin = _starpu_ilaenv_(&c__2, "DGEBRD", " ", m, n, &c_n1, &c_n1);
  209. if (*lwork >= (*m + *n) * nbmin) {
  210. nb = *lwork / (*m + *n);
  211. } else {
  212. nb = 1;
  213. nx = minmn;
  214. }
  215. }
  216. }
  217. } else {
  218. nx = minmn;
  219. }
  220. i__1 = minmn - nx;
  221. i__2 = nb;
  222. for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
  223. /* Reduce rows and columns i:i+nb-1 to bidiagonal form and return */
  224. /* the matrices X and Y which are needed to update the unreduced */
  225. /* part of the matrix */
  226. i__3 = *m - i__ + 1;
  227. i__4 = *n - i__ + 1;
  228. _starpu_dlabrd_(&i__3, &i__4, &nb, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[
  229. i__], &tauq[i__], &taup[i__], &work[1], &ldwrkx, &work[ldwrkx
  230. * nb + 1], &ldwrky);
  231. /* Update the trailing submatrix A(i+nb:m,i+nb:n), using an update */
  232. /* of the form A := A - V*Y' - X*U' */
  233. i__3 = *m - i__ - nb + 1;
  234. i__4 = *n - i__ - nb + 1;
  235. _starpu_dgemm_("No transpose", "Transpose", &i__3, &i__4, &nb, &c_b21, &a[i__
  236. + nb + i__ * a_dim1], lda, &work[ldwrkx * nb + nb + 1], &
  237. ldwrky, &c_b22, &a[i__ + nb + (i__ + nb) * a_dim1], lda);
  238. i__3 = *m - i__ - nb + 1;
  239. i__4 = *n - i__ - nb + 1;
  240. _starpu_dgemm_("No transpose", "No transpose", &i__3, &i__4, &nb, &c_b21, &
  241. work[nb + 1], &ldwrkx, &a[i__ + (i__ + nb) * a_dim1], lda, &
  242. c_b22, &a[i__ + nb + (i__ + nb) * a_dim1], lda);
  243. /* Copy diagonal and off-diagonal elements of B back into A */
  244. if (*m >= *n) {
  245. i__3 = i__ + nb - 1;
  246. for (j = i__; j <= i__3; ++j) {
  247. a[j + j * a_dim1] = d__[j];
  248. a[j + (j + 1) * a_dim1] = e[j];
  249. /* L10: */
  250. }
  251. } else {
  252. i__3 = i__ + nb - 1;
  253. for (j = i__; j <= i__3; ++j) {
  254. a[j + j * a_dim1] = d__[j];
  255. a[j + 1 + j * a_dim1] = e[j];
  256. /* L20: */
  257. }
  258. }
  259. /* L30: */
  260. }
  261. /* Use unblocked code to reduce the remainder of the matrix */
  262. i__2 = *m - i__ + 1;
  263. i__1 = *n - i__ + 1;
  264. _starpu_dgebd2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], &
  265. tauq[i__], &taup[i__], &work[1], &iinfo);
  266. work[1] = ws;
  267. return 0;
  268. /* End of DGEBRD */
  269. } /* _starpu_dgebrd_ */