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.

dlatrs3.c 39 kB

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