dlasda.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /* dlasda.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__0 = 0;
  15. static doublereal c_b11 = 0.;
  16. static doublereal c_b12 = 1.;
  17. static integer c__1 = 1;
  18. static integer c__2 = 2;
  19. /* Subroutine */ int _starpu_dlasda_(integer *icompq, integer *smlsiz, integer *n,
  20. integer *sqre, doublereal *d__, doublereal *e, doublereal *u, integer
  21. *ldu, doublereal *vt, integer *k, doublereal *difl, doublereal *difr,
  22. doublereal *z__, doublereal *poles, integer *givptr, integer *givcol,
  23. integer *ldgcol, integer *perm, doublereal *givnum, doublereal *c__,
  24. doublereal *s, doublereal *work, integer *iwork, integer *info)
  25. {
  26. /* System generated locals */
  27. integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1,
  28. difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset,
  29. poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset,
  30. z_dim1, z_offset, i__1, i__2;
  31. /* Builtin functions */
  32. integer pow_ii(integer *, integer *);
  33. /* Local variables */
  34. integer i__, j, m, i1, ic, lf, nd, ll, nl, vf, nr, vl, im1, ncc, nlf, nrf,
  35. vfi, iwk, vli, lvl, nru, ndb1, nlp1, lvl2, nrp1;
  36. doublereal beta;
  37. integer idxq, nlvl;
  38. doublereal alpha;
  39. integer inode, ndiml, ndimr, idxqi, itemp;
  40. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  41. doublereal *, integer *);
  42. integer sqrei;
  43. extern /* Subroutine */ int _starpu_dlasd6_(integer *, integer *, integer *,
  44. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  45. doublereal *, integer *, integer *, integer *, integer *,
  46. integer *, doublereal *, integer *, doublereal *, doublereal *,
  47. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  48. doublereal *, integer *, integer *);
  49. integer nwork1, nwork2;
  50. extern /* Subroutine */ int _starpu_dlasdq_(char *, integer *, integer *, integer
  51. *, integer *, integer *, doublereal *, doublereal *, doublereal *,
  52. integer *, doublereal *, integer *, doublereal *, integer *,
  53. doublereal *, integer *), _starpu_dlasdt_(integer *, integer *,
  54. integer *, integer *, integer *, integer *, integer *), _starpu_dlaset_(
  55. char *, integer *, integer *, doublereal *, doublereal *,
  56. doublereal *, integer *), _starpu_xerbla_(char *, integer *);
  57. integer smlszp;
  58. /* -- LAPACK auxiliary routine (version 3.2) -- */
  59. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  60. /* November 2006 */
  61. /* .. Scalar Arguments .. */
  62. /* .. */
  63. /* .. Array Arguments .. */
  64. /* .. */
  65. /* Purpose */
  66. /* ======= */
  67. /* Using a divide and conquer approach, DLASDA computes the singular */
  68. /* value decomposition (SVD) of a real upper bidiagonal N-by-M matrix */
  69. /* B with diagonal D and offdiagonal E, where M = N + SQRE. The */
  70. /* algorithm computes the singular values in the SVD B = U * S * VT. */
  71. /* The orthogonal matrices U and VT are optionally computed in */
  72. /* compact form. */
  73. /* A related subroutine, DLASD0, computes the singular values and */
  74. /* the singular vectors in explicit form. */
  75. /* Arguments */
  76. /* ========= */
  77. /* ICOMPQ (input) INTEGER */
  78. /* Specifies whether singular vectors are to be computed */
  79. /* in compact form, as follows */
  80. /* = 0: Compute singular values only. */
  81. /* = 1: Compute singular vectors of upper bidiagonal */
  82. /* matrix in compact form. */
  83. /* SMLSIZ (input) INTEGER */
  84. /* The maximum size of the subproblems at the bottom of the */
  85. /* computation tree. */
  86. /* N (input) INTEGER */
  87. /* The row dimension of the upper bidiagonal matrix. This is */
  88. /* also the dimension of the main diagonal array D. */
  89. /* SQRE (input) INTEGER */
  90. /* Specifies the column dimension of the bidiagonal matrix. */
  91. /* = 0: The bidiagonal matrix has column dimension M = N; */
  92. /* = 1: The bidiagonal matrix has column dimension M = N + 1. */
  93. /* D (input/output) DOUBLE PRECISION array, dimension ( N ) */
  94. /* On entry D contains the main diagonal of the bidiagonal */
  95. /* matrix. On exit D, if INFO = 0, contains its singular values. */
  96. /* E (input) DOUBLE PRECISION array, dimension ( M-1 ) */
  97. /* Contains the subdiagonal entries of the bidiagonal matrix. */
  98. /* On exit, E has been destroyed. */
  99. /* U (output) DOUBLE PRECISION array, */
  100. /* dimension ( LDU, SMLSIZ ) if ICOMPQ = 1, and not referenced */
  101. /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, U contains the left */
  102. /* singular vector matrices of all subproblems at the bottom */
  103. /* level. */
  104. /* LDU (input) INTEGER, LDU = > N. */
  105. /* The leading dimension of arrays U, VT, DIFL, DIFR, POLES, */
  106. /* GIVNUM, and Z. */
  107. /* VT (output) DOUBLE PRECISION array, */
  108. /* dimension ( LDU, SMLSIZ+1 ) if ICOMPQ = 1, and not referenced */
  109. /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, VT' contains the right */
  110. /* singular vector matrices of all subproblems at the bottom */
  111. /* level. */
  112. /* K (output) INTEGER array, */
  113. /* dimension ( N ) if ICOMPQ = 1 and dimension 1 if ICOMPQ = 0. */
  114. /* If ICOMPQ = 1, on exit, K(I) is the dimension of the I-th */
  115. /* secular equation on the computation tree. */
  116. /* DIFL (output) DOUBLE PRECISION array, dimension ( LDU, NLVL ), */
  117. /* where NLVL = floor(log_2 (N/SMLSIZ))). */
  118. /* DIFR (output) DOUBLE PRECISION array, */
  119. /* dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1 and */
  120. /* dimension ( N ) if ICOMPQ = 0. */
  121. /* If ICOMPQ = 1, on exit, DIFL(1:N, I) and DIFR(1:N, 2 * I - 1) */
  122. /* record distances between singular values on the I-th */
  123. /* level and singular values on the (I -1)-th level, and */
  124. /* DIFR(1:N, 2 * I ) contains the normalizing factors for */
  125. /* the right singular vector matrix. See DLASD8 for details. */
  126. /* Z (output) DOUBLE PRECISION array, */
  127. /* dimension ( LDU, NLVL ) if ICOMPQ = 1 and */
  128. /* dimension ( N ) if ICOMPQ = 0. */
  129. /* The first K elements of Z(1, I) contain the components of */
  130. /* the deflation-adjusted updating row vector for subproblems */
  131. /* on the I-th level. */
  132. /* POLES (output) DOUBLE PRECISION array, */
  133. /* dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not referenced */
  134. /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, POLES(1, 2*I - 1) and */
  135. /* POLES(1, 2*I) contain the new and old singular values */
  136. /* involved in the secular equations on the I-th level. */
  137. /* GIVPTR (output) INTEGER array, */
  138. /* dimension ( N ) if ICOMPQ = 1, and not referenced if */
  139. /* ICOMPQ = 0. If ICOMPQ = 1, on exit, GIVPTR( I ) records */
  140. /* the number of Givens rotations performed on the I-th */
  141. /* problem on the computation tree. */
  142. /* GIVCOL (output) INTEGER array, */
  143. /* dimension ( LDGCOL, 2 * NLVL ) if ICOMPQ = 1, and not */
  144. /* referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
  145. /* GIVCOL(1, 2 *I - 1) and GIVCOL(1, 2 *I) record the locations */
  146. /* of Givens rotations performed on the I-th level on the */
  147. /* computation tree. */
  148. /* LDGCOL (input) INTEGER, LDGCOL = > N. */
  149. /* The leading dimension of arrays GIVCOL and PERM. */
  150. /* PERM (output) INTEGER array, */
  151. /* dimension ( LDGCOL, NLVL ) if ICOMPQ = 1, and not referenced */
  152. /* if ICOMPQ = 0. If ICOMPQ = 1, on exit, PERM(1, I) records */
  153. /* permutations done on the I-th level of the computation tree. */
  154. /* GIVNUM (output) DOUBLE PRECISION array, */
  155. /* dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not */
  156. /* referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
  157. /* GIVNUM(1, 2 *I - 1) and GIVNUM(1, 2 *I) record the C- and S- */
  158. /* values of Givens rotations performed on the I-th level on */
  159. /* the computation tree. */
  160. /* C (output) DOUBLE PRECISION array, */
  161. /* dimension ( N ) if ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. */
  162. /* If ICOMPQ = 1 and the I-th subproblem is not square, on exit, */
  163. /* C( I ) contains the C-value of a Givens rotation related to */
  164. /* the right null space of the I-th subproblem. */
  165. /* S (output) DOUBLE PRECISION array, dimension ( N ) if */
  166. /* ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. If ICOMPQ = 1 */
  167. /* and the I-th subproblem is not square, on exit, S( I ) */
  168. /* contains the S-value of a Givens rotation related to */
  169. /* the right null space of the I-th subproblem. */
  170. /* WORK (workspace) DOUBLE PRECISION array, dimension */
  171. /* (6 * N + (SMLSIZ + 1)*(SMLSIZ + 1)). */
  172. /* IWORK (workspace) INTEGER array. */
  173. /* Dimension must be at least (7 * N). */
  174. /* INFO (output) INTEGER */
  175. /* = 0: successful exit. */
  176. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  177. /* > 0: if INFO = 1, an singular value did not converge */
  178. /* Further Details */
  179. /* =============== */
  180. /* Based on contributions by */
  181. /* Ming Gu and Huan Ren, Computer Science Division, University of */
  182. /* California at Berkeley, USA */
  183. /* ===================================================================== */
  184. /* .. Parameters .. */
  185. /* .. */
  186. /* .. Local Scalars .. */
  187. /* .. */
  188. /* .. External Subroutines .. */
  189. /* .. */
  190. /* .. Executable Statements .. */
  191. /* Test the input parameters. */
  192. /* Parameter adjustments */
  193. --d__;
  194. --e;
  195. givnum_dim1 = *ldu;
  196. givnum_offset = 1 + givnum_dim1;
  197. givnum -= givnum_offset;
  198. poles_dim1 = *ldu;
  199. poles_offset = 1 + poles_dim1;
  200. poles -= poles_offset;
  201. z_dim1 = *ldu;
  202. z_offset = 1 + z_dim1;
  203. z__ -= z_offset;
  204. difr_dim1 = *ldu;
  205. difr_offset = 1 + difr_dim1;
  206. difr -= difr_offset;
  207. difl_dim1 = *ldu;
  208. difl_offset = 1 + difl_dim1;
  209. difl -= difl_offset;
  210. vt_dim1 = *ldu;
  211. vt_offset = 1 + vt_dim1;
  212. vt -= vt_offset;
  213. u_dim1 = *ldu;
  214. u_offset = 1 + u_dim1;
  215. u -= u_offset;
  216. --k;
  217. --givptr;
  218. perm_dim1 = *ldgcol;
  219. perm_offset = 1 + perm_dim1;
  220. perm -= perm_offset;
  221. givcol_dim1 = *ldgcol;
  222. givcol_offset = 1 + givcol_dim1;
  223. givcol -= givcol_offset;
  224. --c__;
  225. --s;
  226. --work;
  227. --iwork;
  228. /* Function Body */
  229. *info = 0;
  230. if (*icompq < 0 || *icompq > 1) {
  231. *info = -1;
  232. } else if (*smlsiz < 3) {
  233. *info = -2;
  234. } else if (*n < 0) {
  235. *info = -3;
  236. } else if (*sqre < 0 || *sqre > 1) {
  237. *info = -4;
  238. } else if (*ldu < *n + *sqre) {
  239. *info = -8;
  240. } else if (*ldgcol < *n) {
  241. *info = -17;
  242. }
  243. if (*info != 0) {
  244. i__1 = -(*info);
  245. _starpu_xerbla_("DLASDA", &i__1);
  246. return 0;
  247. }
  248. m = *n + *sqre;
  249. /* If the input matrix is too small, call DLASDQ to find the SVD. */
  250. if (*n <= *smlsiz) {
  251. if (*icompq == 0) {
  252. _starpu_dlasdq_("U", sqre, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
  253. vt_offset], ldu, &u[u_offset], ldu, &u[u_offset], ldu, &
  254. work[1], info);
  255. } else {
  256. _starpu_dlasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
  257. , ldu, &u[u_offset], ldu, &u[u_offset], ldu, &work[1],
  258. info);
  259. }
  260. return 0;
  261. }
  262. /* Book-keeping and set up the computation tree. */
  263. inode = 1;
  264. ndiml = inode + *n;
  265. ndimr = ndiml + *n;
  266. idxq = ndimr + *n;
  267. iwk = idxq + *n;
  268. ncc = 0;
  269. nru = 0;
  270. smlszp = *smlsiz + 1;
  271. vf = 1;
  272. vl = vf + m;
  273. nwork1 = vl + m;
  274. nwork2 = nwork1 + smlszp * smlszp;
  275. _starpu_dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
  276. smlsiz);
  277. /* for the nodes on bottom level of the tree, solve */
  278. /* their subproblems by DLASDQ. */
  279. ndb1 = (nd + 1) / 2;
  280. i__1 = nd;
  281. for (i__ = ndb1; i__ <= i__1; ++i__) {
  282. /* IC : center row of each node */
  283. /* NL : number of rows of left subproblem */
  284. /* NR : number of rows of right subproblem */
  285. /* NLF: starting row of the left subproblem */
  286. /* NRF: starting row of the right subproblem */
  287. i1 = i__ - 1;
  288. ic = iwork[inode + i1];
  289. nl = iwork[ndiml + i1];
  290. nlp1 = nl + 1;
  291. nr = iwork[ndimr + i1];
  292. nlf = ic - nl;
  293. nrf = ic + 1;
  294. idxqi = idxq + nlf - 2;
  295. vfi = vf + nlf - 1;
  296. vli = vl + nlf - 1;
  297. sqrei = 1;
  298. if (*icompq == 0) {
  299. _starpu_dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
  300. _starpu_dlasdq_("U", &sqrei, &nl, &nlp1, &nru, &ncc, &d__[nlf], &e[nlf], &
  301. work[nwork1], &smlszp, &work[nwork2], &nl, &work[nwork2],
  302. &nl, &work[nwork2], info);
  303. itemp = nwork1 + nl * smlszp;
  304. _starpu_dcopy_(&nlp1, &work[nwork1], &c__1, &work[vfi], &c__1);
  305. _starpu_dcopy_(&nlp1, &work[itemp], &c__1, &work[vli], &c__1);
  306. } else {
  307. _starpu_dlaset_("A", &nl, &nl, &c_b11, &c_b12, &u[nlf + u_dim1], ldu);
  308. _starpu_dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &vt[nlf + vt_dim1],
  309. ldu);
  310. _starpu_dlasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &
  311. vt[nlf + vt_dim1], ldu, &u[nlf + u_dim1], ldu, &u[nlf +
  312. u_dim1], ldu, &work[nwork1], info);
  313. _starpu_dcopy_(&nlp1, &vt[nlf + vt_dim1], &c__1, &work[vfi], &c__1);
  314. _starpu_dcopy_(&nlp1, &vt[nlf + nlp1 * vt_dim1], &c__1, &work[vli], &c__1)
  315. ;
  316. }
  317. if (*info != 0) {
  318. return 0;
  319. }
  320. i__2 = nl;
  321. for (j = 1; j <= i__2; ++j) {
  322. iwork[idxqi + j] = j;
  323. /* L10: */
  324. }
  325. if (i__ == nd && *sqre == 0) {
  326. sqrei = 0;
  327. } else {
  328. sqrei = 1;
  329. }
  330. idxqi += nlp1;
  331. vfi += nlp1;
  332. vli += nlp1;
  333. nrp1 = nr + sqrei;
  334. if (*icompq == 0) {
  335. _starpu_dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
  336. _starpu_dlasdq_("U", &sqrei, &nr, &nrp1, &nru, &ncc, &d__[nrf], &e[nrf], &
  337. work[nwork1], &smlszp, &work[nwork2], &nr, &work[nwork2],
  338. &nr, &work[nwork2], info);
  339. itemp = nwork1 + (nrp1 - 1) * smlszp;
  340. _starpu_dcopy_(&nrp1, &work[nwork1], &c__1, &work[vfi], &c__1);
  341. _starpu_dcopy_(&nrp1, &work[itemp], &c__1, &work[vli], &c__1);
  342. } else {
  343. _starpu_dlaset_("A", &nr, &nr, &c_b11, &c_b12, &u[nrf + u_dim1], ldu);
  344. _starpu_dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &vt[nrf + vt_dim1],
  345. ldu);
  346. _starpu_dlasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &
  347. vt[nrf + vt_dim1], ldu, &u[nrf + u_dim1], ldu, &u[nrf +
  348. u_dim1], ldu, &work[nwork1], info);
  349. _starpu_dcopy_(&nrp1, &vt[nrf + vt_dim1], &c__1, &work[vfi], &c__1);
  350. _starpu_dcopy_(&nrp1, &vt[nrf + nrp1 * vt_dim1], &c__1, &work[vli], &c__1)
  351. ;
  352. }
  353. if (*info != 0) {
  354. return 0;
  355. }
  356. i__2 = nr;
  357. for (j = 1; j <= i__2; ++j) {
  358. iwork[idxqi + j] = j;
  359. /* L20: */
  360. }
  361. /* L30: */
  362. }
  363. /* Now conquer each subproblem bottom-up. */
  364. j = pow_ii(&c__2, &nlvl);
  365. for (lvl = nlvl; lvl >= 1; --lvl) {
  366. lvl2 = (lvl << 1) - 1;
  367. /* Find the first node LF and last node LL on */
  368. /* the current level LVL. */
  369. if (lvl == 1) {
  370. lf = 1;
  371. ll = 1;
  372. } else {
  373. i__1 = lvl - 1;
  374. lf = pow_ii(&c__2, &i__1);
  375. ll = (lf << 1) - 1;
  376. }
  377. i__1 = ll;
  378. for (i__ = lf; i__ <= i__1; ++i__) {
  379. im1 = i__ - 1;
  380. ic = iwork[inode + im1];
  381. nl = iwork[ndiml + im1];
  382. nr = iwork[ndimr + im1];
  383. nlf = ic - nl;
  384. nrf = ic + 1;
  385. if (i__ == ll) {
  386. sqrei = *sqre;
  387. } else {
  388. sqrei = 1;
  389. }
  390. vfi = vf + nlf - 1;
  391. vli = vl + nlf - 1;
  392. idxqi = idxq + nlf - 1;
  393. alpha = d__[ic];
  394. beta = e[ic];
  395. if (*icompq == 0) {
  396. _starpu_dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
  397. work[vli], &alpha, &beta, &iwork[idxqi], &perm[
  398. perm_offset], &givptr[1], &givcol[givcol_offset],
  399. ldgcol, &givnum[givnum_offset], ldu, &poles[
  400. poles_offset], &difl[difl_offset], &difr[difr_offset],
  401. &z__[z_offset], &k[1], &c__[1], &s[1], &work[nwork1],
  402. &iwork[iwk], info);
  403. } else {
  404. --j;
  405. _starpu_dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
  406. work[vli], &alpha, &beta, &iwork[idxqi], &perm[nlf +
  407. lvl * perm_dim1], &givptr[j], &givcol[nlf + lvl2 *
  408. givcol_dim1], ldgcol, &givnum[nlf + lvl2 *
  409. givnum_dim1], ldu, &poles[nlf + lvl2 * poles_dim1], &
  410. difl[nlf + lvl * difl_dim1], &difr[nlf + lvl2 *
  411. difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[j],
  412. &s[j], &work[nwork1], &iwork[iwk], info);
  413. }
  414. if (*info != 0) {
  415. return 0;
  416. }
  417. /* L40: */
  418. }
  419. /* L50: */
  420. }
  421. return 0;
  422. /* End of DLASDA */
  423. } /* _starpu_dlasda_ */