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.

zlatrs3.c 36 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle_() continue;
  210. #define myceiling_(w) ceil(w)
  211. #define myhuge_(w) HUGE_VAL
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc_(w,s,e,n) dmaxloc_(w,*(s),*(e),n)
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static doublecomplex c_b1 = {1.,0.};
  363. static integer c__1 = 1;
  364. static integer c_n1 = -1;
  365. /* > \brief \b ZLATRS3 solves a triangular system of equations with the scale factors set to prevent overflow.
  366. */
  367. /* Definition: */
  368. /* =========== */
  369. /* SUBROUTINE ZLATRS3( UPLO, TRANS, DIAG, NORMIN, N, NRHS, A, LDA, */
  370. /* X, LDX, SCALE, CNORM, WORK, LWORK, INFO ) */
  371. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  372. /* INTEGER INFO, LDA, LWORK, LDX, N, NRHS */
  373. /* DOUBLE PRECISION CNORM( * ), SCALE( * ), WORK( * ) */
  374. /* COMPLEX*16 A( LDA, * ), X( LDX, * ) */
  375. /* > \par Purpose: */
  376. /* ============= */
  377. /* > */
  378. /* > \verbatim */
  379. /* > */
  380. /* > ZLATRS3 solves one of the triangular systems */
  381. /* > */
  382. /* > A * X = B * diag(scale), A**T * X = B * diag(scale), or */
  383. /* > A**H * X = B * diag(scale) */
  384. /* > */
  385. /* > with scaling to prevent overflow. Here A is an upper or lower */
  386. /* > triangular matrix, A**T denotes the transpose of A, A**H denotes the */
  387. /* > conjugate transpose of A. X and B are n-by-nrhs matrices and scale */
  388. /* > is an nrhs-element vector of scaling factors. A scaling factor scale(j) */
  389. /* > is usually less than or equal to 1, chosen such that X(:,j) is less */
  390. /* > than the overflow threshold. If the matrix A is singular (A(j,j) = 0 */
  391. /* > for some j), then a non-trivial solution to A*X = 0 is returned. If */
  392. /* > the system is so badly scaled that the solution cannot be represented */
  393. /* > as (1/scale(k))*X(:,k), then x(:,k) = 0 and scale(k) is returned. */
  394. /* > */
  395. /* > This is a BLAS-3 version of LATRS for solving several right */
  396. /* > hand sides simultaneously. */
  397. /* > */
  398. /* > \endverbatim */
  399. /* Arguments: */
  400. /* ========== */
  401. /* > \param[in] UPLO */
  402. /* > \verbatim */
  403. /* > UPLO is CHARACTER*1 */
  404. /* > Specifies whether the matrix A is upper or lower triangular. */
  405. /* > = 'U': Upper triangular */
  406. /* > = 'L': Lower triangular */
  407. /* > \endverbatim */
  408. /* > */
  409. /* > \param[in] TRANS */
  410. /* > \verbatim */
  411. /* > TRANS is CHARACTER*1 */
  412. /* > Specifies the operation applied to A. */
  413. /* > = 'N': Solve A * x = s*b (No transpose) */
  414. /* > = 'T': Solve A**T* x = s*b (Transpose) */
  415. /* > = 'C': Solve A**T* x = s*b (Conjugate transpose) */
  416. /* > \endverbatim */
  417. /* > */
  418. /* > \param[in] DIAG */
  419. /* > \verbatim */
  420. /* > DIAG is CHARACTER*1 */
  421. /* > Specifies whether or not the matrix A is unit triangular. */
  422. /* > = 'N': Non-unit triangular */
  423. /* > = 'U': Unit triangular */
  424. /* > \endverbatim */
  425. /* > */
  426. /* > \param[in] NORMIN */
  427. /* > \verbatim */
  428. /* > NORMIN is CHARACTER*1 */
  429. /* > Specifies whether CNORM has been set or not. */
  430. /* > = 'Y': CNORM contains the column norms on entry */
  431. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  432. /* > be computed and stored in CNORM. */
  433. /* > \endverbatim */
  434. /* > */
  435. /* > \param[in] N */
  436. /* > \verbatim */
  437. /* > N is INTEGER */
  438. /* > The order of the matrix A. N >= 0. */
  439. /* > \endverbatim */
  440. /* > */
  441. /* > \param[in] NRHS */
  442. /* > \verbatim */
  443. /* > NRHS is INTEGER */
  444. /* > The number of columns of X. NRHS >= 0. */
  445. /* > \endverbatim */
  446. /* > */
  447. /* > \param[in] A */
  448. /* > \verbatim */
  449. /* > A is COMPLEX*16 array, dimension (LDA,N) */
  450. /* > The triangular matrix A. If UPLO = 'U', the leading n by n */
  451. /* > upper triangular part of the array A contains the upper */
  452. /* > triangular matrix, and the strictly lower triangular part of */
  453. /* > A is not referenced. If UPLO = 'L', the leading n by n lower */
  454. /* > triangular part of the array A contains the lower triangular */
  455. /* > matrix, and the strictly upper triangular part of A is not */
  456. /* > referenced. If DIAG = 'U', the diagonal elements of A are */
  457. /* > also not referenced and are assumed to be 1. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] LDA */
  461. /* > \verbatim */
  462. /* > LDA is INTEGER */
  463. /* > The leading dimension of the array A. LDA >= f2cmax (1,N). */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[in,out] X */
  467. /* > \verbatim */
  468. /* > X is COMPLEX*16 array, dimension (LDX,NRHS) */
  469. /* > On entry, the right hand side B of the triangular system. */
  470. /* > On exit, X is overwritten by the solution matrix X. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] LDX */
  474. /* > \verbatim */
  475. /* > LDX is INTEGER */
  476. /* > The leading dimension of the array X. LDX >= f2cmax (1,N). */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[out] SCALE */
  480. /* > \verbatim */
  481. /* > SCALE is DOUBLE PRECISION array, dimension (NRHS) */
  482. /* > The scaling factor s(k) is for the triangular system */
  483. /* > A * x(:,k) = s(k)*b(:,k) or A**T* x(:,k) = s(k)*b(:,k). */
  484. /* > If SCALE = 0, the matrix A is singular or badly scaled. */
  485. /* > If A(j,j) = 0 is encountered, a non-trivial vector x(:,k) */
  486. /* > that is an exact or approximate solution to A*x(:,k) = 0 */
  487. /* > is returned. If the system so badly scaled that solution */
  488. /* > cannot be presented as x(:,k) * 1/s(k), then x(:,k) = 0 */
  489. /* > is returned. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[in,out] CNORM */
  493. /* > \verbatim */
  494. /* > CNORM is DOUBLE PRECISION array, dimension (N) */
  495. /* > */
  496. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  497. /* > contains the norm of the off-diagonal part of the j-th column */
  498. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  499. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  500. /* > must be greater than or equal to the 1-norm. */
  501. /* > */
  502. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  503. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  504. /* > of A. */
  505. /* > \endverbatim */
  506. /* > */
  507. /* > \param[out] WORK */
  508. /* > \verbatim */
  509. /* > WORK is DOUBLE PRECISION array, dimension (LWORK). */
  510. /* > On exit, if INFO = 0, WORK(1) returns the optimal size of */
  511. /* > WORK. */
  512. /* > \endverbatim */
  513. /* > */
  514. /* > \param[in] LWORK */
  515. /* > LWORK is INTEGER */
  516. /* > LWORK >= MAX(1, 2*NBA * MAX(NBA, MIN(NRHS, 32)), where */
  517. /* > NBA = (N + NB - 1)/NB and NB is the optimal block size. */
  518. /* > */
  519. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  520. /* > only calculates the optimal dimensions of the WORK array, returns */
  521. /* > this value as the first entry of the WORK array, and no error */
  522. /* > message related to LWORK is issued by XERBLA. */
  523. /* > */
  524. /* > \param[out] INFO */
  525. /* > \verbatim */
  526. /* > INFO is INTEGER */
  527. /* > = 0: successful exit */
  528. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  529. /* > \endverbatim */
  530. /* Authors: */
  531. /* ======== */
  532. /* > \author Univ. of Tennessee */
  533. /* > \author Univ. of California Berkeley */
  534. /* > \author Univ. of Colorado Denver */
  535. /* > \author NAG Ltd. */
  536. /* > \ingroup doubleOTHERauxiliary */
  537. /* > \par Further Details: */
  538. /* ===================== */
  539. /* \verbatim */
  540. /* The algorithm follows the structure of a block triangular solve. */
  541. /* The diagonal block is solved with a call to the robust the triangular */
  542. /* solver LATRS for every right-hand side RHS = 1, ..., NRHS */
  543. /* op(A( J, J )) * x( J, RHS ) = SCALOC * b( J, RHS ), */
  544. /* where op( A ) = A or op( A ) = A**T or op( A ) = A**H. */
  545. /* The linear block updates operate on block columns of X, */
  546. /* B( I, K ) - op(A( I, J )) * X( J, K ) */
  547. /* and use GEMM. To avoid overflow in the linear block update, the worst case */
  548. /* growth is estimated. For every RHS, a scale factor s <= 1.0 is computed */
  549. /* such that */
  550. /* || s * B( I, RHS )||_oo */
  551. /* + || op(A( I, J )) ||_oo * || s * X( J, RHS ) ||_oo <= Overflow threshold */
  552. /* Once all columns of a block column have been rescaled (BLAS-1), the linear */
  553. /* update is executed with GEMM without overflow. */
  554. /* To limit rescaling, local scale factors track the scaling of column segments. */
  555. /* There is one local scale factor s( I, RHS ) per block row I = 1, ..., NBA */
  556. /* per right-hand side column RHS = 1, ..., NRHS. The global scale factor */
  557. /* SCALE( RHS ) is chosen as the smallest local scale factor s( I, RHS ) */
  558. /* I = 1, ..., NBA. */
  559. /* A triangular solve op(A( J, J )) * x( J, RHS ) = SCALOC * b( J, RHS ) */
  560. /* updates the local scale factor s( J, RHS ) := s( J, RHS ) * SCALOC. The */
  561. /* linear update of potentially inconsistently scaled vector segments */
  562. /* s( I, RHS ) * b( I, RHS ) - op(A( I, J )) * ( s( J, RHS )* x( J, RHS ) ) */
  563. /* computes a consistent scaling SCAMIN = MIN( s(I, RHS ), s(J, RHS) ) and, */
  564. /* if necessary, rescales the blocks prior to calling GEMM. */
  565. /* \endverbatim */
  566. /* ===================================================================== */
  567. /* References: */
  568. /* C. C. Kjelgaard Mikkelsen, A. B. Schwarz and L. Karlsson (2019). */
  569. /* Parallel robust solution of triangular linear systems. Concurrency */
  570. /* and Computation: Practice and Experience, 31(19), e5064. */
  571. /* Contributor: */
  572. /* Angelika Schwarz, Umea University, Sweden. */
  573. /* ===================================================================== */
  574. /* Subroutine */ int zlatrs3_(char *uplo, char *trans, char *diag, char *
  575. normin, integer *n, integer *nrhs, doublecomplex *a, integer *lda,
  576. doublecomplex *x, integer *ldx, doublereal *scale, doublereal *cnorm,
  577. doublereal *work, integer *lwork, integer *info)
  578. {
  579. /* System generated locals */
  580. integer a_dim1, a_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5,
  581. i__6, i__7, i__8;
  582. doublereal d__1, d__2;
  583. doublecomplex z__1;
  584. /* Local variables */
  585. integer iinc, jinc;
  586. doublereal scal, anrm, bnrm;
  587. integer awrk;
  588. doublereal tmax, xnrm[32];
  589. integer i__, j, k;
  590. doublereal w[64];
  591. extern logical lsame_(char *, char *);
  592. doublereal rscal;
  593. integer lanrm, ilast, jlast;
  594. extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
  595. integer *, doublecomplex *, doublecomplex *, integer *,
  596. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  597. integer *);
  598. integer i1;
  599. logical upper;
  600. integer i2, j1, j2, k1, k2, nb, ii, kk;
  601. extern doublereal dlamch_(char *);
  602. integer lscale;
  603. doublereal scaloc, scamin;
  604. extern doublereal dlarmm_(doublereal *, doublereal *, doublereal *);
  605. extern /* Subroutine */ int xerbla_(char *, integer *);
  606. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  607. integer *, integer *, ftnlen, ftnlen);
  608. extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
  609. integer *, doublereal *);
  610. doublereal bignum;
  611. extern /* Subroutine */ int zdscal_(integer *, doublereal *,
  612. doublecomplex *, integer *);
  613. integer ifirst;
  614. logical notran;
  615. integer jfirst;
  616. doublereal smlnum;
  617. logical nounit;
  618. extern /* Subroutine */ int zlatrs_(char *, char *, char *, char *,
  619. integer *, doublecomplex *, integer *, doublecomplex *,
  620. doublereal *, doublereal *, integer *);
  621. logical lquery;
  622. integer nba, lds, nbx, rhs;
  623. /* ===================================================================== */
  624. /* Parameter adjustments */
  625. a_dim1 = *lda;
  626. a_offset = 1 + a_dim1 * 1;
  627. a -= a_offset;
  628. x_dim1 = *ldx;
  629. x_offset = 1 + x_dim1 * 1;
  630. x -= x_offset;
  631. --scale;
  632. --cnorm;
  633. --work;
  634. /* Function Body */
  635. *info = 0;
  636. upper = lsame_(uplo, "U");
  637. notran = lsame_(trans, "N");
  638. nounit = lsame_(diag, "N");
  639. lquery = *lwork == -1;
  640. /* Partition A and X into blocks. */
  641. /* Computing MAX */
  642. i__1 = 8, i__2 = ilaenv_(&c__1, "ZLATRS", "", n, n, &c_n1, &c_n1, (ftnlen)
  643. 6, (ftnlen)0);
  644. nb = f2cmax(i__1,i__2);
  645. nb = f2cmin(64,nb);
  646. /* Computing MAX */
  647. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  648. nba = f2cmax(i__1,i__2);
  649. /* Computing MAX */
  650. i__1 = 1, i__2 = (*nrhs + 31) / 32;
  651. nbx = f2cmax(i__1,i__2);
  652. /* Compute the workspace */
  653. /* The workspace comprises two parts. */
  654. /* The first part stores the local scale factors. Each simultaneously */
  655. /* computed right-hand side requires one local scale factor per block */
  656. /* row. WORK( I + KK * LDS ) is the scale factor of the vector */
  657. /* segment associated with the I-th block row and the KK-th vector */
  658. /* in the block column. */
  659. /* Computing MAX */
  660. i__1 = nba, i__2 = f2cmin(*nrhs,32);
  661. lscale = nba * f2cmax(i__1,i__2);
  662. lds = nba;
  663. /* The second part stores upper bounds of the triangular A. There are */
  664. /* a total of NBA x NBA blocks, of which only the upper triangular */
  665. /* part or the lower triangular part is referenced. The upper bound of */
  666. /* the block A( I, J ) is stored as WORK( AWRK + I + J * NBA ). */
  667. lanrm = nba * nba;
  668. awrk = lscale;
  669. work[1] = (doublereal) (lscale + lanrm);
  670. /* Test the input parameters. */
  671. if (! upper && ! lsame_(uplo, "L")) {
  672. *info = -1;
  673. } else if (! notran && ! lsame_(trans, "T") && !
  674. lsame_(trans, "C")) {
  675. *info = -2;
  676. } else if (! nounit && ! lsame_(diag, "U")) {
  677. *info = -3;
  678. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  679. "N")) {
  680. *info = -4;
  681. } else if (*n < 0) {
  682. *info = -5;
  683. } else if (*nrhs < 0) {
  684. *info = -6;
  685. } else if (*lda < f2cmax(1,*n)) {
  686. *info = -8;
  687. } else if (*ldx < f2cmax(1,*n)) {
  688. *info = -10;
  689. } else if (! lquery && (doublereal) (*lwork) < work[1]) {
  690. *info = -14;
  691. }
  692. if (*info != 0) {
  693. i__1 = -(*info);
  694. xerbla_("ZLATRS3", &i__1);
  695. return 0;
  696. } else if (lquery) {
  697. return 0;
  698. }
  699. /* Initialize scaling factors */
  700. i__1 = *nrhs;
  701. for (kk = 1; kk <= i__1; ++kk) {
  702. scale[kk] = 1.;
  703. }
  704. /* Quick return if possible */
  705. if (f2cmin(*n,*nrhs) == 0) {
  706. return 0;
  707. }
  708. /* Determine machine dependent constant to control overflow. */
  709. bignum = dlamch_("Overflow");
  710. smlnum = dlamch_("Safe Minimum");
  711. /* Use unblocked code for small problems */
  712. if (*nrhs < 2) {
  713. zlatrs_(uplo, trans, diag, normin, n, &a[a_offset], lda, &x[x_dim1 +
  714. 1], &scale[1], &cnorm[1], info);
  715. i__1 = *nrhs;
  716. for (k = 2; k <= i__1; ++k) {
  717. zlatrs_(uplo, trans, diag, "Y", n, &a[a_offset], lda, &x[k *
  718. x_dim1 + 1], &scale[k], &cnorm[1], info);
  719. }
  720. return 0;
  721. }
  722. /* Compute norms of blocks of A excluding diagonal blocks and find */
  723. /* the block with the largest norm TMAX. */
  724. tmax = 0.;
  725. i__1 = nba;
  726. for (j = 1; j <= i__1; ++j) {
  727. j1 = (j - 1) * nb + 1;
  728. /* Computing MIN */
  729. i__2 = j * nb;
  730. j2 = f2cmin(i__2,*n) + 1;
  731. if (upper) {
  732. ifirst = 1;
  733. ilast = j - 1;
  734. } else {
  735. ifirst = j + 1;
  736. ilast = nba;
  737. }
  738. i__2 = ilast;
  739. for (i__ = ifirst; i__ <= i__2; ++i__) {
  740. i1 = (i__ - 1) * nb + 1;
  741. /* Computing MIN */
  742. i__3 = i__ * nb;
  743. i2 = f2cmin(i__3,*n) + 1;
  744. /* Compute upper bound of A( I1:I2-1, J1:J2-1 ). */
  745. if (notran) {
  746. i__3 = i2 - i1;
  747. i__4 = j2 - j1;
  748. anrm = zlange_("I", &i__3, &i__4, &a[i1 + j1 * a_dim1], lda,
  749. w);
  750. work[awrk + i__ + (j - 1) * nba] = anrm;
  751. } else {
  752. i__3 = i2 - i1;
  753. i__4 = j2 - j1;
  754. anrm = zlange_("1", &i__3, &i__4, &a[i1 + j1 * a_dim1], lda,
  755. w);
  756. work[awrk + j + (i__ - 1) * nba] = anrm;
  757. }
  758. tmax = f2cmax(tmax,anrm);
  759. }
  760. }
  761. if (! (tmax <= dlamch_("Overflow"))) {
  762. /* Some matrix entries have huge absolute value. At least one upper */
  763. /* bound norm( A(I1:I2-1, J1:J2-1), 'I') is not a valid floating-point */
  764. /* number, either due to overflow in LANGE or due to Inf in A. */
  765. /* Fall back to LATRS. Set normin = 'N' for every right-hand side to */
  766. /* force computation of TSCAL in LATRS to avoid the likely overflow */
  767. /* in the computation of the column norms CNORM. */
  768. i__1 = *nrhs;
  769. for (k = 1; k <= i__1; ++k) {
  770. zlatrs_(uplo, trans, diag, "N", n, &a[a_offset], lda, &x[k *
  771. x_dim1 + 1], &scale[k], &cnorm[1], info);
  772. }
  773. return 0;
  774. }
  775. /* Every right-hand side requires workspace to store NBA local scale */
  776. /* factors. To save workspace, X is computed successively in block columns */
  777. /* of width NBRHS, requiring a total of NBA x NBRHS space. If sufficient */
  778. /* workspace is available, larger values of NBRHS or NBRHS = NRHS are viable. */
  779. i__1 = nbx;
  780. for (k = 1; k <= i__1; ++k) {
  781. /* Loop over block columns (index = K) of X and, for column-wise scalings, */
  782. /* over individual columns (index = KK). */
  783. /* K1: column index of the first column in X( J, K ) */
  784. /* K2: column index of the first column in X( J, K+1 ) */
  785. /* so the K2 - K1 is the column count of the block X( J, K ) */
  786. k1 = (k - 1 << 5) + 1;
  787. /* Computing MIN */
  788. i__2 = k << 5;
  789. k2 = f2cmin(i__2,*nrhs) + 1;
  790. /* Initialize local scaling factors of current block column X( J, K ) */
  791. i__2 = k2 - k1;
  792. for (kk = 1; kk <= i__2; ++kk) {
  793. i__3 = nba;
  794. for (i__ = 1; i__ <= i__3; ++i__) {
  795. work[i__ + kk * lds] = 1.;
  796. }
  797. }
  798. if (notran) {
  799. /* Solve A * X(:, K1:K2-1) = B * diag(scale(K1:K2-1)) */
  800. if (upper) {
  801. jfirst = nba;
  802. jlast = 1;
  803. jinc = -1;
  804. } else {
  805. jfirst = 1;
  806. jlast = nba;
  807. jinc = 1;
  808. }
  809. } else {
  810. /* Solve op(A) * X(:, K1:K2-1) = B * diag(scale(K1:K2-1)) */
  811. /* where op(A) = A**T or op(A) = A**H */
  812. if (upper) {
  813. jfirst = 1;
  814. jlast = nba;
  815. jinc = 1;
  816. } else {
  817. jfirst = nba;
  818. jlast = 1;
  819. jinc = -1;
  820. }
  821. }
  822. i__2 = jlast;
  823. i__3 = jinc;
  824. for (j = jfirst; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) {
  825. /* J1: row index of the first row in A( J, J ) */
  826. /* J2: row index of the first row in A( J+1, J+1 ) */
  827. /* so that J2 - J1 is the row count of the block A( J, J ) */
  828. j1 = (j - 1) * nb + 1;
  829. /* Computing MIN */
  830. i__4 = j * nb;
  831. j2 = f2cmin(i__4,*n) + 1;
  832. /* Solve op(A( J, J )) * X( J, RHS ) = SCALOC * B( J, RHS ) */
  833. i__4 = k2 - k1;
  834. for (kk = 1; kk <= i__4; ++kk) {
  835. rhs = k1 + kk - 1;
  836. if (kk == 1) {
  837. i__5 = j2 - j1;
  838. zlatrs_(uplo, trans, diag, "N", &i__5, &a[j1 + j1 *
  839. a_dim1], lda, &x[j1 + rhs * x_dim1], &scaloc, &
  840. cnorm[1], info);
  841. } else {
  842. i__5 = j2 - j1;
  843. zlatrs_(uplo, trans, diag, "Y", &i__5, &a[j1 + j1 *
  844. a_dim1], lda, &x[j1 + rhs * x_dim1], &scaloc, &
  845. cnorm[1], info);
  846. }
  847. /* Find largest absolute value entry in the vector segment */
  848. /* X( J1:J2-1, RHS ) as an upper bound for the worst case */
  849. /* growth in the linear updates. */
  850. i__5 = j2 - j1;
  851. xnrm[kk - 1] = zlange_("I", &i__5, &c__1, &x[j1 + rhs *
  852. x_dim1], ldx, w);
  853. if (scaloc == 0.) {
  854. /* LATRS found that A is singular through A(j,j) = 0. */
  855. /* Reset the computation x(1:n) = 0, x(j) = 1, SCALE = 0 */
  856. /* and compute op(A)*x = 0. Note that X(J1:J2-1, KK) is */
  857. /* set by LATRS. */
  858. scale[rhs] = 0.;
  859. i__5 = j1 - 1;
  860. for (ii = 1; ii <= i__5; ++ii) {
  861. i__6 = ii + kk * x_dim1;
  862. x[i__6].r = 0., x[i__6].i = 0.;
  863. }
  864. i__5 = *n;
  865. for (ii = j2; ii <= i__5; ++ii) {
  866. i__6 = ii + kk * x_dim1;
  867. x[i__6].r = 0., x[i__6].i = 0.;
  868. }
  869. /* Discard the local scale factors. */
  870. i__5 = nba;
  871. for (ii = 1; ii <= i__5; ++ii) {
  872. work[ii + kk * lds] = 1.;
  873. }
  874. scaloc = 1.;
  875. } else if (scaloc * work[j + kk * lds] == 0.) {
  876. /* LATRS computed a valid scale factor, but combined with */
  877. /* the current scaling the solution does not have a */
  878. /* scale factor > 0. */
  879. /* Set WORK( J+KK*LDS ) to smallest valid scale */
  880. /* factor and increase SCALOC accordingly. */
  881. scal = work[j + kk * lds] / smlnum;
  882. scaloc *= scal;
  883. work[j + kk * lds] = smlnum;
  884. /* If LATRS overestimated the growth, x may be */
  885. /* rescaled to preserve a valid combined scale */
  886. /* factor WORK( J, KK ) > 0. */
  887. rscal = 1. / scaloc;
  888. if (xnrm[kk - 1] * rscal <= bignum) {
  889. xnrm[kk - 1] *= rscal;
  890. i__5 = j2 - j1;
  891. zdscal_(&i__5, &rscal, &x[j1 + rhs * x_dim1], &c__1);
  892. scaloc = 1.;
  893. } else {
  894. /* The system op(A) * x = b is badly scaled and its */
  895. /* solution cannot be represented as (1/scale) * x. */
  896. /* Set x to zero. This approach deviates from LATRS */
  897. /* where a completely meaningless non-zero vector */
  898. /* is returned that is not a solution to op(A) * x = b. */
  899. scale[rhs] = 0.;
  900. i__5 = *n;
  901. for (ii = 1; ii <= i__5; ++ii) {
  902. i__6 = ii + kk * x_dim1;
  903. x[i__6].r = 0., x[i__6].i = 0.;
  904. }
  905. /* Discard the local scale factors. */
  906. i__5 = nba;
  907. for (ii = 1; ii <= i__5; ++ii) {
  908. work[ii + kk * lds] = 1.;
  909. }
  910. scaloc = 1.;
  911. }
  912. }
  913. scaloc *= work[j + kk * lds];
  914. work[j + kk * lds] = scaloc;
  915. }
  916. /* Linear block updates */
  917. if (notran) {
  918. if (upper) {
  919. ifirst = j - 1;
  920. ilast = 1;
  921. iinc = -1;
  922. } else {
  923. ifirst = j + 1;
  924. ilast = nba;
  925. iinc = 1;
  926. }
  927. } else {
  928. if (upper) {
  929. ifirst = j + 1;
  930. ilast = nba;
  931. iinc = 1;
  932. } else {
  933. ifirst = j - 1;
  934. ilast = 1;
  935. iinc = -1;
  936. }
  937. }
  938. i__4 = ilast;
  939. i__5 = iinc;
  940. for (i__ = ifirst; i__5 < 0 ? i__ >= i__4 : i__ <= i__4; i__ +=
  941. i__5) {
  942. /* I1: row index of the first column in X( I, K ) */
  943. /* I2: row index of the first column in X( I+1, K ) */
  944. /* so the I2 - I1 is the row count of the block X( I, K ) */
  945. i1 = (i__ - 1) * nb + 1;
  946. /* Computing MIN */
  947. i__6 = i__ * nb;
  948. i2 = f2cmin(i__6,*n) + 1;
  949. /* Prepare the linear update to be executed with GEMM. */
  950. /* For each column, compute a consistent scaling, a */
  951. /* scaling factor to survive the linear update, and */
  952. /* rescale the column segments, if necesssary. Then */
  953. /* the linear update is safely executed. */
  954. i__6 = k2 - k1;
  955. for (kk = 1; kk <= i__6; ++kk) {
  956. rhs = k1 + kk - 1;
  957. /* Compute consistent scaling */
  958. /* Computing MIN */
  959. d__1 = work[i__ + kk * lds], d__2 = work[j + kk * lds];
  960. scamin = f2cmin(d__1,d__2);
  961. /* Compute scaling factor to survive the linear update */
  962. /* simulating consistent scaling. */
  963. i__7 = i2 - i1;
  964. bnrm = zlange_("I", &i__7, &c__1, &x[i1 + rhs * x_dim1],
  965. ldx, w);
  966. bnrm *= scamin / work[i__ + kk * lds];
  967. xnrm[kk - 1] *= scamin / work[j + kk * lds];
  968. anrm = work[awrk + i__ + (j - 1) * nba];
  969. scaloc = dlarmm_(&anrm, &xnrm[kk - 1], &bnrm);
  970. /* Simultaneously apply the robust update factor and the */
  971. /* consistency scaling factor to X( I, KK ) and X( J, KK ). */
  972. scal = scamin / work[i__ + kk * lds] * scaloc;
  973. if (scal != 1.) {
  974. i__7 = i2 - i1;
  975. zdscal_(&i__7, &scal, &x[i1 + rhs * x_dim1], &c__1);
  976. work[i__ + kk * lds] = scamin * scaloc;
  977. }
  978. scal = scamin / work[j + kk * lds] * scaloc;
  979. if (scal != 1.) {
  980. i__7 = j2 - j1;
  981. zdscal_(&i__7, &scal, &x[j1 + rhs * x_dim1], &c__1);
  982. work[j + kk * lds] = scamin * scaloc;
  983. }
  984. }
  985. if (notran) {
  986. /* B( I, K ) := B( I, K ) - A( I, J ) * X( J, K ) */
  987. i__6 = i2 - i1;
  988. i__7 = k2 - k1;
  989. i__8 = j2 - j1;
  990. z__1.r = -1., z__1.i = 0.;
  991. zgemm_("N", "N", &i__6, &i__7, &i__8, &z__1, &a[i1 + j1 *
  992. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b1, &
  993. x[i1 + k1 * x_dim1], ldx);
  994. } else if (lsame_(trans, "T")) {
  995. /* B( I, K ) := B( I, K ) - A( I, J )**T * X( J, K ) */
  996. i__6 = i2 - i1;
  997. i__7 = k2 - k1;
  998. i__8 = j2 - j1;
  999. z__1.r = -1., z__1.i = 0.;
  1000. zgemm_("T", "N", &i__6, &i__7, &i__8, &z__1, &a[j1 + i1 *
  1001. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b1, &
  1002. x[i1 + k1 * x_dim1], ldx);
  1003. } else {
  1004. /* B( I, K ) := B( I, K ) - A( I, J )**H * X( J, K ) */
  1005. i__6 = i2 - i1;
  1006. i__7 = k2 - k1;
  1007. i__8 = j2 - j1;
  1008. z__1.r = -1., z__1.i = 0.;
  1009. zgemm_("C", "N", &i__6, &i__7, &i__8, &z__1, &a[j1 + i1 *
  1010. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b1, &
  1011. x[i1 + k1 * x_dim1], ldx);
  1012. }
  1013. }
  1014. }
  1015. /* Reduce local scaling factors */
  1016. i__3 = k2 - k1;
  1017. for (kk = 1; kk <= i__3; ++kk) {
  1018. rhs = k1 + kk - 1;
  1019. i__2 = nba;
  1020. for (i__ = 1; i__ <= i__2; ++i__) {
  1021. /* Computing MIN */
  1022. d__1 = scale[rhs], d__2 = work[i__ + kk * lds];
  1023. scale[rhs] = f2cmin(d__1,d__2);
  1024. }
  1025. }
  1026. /* Realize consistent scaling */
  1027. i__3 = k2 - k1;
  1028. for (kk = 1; kk <= i__3; ++kk) {
  1029. rhs = k1 + kk - 1;
  1030. if (scale[rhs] != 1. && scale[rhs] != 0.) {
  1031. i__2 = nba;
  1032. for (i__ = 1; i__ <= i__2; ++i__) {
  1033. i1 = (i__ - 1) * nb + 1;
  1034. /* Computing MIN */
  1035. i__5 = i__ * nb;
  1036. i2 = f2cmin(i__5,*n) + 1;
  1037. scal = scale[rhs] / work[i__ + kk * lds];
  1038. if (scal != 1.) {
  1039. i__5 = i2 - i1;
  1040. zdscal_(&i__5, &scal, &x[i1 + rhs * x_dim1], &c__1);
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }
  1046. return 0;
  1047. /* End of ZLATRS3 */
  1048. } /* zlatrs3_ */