dsytrf.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /* dsytrf.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. /* Subroutine */ int dsytrf_(char *uplo, integer *n, doublereal *a, integer *
  18. lda, integer *ipiv, doublereal *work, integer *lwork, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, i__1, i__2;
  22. /* Local variables */
  23. integer j, k, kb, nb, iws;
  24. extern logical lsame_(char *, char *);
  25. integer nbmin, iinfo;
  26. logical upper;
  27. extern /* Subroutine */ int dsytf2_(char *, integer *, doublereal *,
  28. integer *, integer *, integer *), xerbla_(char *, integer
  29. *);
  30. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  31. integer *, integer *);
  32. extern /* Subroutine */ int dlasyf_(char *, integer *, integer *, integer
  33. *, doublereal *, integer *, integer *, doublereal *, integer *,
  34. integer *);
  35. integer ldwork, lwkopt;
  36. logical lquery;
  37. /* -- LAPACK routine (version 3.2) -- */
  38. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  39. /* November 2006 */
  40. /* .. Scalar Arguments .. */
  41. /* .. */
  42. /* .. Array Arguments .. */
  43. /* .. */
  44. /* Purpose */
  45. /* ======= */
  46. /* DSYTRF computes the factorization of a real symmetric matrix A using */
  47. /* the Bunch-Kaufman diagonal pivoting method. The form of the */
  48. /* factorization is */
  49. /* A = U*D*U**T or A = L*D*L**T */
  50. /* where U (or L) is a product of permutation and unit upper (lower) */
  51. /* triangular matrices, and D is symmetric and block diagonal with */
  52. /* 1-by-1 and 2-by-2 diagonal blocks. */
  53. /* This is the blocked version of the algorithm, calling Level 3 BLAS. */
  54. /* Arguments */
  55. /* ========= */
  56. /* UPLO (input) CHARACTER*1 */
  57. /* = 'U': Upper triangle of A is stored; */
  58. /* = 'L': Lower triangle of A is stored. */
  59. /* N (input) INTEGER */
  60. /* The order of the matrix A. N >= 0. */
  61. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  62. /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  63. /* N-by-N upper triangular part of A contains the upper */
  64. /* triangular part of the matrix A, and the strictly lower */
  65. /* triangular part of A is not referenced. If UPLO = 'L', the */
  66. /* leading N-by-N lower triangular part of A contains the lower */
  67. /* triangular part of the matrix A, and the strictly upper */
  68. /* triangular part of A is not referenced. */
  69. /* On exit, the block diagonal matrix D and the multipliers used */
  70. /* to obtain the factor U or L (see below for further details). */
  71. /* LDA (input) INTEGER */
  72. /* The leading dimension of the array A. LDA >= max(1,N). */
  73. /* IPIV (output) INTEGER array, dimension (N) */
  74. /* Details of the interchanges and the block structure of D. */
  75. /* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  76. /* interchanged and D(k,k) is a 1-by-1 diagonal block. */
  77. /* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
  78. /* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  79. /* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */
  80. /* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
  81. /* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  82. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  83. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  84. /* LWORK (input) INTEGER */
  85. /* The length of WORK. LWORK >=1. For best performance */
  86. /* LWORK >= N*NB, where NB is the block size returned by ILAENV. */
  87. /* If LWORK = -1, then a workspace query is assumed; the routine */
  88. /* only calculates the optimal size of the WORK array, returns */
  89. /* this value as the first entry of the WORK array, and no error */
  90. /* message related to LWORK is issued by XERBLA. */
  91. /* INFO (output) INTEGER */
  92. /* = 0: successful exit */
  93. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  94. /* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */
  95. /* has been completed, but the block diagonal matrix D is */
  96. /* exactly singular, and division by zero will occur if it */
  97. /* is used to solve a system of equations. */
  98. /* Further Details */
  99. /* =============== */
  100. /* If UPLO = 'U', then A = U*D*U', where */
  101. /* U = P(n)*U(n)* ... *P(k)U(k)* ..., */
  102. /* i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
  103. /* 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  104. /* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  105. /* defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
  106. /* that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  107. /* ( I v 0 ) k-s */
  108. /* U(k) = ( 0 I 0 ) s */
  109. /* ( 0 0 I ) n-k */
  110. /* k-s s n-k */
  111. /* If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
  112. /* If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
  113. /* and A(k,k), and v overwrites A(1:k-2,k-1:k). */
  114. /* If UPLO = 'L', then A = L*D*L', where */
  115. /* L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
  116. /* i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
  117. /* n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  118. /* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  119. /* defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
  120. /* that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  121. /* ( I 0 0 ) k-1 */
  122. /* L(k) = ( 0 I 0 ) s */
  123. /* ( 0 v I ) n-k-s+1 */
  124. /* k-1 s n-k-s+1 */
  125. /* If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
  126. /* If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
  127. /* and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
  128. /* ===================================================================== */
  129. /* .. Local Scalars .. */
  130. /* .. */
  131. /* .. External Functions .. */
  132. /* .. */
  133. /* .. External Subroutines .. */
  134. /* .. */
  135. /* .. Intrinsic Functions .. */
  136. /* .. */
  137. /* .. Executable Statements .. */
  138. /* Test the input parameters. */
  139. /* Parameter adjustments */
  140. a_dim1 = *lda;
  141. a_offset = 1 + a_dim1;
  142. a -= a_offset;
  143. --ipiv;
  144. --work;
  145. /* Function Body */
  146. *info = 0;
  147. upper = lsame_(uplo, "U");
  148. lquery = *lwork == -1;
  149. if (! upper && ! lsame_(uplo, "L")) {
  150. *info = -1;
  151. } else if (*n < 0) {
  152. *info = -2;
  153. } else if (*lda < max(1,*n)) {
  154. *info = -4;
  155. } else if (*lwork < 1 && ! lquery) {
  156. *info = -7;
  157. }
  158. if (*info == 0) {
  159. /* Determine the block size */
  160. nb = ilaenv_(&c__1, "DSYTRF", uplo, n, &c_n1, &c_n1, &c_n1);
  161. lwkopt = *n * nb;
  162. work[1] = (doublereal) lwkopt;
  163. }
  164. if (*info != 0) {
  165. i__1 = -(*info);
  166. xerbla_("DSYTRF", &i__1);
  167. return 0;
  168. } else if (lquery) {
  169. return 0;
  170. }
  171. nbmin = 2;
  172. ldwork = *n;
  173. if (nb > 1 && nb < *n) {
  174. iws = ldwork * nb;
  175. if (*lwork < iws) {
  176. /* Computing MAX */
  177. i__1 = *lwork / ldwork;
  178. nb = max(i__1,1);
  179. /* Computing MAX */
  180. i__1 = 2, i__2 = ilaenv_(&c__2, "DSYTRF", uplo, n, &c_n1, &c_n1, &
  181. c_n1);
  182. nbmin = max(i__1,i__2);
  183. }
  184. } else {
  185. iws = 1;
  186. }
  187. if (nb < nbmin) {
  188. nb = *n;
  189. }
  190. if (upper) {
  191. /* Factorize A as U*D*U' using the upper triangle of A */
  192. /* K is the main loop index, decreasing from N to 1 in steps of */
  193. /* KB, where KB is the number of columns factorized by DLASYF; */
  194. /* KB is either NB or NB-1, or K for the last block */
  195. k = *n;
  196. L10:
  197. /* If K < 1, exit from loop */
  198. if (k < 1) {
  199. goto L40;
  200. }
  201. if (k > nb) {
  202. /* Factorize columns k-kb+1:k of A and use blocked code to */
  203. /* update columns 1:k-kb */
  204. dlasyf_(uplo, &k, &nb, &kb, &a[a_offset], lda, &ipiv[1], &work[1],
  205. &ldwork, &iinfo);
  206. } else {
  207. /* Use unblocked code to factorize columns 1:k of A */
  208. dsytf2_(uplo, &k, &a[a_offset], lda, &ipiv[1], &iinfo);
  209. kb = k;
  210. }
  211. /* Set INFO on the first occurrence of a zero pivot */
  212. if (*info == 0 && iinfo > 0) {
  213. *info = iinfo;
  214. }
  215. /* Decrease K and return to the start of the main loop */
  216. k -= kb;
  217. goto L10;
  218. } else {
  219. /* Factorize A as L*D*L' using the lower triangle of A */
  220. /* K is the main loop index, increasing from 1 to N in steps of */
  221. /* KB, where KB is the number of columns factorized by DLASYF; */
  222. /* KB is either NB or NB-1, or N-K+1 for the last block */
  223. k = 1;
  224. L20:
  225. /* If K > N, exit from loop */
  226. if (k > *n) {
  227. goto L40;
  228. }
  229. if (k <= *n - nb) {
  230. /* Factorize columns k:k+kb-1 of A and use blocked code to */
  231. /* update columns k+kb:n */
  232. i__1 = *n - k + 1;
  233. dlasyf_(uplo, &i__1, &nb, &kb, &a[k + k * a_dim1], lda, &ipiv[k],
  234. &work[1], &ldwork, &iinfo);
  235. } else {
  236. /* Use unblocked code to factorize columns k:n of A */
  237. i__1 = *n - k + 1;
  238. dsytf2_(uplo, &i__1, &a[k + k * a_dim1], lda, &ipiv[k], &iinfo);
  239. kb = *n - k + 1;
  240. }
  241. /* Set INFO on the first occurrence of a zero pivot */
  242. if (*info == 0 && iinfo > 0) {
  243. *info = iinfo + k - 1;
  244. }
  245. /* Adjust IPIV */
  246. i__1 = k + kb - 1;
  247. for (j = k; j <= i__1; ++j) {
  248. if (ipiv[j] > 0) {
  249. ipiv[j] = ipiv[j] + k - 1;
  250. } else {
  251. ipiv[j] = ipiv[j] - k + 1;
  252. }
  253. /* L30: */
  254. }
  255. /* Increase K and return to the start of the main loop */
  256. k += kb;
  257. goto L20;
  258. }
  259. L40:
  260. work[1] = (doublereal) lwkopt;
  261. return 0;
  262. /* End of DSYTRF */
  263. } /* dsytrf_ */