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 40 kB

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