sgbtrf.c
Go to the documentation of this file.
00001 /* sgbtrf.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 integer c__65 = 65;
00020 static real c_b18 = -1.f;
00021 static real c_b31 = 1.f;
00022 
00023 /* Subroutine */ int sgbtrf_(integer *m, integer *n, integer *kl, integer *ku, 
00024          real *ab, integer *ldab, integer *ipiv, integer *info)
00025 {
00026     /* System generated locals */
00027     integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00028     real r__1;
00029 
00030     /* Local variables */
00031     integer i__, j, i2, i3, j2, j3, k2, jb, nb, ii, jj, jm, ip, jp, km, ju, 
00032             kv, nw;
00033     extern /* Subroutine */ int sger_(integer *, integer *, real *, real *, 
00034             integer *, real *, integer *, real *, integer *);
00035     real temp;
00036     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
00037             sgemm_(char *, char *, integer *, integer *, integer *, real *, 
00038             real *, integer *, real *, integer *, real *, real *, integer *);
00039     real work13[4160]   /* was [65][64] */, work31[4160]        /* was [65][
00040             64] */;
00041     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00042             integer *), sswap_(integer *, real *, integer *, real *, integer *
00043 ), strsm_(char *, char *, char *, char *, integer *, integer *, 
00044             real *, real *, integer *, real *, integer *), sgbtf2_(integer *, integer *, integer *, integer 
00045             *, real *, integer *, integer *, integer *), xerbla_(char *, 
00046             integer *);
00047     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00048             integer *, integer *), isamax_(integer *, real *, 
00049             integer *);
00050     extern /* Subroutine */ int slaswp_(integer *, real *, integer *, integer 
00051             *, integer *, integer *, integer *);
00052 
00053 
00054 /*  -- LAPACK routine (version 3.2) -- */
00055 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00056 /*     November 2006 */
00057 
00058 /*     .. Scalar Arguments .. */
00059 /*     .. */
00060 /*     .. Array Arguments .. */
00061 /*     .. */
00062 
00063 /*  Purpose */
00064 /*  ======= */
00065 
00066 /*  SGBTRF computes an LU factorization of a real m-by-n band matrix A */
00067 /*  using partial pivoting with row interchanges. */
00068 
00069 /*  This is the blocked version of the algorithm, calling Level 3 BLAS. */
00070 
00071 /*  Arguments */
00072 /*  ========= */
00073 
00074 /*  M       (input) INTEGER */
00075 /*          The number of rows of the matrix A.  M >= 0. */
00076 
00077 /*  N       (input) INTEGER */
00078 /*          The number of columns of the matrix A.  N >= 0. */
00079 
00080 /*  KL      (input) INTEGER */
00081 /*          The number of subdiagonals within the band of A.  KL >= 0. */
00082 
00083 /*  KU      (input) INTEGER */
00084 /*          The number of superdiagonals within the band of A.  KU >= 0. */
00085 
00086 /*  AB      (input/output) REAL array, dimension (LDAB,N) */
00087 /*          On entry, the matrix A in band storage, in rows KL+1 to */
00088 /*          2*KL+KU+1; rows 1 to KL of the array need not be set. */
00089 /*          The j-th column of A is stored in the j-th column of the */
00090 /*          array AB as follows: */
00091 /*          AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl) */
00092 
00093 /*          On exit, details of the factorization: U is stored as an */
00094 /*          upper triangular band matrix with KL+KU superdiagonals in */
00095 /*          rows 1 to KL+KU+1, and the multipliers used during the */
00096 /*          factorization are stored in rows KL+KU+2 to 2*KL+KU+1. */
00097 /*          See below for further details. */
00098 
00099 /*  LDAB    (input) INTEGER */
00100 /*          The leading dimension of the array AB.  LDAB >= 2*KL+KU+1. */
00101 
00102 /*  IPIV    (output) INTEGER array, dimension (min(M,N)) */
00103 /*          The pivot indices; for 1 <= i <= min(M,N), row i of the */
00104 /*          matrix was interchanged with row IPIV(i). */
00105 
00106 /*  INFO    (output) INTEGER */
00107 /*          = 0: successful exit */
00108 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00109 /*          > 0: if INFO = +i, U(i,i) is exactly zero. The factorization */
00110 /*               has been completed, but the factor U is exactly */
00111 /*               singular, and division by zero will occur if it is used */
00112 /*               to solve a system of equations. */
00113 
00114 /*  Further Details */
00115 /*  =============== */
00116 
00117 /*  The band storage scheme is illustrated by the following example, when */
00118 /*  M = N = 6, KL = 2, KU = 1: */
00119 
00120 /*  On entry:                       On exit: */
00121 
00122 /*      *    *    *    +    +    +       *    *    *   u14  u25  u36 */
00123 /*      *    *    +    +    +    +       *    *   u13  u24  u35  u46 */
00124 /*      *   a12  a23  a34  a45  a56      *   u12  u23  u34  u45  u56 */
00125 /*     a11  a22  a33  a44  a55  a66     u11  u22  u33  u44  u55  u66 */
00126 /*     a21  a32  a43  a54  a65   *      m21  m32  m43  m54  m65   * */
00127 /*     a31  a42  a53  a64   *    *      m31  m42  m53  m64   *    * */
00128 
00129 /*  Array elements marked * are not used by the routine; elements marked */
00130 /*  + need not be set on entry, but are required by the routine to store */
00131 /*  elements of U because of fill-in resulting from the row interchanges. */
00132 
00133 /*  ===================================================================== */
00134 
00135 /*     .. Parameters .. */
00136 /*     .. */
00137 /*     .. Local Scalars .. */
00138 /*     .. */
00139 /*     .. Local Arrays .. */
00140 /*     .. */
00141 /*     .. External Functions .. */
00142 /*     .. */
00143 /*     .. External Subroutines .. */
00144 /*     .. */
00145 /*     .. Intrinsic Functions .. */
00146 /*     .. */
00147 /*     .. Executable Statements .. */
00148 
00149 /*     KV is the number of superdiagonals in the factor U, allowing for */
00150 /*     fill-in */
00151 
00152     /* Parameter adjustments */
00153     ab_dim1 = *ldab;
00154     ab_offset = 1 + ab_dim1;
00155     ab -= ab_offset;
00156     --ipiv;
00157 
00158     /* Function Body */
00159     kv = *ku + *kl;
00160 
00161 /*     Test the input parameters. */
00162 
00163     *info = 0;
00164     if (*m < 0) {
00165         *info = -1;
00166     } else if (*n < 0) {
00167         *info = -2;
00168     } else if (*kl < 0) {
00169         *info = -3;
00170     } else if (*ku < 0) {
00171         *info = -4;
00172     } else if (*ldab < *kl + kv + 1) {
00173         *info = -6;
00174     }
00175     if (*info != 0) {
00176         i__1 = -(*info);
00177         xerbla_("SGBTRF", &i__1);
00178         return 0;
00179     }
00180 
00181 /*     Quick return if possible */
00182 
00183     if (*m == 0 || *n == 0) {
00184         return 0;
00185     }
00186 
00187 /*     Determine the block size for this environment */
00188 
00189     nb = ilaenv_(&c__1, "SGBTRF", " ", m, n, kl, ku);
00190 
00191 /*     The block size must not exceed the limit set by the size of the */
00192 /*     local arrays WORK13 and WORK31. */
00193 
00194     nb = min(nb,64);
00195 
00196     if (nb <= 1 || nb > *kl) {
00197 
00198 /*        Use unblocked code */
00199 
00200         sgbtf2_(m, n, kl, ku, &ab[ab_offset], ldab, &ipiv[1], info);
00201     } else {
00202 
00203 /*        Use blocked code */
00204 
00205 /*        Zero the superdiagonal elements of the work array WORK13 */
00206 
00207         i__1 = nb;
00208         for (j = 1; j <= i__1; ++j) {
00209             i__2 = j - 1;
00210             for (i__ = 1; i__ <= i__2; ++i__) {
00211                 work13[i__ + j * 65 - 66] = 0.f;
00212 /* L10: */
00213             }
00214 /* L20: */
00215         }
00216 
00217 /*        Zero the subdiagonal elements of the work array WORK31 */
00218 
00219         i__1 = nb;
00220         for (j = 1; j <= i__1; ++j) {
00221             i__2 = nb;
00222             for (i__ = j + 1; i__ <= i__2; ++i__) {
00223                 work31[i__ + j * 65 - 66] = 0.f;
00224 /* L30: */
00225             }
00226 /* L40: */
00227         }
00228 
00229 /*        Gaussian elimination with partial pivoting */
00230 
00231 /*        Set fill-in elements in columns KU+2 to KV to zero */
00232 
00233         i__1 = min(kv,*n);
00234         for (j = *ku + 2; j <= i__1; ++j) {
00235             i__2 = *kl;
00236             for (i__ = kv - j + 2; i__ <= i__2; ++i__) {
00237                 ab[i__ + j * ab_dim1] = 0.f;
00238 /* L50: */
00239             }
00240 /* L60: */
00241         }
00242 
00243 /*        JU is the index of the last column affected by the current */
00244 /*        stage of the factorization */
00245 
00246         ju = 1;
00247 
00248         i__1 = min(*m,*n);
00249         i__2 = nb;
00250         for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00251 /* Computing MIN */
00252             i__3 = nb, i__4 = min(*m,*n) - j + 1;
00253             jb = min(i__3,i__4);
00254 
00255 /*           The active part of the matrix is partitioned */
00256 
00257 /*              A11   A12   A13 */
00258 /*              A21   A22   A23 */
00259 /*              A31   A32   A33 */
00260 
00261 /*           Here A11, A21 and A31 denote the current block of JB columns */
00262 /*           which is about to be factorized. The number of rows in the */
00263 /*           partitioning are JB, I2, I3 respectively, and the numbers */
00264 /*           of columns are JB, J2, J3. The superdiagonal elements of A13 */
00265 /*           and the subdiagonal elements of A31 lie outside the band. */
00266 
00267 /* Computing MIN */
00268             i__3 = *kl - jb, i__4 = *m - j - jb + 1;
00269             i2 = min(i__3,i__4);
00270 /* Computing MIN */
00271             i__3 = jb, i__4 = *m - j - *kl + 1;
00272             i3 = min(i__3,i__4);
00273 
00274 /*           J2 and J3 are computed after JU has been updated. */
00275 
00276 /*           Factorize the current block of JB columns */
00277 
00278             i__3 = j + jb - 1;
00279             for (jj = j; jj <= i__3; ++jj) {
00280 
00281 /*              Set fill-in elements in column JJ+KV to zero */
00282 
00283                 if (jj + kv <= *n) {
00284                     i__4 = *kl;
00285                     for (i__ = 1; i__ <= i__4; ++i__) {
00286                         ab[i__ + (jj + kv) * ab_dim1] = 0.f;
00287 /* L70: */
00288                     }
00289                 }
00290 
00291 /*              Find pivot and test for singularity. KM is the number of */
00292 /*              subdiagonal elements in the current column. */
00293 
00294 /* Computing MIN */
00295                 i__4 = *kl, i__5 = *m - jj;
00296                 km = min(i__4,i__5);
00297                 i__4 = km + 1;
00298                 jp = isamax_(&i__4, &ab[kv + 1 + jj * ab_dim1], &c__1);
00299                 ipiv[jj] = jp + jj - j;
00300                 if (ab[kv + jp + jj * ab_dim1] != 0.f) {
00301 /* Computing MAX */
00302 /* Computing MIN */
00303                     i__6 = jj + *ku + jp - 1;
00304                     i__4 = ju, i__5 = min(i__6,*n);
00305                     ju = max(i__4,i__5);
00306                     if (jp != 1) {
00307 
00308 /*                    Apply interchange to columns J to J+JB-1 */
00309 
00310                         if (jp + jj - 1 < j + *kl) {
00311 
00312                             i__4 = *ldab - 1;
00313                             i__5 = *ldab - 1;
00314                             sswap_(&jb, &ab[kv + 1 + jj - j + j * ab_dim1], &
00315                                     i__4, &ab[kv + jp + jj - j + j * ab_dim1], 
00316                                      &i__5);
00317                         } else {
00318 
00319 /*                       The interchange affects columns J to JJ-1 of A31 */
00320 /*                       which are stored in the work array WORK31 */
00321 
00322                             i__4 = jj - j;
00323                             i__5 = *ldab - 1;
00324                             sswap_(&i__4, &ab[kv + 1 + jj - j + j * ab_dim1], 
00325                                     &i__5, &work31[jp + jj - j - *kl - 1], &
00326                                     c__65);
00327                             i__4 = j + jb - jj;
00328                             i__5 = *ldab - 1;
00329                             i__6 = *ldab - 1;
00330                             sswap_(&i__4, &ab[kv + 1 + jj * ab_dim1], &i__5, &
00331                                     ab[kv + jp + jj * ab_dim1], &i__6);
00332                         }
00333                     }
00334 
00335 /*                 Compute multipliers */
00336 
00337                     r__1 = 1.f / ab[kv + 1 + jj * ab_dim1];
00338                     sscal_(&km, &r__1, &ab[kv + 2 + jj * ab_dim1], &c__1);
00339 
00340 /*                 Update trailing submatrix within the band and within */
00341 /*                 the current block. JM is the index of the last column */
00342 /*                 which needs to be updated. */
00343 
00344 /* Computing MIN */
00345                     i__4 = ju, i__5 = j + jb - 1;
00346                     jm = min(i__4,i__5);
00347                     if (jm > jj) {
00348                         i__4 = jm - jj;
00349                         i__5 = *ldab - 1;
00350                         i__6 = *ldab - 1;
00351                         sger_(&km, &i__4, &c_b18, &ab[kv + 2 + jj * ab_dim1], 
00352                                 &c__1, &ab[kv + (jj + 1) * ab_dim1], &i__5, &
00353                                 ab[kv + 1 + (jj + 1) * ab_dim1], &i__6);
00354                     }
00355                 } else {
00356 
00357 /*                 If pivot is zero, set INFO to the index of the pivot */
00358 /*                 unless a zero pivot has already been found. */
00359 
00360                     if (*info == 0) {
00361                         *info = jj;
00362                     }
00363                 }
00364 
00365 /*              Copy current column of A31 into the work array WORK31 */
00366 
00367 /* Computing MIN */
00368                 i__4 = jj - j + 1;
00369                 nw = min(i__4,i3);
00370                 if (nw > 0) {
00371                     scopy_(&nw, &ab[kv + *kl + 1 - jj + j + jj * ab_dim1], &
00372                             c__1, &work31[(jj - j + 1) * 65 - 65], &c__1);
00373                 }
00374 /* L80: */
00375             }
00376             if (j + jb <= *n) {
00377 
00378 /*              Apply the row interchanges to the other blocks. */
00379 
00380 /* Computing MIN */
00381                 i__3 = ju - j + 1;
00382                 j2 = min(i__3,kv) - jb;
00383 /* Computing MAX */
00384                 i__3 = 0, i__4 = ju - j - kv + 1;
00385                 j3 = max(i__3,i__4);
00386 
00387 /*              Use SLASWP to apply the row interchanges to A12, A22, and */
00388 /*              A32. */
00389 
00390                 i__3 = *ldab - 1;
00391                 slaswp_(&j2, &ab[kv + 1 - jb + (j + jb) * ab_dim1], &i__3, &
00392                         c__1, &jb, &ipiv[j], &c__1);
00393 
00394 /*              Adjust the pivot indices. */
00395 
00396                 i__3 = j + jb - 1;
00397                 for (i__ = j; i__ <= i__3; ++i__) {
00398                     ipiv[i__] = ipiv[i__] + j - 1;
00399 /* L90: */
00400                 }
00401 
00402 /*              Apply the row interchanges to A13, A23, and A33 */
00403 /*              columnwise. */
00404 
00405                 k2 = j - 1 + jb + j2;
00406                 i__3 = j3;
00407                 for (i__ = 1; i__ <= i__3; ++i__) {
00408                     jj = k2 + i__;
00409                     i__4 = j + jb - 1;
00410                     for (ii = j + i__ - 1; ii <= i__4; ++ii) {
00411                         ip = ipiv[ii];
00412                         if (ip != ii) {
00413                             temp = ab[kv + 1 + ii - jj + jj * ab_dim1];
00414                             ab[kv + 1 + ii - jj + jj * ab_dim1] = ab[kv + 1 + 
00415                                     ip - jj + jj * ab_dim1];
00416                             ab[kv + 1 + ip - jj + jj * ab_dim1] = temp;
00417                         }
00418 /* L100: */
00419                     }
00420 /* L110: */
00421                 }
00422 
00423 /*              Update the relevant part of the trailing submatrix */
00424 
00425                 if (j2 > 0) {
00426 
00427 /*                 Update A12 */
00428 
00429                     i__3 = *ldab - 1;
00430                     i__4 = *ldab - 1;
00431                     strsm_("Left", "Lower", "No transpose", "Unit", &jb, &j2, 
00432                             &c_b31, &ab[kv + 1 + j * ab_dim1], &i__3, &ab[kv 
00433                             + 1 - jb + (j + jb) * ab_dim1], &i__4);
00434 
00435                     if (i2 > 0) {
00436 
00437 /*                    Update A22 */
00438 
00439                         i__3 = *ldab - 1;
00440                         i__4 = *ldab - 1;
00441                         i__5 = *ldab - 1;
00442                         sgemm_("No transpose", "No transpose", &i2, &j2, &jb, 
00443                                 &c_b18, &ab[kv + 1 + jb + j * ab_dim1], &i__3, 
00444                                  &ab[kv + 1 - jb + (j + jb) * ab_dim1], &i__4, 
00445                                  &c_b31, &ab[kv + 1 + (j + jb) * ab_dim1], &
00446                                 i__5);
00447                     }
00448 
00449                     if (i3 > 0) {
00450 
00451 /*                    Update A32 */
00452 
00453                         i__3 = *ldab - 1;
00454                         i__4 = *ldab - 1;
00455                         sgemm_("No transpose", "No transpose", &i3, &j2, &jb, 
00456                                 &c_b18, work31, &c__65, &ab[kv + 1 - jb + (j 
00457                                 + jb) * ab_dim1], &i__3, &c_b31, &ab[kv + *kl 
00458                                 + 1 - jb + (j + jb) * ab_dim1], &i__4);
00459                     }
00460                 }
00461 
00462                 if (j3 > 0) {
00463 
00464 /*                 Copy the lower triangle of A13 into the work array */
00465 /*                 WORK13 */
00466 
00467                     i__3 = j3;
00468                     for (jj = 1; jj <= i__3; ++jj) {
00469                         i__4 = jb;
00470                         for (ii = jj; ii <= i__4; ++ii) {
00471                             work13[ii + jj * 65 - 66] = ab[ii - jj + 1 + (jj 
00472                                     + j + kv - 1) * ab_dim1];
00473 /* L120: */
00474                         }
00475 /* L130: */
00476                     }
00477 
00478 /*                 Update A13 in the work array */
00479 
00480                     i__3 = *ldab - 1;
00481                     strsm_("Left", "Lower", "No transpose", "Unit", &jb, &j3, 
00482                             &c_b31, &ab[kv + 1 + j * ab_dim1], &i__3, work13, 
00483                             &c__65);
00484 
00485                     if (i2 > 0) {
00486 
00487 /*                    Update A23 */
00488 
00489                         i__3 = *ldab - 1;
00490                         i__4 = *ldab - 1;
00491                         sgemm_("No transpose", "No transpose", &i2, &j3, &jb, 
00492                                 &c_b18, &ab[kv + 1 + jb + j * ab_dim1], &i__3, 
00493                                  work13, &c__65, &c_b31, &ab[jb + 1 + (j + kv)
00494                                  * ab_dim1], &i__4);
00495                     }
00496 
00497                     if (i3 > 0) {
00498 
00499 /*                    Update A33 */
00500 
00501                         i__3 = *ldab - 1;
00502                         sgemm_("No transpose", "No transpose", &i3, &j3, &jb, 
00503                                 &c_b18, work31, &c__65, work13, &c__65, &
00504                                 c_b31, &ab[*kl + 1 + (j + kv) * ab_dim1], &
00505                                 i__3);
00506                     }
00507 
00508 /*                 Copy the lower triangle of A13 back into place */
00509 
00510                     i__3 = j3;
00511                     for (jj = 1; jj <= i__3; ++jj) {
00512                         i__4 = jb;
00513                         for (ii = jj; ii <= i__4; ++ii) {
00514                             ab[ii - jj + 1 + (jj + j + kv - 1) * ab_dim1] = 
00515                                     work13[ii + jj * 65 - 66];
00516 /* L140: */
00517                         }
00518 /* L150: */
00519                     }
00520                 }
00521             } else {
00522 
00523 /*              Adjust the pivot indices. */
00524 
00525                 i__3 = j + jb - 1;
00526                 for (i__ = j; i__ <= i__3; ++i__) {
00527                     ipiv[i__] = ipiv[i__] + j - 1;
00528 /* L160: */
00529                 }
00530             }
00531 
00532 /*           Partially undo the interchanges in the current block to */
00533 /*           restore the upper triangular form of A31 and copy the upper */
00534 /*           triangle of A31 back into place */
00535 
00536             i__3 = j;
00537             for (jj = j + jb - 1; jj >= i__3; --jj) {
00538                 jp = ipiv[jj] - jj + 1;
00539                 if (jp != 1) {
00540 
00541 /*                 Apply interchange to columns J to JJ-1 */
00542 
00543                     if (jp + jj - 1 < j + *kl) {
00544 
00545 /*                    The interchange does not affect A31 */
00546 
00547                         i__4 = jj - j;
00548                         i__5 = *ldab - 1;
00549                         i__6 = *ldab - 1;
00550                         sswap_(&i__4, &ab[kv + 1 + jj - j + j * ab_dim1], &
00551                                 i__5, &ab[kv + jp + jj - j + j * ab_dim1], &
00552                                 i__6);
00553                     } else {
00554 
00555 /*                    The interchange does affect A31 */
00556 
00557                         i__4 = jj - j;
00558                         i__5 = *ldab - 1;
00559                         sswap_(&i__4, &ab[kv + 1 + jj - j + j * ab_dim1], &
00560                                 i__5, &work31[jp + jj - j - *kl - 1], &c__65);
00561                     }
00562                 }
00563 
00564 /*              Copy the current column of A31 back into place */
00565 
00566 /* Computing MIN */
00567                 i__4 = i3, i__5 = jj - j + 1;
00568                 nw = min(i__4,i__5);
00569                 if (nw > 0) {
00570                     scopy_(&nw, &work31[(jj - j + 1) * 65 - 65], &c__1, &ab[
00571                             kv + *kl + 1 - jj + j + jj * ab_dim1], &c__1);
00572                 }
00573 /* L170: */
00574             }
00575 /* L180: */
00576         }
00577     }
00578 
00579     return 0;
00580 
00581 /*     End of SGBTRF */
00582 
00583 } /* sgbtrf_ */


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