dgttrf.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* dgttrf.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. /* Subroutine */ int _starpu_dgttrf_(integer *n, doublereal *dl, doublereal *d__,
  14. doublereal *du, doublereal *du2, integer *ipiv, integer *info)
  15. {
  16. /* System generated locals */
  17. integer i__1;
  18. doublereal d__1, d__2;
  19. /* Local variables */
  20. integer i__;
  21. doublereal fact, temp;
  22. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  23. /* -- LAPACK routine (version 3.2) -- */
  24. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  25. /* November 2006 */
  26. /* .. Scalar Arguments .. */
  27. /* .. */
  28. /* .. Array Arguments .. */
  29. /* .. */
  30. /* Purpose */
  31. /* ======= */
  32. /* DGTTRF computes an LU factorization of a real tridiagonal matrix A */
  33. /* using elimination with partial pivoting and row interchanges. */
  34. /* The factorization has the form */
  35. /* A = L * U */
  36. /* where L is a product of permutation and unit lower bidiagonal */
  37. /* matrices and U is upper triangular with nonzeros in only the main */
  38. /* diagonal and first two superdiagonals. */
  39. /* Arguments */
  40. /* ========= */
  41. /* N (input) INTEGER */
  42. /* The order of the matrix A. */
  43. /* DL (input/output) DOUBLE PRECISION array, dimension (N-1) */
  44. /* On entry, DL must contain the (n-1) sub-diagonal elements of */
  45. /* A. */
  46. /* On exit, DL is overwritten by the (n-1) multipliers that */
  47. /* define the matrix L from the LU factorization of A. */
  48. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  49. /* On entry, D must contain the diagonal elements of A. */
  50. /* On exit, D is overwritten by the n diagonal elements of the */
  51. /* upper triangular matrix U from the LU factorization of A. */
  52. /* DU (input/output) DOUBLE PRECISION array, dimension (N-1) */
  53. /* On entry, DU must contain the (n-1) super-diagonal elements */
  54. /* of A. */
  55. /* On exit, DU is overwritten by the (n-1) elements of the first */
  56. /* super-diagonal of U. */
  57. /* DU2 (output) DOUBLE PRECISION array, dimension (N-2) */
  58. /* On exit, DU2 is overwritten by the (n-2) elements of the */
  59. /* second super-diagonal of U. */
  60. /* IPIV (output) INTEGER array, dimension (N) */
  61. /* The pivot indices; for 1 <= i <= n, row i of the matrix was */
  62. /* interchanged with row IPIV(i). IPIV(i) will always be either */
  63. /* i or i+1; IPIV(i) = i indicates a row interchange was not */
  64. /* required. */
  65. /* INFO (output) INTEGER */
  66. /* = 0: successful exit */
  67. /* < 0: if INFO = -k, the k-th argument had an illegal value */
  68. /* > 0: if INFO = k, U(k,k) is exactly zero. The factorization */
  69. /* has been completed, but the factor U is exactly */
  70. /* singular, and division by zero will occur if it is used */
  71. /* to solve a system of equations. */
  72. /* ===================================================================== */
  73. /* .. Parameters .. */
  74. /* .. */
  75. /* .. Local Scalars .. */
  76. /* .. */
  77. /* .. Intrinsic Functions .. */
  78. /* .. */
  79. /* .. External Subroutines .. */
  80. /* .. */
  81. /* .. Executable Statements .. */
  82. /* Parameter adjustments */
  83. --ipiv;
  84. --du2;
  85. --du;
  86. --d__;
  87. --dl;
  88. /* Function Body */
  89. *info = 0;
  90. if (*n < 0) {
  91. *info = -1;
  92. i__1 = -(*info);
  93. _starpu_xerbla_("DGTTRF", &i__1);
  94. return 0;
  95. }
  96. /* Quick return if possible */
  97. if (*n == 0) {
  98. return 0;
  99. }
  100. /* Initialize IPIV(i) = i and DU2(I) = 0 */
  101. i__1 = *n;
  102. for (i__ = 1; i__ <= i__1; ++i__) {
  103. ipiv[i__] = i__;
  104. /* L10: */
  105. }
  106. i__1 = *n - 2;
  107. for (i__ = 1; i__ <= i__1; ++i__) {
  108. du2[i__] = 0.;
  109. /* L20: */
  110. }
  111. i__1 = *n - 2;
  112. for (i__ = 1; i__ <= i__1; ++i__) {
  113. if ((d__1 = d__[i__], abs(d__1)) >= (d__2 = dl[i__], abs(d__2))) {
  114. /* No row interchange required, eliminate DL(I) */
  115. if (d__[i__] != 0.) {
  116. fact = dl[i__] / d__[i__];
  117. dl[i__] = fact;
  118. d__[i__ + 1] -= fact * du[i__];
  119. }
  120. } else {
  121. /* Interchange rows I and I+1, eliminate DL(I) */
  122. fact = d__[i__] / dl[i__];
  123. d__[i__] = dl[i__];
  124. dl[i__] = fact;
  125. temp = du[i__];
  126. du[i__] = d__[i__ + 1];
  127. d__[i__ + 1] = temp - fact * d__[i__ + 1];
  128. du2[i__] = du[i__ + 1];
  129. du[i__ + 1] = -fact * du[i__ + 1];
  130. ipiv[i__] = i__ + 1;
  131. }
  132. /* L30: */
  133. }
  134. if (*n > 1) {
  135. i__ = *n - 1;
  136. if ((d__1 = d__[i__], abs(d__1)) >= (d__2 = dl[i__], abs(d__2))) {
  137. if (d__[i__] != 0.) {
  138. fact = dl[i__] / d__[i__];
  139. dl[i__] = fact;
  140. d__[i__ + 1] -= fact * du[i__];
  141. }
  142. } else {
  143. fact = d__[i__] / dl[i__];
  144. d__[i__] = dl[i__];
  145. dl[i__] = fact;
  146. temp = du[i__];
  147. du[i__] = d__[i__ + 1];
  148. d__[i__ + 1] = temp - fact * d__[i__ + 1];
  149. ipiv[i__] = i__ + 1;
  150. }
  151. }
  152. /* Check for a zero on the diagonal of U. */
  153. i__1 = *n;
  154. for (i__ = 1; i__ <= i__1; ++i__) {
  155. if (d__[i__] == 0.) {
  156. *info = i__;
  157. goto L50;
  158. }
  159. /* L40: */
  160. }
  161. L50:
  162. return 0;
  163. /* End of DGTTRF */
  164. } /* _starpu_dgttrf_ */