dgetf2.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* dgetf2.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_b8 = -1.;
  16. /* Subroutine */ int _starpu_dgetf2_(integer *m, integer *n, doublereal *a, integer *
  17. lda, integer *ipiv, integer *info)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, i__1, i__2, i__3;
  21. doublereal d__1;
  22. /* Local variables */
  23. integer i__, j, jp;
  24. extern /* Subroutine */ int _starpu_dger_(integer *, integer *, doublereal *,
  25. doublereal *, integer *, doublereal *, integer *, doublereal *,
  26. integer *), _starpu_dscal_(integer *, doublereal *, doublereal *, integer
  27. *);
  28. doublereal sfmin;
  29. extern /* Subroutine */ int _starpu_dswap_(integer *, doublereal *, integer *,
  30. doublereal *, integer *);
  31. extern doublereal _starpu_dlamch_(char *);
  32. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  33. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  34. /* -- LAPACK routine (version 3.2) -- */
  35. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  36. /* November 2006 */
  37. /* .. Scalar Arguments .. */
  38. /* .. */
  39. /* .. Array Arguments .. */
  40. /* .. */
  41. /* Purpose */
  42. /* ======= */
  43. /* DGETF2 computes an LU factorization of a general m-by-n matrix A */
  44. /* using partial pivoting with row interchanges. */
  45. /* The factorization has the form */
  46. /* A = P * L * U */
  47. /* where P is a permutation matrix, L is lower triangular with unit */
  48. /* diagonal elements (lower trapezoidal if m > n), and U is upper */
  49. /* triangular (upper trapezoidal if m < n). */
  50. /* This is the right-looking Level 2 BLAS version of the algorithm. */
  51. /* Arguments */
  52. /* ========= */
  53. /* M (input) INTEGER */
  54. /* The number of rows of the matrix A. M >= 0. */
  55. /* N (input) INTEGER */
  56. /* The number of columns of the matrix A. N >= 0. */
  57. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  58. /* On entry, the m by n matrix to be factored. */
  59. /* On exit, the factors L and U from the factorization */
  60. /* A = P*L*U; the unit diagonal elements of L are not stored. */
  61. /* LDA (input) INTEGER */
  62. /* The leading dimension of the array A. LDA >= max(1,M). */
  63. /* IPIV (output) INTEGER array, dimension (min(M,N)) */
  64. /* The pivot indices; for 1 <= i <= min(M,N), row i of the */
  65. /* matrix was interchanged with row IPIV(i). */
  66. /* INFO (output) INTEGER */
  67. /* = 0: successful exit */
  68. /* < 0: if INFO = -k, the k-th argument had an illegal value */
  69. /* > 0: if INFO = k, U(k,k) is exactly zero. The factorization */
  70. /* has been completed, but the factor U is exactly */
  71. /* singular, and division by zero will occur if it is used */
  72. /* to solve a system of equations. */
  73. /* ===================================================================== */
  74. /* .. Parameters .. */
  75. /* .. */
  76. /* .. Local Scalars .. */
  77. /* .. */
  78. /* .. External Functions .. */
  79. /* .. */
  80. /* .. External Subroutines .. */
  81. /* .. */
  82. /* .. Intrinsic Functions .. */
  83. /* .. */
  84. /* .. Executable Statements .. */
  85. /* Test the input parameters. */
  86. /* Parameter adjustments */
  87. a_dim1 = *lda;
  88. a_offset = 1 + a_dim1;
  89. a -= a_offset;
  90. --ipiv;
  91. /* Function Body */
  92. *info = 0;
  93. if (*m < 0) {
  94. *info = -1;
  95. } else if (*n < 0) {
  96. *info = -2;
  97. } else if (*lda < max(1,*m)) {
  98. *info = -4;
  99. }
  100. if (*info != 0) {
  101. i__1 = -(*info);
  102. _starpu_xerbla_("DGETF2", &i__1);
  103. return 0;
  104. }
  105. /* Quick return if possible */
  106. if (*m == 0 || *n == 0) {
  107. return 0;
  108. }
  109. /* Compute machine safe minimum */
  110. sfmin = _starpu_dlamch_("S");
  111. i__1 = min(*m,*n);
  112. for (j = 1; j <= i__1; ++j) {
  113. /* Find pivot and test for singularity. */
  114. i__2 = *m - j + 1;
  115. jp = j - 1 + _starpu_idamax_(&i__2, &a[j + j * a_dim1], &c__1);
  116. ipiv[j] = jp;
  117. if (a[jp + j * a_dim1] != 0.) {
  118. /* Apply the interchange to columns 1:N. */
  119. if (jp != j) {
  120. _starpu_dswap_(n, &a[j + a_dim1], lda, &a[jp + a_dim1], lda);
  121. }
  122. /* Compute elements J+1:M of J-th column. */
  123. if (j < *m) {
  124. if ((d__1 = a[j + j * a_dim1], abs(d__1)) >= sfmin) {
  125. i__2 = *m - j;
  126. d__1 = 1. / a[j + j * a_dim1];
  127. _starpu_dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
  128. } else {
  129. i__2 = *m - j;
  130. for (i__ = 1; i__ <= i__2; ++i__) {
  131. a[j + i__ + j * a_dim1] /= a[j + j * a_dim1];
  132. /* L20: */
  133. }
  134. }
  135. }
  136. } else if (*info == 0) {
  137. *info = j;
  138. }
  139. if (j < min(*m,*n)) {
  140. /* Update trailing submatrix. */
  141. i__2 = *m - j;
  142. i__3 = *n - j;
  143. _starpu_dger_(&i__2, &i__3, &c_b8, &a[j + 1 + j * a_dim1], &c__1, &a[j + (
  144. j + 1) * a_dim1], lda, &a[j + 1 + (j + 1) * a_dim1], lda);
  145. }
  146. /* L10: */
  147. }
  148. return 0;
  149. /* End of DGETF2 */
  150. } /* _starpu_dgetf2_ */