dpstrf.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /* dpstrf.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 doublereal c_b22 = -1.;
  17. static doublereal c_b24 = 1.;
  18. /* Subroutine */ int _starpu_dpstrf_(char *uplo, integer *n, doublereal *a, integer *
  19. lda, integer *piv, integer *rank, doublereal *tol, doublereal *work,
  20. integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
  24. doublereal d__1;
  25. /* Builtin functions */
  26. double sqrt(doublereal);
  27. /* Local variables */
  28. integer i__, j, k, maxlocvar, jb, nb;
  29. doublereal ajj;
  30. integer pvt;
  31. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  32. integer *);
  33. extern logical _starpu_lsame_(char *, char *);
  34. extern /* Subroutine */ int _starpu_dgemv_(char *, integer *, integer *,
  35. doublereal *, doublereal *, integer *, doublereal *, integer *,
  36. doublereal *, doublereal *, integer *);
  37. doublereal dtemp;
  38. integer itemp;
  39. extern /* Subroutine */ int _starpu_dswap_(integer *, doublereal *, integer *,
  40. doublereal *, integer *);
  41. doublereal dstop;
  42. logical upper;
  43. extern /* Subroutine */ int _starpu_dsyrk_(char *, char *, integer *, integer *,
  44. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  45. integer *), _starpu_dpstf2_(char *, integer *,
  46. doublereal *, integer *, integer *, integer *, doublereal *,
  47. doublereal *, integer *);
  48. extern doublereal _starpu_dlamch_(char *);
  49. extern logical _starpu_disnan_(doublereal *);
  50. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  51. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  52. integer *, integer *);
  53. extern integer _starpu_dmaxloc_(doublereal *, integer *);
  54. /* -- LAPACK routine (version 3.2) -- */
  55. /* Craig Lucas, University of Manchester / NAG Ltd. */
  56. /* October, 2008 */
  57. /* .. Scalar Arguments .. */
  58. /* .. */
  59. /* .. Array Arguments .. */
  60. /* .. */
  61. /* Purpose */
  62. /* ======= */
  63. /* DPSTRF computes the Cholesky factorization with complete */
  64. /* pivoting of a real symmetric positive semidefinite matrix A. */
  65. /* The factorization has the form */
  66. /* P' * A * P = U' * U , if UPLO = 'U', */
  67. /* P' * A * P = L * L', if UPLO = 'L', */
  68. /* where U is an upper triangular matrix and L is lower triangular, and */
  69. /* P is stored as vector PIV. */
  70. /* This algorithm does not attempt to check that A is positive */
  71. /* semidefinite. This version of the algorithm calls level 3 BLAS. */
  72. /* Arguments */
  73. /* ========= */
  74. /* UPLO (input) CHARACTER*1 */
  75. /* Specifies whether the upper or lower triangular part of the */
  76. /* symmetric matrix A is stored. */
  77. /* = 'U': Upper triangular */
  78. /* = 'L': Lower triangular */
  79. /* N (input) INTEGER */
  80. /* The order of the matrix A. N >= 0. */
  81. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  82. /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  83. /* n by n upper triangular part of A contains the upper */
  84. /* triangular part of the matrix A, and the strictly lower */
  85. /* triangular part of A is not referenced. If UPLO = 'L', the */
  86. /* leading n by n lower triangular part of A contains the lower */
  87. /* triangular part of the matrix A, and the strictly upper */
  88. /* triangular part of A is not referenced. */
  89. /* On exit, if INFO = 0, the factor U or L from the Cholesky */
  90. /* factorization as above. */
  91. /* LDA (input) INTEGER */
  92. /* The leading dimension of the array A. LDA >= max(1,N). */
  93. /* PIV (output) INTEGER array, dimension (N) */
  94. /* PIV is such that the nonzero entries are P( PIV(K), K ) = 1. */
  95. /* RANK (output) INTEGER */
  96. /* The rank of A given by the number of steps the algorithm */
  97. /* completed. */
  98. /* TOL (input) DOUBLE PRECISION */
  99. /* User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) ) */
  100. /* will be used. The algorithm terminates at the (K-1)st step */
  101. /* if the pivot <= TOL. */
  102. /* WORK DOUBLE PRECISION array, dimension (2*N) */
  103. /* Work space. */
  104. /* INFO (output) INTEGER */
  105. /* < 0: If INFO = -K, the K-th argument had an illegal value, */
  106. /* = 0: algorithm completed successfully, and */
  107. /* > 0: the matrix A is either rank deficient with computed rank */
  108. /* as returned in RANK, or is indefinite. See Section 7 of */
  109. /* LAPACK Working Note #161 for further information. */
  110. /* ===================================================================== */
  111. /* .. Parameters .. */
  112. /* .. */
  113. /* .. Local Scalars .. */
  114. /* .. */
  115. /* .. External Functions .. */
  116. /* .. */
  117. /* .. External Subroutines .. */
  118. /* .. */
  119. /* .. Intrinsic Functions .. */
  120. /* .. */
  121. /* .. Executable Statements .. */
  122. /* Test the input parameters. */
  123. /* Parameter adjustments */
  124. --work;
  125. --piv;
  126. a_dim1 = *lda;
  127. a_offset = 1 + a_dim1;
  128. a -= a_offset;
  129. /* Function Body */
  130. *info = 0;
  131. upper = _starpu_lsame_(uplo, "U");
  132. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  133. *info = -1;
  134. } else if (*n < 0) {
  135. *info = -2;
  136. } else if (*lda < max(1,*n)) {
  137. *info = -4;
  138. }
  139. if (*info != 0) {
  140. i__1 = -(*info);
  141. _starpu_xerbla_("DPSTRF", &i__1);
  142. return 0;
  143. }
  144. /* Quick return if possible */
  145. if (*n == 0) {
  146. return 0;
  147. }
  148. /* Get block size */
  149. nb = _starpu_ilaenv_(&c__1, "DPOTRF", uplo, n, &c_n1, &c_n1, &c_n1);
  150. if (nb <= 1 || nb >= *n) {
  151. /* Use unblocked code */
  152. _starpu_dpstf2_(uplo, n, &a[a_dim1 + 1], lda, &piv[1], rank, tol, &work[1],
  153. info);
  154. goto L200;
  155. } else {
  156. /* Initialize PIV */
  157. i__1 = *n;
  158. for (i__ = 1; i__ <= i__1; ++i__) {
  159. piv[i__] = i__;
  160. /* L100: */
  161. }
  162. /* Compute stopping value */
  163. pvt = 1;
  164. ajj = a[pvt + pvt * a_dim1];
  165. i__1 = *n;
  166. for (i__ = 2; i__ <= i__1; ++i__) {
  167. if (a[i__ + i__ * a_dim1] > ajj) {
  168. pvt = i__;
  169. ajj = a[pvt + pvt * a_dim1];
  170. }
  171. }
  172. if (ajj == 0. || _starpu_disnan_(&ajj)) {
  173. *rank = 0;
  174. *info = 1;
  175. goto L200;
  176. }
  177. /* Compute stopping value if not supplied */
  178. if (*tol < 0.) {
  179. dstop = *n * _starpu_dlamch_("Epsilon") * ajj;
  180. } else {
  181. dstop = *tol;
  182. }
  183. if (upper) {
  184. /* Compute the Cholesky factorization P' * A * P = U' * U */
  185. i__1 = *n;
  186. i__2 = nb;
  187. for (k = 1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) {
  188. /* Account for last block not being NB wide */
  189. /* Computing MIN */
  190. i__3 = nb, i__4 = *n - k + 1;
  191. jb = min(i__3,i__4);
  192. /* Set relevant part of first half of WORK to zero, */
  193. /* holds dot products */
  194. i__3 = *n;
  195. for (i__ = k; i__ <= i__3; ++i__) {
  196. work[i__] = 0.;
  197. /* L110: */
  198. }
  199. i__3 = k + jb - 1;
  200. for (j = k; j <= i__3; ++j) {
  201. /* Find pivot, test for exit, else swap rows and columns */
  202. /* Update dot products, compute possible pivots which are */
  203. /* stored in the second half of WORK */
  204. i__4 = *n;
  205. for (i__ = j; i__ <= i__4; ++i__) {
  206. if (j > k) {
  207. /* Computing 2nd power */
  208. d__1 = a[j - 1 + i__ * a_dim1];
  209. work[i__] += d__1 * d__1;
  210. }
  211. work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
  212. /* L120: */
  213. }
  214. if (j > 1) {
  215. maxlocvar = (*n << 1) - (*n + j) + 1;
  216. itemp = _starpu_dmaxloc_(&work[*n + j], &maxlocvar);
  217. pvt = itemp + j - 1;
  218. ajj = work[*n + pvt];
  219. if (ajj <= dstop || _starpu_disnan_(&ajj)) {
  220. a[j + j * a_dim1] = ajj;
  221. goto L190;
  222. }
  223. }
  224. if (j != pvt) {
  225. /* Pivot OK, so can now swap pivot rows and columns */
  226. a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
  227. i__4 = j - 1;
  228. _starpu_dswap_(&i__4, &a[j * a_dim1 + 1], &c__1, &a[pvt *
  229. a_dim1 + 1], &c__1);
  230. if (pvt < *n) {
  231. i__4 = *n - pvt;
  232. _starpu_dswap_(&i__4, &a[j + (pvt + 1) * a_dim1], lda, &a[
  233. pvt + (pvt + 1) * a_dim1], lda);
  234. }
  235. i__4 = pvt - j - 1;
  236. _starpu_dswap_(&i__4, &a[j + (j + 1) * a_dim1], lda, &a[j + 1
  237. + pvt * a_dim1], &c__1);
  238. /* Swap dot products and PIV */
  239. dtemp = work[j];
  240. work[j] = work[pvt];
  241. work[pvt] = dtemp;
  242. itemp = piv[pvt];
  243. piv[pvt] = piv[j];
  244. piv[j] = itemp;
  245. }
  246. ajj = sqrt(ajj);
  247. a[j + j * a_dim1] = ajj;
  248. /* Compute elements J+1:N of row J. */
  249. if (j < *n) {
  250. i__4 = j - k;
  251. i__5 = *n - j;
  252. _starpu_dgemv_("Trans", &i__4, &i__5, &c_b22, &a[k + (j + 1) *
  253. a_dim1], lda, &a[k + j * a_dim1], &c__1, &
  254. c_b24, &a[j + (j + 1) * a_dim1], lda);
  255. i__4 = *n - j;
  256. d__1 = 1. / ajj;
  257. _starpu_dscal_(&i__4, &d__1, &a[j + (j + 1) * a_dim1], lda);
  258. }
  259. /* L130: */
  260. }
  261. /* Update trailing matrix, J already incremented */
  262. if (k + jb <= *n) {
  263. i__3 = *n - j + 1;
  264. _starpu_dsyrk_("Upper", "Trans", &i__3, &jb, &c_b22, &a[k + j *
  265. a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
  266. }
  267. /* L140: */
  268. }
  269. } else {
  270. /* Compute the Cholesky factorization P' * A * P = L * L' */
  271. i__2 = *n;
  272. i__1 = nb;
  273. for (k = 1; i__1 < 0 ? k >= i__2 : k <= i__2; k += i__1) {
  274. /* Account for last block not being NB wide */
  275. /* Computing MIN */
  276. i__3 = nb, i__4 = *n - k + 1;
  277. jb = min(i__3,i__4);
  278. /* Set relevant part of first half of WORK to zero, */
  279. /* holds dot products */
  280. i__3 = *n;
  281. for (i__ = k; i__ <= i__3; ++i__) {
  282. work[i__] = 0.;
  283. /* L150: */
  284. }
  285. i__3 = k + jb - 1;
  286. for (j = k; j <= i__3; ++j) {
  287. /* Find pivot, test for exit, else swap rows and columns */
  288. /* Update dot products, compute possible pivots which are */
  289. /* stored in the second half of WORK */
  290. i__4 = *n;
  291. for (i__ = j; i__ <= i__4; ++i__) {
  292. if (j > k) {
  293. /* Computing 2nd power */
  294. d__1 = a[i__ + (j - 1) * a_dim1];
  295. work[i__] += d__1 * d__1;
  296. }
  297. work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
  298. /* L160: */
  299. }
  300. if (j > 1) {
  301. maxlocvar = (*n << 1) - (*n + j) + 1;
  302. itemp = _starpu_dmaxloc_(&work[*n + j], &maxlocvar);
  303. pvt = itemp + j - 1;
  304. ajj = work[*n + pvt];
  305. if (ajj <= dstop || _starpu_disnan_(&ajj)) {
  306. a[j + j * a_dim1] = ajj;
  307. goto L190;
  308. }
  309. }
  310. if (j != pvt) {
  311. /* Pivot OK, so can now swap pivot rows and columns */
  312. a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
  313. i__4 = j - 1;
  314. _starpu_dswap_(&i__4, &a[j + a_dim1], lda, &a[pvt + a_dim1],
  315. lda);
  316. if (pvt < *n) {
  317. i__4 = *n - pvt;
  318. _starpu_dswap_(&i__4, &a[pvt + 1 + j * a_dim1], &c__1, &a[
  319. pvt + 1 + pvt * a_dim1], &c__1);
  320. }
  321. i__4 = pvt - j - 1;
  322. _starpu_dswap_(&i__4, &a[j + 1 + j * a_dim1], &c__1, &a[pvt +
  323. (j + 1) * a_dim1], lda);
  324. /* Swap dot products and PIV */
  325. dtemp = work[j];
  326. work[j] = work[pvt];
  327. work[pvt] = dtemp;
  328. itemp = piv[pvt];
  329. piv[pvt] = piv[j];
  330. piv[j] = itemp;
  331. }
  332. ajj = sqrt(ajj);
  333. a[j + j * a_dim1] = ajj;
  334. /* Compute elements J+1:N of column J. */
  335. if (j < *n) {
  336. i__4 = *n - j;
  337. i__5 = j - k;
  338. _starpu_dgemv_("No Trans", &i__4, &i__5, &c_b22, &a[j + 1 + k
  339. * a_dim1], lda, &a[j + k * a_dim1], lda, &
  340. c_b24, &a[j + 1 + j * a_dim1], &c__1);
  341. i__4 = *n - j;
  342. d__1 = 1. / ajj;
  343. _starpu_dscal_(&i__4, &d__1, &a[j + 1 + j * a_dim1], &c__1);
  344. }
  345. /* L170: */
  346. }
  347. /* Update trailing matrix, J already incremented */
  348. if (k + jb <= *n) {
  349. i__3 = *n - j + 1;
  350. _starpu_dsyrk_("Lower", "No Trans", &i__3, &jb, &c_b22, &a[j + k *
  351. a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
  352. }
  353. /* L180: */
  354. }
  355. }
  356. }
  357. /* Ran to completion, A has full rank */
  358. *rank = *n;
  359. goto L200;
  360. L190:
  361. /* Rank is the number of steps completed. Set INFO = 1 to signal */
  362. /* that the factorization cannot be used to solve a system. */
  363. *rank = j - 1;
  364. *info = 1;
  365. L200:
  366. return 0;
  367. /* End of DPSTRF */
  368. } /* _starpu_dpstrf_ */