dlalsa.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /* dlalsa.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 doublereal c_b7 = 1.;
  15. static doublereal c_b8 = 0.;
  16. static integer c__2 = 2;
  17. /* Subroutine */ int _starpu_dlalsa_(integer *icompq, integer *smlsiz, integer *n,
  18. integer *nrhs, doublereal *b, integer *ldb, doublereal *bx, integer *
  19. ldbx, doublereal *u, integer *ldu, doublereal *vt, integer *k,
  20. doublereal *difl, doublereal *difr, doublereal *z__, doublereal *
  21. poles, integer *givptr, integer *givcol, integer *ldgcol, integer *
  22. perm, doublereal *givnum, doublereal *c__, doublereal *s, doublereal *
  23. work, integer *iwork, integer *info)
  24. {
  25. /* System generated locals */
  26. integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, b_dim1,
  27. b_offset, bx_dim1, bx_offset, difl_dim1, difl_offset, difr_dim1,
  28. difr_offset, givnum_dim1, givnum_offset, poles_dim1, poles_offset,
  29. u_dim1, u_offset, vt_dim1, vt_offset, z_dim1, z_offset, i__1,
  30. i__2;
  31. /* Builtin functions */
  32. integer pow_ii(integer *, integer *);
  33. /* Local variables */
  34. integer i__, j, i1, ic, lf, nd, ll, nl, nr, im1, nlf, nrf, lvl, ndb1,
  35. nlp1, lvl2, nrp1, nlvl, sqre;
  36. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  37. integer *, doublereal *, doublereal *, integer *, doublereal *,
  38. integer *, doublereal *, doublereal *, integer *);
  39. integer inode, ndiml, ndimr;
  40. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  41. doublereal *, integer *), _starpu_dlals0_(integer *, integer *, integer *,
  42. integer *, integer *, doublereal *, integer *, doublereal *,
  43. integer *, integer *, integer *, integer *, integer *, doublereal
  44. *, integer *, doublereal *, doublereal *, doublereal *,
  45. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  46. integer *), _starpu_dlasdt_(integer *, integer *, integer *, integer *,
  47. integer *, integer *, integer *), _starpu_xerbla_(char *, integer *);
  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. /* DLALSA is an itermediate step in solving the least squares problem */
  58. /* by computing the SVD of the coefficient matrix in compact form (The */
  59. /* singular vectors are computed as products of simple orthorgonal */
  60. /* matrices.). */
  61. /* If ICOMPQ = 0, DLALSA applies the inverse of the left singular vector */
  62. /* matrix of an upper bidiagonal matrix to the right hand side; and if */
  63. /* ICOMPQ = 1, DLALSA applies the right singular vector matrix to the */
  64. /* right hand side. The singular vector matrices were generated in */
  65. /* compact form by DLALSA. */
  66. /* Arguments */
  67. /* ========= */
  68. /* ICOMPQ (input) INTEGER */
  69. /* Specifies whether the left or the right singular vector */
  70. /* matrix is involved. */
  71. /* = 0: Left singular vector matrix */
  72. /* = 1: Right singular vector matrix */
  73. /* SMLSIZ (input) INTEGER */
  74. /* The maximum size of the subproblems at the bottom of the */
  75. /* computation tree. */
  76. /* N (input) INTEGER */
  77. /* The row and column dimensions of the upper bidiagonal matrix. */
  78. /* NRHS (input) INTEGER */
  79. /* The number of columns of B and BX. NRHS must be at least 1. */
  80. /* B (input/output) DOUBLE PRECISION array, dimension ( LDB, NRHS ) */
  81. /* On input, B contains the right hand sides of the least */
  82. /* squares problem in rows 1 through M. */
  83. /* On output, B contains the solution X in rows 1 through N. */
  84. /* LDB (input) INTEGER */
  85. /* The leading dimension of B in the calling subprogram. */
  86. /* LDB must be at least max(1,MAX( M, N ) ). */
  87. /* BX (output) DOUBLE PRECISION array, dimension ( LDBX, NRHS ) */
  88. /* On exit, the result of applying the left or right singular */
  89. /* vector matrix to B. */
  90. /* LDBX (input) INTEGER */
  91. /* The leading dimension of BX. */
  92. /* U (input) DOUBLE PRECISION array, dimension ( LDU, SMLSIZ ). */
  93. /* On entry, U contains the left singular vector matrices of all */
  94. /* subproblems at the bottom level. */
  95. /* LDU (input) INTEGER, LDU = > N. */
  96. /* The leading dimension of arrays U, VT, DIFL, DIFR, */
  97. /* POLES, GIVNUM, and Z. */
  98. /* VT (input) DOUBLE PRECISION array, dimension ( LDU, SMLSIZ+1 ). */
  99. /* On entry, VT' contains the right singular vector matrices of */
  100. /* all subproblems at the bottom level. */
  101. /* K (input) INTEGER array, dimension ( N ). */
  102. /* DIFL (input) DOUBLE PRECISION array, dimension ( LDU, NLVL ). */
  103. /* where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1. */
  104. /* DIFR (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ). */
  105. /* On entry, DIFL(*, I) and DIFR(*, 2 * I -1) record */
  106. /* distances between singular values on the I-th level and */
  107. /* singular values on the (I -1)-th level, and DIFR(*, 2 * I) */
  108. /* record the normalizing factors of the right singular vectors */
  109. /* matrices of subproblems on I-th level. */
  110. /* Z (input) DOUBLE PRECISION array, dimension ( LDU, NLVL ). */
  111. /* On entry, Z(1, I) contains the components of the deflation- */
  112. /* adjusted updating row vector for subproblems on the I-th */
  113. /* level. */
  114. /* POLES (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ). */
  115. /* On entry, POLES(*, 2 * I -1: 2 * I) contains the new and old */
  116. /* singular values involved in the secular equations on the I-th */
  117. /* level. */
  118. /* GIVPTR (input) INTEGER array, dimension ( N ). */
  119. /* On entry, GIVPTR( I ) records the number of Givens */
  120. /* rotations performed on the I-th problem on the computation */
  121. /* tree. */
  122. /* GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 * NLVL ). */
  123. /* On entry, for each I, GIVCOL(*, 2 * I - 1: 2 * I) records the */
  124. /* locations of Givens rotations performed on the I-th level on */
  125. /* the computation tree. */
  126. /* LDGCOL (input) INTEGER, LDGCOL = > N. */
  127. /* The leading dimension of arrays GIVCOL and PERM. */
  128. /* PERM (input) INTEGER array, dimension ( LDGCOL, NLVL ). */
  129. /* On entry, PERM(*, I) records permutations done on the I-th */
  130. /* level of the computation tree. */
  131. /* GIVNUM (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ). */
  132. /* On entry, GIVNUM(*, 2 *I -1 : 2 * I) records the C- and S- */
  133. /* values of Givens rotations performed on the I-th level on the */
  134. /* computation tree. */
  135. /* C (input) DOUBLE PRECISION array, dimension ( N ). */
  136. /* On entry, if the I-th subproblem is not square, */
  137. /* C( I ) contains the C-value of a Givens rotation related to */
  138. /* the right null space of the I-th subproblem. */
  139. /* S (input) DOUBLE PRECISION array, dimension ( N ). */
  140. /* On entry, if the I-th subproblem is not square, */
  141. /* S( I ) contains the S-value of a Givens rotation related to */
  142. /* the right null space of the I-th subproblem. */
  143. /* WORK (workspace) DOUBLE PRECISION array. */
  144. /* The dimension must be at least N. */
  145. /* IWORK (workspace) INTEGER array. */
  146. /* The dimension must be at least 3 * N */
  147. /* INFO (output) INTEGER */
  148. /* = 0: successful exit. */
  149. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  150. /* Further Details */
  151. /* =============== */
  152. /* Based on contributions by */
  153. /* Ming Gu and Ren-Cang Li, Computer Science Division, University of */
  154. /* California at Berkeley, USA */
  155. /* Osni Marques, LBNL/NERSC, USA */
  156. /* ===================================================================== */
  157. /* .. Parameters .. */
  158. /* .. */
  159. /* .. Local Scalars .. */
  160. /* .. */
  161. /* .. External Subroutines .. */
  162. /* .. */
  163. /* .. Executable Statements .. */
  164. /* Test the input parameters. */
  165. /* Parameter adjustments */
  166. b_dim1 = *ldb;
  167. b_offset = 1 + b_dim1;
  168. b -= b_offset;
  169. bx_dim1 = *ldbx;
  170. bx_offset = 1 + bx_dim1;
  171. bx -= bx_offset;
  172. givnum_dim1 = *ldu;
  173. givnum_offset = 1 + givnum_dim1;
  174. givnum -= givnum_offset;
  175. poles_dim1 = *ldu;
  176. poles_offset = 1 + poles_dim1;
  177. poles -= poles_offset;
  178. z_dim1 = *ldu;
  179. z_offset = 1 + z_dim1;
  180. z__ -= z_offset;
  181. difr_dim1 = *ldu;
  182. difr_offset = 1 + difr_dim1;
  183. difr -= difr_offset;
  184. difl_dim1 = *ldu;
  185. difl_offset = 1 + difl_dim1;
  186. difl -= difl_offset;
  187. vt_dim1 = *ldu;
  188. vt_offset = 1 + vt_dim1;
  189. vt -= vt_offset;
  190. u_dim1 = *ldu;
  191. u_offset = 1 + u_dim1;
  192. u -= u_offset;
  193. --k;
  194. --givptr;
  195. perm_dim1 = *ldgcol;
  196. perm_offset = 1 + perm_dim1;
  197. perm -= perm_offset;
  198. givcol_dim1 = *ldgcol;
  199. givcol_offset = 1 + givcol_dim1;
  200. givcol -= givcol_offset;
  201. --c__;
  202. --s;
  203. --work;
  204. --iwork;
  205. /* Function Body */
  206. *info = 0;
  207. if (*icompq < 0 || *icompq > 1) {
  208. *info = -1;
  209. } else if (*smlsiz < 3) {
  210. *info = -2;
  211. } else if (*n < *smlsiz) {
  212. *info = -3;
  213. } else if (*nrhs < 1) {
  214. *info = -4;
  215. } else if (*ldb < *n) {
  216. *info = -6;
  217. } else if (*ldbx < *n) {
  218. *info = -8;
  219. } else if (*ldu < *n) {
  220. *info = -10;
  221. } else if (*ldgcol < *n) {
  222. *info = -19;
  223. }
  224. if (*info != 0) {
  225. i__1 = -(*info);
  226. _starpu_xerbla_("DLALSA", &i__1);
  227. return 0;
  228. }
  229. /* Book-keeping and setting up the computation tree. */
  230. inode = 1;
  231. ndiml = inode + *n;
  232. ndimr = ndiml + *n;
  233. _starpu_dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
  234. smlsiz);
  235. /* The following code applies back the left singular vector factors. */
  236. /* For applying back the right singular vector factors, go to 50. */
  237. if (*icompq == 1) {
  238. goto L50;
  239. }
  240. /* The nodes on the bottom level of the tree were solved */
  241. /* by DLASDQ. The corresponding left and right singular vector */
  242. /* matrices are in explicit form. First apply back the left */
  243. /* singular vector matrices. */
  244. ndb1 = (nd + 1) / 2;
  245. i__1 = nd;
  246. for (i__ = ndb1; i__ <= i__1; ++i__) {
  247. /* IC : center row of each node */
  248. /* NL : number of rows of left subproblem */
  249. /* NR : number of rows of right subproblem */
  250. /* NLF: starting row of the left subproblem */
  251. /* NRF: starting row of the right subproblem */
  252. i1 = i__ - 1;
  253. ic = iwork[inode + i1];
  254. nl = iwork[ndiml + i1];
  255. nr = iwork[ndimr + i1];
  256. nlf = ic - nl;
  257. nrf = ic + 1;
  258. _starpu_dgemm_("T", "N", &nl, nrhs, &nl, &c_b7, &u[nlf + u_dim1], ldu, &b[nlf
  259. + b_dim1], ldb, &c_b8, &bx[nlf + bx_dim1], ldbx);
  260. _starpu_dgemm_("T", "N", &nr, nrhs, &nr, &c_b7, &u[nrf + u_dim1], ldu, &b[nrf
  261. + b_dim1], ldb, &c_b8, &bx[nrf + bx_dim1], ldbx);
  262. /* L10: */
  263. }
  264. /* Next copy the rows of B that correspond to unchanged rows */
  265. /* in the bidiagonal matrix to BX. */
  266. i__1 = nd;
  267. for (i__ = 1; i__ <= i__1; ++i__) {
  268. ic = iwork[inode + i__ - 1];
  269. _starpu_dcopy_(nrhs, &b[ic + b_dim1], ldb, &bx[ic + bx_dim1], ldbx);
  270. /* L20: */
  271. }
  272. /* Finally go through the left singular vector matrices of all */
  273. /* the other subproblems bottom-up on the tree. */
  274. j = pow_ii(&c__2, &nlvl);
  275. sqre = 0;
  276. for (lvl = nlvl; lvl >= 1; --lvl) {
  277. lvl2 = (lvl << 1) - 1;
  278. /* find the first node LF and last node LL on */
  279. /* the current level LVL */
  280. if (lvl == 1) {
  281. lf = 1;
  282. ll = 1;
  283. } else {
  284. i__1 = lvl - 1;
  285. lf = pow_ii(&c__2, &i__1);
  286. ll = (lf << 1) - 1;
  287. }
  288. i__1 = ll;
  289. for (i__ = lf; i__ <= i__1; ++i__) {
  290. im1 = i__ - 1;
  291. ic = iwork[inode + im1];
  292. nl = iwork[ndiml + im1];
  293. nr = iwork[ndimr + im1];
  294. nlf = ic - nl;
  295. nrf = ic + 1;
  296. --j;
  297. _starpu_dlals0_(icompq, &nl, &nr, &sqre, nrhs, &bx[nlf + bx_dim1], ldbx, &
  298. b[nlf + b_dim1], ldb, &perm[nlf + lvl * perm_dim1], &
  299. givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
  300. givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
  301. poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
  302. lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
  303. j], &s[j], &work[1], info);
  304. /* L30: */
  305. }
  306. /* L40: */
  307. }
  308. goto L90;
  309. /* ICOMPQ = 1: applying back the right singular vector factors. */
  310. L50:
  311. /* First now go through the right singular vector matrices of all */
  312. /* the tree nodes top-down. */
  313. j = 0;
  314. i__1 = nlvl;
  315. for (lvl = 1; lvl <= i__1; ++lvl) {
  316. lvl2 = (lvl << 1) - 1;
  317. /* Find the first node LF and last node LL on */
  318. /* the current level LVL. */
  319. if (lvl == 1) {
  320. lf = 1;
  321. ll = 1;
  322. } else {
  323. i__2 = lvl - 1;
  324. lf = pow_ii(&c__2, &i__2);
  325. ll = (lf << 1) - 1;
  326. }
  327. i__2 = lf;
  328. for (i__ = ll; i__ >= i__2; --i__) {
  329. im1 = i__ - 1;
  330. ic = iwork[inode + im1];
  331. nl = iwork[ndiml + im1];
  332. nr = iwork[ndimr + im1];
  333. nlf = ic - nl;
  334. nrf = ic + 1;
  335. if (i__ == ll) {
  336. sqre = 0;
  337. } else {
  338. sqre = 1;
  339. }
  340. ++j;
  341. _starpu_dlals0_(icompq, &nl, &nr, &sqre, nrhs, &b[nlf + b_dim1], ldb, &bx[
  342. nlf + bx_dim1], ldbx, &perm[nlf + lvl * perm_dim1], &
  343. givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
  344. givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
  345. poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
  346. lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
  347. j], &s[j], &work[1], info);
  348. /* L60: */
  349. }
  350. /* L70: */
  351. }
  352. /* The nodes on the bottom level of the tree were solved */
  353. /* by DLASDQ. The corresponding right singular vector */
  354. /* matrices are in explicit form. Apply them back. */
  355. ndb1 = (nd + 1) / 2;
  356. i__1 = nd;
  357. for (i__ = ndb1; i__ <= i__1; ++i__) {
  358. i1 = i__ - 1;
  359. ic = iwork[inode + i1];
  360. nl = iwork[ndiml + i1];
  361. nr = iwork[ndimr + i1];
  362. nlp1 = nl + 1;
  363. if (i__ == nd) {
  364. nrp1 = nr;
  365. } else {
  366. nrp1 = nr + 1;
  367. }
  368. nlf = ic - nl;
  369. nrf = ic + 1;
  370. _starpu_dgemm_("T", "N", &nlp1, nrhs, &nlp1, &c_b7, &vt[nlf + vt_dim1], ldu, &
  371. b[nlf + b_dim1], ldb, &c_b8, &bx[nlf + bx_dim1], ldbx);
  372. _starpu_dgemm_("T", "N", &nrp1, nrhs, &nrp1, &c_b7, &vt[nrf + vt_dim1], ldu, &
  373. b[nrf + b_dim1], ldb, &c_b8, &bx[nrf + bx_dim1], ldbx);
  374. /* L80: */
  375. }
  376. L90:
  377. return 0;
  378. /* End of DLALSA */
  379. } /* _starpu_dlalsa_ */