You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sgbtrf.c 25 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static integer c__1 = 1;
  236. static integer c__65 = 65;
  237. static real c_b18 = -1.f;
  238. static real c_b31 = 1.f;
  239. /* > \brief \b SGBTRF */
  240. /* =========== DOCUMENTATION =========== */
  241. /* Online html documentation available at */
  242. /* http://www.netlib.org/lapack/explore-html/ */
  243. /* > \htmlonly */
  244. /* > Download SGBTRF + dependencies */
  245. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgbtrf.
  246. f"> */
  247. /* > [TGZ]</a> */
  248. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgbtrf.
  249. f"> */
  250. /* > [ZIP]</a> */
  251. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgbtrf.
  252. f"> */
  253. /* > [TXT]</a> */
  254. /* > \endhtmlonly */
  255. /* Definition: */
  256. /* =========== */
  257. /* SUBROUTINE SGBTRF( M, N, KL, KU, AB, LDAB, IPIV, INFO ) */
  258. /* INTEGER INFO, KL, KU, LDAB, M, N */
  259. /* INTEGER IPIV( * ) */
  260. /* REAL AB( LDAB, * ) */
  261. /* > \par Purpose: */
  262. /* ============= */
  263. /* > */
  264. /* > \verbatim */
  265. /* > */
  266. /* > SGBTRF computes an LU factorization of a real m-by-n band matrix A */
  267. /* > using partial pivoting with row interchanges. */
  268. /* > */
  269. /* > This is the blocked version of the algorithm, calling Level 3 BLAS. */
  270. /* > \endverbatim */
  271. /* Arguments: */
  272. /* ========== */
  273. /* > \param[in] M */
  274. /* > \verbatim */
  275. /* > M is INTEGER */
  276. /* > The number of rows of the matrix A. M >= 0. */
  277. /* > \endverbatim */
  278. /* > */
  279. /* > \param[in] N */
  280. /* > \verbatim */
  281. /* > N is INTEGER */
  282. /* > The number of columns of the matrix A. N >= 0. */
  283. /* > \endverbatim */
  284. /* > */
  285. /* > \param[in] KL */
  286. /* > \verbatim */
  287. /* > KL is INTEGER */
  288. /* > The number of subdiagonals within the band of A. KL >= 0. */
  289. /* > \endverbatim */
  290. /* > */
  291. /* > \param[in] KU */
  292. /* > \verbatim */
  293. /* > KU is INTEGER */
  294. /* > The number of superdiagonals within the band of A. KU >= 0. */
  295. /* > \endverbatim */
  296. /* > */
  297. /* > \param[in,out] AB */
  298. /* > \verbatim */
  299. /* > AB is REAL array, dimension (LDAB,N) */
  300. /* > On entry, the matrix A in band storage, in rows KL+1 to */
  301. /* > 2*KL+KU+1; rows 1 to KL of the array need not be set. */
  302. /* > The j-th column of A is stored in the j-th column of the */
  303. /* > array AB as follows: */
  304. /* > AB(kl+ku+1+i-j,j) = A(i,j) for f2cmax(1,j-ku)<=i<=f2cmin(m,j+kl) */
  305. /* > */
  306. /* > On exit, details of the factorization: U is stored as an */
  307. /* > upper triangular band matrix with KL+KU superdiagonals in */
  308. /* > rows 1 to KL+KU+1, and the multipliers used during the */
  309. /* > factorization are stored in rows KL+KU+2 to 2*KL+KU+1. */
  310. /* > See below for further details. */
  311. /* > \endverbatim */
  312. /* > */
  313. /* > \param[in] LDAB */
  314. /* > \verbatim */
  315. /* > LDAB is INTEGER */
  316. /* > The leading dimension of the array AB. LDAB >= 2*KL+KU+1. */
  317. /* > \endverbatim */
  318. /* > */
  319. /* > \param[out] IPIV */
  320. /* > \verbatim */
  321. /* > IPIV is INTEGER array, dimension (f2cmin(M,N)) */
  322. /* > The pivot indices; for 1 <= i <= f2cmin(M,N), row i of the */
  323. /* > matrix was interchanged with row IPIV(i). */
  324. /* > \endverbatim */
  325. /* > */
  326. /* > \param[out] INFO */
  327. /* > \verbatim */
  328. /* > INFO is INTEGER */
  329. /* > = 0: successful exit */
  330. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  331. /* > > 0: if INFO = +i, U(i,i) is exactly zero. The factorization */
  332. /* > has been completed, but the factor U is exactly */
  333. /* > singular, and division by zero will occur if it is used */
  334. /* > to solve a system of equations. */
  335. /* > \endverbatim */
  336. /* Authors: */
  337. /* ======== */
  338. /* > \author Univ. of Tennessee */
  339. /* > \author Univ. of California Berkeley */
  340. /* > \author Univ. of Colorado Denver */
  341. /* > \author NAG Ltd. */
  342. /* > \date December 2016 */
  343. /* > \ingroup realGBcomputational */
  344. /* > \par Further Details: */
  345. /* ===================== */
  346. /* > */
  347. /* > \verbatim */
  348. /* > */
  349. /* > The band storage scheme is illustrated by the following example, when */
  350. /* > M = N = 6, KL = 2, KU = 1: */
  351. /* > */
  352. /* > On entry: On exit: */
  353. /* > */
  354. /* > * * * + + + * * * u14 u25 u36 */
  355. /* > * * + + + + * * u13 u24 u35 u46 */
  356. /* > * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 */
  357. /* > a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 */
  358. /* > a21 a32 a43 a54 a65 * m21 m32 m43 m54 m65 * */
  359. /* > a31 a42 a53 a64 * * m31 m42 m53 m64 * * */
  360. /* > */
  361. /* > Array elements marked * are not used by the routine; elements marked */
  362. /* > + need not be set on entry, but are required by the routine to store */
  363. /* > elements of U because of fill-in resulting from the row interchanges. */
  364. /* > \endverbatim */
  365. /* > */
  366. /* ===================================================================== */
  367. /* Subroutine */ void sgbtrf_(integer *m, integer *n, integer *kl, integer *ku,
  368. real *ab, integer *ldab, integer *ipiv, integer *info)
  369. {
  370. /* System generated locals */
  371. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  372. real r__1;
  373. /* Local variables */
  374. extern /* Subroutine */ void sger_(integer *, integer *, real *, real *,
  375. integer *, real *, integer *, real *, integer *);
  376. real temp;
  377. integer i__, j;
  378. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *),
  379. sgemm_(char *, char *, integer *, integer *, integer *, real *,
  380. real *, integer *, real *, integer *, real *, real *, integer *);
  381. real work13[4160] /* was [65][64] */, work31[4160] /* was [65][
  382. 64] */;
  383. integer i2, i3, j2, j3, k2;
  384. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  385. integer *), sswap_(integer *, real *, integer *, real *, integer *
  386. ), strsm_(char *, char *, char *, char *, integer *, integer *,
  387. real *, real *, integer *, real *, integer *), sgbtf2_(integer *, integer *, integer *, integer
  388. *, real *, integer *, integer *, integer *);
  389. integer jb, nb, ii, jj, jm, ip, jp, km, ju, kv, nw;
  390. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  391. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  392. integer *, integer *, ftnlen, ftnlen), isamax_(integer *, real *,
  393. integer *);
  394. extern /* Subroutine */ int slaswp_(integer *, real *, integer *, integer
  395. *, integer *, integer *, integer *);
  396. /* -- LAPACK computational routine (version 3.7.0) -- */
  397. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  398. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  399. /* December 2016 */
  400. /* ===================================================================== */
  401. /* KV is the number of superdiagonals in the factor U, allowing for */
  402. /* fill-in */
  403. /* Parameter adjustments */
  404. ab_dim1 = *ldab;
  405. ab_offset = 1 + ab_dim1 * 1;
  406. ab -= ab_offset;
  407. --ipiv;
  408. /* Function Body */
  409. kv = *ku + *kl;
  410. /* Test the input parameters. */
  411. *info = 0;
  412. if (*m < 0) {
  413. *info = -1;
  414. } else if (*n < 0) {
  415. *info = -2;
  416. } else if (*kl < 0) {
  417. *info = -3;
  418. } else if (*ku < 0) {
  419. *info = -4;
  420. } else if (*ldab < *kl + kv + 1) {
  421. *info = -6;
  422. }
  423. if (*info != 0) {
  424. i__1 = -(*info);
  425. xerbla_("SGBTRF", &i__1, (ftnlen)6);
  426. return;
  427. }
  428. /* Quick return if possible */
  429. if (*m == 0 || *n == 0) {
  430. return;
  431. }
  432. /* Determine the block size for this environment */
  433. nb = ilaenv_(&c__1, "SGBTRF", " ", m, n, kl, ku, (ftnlen)6, (ftnlen)1);
  434. /* The block size must not exceed the limit set by the size of the */
  435. /* local arrays WORK13 and WORK31. */
  436. nb = f2cmin(nb,64);
  437. if (nb <= 1 || nb > *kl) {
  438. /* Use unblocked code */
  439. sgbtf2_(m, n, kl, ku, &ab[ab_offset], ldab, &ipiv[1], info);
  440. } else {
  441. /* Use blocked code */
  442. /* Zero the superdiagonal elements of the work array WORK13 */
  443. i__1 = nb;
  444. for (j = 1; j <= i__1; ++j) {
  445. i__2 = j - 1;
  446. for (i__ = 1; i__ <= i__2; ++i__) {
  447. work13[i__ + j * 65 - 66] = 0.f;
  448. /* L10: */
  449. }
  450. /* L20: */
  451. }
  452. /* Zero the subdiagonal elements of the work array WORK31 */
  453. i__1 = nb;
  454. for (j = 1; j <= i__1; ++j) {
  455. i__2 = nb;
  456. for (i__ = j + 1; i__ <= i__2; ++i__) {
  457. work31[i__ + j * 65 - 66] = 0.f;
  458. /* L30: */
  459. }
  460. /* L40: */
  461. }
  462. /* Gaussian elimination with partial pivoting */
  463. /* Set fill-in elements in columns KU+2 to KV to zero */
  464. i__1 = f2cmin(kv,*n);
  465. for (j = *ku + 2; j <= i__1; ++j) {
  466. i__2 = *kl;
  467. for (i__ = kv - j + 2; i__ <= i__2; ++i__) {
  468. ab[i__ + j * ab_dim1] = 0.f;
  469. /* L50: */
  470. }
  471. /* L60: */
  472. }
  473. /* JU is the index of the last column affected by the current */
  474. /* stage of the factorization */
  475. ju = 1;
  476. i__1 = f2cmin(*m,*n);
  477. i__2 = nb;
  478. for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  479. /* Computing MIN */
  480. i__3 = nb, i__4 = f2cmin(*m,*n) - j + 1;
  481. jb = f2cmin(i__3,i__4);
  482. /* The active part of the matrix is partitioned */
  483. /* A11 A12 A13 */
  484. /* A21 A22 A23 */
  485. /* A31 A32 A33 */
  486. /* Here A11, A21 and A31 denote the current block of JB columns */
  487. /* which is about to be factorized. The number of rows in the */
  488. /* partitioning are JB, I2, I3 respectively, and the numbers */
  489. /* of columns are JB, J2, J3. The superdiagonal elements of A13 */
  490. /* and the subdiagonal elements of A31 lie outside the band. */
  491. /* Computing MIN */
  492. i__3 = *kl - jb, i__4 = *m - j - jb + 1;
  493. i2 = f2cmin(i__3,i__4);
  494. /* Computing MIN */
  495. i__3 = jb, i__4 = *m - j - *kl + 1;
  496. i3 = f2cmin(i__3,i__4);
  497. /* J2 and J3 are computed after JU has been updated. */
  498. /* Factorize the current block of JB columns */
  499. i__3 = j + jb - 1;
  500. for (jj = j; jj <= i__3; ++jj) {
  501. /* Set fill-in elements in column JJ+KV to zero */
  502. if (jj + kv <= *n) {
  503. i__4 = *kl;
  504. for (i__ = 1; i__ <= i__4; ++i__) {
  505. ab[i__ + (jj + kv) * ab_dim1] = 0.f;
  506. /* L70: */
  507. }
  508. }
  509. /* Find pivot and test for singularity. KM is the number of */
  510. /* subdiagonal elements in the current column. */
  511. /* Computing MIN */
  512. i__4 = *kl, i__5 = *m - jj;
  513. km = f2cmin(i__4,i__5);
  514. i__4 = km + 1;
  515. jp = isamax_(&i__4, &ab[kv + 1 + jj * ab_dim1], &c__1);
  516. ipiv[jj] = jp + jj - j;
  517. if (ab[kv + jp + jj * ab_dim1] != 0.f) {
  518. /* Computing MAX */
  519. /* Computing MIN */
  520. i__6 = jj + *ku + jp - 1;
  521. i__4 = ju, i__5 = f2cmin(i__6,*n);
  522. ju = f2cmax(i__4,i__5);
  523. if (jp != 1) {
  524. /* Apply interchange to columns J to J+JB-1 */
  525. if (jp + jj - 1 < j + *kl) {
  526. i__4 = *ldab - 1;
  527. i__5 = *ldab - 1;
  528. sswap_(&jb, &ab[kv + 1 + jj - j + j * ab_dim1], &
  529. i__4, &ab[kv + jp + jj - j + j * ab_dim1],
  530. &i__5);
  531. } else {
  532. /* The interchange affects columns J to JJ-1 of A31 */
  533. /* which are stored in the work array WORK31 */
  534. i__4 = jj - j;
  535. i__5 = *ldab - 1;
  536. sswap_(&i__4, &ab[kv + 1 + jj - j + j * ab_dim1],
  537. &i__5, &work31[jp + jj - j - *kl - 1], &
  538. c__65);
  539. i__4 = j + jb - jj;
  540. i__5 = *ldab - 1;
  541. i__6 = *ldab - 1;
  542. sswap_(&i__4, &ab[kv + 1 + jj * ab_dim1], &i__5, &
  543. ab[kv + jp + jj * ab_dim1], &i__6);
  544. }
  545. }
  546. /* Compute multipliers */
  547. r__1 = 1.f / ab[kv + 1 + jj * ab_dim1];
  548. sscal_(&km, &r__1, &ab[kv + 2 + jj * ab_dim1], &c__1);
  549. /* Update trailing submatrix within the band and within */
  550. /* the current block. JM is the index of the last column */
  551. /* which needs to be updated. */
  552. /* Computing MIN */
  553. i__4 = ju, i__5 = j + jb - 1;
  554. jm = f2cmin(i__4,i__5);
  555. if (jm > jj) {
  556. i__4 = jm - jj;
  557. i__5 = *ldab - 1;
  558. i__6 = *ldab - 1;
  559. sger_(&km, &i__4, &c_b18, &ab[kv + 2 + jj * ab_dim1],
  560. &c__1, &ab[kv + (jj + 1) * ab_dim1], &i__5, &
  561. ab[kv + 1 + (jj + 1) * ab_dim1], &i__6);
  562. }
  563. } else {
  564. /* If pivot is zero, set INFO to the index of the pivot */
  565. /* unless a zero pivot has already been found. */
  566. if (*info == 0) {
  567. *info = jj;
  568. }
  569. }
  570. /* Copy current column of A31 into the work array WORK31 */
  571. /* Computing MIN */
  572. i__4 = jj - j + 1;
  573. nw = f2cmin(i__4,i3);
  574. if (nw > 0) {
  575. scopy_(&nw, &ab[kv + *kl + 1 - jj + j + jj * ab_dim1], &
  576. c__1, &work31[(jj - j + 1) * 65 - 65], &c__1);
  577. }
  578. /* L80: */
  579. }
  580. if (j + jb <= *n) {
  581. /* Apply the row interchanges to the other blocks. */
  582. /* Computing MIN */
  583. i__3 = ju - j + 1;
  584. j2 = f2cmin(i__3,kv) - jb;
  585. /* Computing MAX */
  586. i__3 = 0, i__4 = ju - j - kv + 1;
  587. j3 = f2cmax(i__3,i__4);
  588. /* Use SLASWP to apply the row interchanges to A12, A22, and */
  589. /* A32. */
  590. i__3 = *ldab - 1;
  591. slaswp_(&j2, &ab[kv + 1 - jb + (j + jb) * ab_dim1], &i__3, &
  592. c__1, &jb, &ipiv[j], &c__1);
  593. /* Adjust the pivot indices. */
  594. i__3 = j + jb - 1;
  595. for (i__ = j; i__ <= i__3; ++i__) {
  596. ipiv[i__] = ipiv[i__] + j - 1;
  597. /* L90: */
  598. }
  599. /* Apply the row interchanges to A13, A23, and A33 */
  600. /* columnwise. */
  601. k2 = j - 1 + jb + j2;
  602. i__3 = j3;
  603. for (i__ = 1; i__ <= i__3; ++i__) {
  604. jj = k2 + i__;
  605. i__4 = j + jb - 1;
  606. for (ii = j + i__ - 1; ii <= i__4; ++ii) {
  607. ip = ipiv[ii];
  608. if (ip != ii) {
  609. temp = ab[kv + 1 + ii - jj + jj * ab_dim1];
  610. ab[kv + 1 + ii - jj + jj * ab_dim1] = ab[kv + 1 +
  611. ip - jj + jj * ab_dim1];
  612. ab[kv + 1 + ip - jj + jj * ab_dim1] = temp;
  613. }
  614. /* L100: */
  615. }
  616. /* L110: */
  617. }
  618. /* Update the relevant part of the trailing submatrix */
  619. if (j2 > 0) {
  620. /* Update A12 */
  621. i__3 = *ldab - 1;
  622. i__4 = *ldab - 1;
  623. strsm_("Left", "Lower", "No transpose", "Unit", &jb, &j2,
  624. &c_b31, &ab[kv + 1 + j * ab_dim1], &i__3, &ab[kv
  625. + 1 - jb + (j + jb) * ab_dim1], &i__4);
  626. if (i2 > 0) {
  627. /* Update A22 */
  628. i__3 = *ldab - 1;
  629. i__4 = *ldab - 1;
  630. i__5 = *ldab - 1;
  631. sgemm_("No transpose", "No transpose", &i2, &j2, &jb,
  632. &c_b18, &ab[kv + 1 + jb + j * ab_dim1], &i__3,
  633. &ab[kv + 1 - jb + (j + jb) * ab_dim1], &i__4,
  634. &c_b31, &ab[kv + 1 + (j + jb) * ab_dim1], &
  635. i__5);
  636. }
  637. if (i3 > 0) {
  638. /* Update A32 */
  639. i__3 = *ldab - 1;
  640. i__4 = *ldab - 1;
  641. sgemm_("No transpose", "No transpose", &i3, &j2, &jb,
  642. &c_b18, work31, &c__65, &ab[kv + 1 - jb + (j
  643. + jb) * ab_dim1], &i__3, &c_b31, &ab[kv + *kl
  644. + 1 - jb + (j + jb) * ab_dim1], &i__4);
  645. }
  646. }
  647. if (j3 > 0) {
  648. /* Copy the lower triangle of A13 into the work array */
  649. /* WORK13 */
  650. i__3 = j3;
  651. for (jj = 1; jj <= i__3; ++jj) {
  652. i__4 = jb;
  653. for (ii = jj; ii <= i__4; ++ii) {
  654. work13[ii + jj * 65 - 66] = ab[ii - jj + 1 + (jj
  655. + j + kv - 1) * ab_dim1];
  656. /* L120: */
  657. }
  658. /* L130: */
  659. }
  660. /* Update A13 in the work array */
  661. i__3 = *ldab - 1;
  662. strsm_("Left", "Lower", "No transpose", "Unit", &jb, &j3,
  663. &c_b31, &ab[kv + 1 + j * ab_dim1], &i__3, work13,
  664. &c__65);
  665. if (i2 > 0) {
  666. /* Update A23 */
  667. i__3 = *ldab - 1;
  668. i__4 = *ldab - 1;
  669. sgemm_("No transpose", "No transpose", &i2, &j3, &jb,
  670. &c_b18, &ab[kv + 1 + jb + j * ab_dim1], &i__3,
  671. work13, &c__65, &c_b31, &ab[jb + 1 + (j + kv)
  672. * ab_dim1], &i__4);
  673. }
  674. if (i3 > 0) {
  675. /* Update A33 */
  676. i__3 = *ldab - 1;
  677. sgemm_("No transpose", "No transpose", &i3, &j3, &jb,
  678. &c_b18, work31, &c__65, work13, &c__65, &
  679. c_b31, &ab[*kl + 1 + (j + kv) * ab_dim1], &
  680. i__3);
  681. }
  682. /* Copy the lower triangle of A13 back into place */
  683. i__3 = j3;
  684. for (jj = 1; jj <= i__3; ++jj) {
  685. i__4 = jb;
  686. for (ii = jj; ii <= i__4; ++ii) {
  687. ab[ii - jj + 1 + (jj + j + kv - 1) * ab_dim1] =
  688. work13[ii + jj * 65 - 66];
  689. /* L140: */
  690. }
  691. /* L150: */
  692. }
  693. }
  694. } else {
  695. /* Adjust the pivot indices. */
  696. i__3 = j + jb - 1;
  697. for (i__ = j; i__ <= i__3; ++i__) {
  698. ipiv[i__] = ipiv[i__] + j - 1;
  699. /* L160: */
  700. }
  701. }
  702. /* Partially undo the interchanges in the current block to */
  703. /* restore the upper triangular form of A31 and copy the upper */
  704. /* triangle of A31 back into place */
  705. i__3 = j;
  706. for (jj = j + jb - 1; jj >= i__3; --jj) {
  707. jp = ipiv[jj] - jj + 1;
  708. if (jp != 1) {
  709. /* Apply interchange to columns J to JJ-1 */
  710. if (jp + jj - 1 < j + *kl) {
  711. /* The interchange does not affect A31 */
  712. i__4 = jj - j;
  713. i__5 = *ldab - 1;
  714. i__6 = *ldab - 1;
  715. sswap_(&i__4, &ab[kv + 1 + jj - j + j * ab_dim1], &
  716. i__5, &ab[kv + jp + jj - j + j * ab_dim1], &
  717. i__6);
  718. } else {
  719. /* The interchange does affect A31 */
  720. i__4 = jj - j;
  721. i__5 = *ldab - 1;
  722. sswap_(&i__4, &ab[kv + 1 + jj - j + j * ab_dim1], &
  723. i__5, &work31[jp + jj - j - *kl - 1], &c__65);
  724. }
  725. }
  726. /* Copy the current column of A31 back into place */
  727. /* Computing MIN */
  728. i__4 = i3, i__5 = jj - j + 1;
  729. nw = f2cmin(i__4,i__5);
  730. if (nw > 0) {
  731. scopy_(&nw, &work31[(jj - j + 1) * 65 - 65], &c__1, &ab[
  732. kv + *kl + 1 - jj + j + jj * ab_dim1], &c__1);
  733. }
  734. /* L170: */
  735. }
  736. /* L180: */
  737. }
  738. }
  739. return;
  740. /* End of SGBTRF */
  741. } /* sgbtrf_ */