dpstf2.c 10 KB

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