dgehrd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /* dgehrd.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 integer c__65 = 65;
  19. static doublereal c_b25 = -1.;
  20. static doublereal c_b26 = 1.;
  21. /* Subroutine */ int _starpu_dgehrd_(integer *n, integer *ilo, integer *ihi,
  22. doublereal *a, integer *lda, doublereal *tau, doublereal *work,
  23. integer *lwork, integer *info)
  24. {
  25. /* System generated locals */
  26. integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
  27. /* Local variables */
  28. integer i__, j;
  29. doublereal t[4160] /* was [65][64] */;
  30. integer ib;
  31. doublereal ei;
  32. integer nb, nh, nx, iws;
  33. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  34. integer *, doublereal *, doublereal *, integer *, doublereal *,
  35. integer *, doublereal *, doublereal *, integer *);
  36. integer nbmin, iinfo;
  37. extern /* Subroutine */ int _starpu_dtrmm_(char *, char *, char *, char *,
  38. integer *, integer *, doublereal *, doublereal *, integer *,
  39. doublereal *, integer *), _starpu_daxpy_(
  40. integer *, doublereal *, doublereal *, integer *, doublereal *,
  41. integer *), _starpu_dgehd2_(integer *, integer *, integer *, doublereal *,
  42. integer *, doublereal *, doublereal *, integer *), _starpu_dlahr2_(
  43. integer *, integer *, integer *, doublereal *, integer *,
  44. doublereal *, doublereal *, integer *, doublereal *, integer *),
  45. _starpu_dlarfb_(char *, char *, char *, char *, integer *, integer *,
  46. integer *, doublereal *, integer *, doublereal *, integer *,
  47. doublereal *, integer *, doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  48. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  49. integer *, integer *);
  50. integer ldwork, lwkopt;
  51. logical lquery;
  52. /* -- LAPACK routine (version 3.2) -- */
  53. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  54. /* November 2006 */
  55. /* .. Scalar Arguments .. */
  56. /* .. */
  57. /* .. Array Arguments .. */
  58. /* .. */
  59. /* Purpose */
  60. /* ======= */
  61. /* DGEHRD reduces a real general matrix A to upper Hessenberg form H by */
  62. /* an orthogonal similarity transformation: Q' * A * Q = H . */
  63. /* Arguments */
  64. /* ========= */
  65. /* N (input) INTEGER */
  66. /* The order of the matrix A. N >= 0. */
  67. /* ILO (input) INTEGER */
  68. /* IHI (input) INTEGER */
  69. /* It is assumed that A is already upper triangular in rows */
  70. /* and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally */
  71. /* set by a previous call to DGEBAL; otherwise they should be */
  72. /* set to 1 and N respectively. See Further Details. */
  73. /* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
  74. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  75. /* On entry, the N-by-N general matrix to be reduced. */
  76. /* On exit, the upper triangle and the first subdiagonal of A */
  77. /* are overwritten with the upper Hessenberg matrix H, and the */
  78. /* elements below the first subdiagonal, with the array TAU, */
  79. /* represent the orthogonal matrix Q as a product of elementary */
  80. /* reflectors. See Further Details. */
  81. /* LDA (input) INTEGER */
  82. /* The leading dimension of the array A. LDA >= max(1,N). */
  83. /* TAU (output) DOUBLE PRECISION array, dimension (N-1) */
  84. /* The scalar factors of the elementary reflectors (see Further */
  85. /* Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to */
  86. /* zero. */
  87. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */
  88. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  89. /* LWORK (input) INTEGER */
  90. /* The length of the array WORK. LWORK >= max(1,N). */
  91. /* For optimum performance LWORK >= N*NB, where NB is the */
  92. /* optimal blocksize. */
  93. /* If LWORK = -1, then a workspace query is assumed; the routine */
  94. /* only calculates the optimal size of the WORK array, returns */
  95. /* this value as the first entry of the WORK array, and no error */
  96. /* message related to LWORK is issued by XERBLA. */
  97. /* INFO (output) INTEGER */
  98. /* = 0: successful exit */
  99. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  100. /* Further Details */
  101. /* =============== */
  102. /* The matrix Q is represented as a product of (ihi-ilo) elementary */
  103. /* reflectors */
  104. /* Q = H(ilo) H(ilo+1) . . . H(ihi-1). */
  105. /* Each H(i) has the form */
  106. /* H(i) = I - tau * v * v' */
  107. /* where tau is a real scalar, and v is a real vector with */
  108. /* v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on */
  109. /* exit in A(i+2:ihi,i), and tau in TAU(i). */
  110. /* The contents of A are illustrated by the following example, with */
  111. /* n = 7, ilo = 2 and ihi = 6: */
  112. /* on entry, on exit, */
  113. /* ( a a a a a a a ) ( a a h h h h a ) */
  114. /* ( a a a a a a ) ( a h h h h a ) */
  115. /* ( a a a a a a ) ( h h h h h h ) */
  116. /* ( a a a a a a ) ( v2 h h h h h ) */
  117. /* ( a a a a a a ) ( v2 v3 h h h h ) */
  118. /* ( a a a a a a ) ( v2 v3 v4 h h h ) */
  119. /* ( a ) ( a ) */
  120. /* where a denotes an element of the original matrix A, h denotes a */
  121. /* modified element of the upper Hessenberg matrix H, and vi denotes an */
  122. /* element of the vector defining H(i). */
  123. /* This file is a slight modification of LAPACK-3.0's DGEHRD */
  124. /* subroutine incorporating improvements proposed by Quintana-Orti and */
  125. /* Van de Geijn (2005). */
  126. /* ===================================================================== */
  127. /* .. Parameters .. */
  128. /* .. */
  129. /* .. Local Scalars .. */
  130. /* .. */
  131. /* .. Local Arrays .. */
  132. /* .. */
  133. /* .. External Subroutines .. */
  134. /* .. */
  135. /* .. Intrinsic Functions .. */
  136. /* .. */
  137. /* .. External Functions .. */
  138. /* .. */
  139. /* .. Executable Statements .. */
  140. /* Test the input parameters */
  141. /* Parameter adjustments */
  142. a_dim1 = *lda;
  143. a_offset = 1 + a_dim1;
  144. a -= a_offset;
  145. --tau;
  146. --work;
  147. /* Function Body */
  148. *info = 0;
  149. /* Computing MIN */
  150. i__1 = 64, i__2 = _starpu_ilaenv_(&c__1, "DGEHRD", " ", n, ilo, ihi, &c_n1);
  151. nb = min(i__1,i__2);
  152. lwkopt = *n * nb;
  153. work[1] = (doublereal) lwkopt;
  154. lquery = *lwork == -1;
  155. if (*n < 0) {
  156. *info = -1;
  157. } else if (*ilo < 1 || *ilo > max(1,*n)) {
  158. *info = -2;
  159. } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
  160. *info = -3;
  161. } else if (*lda < max(1,*n)) {
  162. *info = -5;
  163. } else if (*lwork < max(1,*n) && ! lquery) {
  164. *info = -8;
  165. }
  166. if (*info != 0) {
  167. i__1 = -(*info);
  168. _starpu_xerbla_("DGEHRD", &i__1);
  169. return 0;
  170. } else if (lquery) {
  171. return 0;
  172. }
  173. /* Set elements 1:ILO-1 and IHI:N-1 of TAU to zero */
  174. i__1 = *ilo - 1;
  175. for (i__ = 1; i__ <= i__1; ++i__) {
  176. tau[i__] = 0.;
  177. /* L10: */
  178. }
  179. i__1 = *n - 1;
  180. for (i__ = max(1,*ihi); i__ <= i__1; ++i__) {
  181. tau[i__] = 0.;
  182. /* L20: */
  183. }
  184. /* Quick return if possible */
  185. nh = *ihi - *ilo + 1;
  186. if (nh <= 1) {
  187. work[1] = 1.;
  188. return 0;
  189. }
  190. /* Determine the block size */
  191. /* Computing MIN */
  192. i__1 = 64, i__2 = _starpu_ilaenv_(&c__1, "DGEHRD", " ", n, ilo, ihi, &c_n1);
  193. nb = min(i__1,i__2);
  194. nbmin = 2;
  195. iws = 1;
  196. if (nb > 1 && nb < nh) {
  197. /* Determine when to cross over from blocked to unblocked code */
  198. /* (last block is always handled by unblocked code) */
  199. /* Computing MAX */
  200. i__1 = nb, i__2 = _starpu_ilaenv_(&c__3, "DGEHRD", " ", n, ilo, ihi, &c_n1);
  201. nx = max(i__1,i__2);
  202. if (nx < nh) {
  203. /* Determine if workspace is large enough for blocked code */
  204. iws = *n * nb;
  205. if (*lwork < iws) {
  206. /* Not enough workspace to use optimal NB: determine the */
  207. /* minimum value of NB, and reduce NB or force use of */
  208. /* unblocked code */
  209. /* Computing MAX */
  210. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DGEHRD", " ", n, ilo, ihi, &
  211. c_n1);
  212. nbmin = max(i__1,i__2);
  213. if (*lwork >= *n * nbmin) {
  214. nb = *lwork / *n;
  215. } else {
  216. nb = 1;
  217. }
  218. }
  219. }
  220. }
  221. ldwork = *n;
  222. if (nb < nbmin || nb >= nh) {
  223. /* Use unblocked code below */
  224. i__ = *ilo;
  225. } else {
  226. /* Use blocked code */
  227. i__1 = *ihi - 1 - nx;
  228. i__2 = nb;
  229. for (i__ = *ilo; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
  230. /* Computing MIN */
  231. i__3 = nb, i__4 = *ihi - i__;
  232. ib = min(i__3,i__4);
  233. /* Reduce columns i:i+ib-1 to Hessenberg form, returning the */
  234. /* matrices V and T of the block reflector H = I - V*T*V' */
  235. /* which performs the reduction, and also the matrix Y = A*V*T */
  236. _starpu_dlahr2_(ihi, &i__, &ib, &a[i__ * a_dim1 + 1], lda, &tau[i__], t, &
  237. c__65, &work[1], &ldwork);
  238. /* Apply the block reflector H to A(1:ihi,i+ib:ihi) from the */
  239. /* right, computing A := A - Y * V'. V(i+ib,ib-1) must be set */
  240. /* to 1 */
  241. ei = a[i__ + ib + (i__ + ib - 1) * a_dim1];
  242. a[i__ + ib + (i__ + ib - 1) * a_dim1] = 1.;
  243. i__3 = *ihi - i__ - ib + 1;
  244. _starpu_dgemm_("No transpose", "Transpose", ihi, &i__3, &ib, &c_b25, &
  245. work[1], &ldwork, &a[i__ + ib + i__ * a_dim1], lda, &
  246. c_b26, &a[(i__ + ib) * a_dim1 + 1], lda);
  247. a[i__ + ib + (i__ + ib - 1) * a_dim1] = ei;
  248. /* Apply the block reflector H to A(1:i,i+1:i+ib-1) from the */
  249. /* right */
  250. i__3 = ib - 1;
  251. _starpu_dtrmm_("Right", "Lower", "Transpose", "Unit", &i__, &i__3, &c_b26,
  252. &a[i__ + 1 + i__ * a_dim1], lda, &work[1], &ldwork);
  253. i__3 = ib - 2;
  254. for (j = 0; j <= i__3; ++j) {
  255. _starpu_daxpy_(&i__, &c_b25, &work[ldwork * j + 1], &c__1, &a[(i__ +
  256. j + 1) * a_dim1 + 1], &c__1);
  257. /* L30: */
  258. }
  259. /* Apply the block reflector H to A(i+1:ihi,i+ib:n) from the */
  260. /* left */
  261. i__3 = *ihi - i__;
  262. i__4 = *n - i__ - ib + 1;
  263. _starpu_dlarfb_("Left", "Transpose", "Forward", "Columnwise", &i__3, &
  264. i__4, &ib, &a[i__ + 1 + i__ * a_dim1], lda, t, &c__65, &a[
  265. i__ + 1 + (i__ + ib) * a_dim1], lda, &work[1], &ldwork);
  266. /* L40: */
  267. }
  268. }
  269. /* Use unblocked code to reduce the rest of the matrix */
  270. _starpu_dgehd2_(n, &i__, ihi, &a[a_offset], lda, &tau[1], &work[1], &iinfo);
  271. work[1] = (doublereal) iws;
  272. return 0;
  273. /* End of DGEHRD */
  274. } /* _starpu_dgehrd_ */