dtrtri.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* dtrtri.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_b18 = 1.;
  18. static doublereal c_b22 = -1.;
  19. /* Subroutine */ int _starpu_dtrtri_(char *uplo, char *diag, integer *n, doublereal *
  20. a, integer *lda, integer *info)
  21. {
  22. /* System generated locals */
  23. address a__1[2];
  24. integer a_dim1, a_offset, i__1, i__2[2], i__3, i__4, i__5;
  25. char ch__1[2];
  26. /* Builtin functions */
  27. /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
  28. /* Local variables */
  29. integer j, jb, nb, nn;
  30. extern logical _starpu_lsame_(char *, char *);
  31. extern /* Subroutine */ int _starpu_dtrmm_(char *, char *, char *, char *,
  32. integer *, integer *, doublereal *, doublereal *, integer *,
  33. doublereal *, integer *), _starpu_dtrsm_(
  34. char *, char *, char *, char *, integer *, integer *, doublereal *
  35. , doublereal *, integer *, doublereal *, integer *);
  36. logical upper;
  37. extern /* Subroutine */ int _starpu_dtrti2_(char *, char *, integer *, doublereal
  38. *, integer *, integer *), _starpu_xerbla_(char *, integer
  39. *);
  40. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  41. integer *, integer *);
  42. logical nounit;
  43. /* -- LAPACK routine (version 3.2) -- */
  44. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  45. /* November 2006 */
  46. /* .. Scalar Arguments .. */
  47. /* .. */
  48. /* .. Array Arguments .. */
  49. /* .. */
  50. /* Purpose */
  51. /* ======= */
  52. /* DTRTRI computes the inverse of a real upper or lower triangular */
  53. /* matrix A. */
  54. /* This is the Level 3 BLAS version of the algorithm. */
  55. /* Arguments */
  56. /* ========= */
  57. /* UPLO (input) CHARACTER*1 */
  58. /* = 'U': A is upper triangular; */
  59. /* = 'L': A is lower triangular. */
  60. /* DIAG (input) CHARACTER*1 */
  61. /* = 'N': A is non-unit triangular; */
  62. /* = 'U': A is unit triangular. */
  63. /* N (input) INTEGER */
  64. /* The order of the matrix A. N >= 0. */
  65. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  66. /* On entry, the triangular matrix A. If UPLO = 'U', the */
  67. /* leading N-by-N upper triangular part of the array A contains */
  68. /* the upper triangular matrix, and the strictly lower */
  69. /* triangular part of A is not referenced. If UPLO = 'L', the */
  70. /* leading N-by-N lower triangular part of the array A contains */
  71. /* the lower triangular matrix, and the strictly upper */
  72. /* triangular part of A is not referenced. If DIAG = 'U', the */
  73. /* diagonal elements of A are also not referenced and are */
  74. /* assumed to be 1. */
  75. /* On exit, the (triangular) inverse of the original matrix, in */
  76. /* the same storage format. */
  77. /* LDA (input) INTEGER */
  78. /* The leading dimension of the array A. LDA >= max(1,N). */
  79. /* INFO (output) INTEGER */
  80. /* = 0: successful exit */
  81. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  82. /* > 0: if INFO = i, A(i,i) is exactly zero. The triangular */
  83. /* matrix is singular and its inverse can not be computed. */
  84. /* ===================================================================== */
  85. /* .. Parameters .. */
  86. /* .. */
  87. /* .. Local Scalars .. */
  88. /* .. */
  89. /* .. External Functions .. */
  90. /* .. */
  91. /* .. External Subroutines .. */
  92. /* .. */
  93. /* .. Intrinsic Functions .. */
  94. /* .. */
  95. /* .. Executable Statements .. */
  96. /* Test the input parameters. */
  97. /* Parameter adjustments */
  98. a_dim1 = *lda;
  99. a_offset = 1 + a_dim1;
  100. a -= a_offset;
  101. /* Function Body */
  102. *info = 0;
  103. upper = _starpu_lsame_(uplo, "U");
  104. nounit = _starpu_lsame_(diag, "N");
  105. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  106. *info = -1;
  107. } else if (! nounit && ! _starpu_lsame_(diag, "U")) {
  108. *info = -2;
  109. } else if (*n < 0) {
  110. *info = -3;
  111. } else if (*lda < max(1,*n)) {
  112. *info = -5;
  113. }
  114. if (*info != 0) {
  115. i__1 = -(*info);
  116. _starpu_xerbla_("DTRTRI", &i__1);
  117. return 0;
  118. }
  119. /* Quick return if possible */
  120. if (*n == 0) {
  121. return 0;
  122. }
  123. /* Check for singularity if non-unit. */
  124. if (nounit) {
  125. i__1 = *n;
  126. for (*info = 1; *info <= i__1; ++(*info)) {
  127. if (a[*info + *info * a_dim1] == 0.) {
  128. return 0;
  129. }
  130. /* L10: */
  131. }
  132. *info = 0;
  133. }
  134. /* Determine the block size for this environment. */
  135. /* Writing concatenation */
  136. i__2[0] = 1, a__1[0] = uplo;
  137. i__2[1] = 1, a__1[1] = diag;
  138. s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2);
  139. nb = _starpu_ilaenv_(&c__1, "DTRTRI", ch__1, n, &c_n1, &c_n1, &c_n1);
  140. if (nb <= 1 || nb >= *n) {
  141. /* Use unblocked code */
  142. _starpu_dtrti2_(uplo, diag, n, &a[a_offset], lda, info);
  143. } else {
  144. /* Use blocked code */
  145. if (upper) {
  146. /* Compute inverse of upper triangular matrix */
  147. i__1 = *n;
  148. i__3 = nb;
  149. for (j = 1; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) {
  150. /* Computing MIN */
  151. i__4 = nb, i__5 = *n - j + 1;
  152. jb = min(i__4,i__5);
  153. /* Compute rows 1:j-1 of current block column */
  154. i__4 = j - 1;
  155. _starpu_dtrmm_("Left", "Upper", "No transpose", diag, &i__4, &jb, &
  156. c_b18, &a[a_offset], lda, &a[j * a_dim1 + 1], lda);
  157. i__4 = j - 1;
  158. _starpu_dtrsm_("Right", "Upper", "No transpose", diag, &i__4, &jb, &
  159. c_b22, &a[j + j * a_dim1], lda, &a[j * a_dim1 + 1],
  160. lda);
  161. /* Compute inverse of current diagonal block */
  162. _starpu_dtrti2_("Upper", diag, &jb, &a[j + j * a_dim1], lda, info);
  163. /* L20: */
  164. }
  165. } else {
  166. /* Compute inverse of lower triangular matrix */
  167. nn = (*n - 1) / nb * nb + 1;
  168. i__3 = -nb;
  169. for (j = nn; i__3 < 0 ? j >= 1 : j <= 1; j += i__3) {
  170. /* Computing MIN */
  171. i__1 = nb, i__4 = *n - j + 1;
  172. jb = min(i__1,i__4);
  173. if (j + jb <= *n) {
  174. /* Compute rows j+jb:n of current block column */
  175. i__1 = *n - j - jb + 1;
  176. _starpu_dtrmm_("Left", "Lower", "No transpose", diag, &i__1, &jb,
  177. &c_b18, &a[j + jb + (j + jb) * a_dim1], lda, &a[j
  178. + jb + j * a_dim1], lda);
  179. i__1 = *n - j - jb + 1;
  180. _starpu_dtrsm_("Right", "Lower", "No transpose", diag, &i__1, &jb,
  181. &c_b22, &a[j + j * a_dim1], lda, &a[j + jb + j *
  182. a_dim1], lda);
  183. }
  184. /* Compute inverse of current diagonal block */
  185. _starpu_dtrti2_("Lower", diag, &jb, &a[j + j * a_dim1], lda, info);
  186. /* L30: */
  187. }
  188. }
  189. }
  190. return 0;
  191. /* End of DTRTRI */
  192. } /* _starpu_dtrtri_ */