dormlq.c 9.3 KB

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