dgetri.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* dgetri.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. static doublereal c_b20 = -1.;
  18. static doublereal c_b22 = 1.;
  19. /* Subroutine */ int _starpu_dgetri_(integer *n, doublereal *a, integer *lda, integer
  20. *ipiv, doublereal *work, integer *lwork, integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, i__1, i__2, i__3;
  24. /* Local variables */
  25. integer i__, j, jb, nb, jj, jp, nn, iws;
  26. extern /* Subroutine */ int _starpu_dgemm_(char *, char *, integer *, integer *,
  27. integer *, doublereal *, doublereal *, integer *, doublereal *,
  28. integer *, doublereal *, doublereal *, integer *),
  29. _starpu_dgemv_(char *, integer *, integer *, doublereal *, doublereal *,
  30. integer *, doublereal *, integer *, doublereal *, doublereal *,
  31. integer *);
  32. integer nbmin;
  33. extern /* Subroutine */ int _starpu_dswap_(integer *, doublereal *, integer *,
  34. doublereal *, integer *), _starpu_dtrsm_(char *, char *, char *, char *,
  35. integer *, integer *, doublereal *, doublereal *, integer *,
  36. doublereal *, integer *), _starpu_xerbla_(
  37. char *, integer *);
  38. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  39. integer *, integer *);
  40. integer ldwork;
  41. extern /* Subroutine */ int _starpu_dtrtri_(char *, char *, integer *, doublereal
  42. *, integer *, integer *);
  43. integer lwkopt;
  44. logical lquery;
  45. /* -- LAPACK routine (version 3.2) -- */
  46. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  47. /* November 2006 */
  48. /* .. Scalar Arguments .. */
  49. /* .. */
  50. /* .. Array Arguments .. */
  51. /* .. */
  52. /* Purpose */
  53. /* ======= */
  54. /* DGETRI computes the inverse of a matrix using the LU factorization */
  55. /* computed by DGETRF. */
  56. /* This method inverts U and then computes inv(A) by solving the system */
  57. /* inv(A)*L = inv(U) for inv(A). */
  58. /* Arguments */
  59. /* ========= */
  60. /* N (input) INTEGER */
  61. /* The order of the matrix A. N >= 0. */
  62. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  63. /* On entry, the factors L and U from the factorization */
  64. /* A = P*L*U as computed by DGETRF. */
  65. /* On exit, if INFO = 0, the inverse of the original matrix A. */
  66. /* LDA (input) INTEGER */
  67. /* The leading dimension of the array A. LDA >= max(1,N). */
  68. /* IPIV (input) INTEGER array, dimension (N) */
  69. /* The pivot indices from DGETRF; for 1<=i<=N, row i of the */
  70. /* matrix was interchanged with row IPIV(i). */
  71. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  72. /* On exit, if INFO=0, then WORK(1) returns the optimal LWORK. */
  73. /* LWORK (input) INTEGER */
  74. /* The dimension of the array WORK. LWORK >= max(1,N). */
  75. /* For optimal performance LWORK >= N*NB, where NB is */
  76. /* the optimal blocksize returned by ILAENV. */
  77. /* If LWORK = -1, then a workspace query is assumed; the routine */
  78. /* only calculates the optimal size of the WORK array, returns */
  79. /* this value as the first entry of the WORK array, and no error */
  80. /* message related to LWORK is issued by XERBLA. */
  81. /* INFO (output) INTEGER */
  82. /* = 0: successful exit */
  83. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  84. /* > 0: if INFO = i, U(i,i) is exactly zero; the matrix is */
  85. /* singular and its inverse could not be computed. */
  86. /* ===================================================================== */
  87. /* .. Parameters .. */
  88. /* .. */
  89. /* .. Local Scalars .. */
  90. /* .. */
  91. /* .. External Functions .. */
  92. /* .. */
  93. /* .. External Subroutines .. */
  94. /* .. */
  95. /* .. Intrinsic Functions .. */
  96. /* .. */
  97. /* .. Executable Statements .. */
  98. /* Test the input parameters. */
  99. /* Parameter adjustments */
  100. a_dim1 = *lda;
  101. a_offset = 1 + a_dim1;
  102. a -= a_offset;
  103. --ipiv;
  104. --work;
  105. /* Function Body */
  106. *info = 0;
  107. nb = _starpu_ilaenv_(&c__1, "DGETRI", " ", n, &c_n1, &c_n1, &c_n1);
  108. lwkopt = *n * nb;
  109. work[1] = (doublereal) lwkopt;
  110. lquery = *lwork == -1;
  111. if (*n < 0) {
  112. *info = -1;
  113. } else if (*lda < max(1,*n)) {
  114. *info = -3;
  115. } else if (*lwork < max(1,*n) && ! lquery) {
  116. *info = -6;
  117. }
  118. if (*info != 0) {
  119. i__1 = -(*info);
  120. _starpu_xerbla_("DGETRI", &i__1);
  121. return 0;
  122. } else if (lquery) {
  123. return 0;
  124. }
  125. /* Quick return if possible */
  126. if (*n == 0) {
  127. return 0;
  128. }
  129. /* Form inv(U). If INFO > 0 from DTRTRI, then U is singular, */
  130. /* and the inverse is not computed. */
  131. _starpu_dtrtri_("Upper", "Non-unit", n, &a[a_offset], lda, info);
  132. if (*info > 0) {
  133. return 0;
  134. }
  135. nbmin = 2;
  136. ldwork = *n;
  137. if (nb > 1 && nb < *n) {
  138. /* Computing MAX */
  139. i__1 = ldwork * nb;
  140. iws = max(i__1,1);
  141. if (*lwork < iws) {
  142. nb = *lwork / ldwork;
  143. /* Computing MAX */
  144. i__1 = 2, i__2 = _starpu_ilaenv_(&c__2, "DGETRI", " ", n, &c_n1, &c_n1, &
  145. c_n1);
  146. nbmin = max(i__1,i__2);
  147. }
  148. } else {
  149. iws = *n;
  150. }
  151. /* Solve the equation inv(A)*L = inv(U) for inv(A). */
  152. if (nb < nbmin || nb >= *n) {
  153. /* Use unblocked code. */
  154. for (j = *n; j >= 1; --j) {
  155. /* Copy current column of L to WORK and replace with zeros. */
  156. i__1 = *n;
  157. for (i__ = j + 1; i__ <= i__1; ++i__) {
  158. work[i__] = a[i__ + j * a_dim1];
  159. a[i__ + j * a_dim1] = 0.;
  160. /* L10: */
  161. }
  162. /* Compute current column of inv(A). */
  163. if (j < *n) {
  164. i__1 = *n - j;
  165. _starpu_dgemv_("No transpose", n, &i__1, &c_b20, &a[(j + 1) * a_dim1
  166. + 1], lda, &work[j + 1], &c__1, &c_b22, &a[j * a_dim1
  167. + 1], &c__1);
  168. }
  169. /* L20: */
  170. }
  171. } else {
  172. /* Use blocked code. */
  173. nn = (*n - 1) / nb * nb + 1;
  174. i__1 = -nb;
  175. for (j = nn; i__1 < 0 ? j >= 1 : j <= 1; j += i__1) {
  176. /* Computing MIN */
  177. i__2 = nb, i__3 = *n - j + 1;
  178. jb = min(i__2,i__3);
  179. /* Copy current block column of L to WORK and replace with */
  180. /* zeros. */
  181. i__2 = j + jb - 1;
  182. for (jj = j; jj <= i__2; ++jj) {
  183. i__3 = *n;
  184. for (i__ = jj + 1; i__ <= i__3; ++i__) {
  185. work[i__ + (jj - j) * ldwork] = a[i__ + jj * a_dim1];
  186. a[i__ + jj * a_dim1] = 0.;
  187. /* L30: */
  188. }
  189. /* L40: */
  190. }
  191. /* Compute current block column of inv(A). */
  192. if (j + jb <= *n) {
  193. i__2 = *n - j - jb + 1;
  194. _starpu_dgemm_("No transpose", "No transpose", n, &jb, &i__2, &c_b20,
  195. &a[(j + jb) * a_dim1 + 1], lda, &work[j + jb], &
  196. ldwork, &c_b22, &a[j * a_dim1 + 1], lda);
  197. }
  198. _starpu_dtrsm_("Right", "Lower", "No transpose", "Unit", n, &jb, &c_b22, &
  199. work[j], &ldwork, &a[j * a_dim1 + 1], lda);
  200. /* L50: */
  201. }
  202. }
  203. /* Apply column interchanges. */
  204. for (j = *n - 1; j >= 1; --j) {
  205. jp = ipiv[j];
  206. if (jp != j) {
  207. _starpu_dswap_(n, &a[j * a_dim1 + 1], &c__1, &a[jp * a_dim1 + 1], &c__1);
  208. }
  209. /* L60: */
  210. }
  211. work[1] = (doublereal) iws;
  212. return 0;
  213. /* End of DGETRI */
  214. } /* _starpu_dgetri_ */