dormqr.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /* dormqr.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__2 = 2;
  17. static integer c__65 = 65;
  18. /* Subroutine */ int _starpu_dormqr_(char *side, char *trans, integer *m, integer *n,
  19. integer *k, doublereal *a, integer *lda, doublereal *tau, doublereal *
  20. c__, integer *ldc, doublereal *work, integer *lwork, integer *info)
  21. {
  22. /* System generated locals */
  23. address a__1[2];
  24. integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
  25. i__5;
  26. char ch__1[2];
  27. /* Builtin functions */
  28. /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
  29. /* Local variables */
  30. integer i__;
  31. doublereal t[4160] /* was [65][64] */;
  32. integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
  33. logical left;
  34. extern logical _starpu_lsame_(char *, char *);
  35. integer nbmin, iinfo;
  36. extern /* Subroutine */ int _starpu_dorm2r_(char *, char *, integer *, integer *,
  37. integer *, doublereal *, integer *, doublereal *, doublereal *,
  38. integer *, doublereal *, integer *), _starpu_dlarfb_(char
  39. *, char *, char *, char *, integer *, integer *, integer *,
  40. doublereal *, integer *, doublereal *, integer *, doublereal *,
  41. integer *, doublereal *, integer *), _starpu_dlarft_(char *, char *, integer *, integer *, doublereal
  42. *, integer *, doublereal *, doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  43. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  44. integer *, integer *);
  45. logical notran;
  46. integer ldwork, lwkopt;
  47. logical lquery;
  48. /* -- LAPACK routine (version 3.2) -- */
  49. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  50. /* November 2006 */
  51. /* .. Scalar Arguments .. */
  52. /* .. */
  53. /* .. Array Arguments .. */
  54. /* .. */
  55. /* Purpose */
  56. /* ======= */
  57. /* DORMQR overwrites the general real M-by-N matrix C with */
  58. /* SIDE = 'L' SIDE = 'R' */
  59. /* TRANS = 'N': Q * C C * Q */
  60. /* TRANS = 'T': Q**T * C C * Q**T */
  61. /* where Q is a real orthogonal matrix defined as the product of k */
  62. /* elementary reflectors */
  63. /* Q = H(1) H(2) . . . H(k) */
  64. /* as returned by DGEQRF. Q is of order M if SIDE = 'L' and of order N */
  65. /* if SIDE = 'R'. */
  66. /* Arguments */
  67. /* ========= */
  68. /* SIDE (input) CHARACTER*1 */
  69. /* = 'L': apply Q or Q**T from the Left; */
  70. /* = 'R': apply Q or Q**T from the Right. */
  71. /* TRANS (input) CHARACTER*1 */
  72. /* = 'N': No transpose, apply Q; */
  73. /* = 'T': Transpose, apply Q**T. */
  74. /* M (input) INTEGER */
  75. /* The number of rows of the matrix C. M >= 0. */
  76. /* N (input) INTEGER */
  77. /* The number of columns of the matrix C. N >= 0. */
  78. /* K (input) INTEGER */
  79. /* The number of elementary reflectors whose product defines */
  80. /* the matrix Q. */
  81. /* If SIDE = 'L', M >= K >= 0; */
  82. /* if SIDE = 'R', N >= K >= 0. */
  83. /* A (input) DOUBLE PRECISION array, dimension (LDA,K) */
  84. /* The i-th column must contain the vector which defines the */
  85. /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
  86. /* DGEQRF in the first k columns of its array argument A. */
  87. /* A is modified by the routine but restored on exit. */
  88. /* LDA (input) INTEGER */
  89. /* The leading dimension of the array A. */
  90. /* If SIDE = 'L', LDA >= max(1,M); */
  91. /* if SIDE = 'R', LDA >= max(1,N). */
  92. /* TAU (input) DOUBLE PRECISION array, dimension (K) */
  93. /* TAU(i) must contain the scalar factor of the elementary */
  94. /* reflector H(i), as returned by DGEQRF. */
  95. /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
  96. /* On entry, the M-by-N matrix C. */
  97. /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
  98. /* LDC (input) INTEGER */
  99. /* The leading dimension of the array C. LDC >= max(1,M). */
  100. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  101. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  102. /* LWORK (input) INTEGER */
  103. /* The dimension of the array WORK. */
  104. /* If SIDE = 'L', LWORK >= max(1,N); */
  105. /* if SIDE = 'R', LWORK >= max(1,M). */
  106. /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
  107. /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
  108. /* blocksize. */
  109. /* If LWORK = -1, then a workspace query is assumed; the routine */
  110. /* only calculates the optimal size of the WORK array, returns */
  111. /* this value as the first entry of the WORK array, and no error */
  112. /* message related to LWORK is issued by XERBLA. */
  113. /* INFO (output) INTEGER */
  114. /* = 0: successful exit */
  115. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  116. /* ===================================================================== */
  117. /* .. Parameters .. */
  118. /* .. */
  119. /* .. Local Scalars .. */
  120. /* .. */
  121. /* .. Local Arrays .. */
  122. /* .. */
  123. /* .. External Functions .. */
  124. /* .. */
  125. /* .. External Subroutines .. */
  126. /* .. */
  127. /* .. Intrinsic Functions .. */
  128. /* .. */
  129. /* .. Executable Statements .. */
  130. /* Test the input arguments */
  131. /* Parameter adjustments */
  132. a_dim1 = *lda;
  133. a_offset = 1 + a_dim1;
  134. a -= a_offset;
  135. --tau;
  136. c_dim1 = *ldc;
  137. c_offset = 1 + c_dim1;
  138. c__ -= c_offset;
  139. --work;
  140. /* Function Body */
  141. *info = 0;
  142. left = _starpu_lsame_(side, "L");
  143. notran = _starpu_lsame_(trans, "N");
  144. lquery = *lwork == -1;
  145. /* NQ is the order of Q and NW is the minimum dimension of WORK */
  146. if (left) {
  147. nq = *m;
  148. nw = *n;
  149. } else {
  150. nq = *n;
  151. nw = *m;
  152. }
  153. if (! left && ! _starpu_lsame_(side, "R")) {
  154. *info = -1;
  155. } else if (! notran && ! _starpu_lsame_(trans, "T")) {
  156. *info = -2;
  157. } else if (*m < 0) {
  158. *info = -3;
  159. } else if (*n < 0) {
  160. *info = -4;
  161. } else if (*k < 0 || *k > nq) {
  162. *info = -5;
  163. } else if (*lda < max(1,nq)) {
  164. *info = -7;
  165. } else if (*ldc < max(1,*m)) {
  166. *info = -10;
  167. } else if (*lwork < max(1,nw) && ! lquery) {
  168. *info = -12;
  169. }
  170. if (*info == 0) {
  171. /* Determine the block size. NB may be at most NBMAX, where NBMAX */
  172. /* is used to define the local array T. */
  173. /* Computing MIN */
  174. /* Writing concatenation */
  175. i__3[0] = 1, a__1[0] = side;
  176. i__3[1] = 1, a__1[1] = trans;
  177. s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
  178. i__1 = 64, i__2 = _starpu_ilaenv_(&c__1, "DORMQR", ch__1, m, n, k, &c_n1);
  179. nb = min(i__1,i__2);
  180. lwkopt = max(1,nw) * nb;
  181. work[1] = (doublereal) lwkopt;
  182. }
  183. if (*info != 0) {
  184. i__1 = -(*info);
  185. _starpu_xerbla_("DORMQR", &i__1);
  186. return 0;
  187. } else if (lquery) {
  188. return 0;
  189. }
  190. /* Quick return if possible */
  191. if (*m == 0 || *n == 0 || *k == 0) {
  192. work[1] = 1.;
  193. return 0;
  194. }
  195. nbmin = 2;
  196. ldwork = nw;
  197. if (nb > 1 && nb < *k) {
  198. iws = nw * nb;
  199. if (*lwork < iws) {
  200. nb = *lwork / ldwork;
  201. /* Computing MAX */
  202. /* Writing concatenation */
  203. i__3[0] = 1, a__1[0] = side;
  204. i__3[1] = 1, a__1[1] = trans;
  205. s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
  206. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DORMQR", ch__1, m, n, k, &c_n1);
  207. nbmin = max(i__1,i__2);
  208. }
  209. } else {
  210. iws = nw;
  211. }
  212. if (nb < nbmin || nb >= *k) {
  213. /* Use unblocked code */
  214. _starpu_dorm2r_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
  215. c_offset], ldc, &work[1], &iinfo);
  216. } else {
  217. /* Use blocked code */
  218. if (left && ! notran || ! left && notran) {
  219. i1 = 1;
  220. i2 = *k;
  221. i3 = nb;
  222. } else {
  223. i1 = (*k - 1) / nb * nb + 1;
  224. i2 = 1;
  225. i3 = -nb;
  226. }
  227. if (left) {
  228. ni = *n;
  229. jc = 1;
  230. } else {
  231. mi = *m;
  232. ic = 1;
  233. }
  234. i__1 = i2;
  235. i__2 = i3;
  236. for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
  237. /* Computing MIN */
  238. i__4 = nb, i__5 = *k - i__ + 1;
  239. ib = min(i__4,i__5);
  240. /* Form the triangular factor of the block reflector */
  241. /* H = H(i) H(i+1) . . . H(i+ib-1) */
  242. i__4 = nq - i__ + 1;
  243. _starpu_dlarft_("Forward", "Columnwise", &i__4, &ib, &a[i__ + i__ *
  244. a_dim1], lda, &tau[i__], t, &c__65)
  245. ;
  246. if (left) {
  247. /* H or H' is applied to C(i:m,1:n) */
  248. mi = *m - i__ + 1;
  249. ic = i__;
  250. } else {
  251. /* H or H' is applied to C(1:m,i:n) */
  252. ni = *n - i__ + 1;
  253. jc = i__;
  254. }
  255. /* Apply H or H' */
  256. _starpu_dlarfb_(side, trans, "Forward", "Columnwise", &mi, &ni, &ib, &a[
  257. i__ + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc *
  258. c_dim1], ldc, &work[1], &ldwork);
  259. /* L10: */
  260. }
  261. }
  262. work[1] = (doublereal) lwkopt;
  263. return 0;
  264. /* End of DORMQR */
  265. } /* _starpu_dormqr_ */