sgetc2.c
Go to the documentation of this file.
00001 /* sgetc2.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static real c_b10 = -1.f;
00020 
00021 /* Subroutine */ int sgetc2_(integer *n, real *a, integer *lda, integer *ipiv, 
00022          integer *jpiv, integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2, i__3;
00026     real r__1;
00027 
00028     /* Local variables */
00029     integer i__, j, ip, jp;
00030     real eps;
00031     integer ipv, jpv;
00032     extern /* Subroutine */ int sger_(integer *, integer *, real *, real *, 
00033             integer *, real *, integer *, real *, integer *);
00034     real smin, xmax;
00035     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
00036             integer *), slabad_(real *, real *);
00037     extern doublereal slamch_(char *);
00038     real bignum, smlnum;
00039 
00040 
00041 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00042 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00043 /*     November 2006 */
00044 
00045 /*     .. Scalar Arguments .. */
00046 /*     .. */
00047 /*     .. Array Arguments .. */
00048 /*     .. */
00049 
00050 /*  Purpose */
00051 /*  ======= */
00052 
00053 /*  SGETC2 computes an LU factorization with complete pivoting of the */
00054 /*  n-by-n matrix A. The factorization has the form A = P * L * U * Q, */
00055 /*  where P and Q are permutation matrices, L is lower triangular with */
00056 /*  unit diagonal elements and U is upper triangular. */
00057 
00058 /*  This is the Level 2 BLAS algorithm. */
00059 
00060 /*  Arguments */
00061 /*  ========= */
00062 
00063 /*  N       (input) INTEGER */
00064 /*          The order of the matrix A. N >= 0. */
00065 
00066 /*  A       (input/output) REAL array, dimension (LDA, N) */
00067 /*          On entry, the n-by-n matrix A to be factored. */
00068 /*          On exit, the factors L and U from the factorization */
00069 /*          A = P*L*U*Q; the unit diagonal elements of L are not stored. */
00070 /*          If U(k, k) appears to be less than SMIN, U(k, k) is given the */
00071 /*          value of SMIN, i.e., giving a nonsingular perturbed system. */
00072 
00073 /*  LDA     (input) INTEGER */
00074 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00075 
00076 /*  IPIV    (output) INTEGER array, dimension(N). */
00077 /*          The pivot indices; for 1 <= i <= N, row i of the */
00078 /*          matrix has been interchanged with row IPIV(i). */
00079 
00080 /*  JPIV    (output) INTEGER array, dimension(N). */
00081 /*          The pivot indices; for 1 <= j <= N, column j of the */
00082 /*          matrix has been interchanged with column JPIV(j). */
00083 
00084 /*  INFO    (output) INTEGER */
00085 /*           = 0: successful exit */
00086 /*           > 0: if INFO = k, U(k, k) is likely to produce owerflow if */
00087 /*                we try to solve for x in Ax = b. So U is perturbed to */
00088 /*                avoid the overflow. */
00089 
00090 /*  Further Details */
00091 /*  =============== */
00092 
00093 /*  Based on contributions by */
00094 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00095 /*     Umea University, S-901 87 Umea, Sweden. */
00096 
00097 /*  ===================================================================== */
00098 
00099 /*     .. Parameters .. */
00100 /*     .. */
00101 /*     .. Local Scalars .. */
00102 /*     .. */
00103 /*     .. External Subroutines .. */
00104 /*     .. */
00105 /*     .. External Functions .. */
00106 /*     .. */
00107 /*     .. Intrinsic Functions .. */
00108 /*     .. */
00109 /*     .. Executable Statements .. */
00110 
00111 /*     Set constants to control overflow */
00112 
00113     /* Parameter adjustments */
00114     a_dim1 = *lda;
00115     a_offset = 1 + a_dim1;
00116     a -= a_offset;
00117     --ipiv;
00118     --jpiv;
00119 
00120     /* Function Body */
00121     *info = 0;
00122     eps = slamch_("P");
00123     smlnum = slamch_("S") / eps;
00124     bignum = 1.f / smlnum;
00125     slabad_(&smlnum, &bignum);
00126 
00127 /*     Factorize A using complete pivoting. */
00128 /*     Set pivots less than SMIN to SMIN. */
00129 
00130     i__1 = *n - 1;
00131     for (i__ = 1; i__ <= i__1; ++i__) {
00132 
00133 /*        Find max element in matrix A */
00134 
00135         xmax = 0.f;
00136         i__2 = *n;
00137         for (ip = i__; ip <= i__2; ++ip) {
00138             i__3 = *n;
00139             for (jp = i__; jp <= i__3; ++jp) {
00140                 if ((r__1 = a[ip + jp * a_dim1], dabs(r__1)) >= xmax) {
00141                     xmax = (r__1 = a[ip + jp * a_dim1], dabs(r__1));
00142                     ipv = ip;
00143                     jpv = jp;
00144                 }
00145 /* L10: */
00146             }
00147 /* L20: */
00148         }
00149         if (i__ == 1) {
00150 /* Computing MAX */
00151             r__1 = eps * xmax;
00152             smin = dmax(r__1,smlnum);
00153         }
00154 
00155 /*        Swap rows */
00156 
00157         if (ipv != i__) {
00158             sswap_(n, &a[ipv + a_dim1], lda, &a[i__ + a_dim1], lda);
00159         }
00160         ipiv[i__] = ipv;
00161 
00162 /*        Swap columns */
00163 
00164         if (jpv != i__) {
00165             sswap_(n, &a[jpv * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
00166                     c__1);
00167         }
00168         jpiv[i__] = jpv;
00169 
00170 /*        Check for singularity */
00171 
00172         if ((r__1 = a[i__ + i__ * a_dim1], dabs(r__1)) < smin) {
00173             *info = i__;
00174             a[i__ + i__ * a_dim1] = smin;
00175         }
00176         i__2 = *n;
00177         for (j = i__ + 1; j <= i__2; ++j) {
00178             a[j + i__ * a_dim1] /= a[i__ + i__ * a_dim1];
00179 /* L30: */
00180         }
00181         i__2 = *n - i__;
00182         i__3 = *n - i__;
00183         sger_(&i__2, &i__3, &c_b10, &a[i__ + 1 + i__ * a_dim1], &c__1, &a[i__ 
00184                 + (i__ + 1) * a_dim1], lda, &a[i__ + 1 + (i__ + 1) * a_dim1], 
00185                 lda);
00186 /* L40: */
00187     }
00188 
00189     if ((r__1 = a[*n + *n * a_dim1], dabs(r__1)) < smin) {
00190         *info = *n;
00191         a[*n + *n * a_dim1] = smin;
00192     }
00193 
00194     return 0;
00195 
00196 /*     End of SGETC2 */
00197 
00198 } /* sgetc2_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:08