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 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 integer c__1 = 1;
  489. static integer c_n1 = -1;
  490. static doublereal c_b35 = -1.;
  491. static doublereal c_b36 = 1.;
  492. /* > \brief \b DLATRS3 solves a triangular system of equations with the scale factors set to prevent overflow.
  493. */
  494. /* Definition: */
  495. /* =========== */
  496. /* SUBROUTINE DLATRS3( UPLO, TRANS, DIAG, NORMIN, N, NRHS, A, LDA, */
  497. /* X, LDX, SCALE, CNORM, WORK, LWORK, INFO ) */
  498. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  499. /* INTEGER INFO, LDA, LWORK, LDX, N, NRHS */
  500. /* DOUBLE PRECISION A( LDA, * ), CNORM( * ), SCALE( * ), */
  501. /* WORK( * ), X( LDX, * ) */
  502. /* > \par Purpose: */
  503. /* ============= */
  504. /* > */
  505. /* > \verbatim */
  506. /* > */
  507. /* > DLATRS3 solves one of the triangular systems */
  508. /* > */
  509. /* > A * X = B * diag(scale) or A**T * 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. X and B are */
  513. /* > n by nrhs matrices and scale is an nrhs element vector of scaling */
  514. /* > factors. A scaling factor scale(j) is usually less than or equal */
  515. /* > to 1, chosen such that X(:,j) is less than the overflow threshold. */
  516. /* > If the matrix A is singular (A(j,j) = 0 for some j), then */
  517. /* > a non-trivial solution to A*X = 0 is returned. If the system is */
  518. /* > so badly scaled that the solution cannot be represented as */
  519. /* > (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 = 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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. */
  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 dlatrs3_(char *uplo, char *trans, char *diag, char *
  701. normin, integer *n, integer *nrhs, doublereal *a, integer *lda,
  702. doublereal *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. /* Local variables */
  710. integer iinc, jinc;
  711. doublereal scal, anrm, bnrm;
  712. integer awrk;
  713. doublereal tmax, xnrm[32];
  714. integer i__, j, k;
  715. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  716. integer *);
  717. doublereal w[64];
  718. extern /* Subroutine */ void dgemm_(char *, char *, integer *, integer *,
  719. integer *, doublereal *, doublereal *, integer *, doublereal *,
  720. integer *, doublereal *, doublereal *, integer *);
  721. extern logical lsame_(char *, char *);
  722. doublereal rscal;
  723. integer lanrm, ilast, jlast, i1;
  724. logical upper;
  725. integer i2, j1, j2, k1, k2, nb, ii, kk;
  726. extern doublereal dlamch_(char *), dlange_(char *, integer *,
  727. integer *, doublereal *, integer *, doublereal *);
  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. doublereal bignum;
  735. extern /* Subroutine */ void dlatrs_(char *, char *, char *, char *,
  736. integer *, doublereal *, integer *, doublereal *, doublereal *,
  737. doublereal *, integer *);
  738. integer ifirst;
  739. logical notran;
  740. integer jfirst;
  741. doublereal smlnum;
  742. logical nounit, lquery;
  743. integer nba, lds, nbx, rhs;
  744. /* ===================================================================== */
  745. /* Parameter adjustments */
  746. a_dim1 = *lda;
  747. a_offset = 1 + a_dim1 * 1;
  748. a -= a_offset;
  749. x_dim1 = *ldx;
  750. x_offset = 1 + x_dim1 * 1;
  751. x -= x_offset;
  752. --scale;
  753. --cnorm;
  754. --work;
  755. /* Function Body */
  756. *info = 0;
  757. upper = lsame_(uplo, "U");
  758. notran = lsame_(trans, "N");
  759. nounit = lsame_(diag, "N");
  760. lquery = *lwork == -1;
  761. /* Partition A and X into blocks */
  762. /* Computing MAX */
  763. i__1 = 8, i__2 = ilaenv_(&c__1, "DLATRS", "", n, n, &c_n1, &c_n1, (ftnlen)
  764. 6, (ftnlen)0);
  765. nb = f2cmax(i__1,i__2);
  766. nb = f2cmin(64,nb);
  767. /* Computing MAX */
  768. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  769. nba = f2cmax(i__1,i__2);
  770. /* Computing MAX */
  771. i__1 = 1, i__2 = (*nrhs + 31) / 32;
  772. nbx = f2cmax(i__1,i__2);
  773. /* Compute the workspace */
  774. /* The workspace comprises two parts. */
  775. /* The first part stores the local scale factors. Each simultaneously */
  776. /* computed right-hand side requires one local scale factor per block */
  777. /* row. WORK( I+KK*LDS ) is the scale factor of the vector */
  778. /* segment associated with the I-th block row and the KK-th vector */
  779. /* in the block column. */
  780. /* Computing MAX */
  781. i__1 = nba, i__2 = f2cmin(*nrhs,32);
  782. lscale = nba * f2cmax(i__1,i__2);
  783. lds = nba;
  784. /* The second part stores upper bounds of the triangular A. There are */
  785. /* a total of NBA x NBA blocks, of which only the upper triangular */
  786. /* part or the lower triangular part is referenced. The upper bound of */
  787. /* the block A( I, J ) is stored as WORK( AWRK + I + J * NBA ). */
  788. lanrm = nba * nba;
  789. awrk = lscale;
  790. work[1] = (doublereal) (lscale + lanrm);
  791. /* Test the input parameters */
  792. if (! upper && ! lsame_(uplo, "L")) {
  793. *info = -1;
  794. } else if (! notran && ! lsame_(trans, "T") && !
  795. lsame_(trans, "C")) {
  796. *info = -2;
  797. } else if (! nounit && ! lsame_(diag, "U")) {
  798. *info = -3;
  799. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  800. "N")) {
  801. *info = -4;
  802. } else if (*n < 0) {
  803. *info = -5;
  804. } else if (*nrhs < 0) {
  805. *info = -6;
  806. } else if (*lda < f2cmax(1,*n)) {
  807. *info = -8;
  808. } else if (*ldx < f2cmax(1,*n)) {
  809. *info = -10;
  810. } else if (! lquery && (doublereal) (*lwork) < work[1]) {
  811. *info = -14;
  812. }
  813. if (*info != 0) {
  814. i__1 = -(*info);
  815. xerbla_("DLATRS3", &i__1, 7);
  816. return;
  817. } else if (lquery) {
  818. return;
  819. }
  820. /* Initialize scaling factors */
  821. i__1 = *nrhs;
  822. for (kk = 1; kk <= i__1; ++kk) {
  823. scale[kk] = 1.;
  824. }
  825. /* Quick return if possible */
  826. if (f2cmin(*n,*nrhs) == 0) {
  827. return;
  828. }
  829. /* Determine machine dependent constant to control overflow. */
  830. bignum = dlamch_("Overflow");
  831. smlnum = dlamch_("Safe Minimum");
  832. /* Use unblocked code for small problems */
  833. if (*nrhs < 2) {
  834. dlatrs_(uplo, trans, diag, normin, n, &a[a_offset], lda, &x[x_dim1 +
  835. 1], &scale[1], &cnorm[1], info);
  836. i__1 = *nrhs;
  837. for (k = 2; k <= i__1; ++k) {
  838. dlatrs_(uplo, trans, diag, "Y", n, &a[a_offset], lda, &x[k *
  839. x_dim1 + 1], &scale[k], &cnorm[1], info);
  840. }
  841. return;
  842. }
  843. /* Compute norms of blocks of A excluding diagonal blocks and find */
  844. /* the block with the largest norm TMAX. */
  845. tmax = 0.;
  846. i__1 = nba;
  847. for (j = 1; j <= i__1; ++j) {
  848. j1 = (j - 1) * nb + 1;
  849. /* Computing MIN */
  850. i__2 = j * nb;
  851. j2 = f2cmin(i__2,*n) + 1;
  852. if (upper) {
  853. ifirst = 1;
  854. ilast = j - 1;
  855. } else {
  856. ifirst = j + 1;
  857. ilast = nba;
  858. }
  859. i__2 = ilast;
  860. for (i__ = ifirst; i__ <= i__2; ++i__) {
  861. i1 = (i__ - 1) * nb + 1;
  862. /* Computing MIN */
  863. i__3 = i__ * nb;
  864. i2 = f2cmin(i__3,*n) + 1;
  865. /* Compute upper bound of A( I1:I2-1, J1:J2-1 ). */
  866. if (notran) {
  867. i__3 = i2 - i1;
  868. i__4 = j2 - j1;
  869. anrm = dlange_("I", &i__3, &i__4, &a[i1 + j1 * a_dim1], lda,
  870. w);
  871. work[awrk + i__ + (j - 1) * nba] = anrm;
  872. } else {
  873. i__3 = i2 - i1;
  874. i__4 = j2 - j1;
  875. anrm = dlange_("1", &i__3, &i__4, &a[i1 + j1 * a_dim1], lda,
  876. w);
  877. work[awrk + j + (i__ - 1) * nba] = anrm;
  878. }
  879. tmax = f2cmax(tmax,anrm);
  880. }
  881. }
  882. if (! (tmax <= dlamch_("Overflow"))) {
  883. /* Some matrix entries have huge absolute value. At least one upper */
  884. /* bound norm( A(I1:I2-1, J1:J2-1), 'I') is not a valid floating-point */
  885. /* number, either due to overflow in LANGE or due to Inf in A. */
  886. /* Fall back to LATRS. Set normin = 'N' for every right-hand side to */
  887. /* force computation of TSCAL in LATRS to avoid the likely overflow */
  888. /* in the computation of the column norms CNORM. */
  889. i__1 = *nrhs;
  890. for (k = 1; k <= i__1; ++k) {
  891. dlatrs_(uplo, trans, diag, "N", n, &a[a_offset], lda, &x[k *
  892. x_dim1 + 1], &scale[k], &cnorm[1], info);
  893. }
  894. return;
  895. }
  896. /* Every right-hand side requires workspace to store NBA local scale */
  897. /* factors. To save workspace, X is computed successively in block columns */
  898. /* of width NBRHS, requiring a total of NBA x NBRHS space. If sufficient */
  899. /* workspace is available, larger values of NBRHS or NBRHS = NRHS are viable. */
  900. i__1 = nbx;
  901. for (k = 1; k <= i__1; ++k) {
  902. /* Loop over block columns (index = K) of X and, for column-wise scalings, */
  903. /* over individual columns (index = KK). */
  904. /* K1: column index of the first column in X( J, K ) */
  905. /* K2: column index of the first column in X( J, K+1 ) */
  906. /* so the K2 - K1 is the column count of the block X( J, K ) */
  907. k1 = (k - 1 << 5) + 1;
  908. /* Computing MIN */
  909. i__2 = k << 5;
  910. k2 = f2cmin(i__2,*nrhs) + 1;
  911. /* Initialize local scaling factors of current block column X( J, K ) */
  912. i__2 = k2 - k1;
  913. for (kk = 1; kk <= i__2; ++kk) {
  914. i__3 = nba;
  915. for (i__ = 1; i__ <= i__3; ++i__) {
  916. work[i__ + kk * lds] = 1.;
  917. }
  918. }
  919. if (notran) {
  920. /* Solve A * X(:, K1:K2-1) = B * diag(scale(K1:K2-1)) */
  921. if (upper) {
  922. jfirst = nba;
  923. jlast = 1;
  924. jinc = -1;
  925. } else {
  926. jfirst = 1;
  927. jlast = nba;
  928. jinc = 1;
  929. }
  930. } else {
  931. /* Solve A**T * X(:, K1:K2-1) = B * diag(scale(K1:K2-1)) */
  932. if (upper) {
  933. jfirst = 1;
  934. jlast = nba;
  935. jinc = 1;
  936. } else {
  937. jfirst = nba;
  938. jlast = 1;
  939. jinc = -1;
  940. }
  941. }
  942. i__2 = jlast;
  943. i__3 = jinc;
  944. for (j = jfirst; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) {
  945. /* J1: row index of the first row in A( J, J ) */
  946. /* J2: row index of the first row in A( J+1, J+1 ) */
  947. /* so that J2 - J1 is the row count of the block A( J, J ) */
  948. j1 = (j - 1) * nb + 1;
  949. /* Computing MIN */
  950. i__4 = j * nb;
  951. j2 = f2cmin(i__4,*n) + 1;
  952. /* Solve op(A( J, J )) * X( J, RHS ) = SCALOC * B( J, RHS ) */
  953. /* for all right-hand sides in the current block column, */
  954. /* one RHS at a time. */
  955. i__4 = k2 - k1;
  956. for (kk = 1; kk <= i__4; ++kk) {
  957. rhs = k1 + kk - 1;
  958. if (kk == 1) {
  959. i__5 = j2 - j1;
  960. dlatrs_(uplo, trans, diag, "N", &i__5, &a[j1 + j1 *
  961. a_dim1], lda, &x[j1 + rhs * x_dim1], &scaloc, &
  962. cnorm[1], info);
  963. } else {
  964. i__5 = j2 - j1;
  965. dlatrs_(uplo, trans, diag, "Y", &i__5, &a[j1 + j1 *
  966. a_dim1], lda, &x[j1 + rhs * x_dim1], &scaloc, &
  967. cnorm[1], info);
  968. }
  969. /* Find largest absolute value entry in the vector segment */
  970. /* X( J1:J2-1, RHS ) as an upper bound for the worst case */
  971. /* growth in the linear updates. */
  972. i__5 = j2 - j1;
  973. xnrm[kk - 1] = dlange_("I", &i__5, &c__1, &x[j1 + rhs *
  974. x_dim1], ldx, w);
  975. if (scaloc == 0.) {
  976. /* LATRS found that A is singular through A(j,j) = 0. */
  977. /* Reset the computation x(1:n) = 0, x(j) = 1, SCALE = 0 */
  978. /* and compute A*x = 0 (or A**T*x = 0). Note that */
  979. /* X(J1:J2-1, KK) is set by LATRS. */
  980. scale[rhs] = 0.;
  981. i__5 = j1 - 1;
  982. for (ii = 1; ii <= i__5; ++ii) {
  983. x[ii + kk * x_dim1] = 0.;
  984. }
  985. i__5 = *n;
  986. for (ii = j2; ii <= i__5; ++ii) {
  987. x[ii + kk * x_dim1] = 0.;
  988. }
  989. /* Discard the local scale factors. */
  990. i__5 = nba;
  991. for (ii = 1; ii <= i__5; ++ii) {
  992. work[ii + kk * lds] = 1.;
  993. }
  994. scaloc = 1.;
  995. } else if (scaloc * work[j + kk * lds] == 0.) {
  996. /* LATRS computed a valid scale factor, but combined with */
  997. /* the current scaling the solution does not have a */
  998. /* scale factor > 0. */
  999. /* Set WORK( J+KK*LDS ) to smallest valid scale */
  1000. /* factor and increase SCALOC accordingly. */
  1001. scal = work[j + kk * lds] / smlnum;
  1002. scaloc *= scal;
  1003. work[j + kk * lds] = smlnum;
  1004. /* If LATRS overestimated the growth, x may be */
  1005. /* rescaled to preserve a valid combined scale */
  1006. /* factor WORK( J, KK ) > 0. */
  1007. rscal = 1. / scaloc;
  1008. if (xnrm[kk - 1] * rscal <= bignum) {
  1009. xnrm[kk - 1] *= rscal;
  1010. i__5 = j2 - j1;
  1011. dscal_(&i__5, &rscal, &x[j1 + rhs * x_dim1], &c__1);
  1012. scaloc = 1.;
  1013. } else {
  1014. /* The system op(A) * x = b is badly scaled and its */
  1015. /* solution cannot be represented as (1/scale) * x. */
  1016. /* Set x to zero. This approach deviates from LATRS */
  1017. /* where a completely meaningless non-zero vector */
  1018. /* is returned that is not a solution to op(A) * x = b. */
  1019. scale[rhs] = 0.;
  1020. i__5 = *n;
  1021. for (ii = 1; ii <= i__5; ++ii) {
  1022. x[ii + kk * x_dim1] = 0.;
  1023. }
  1024. /* Discard the local scale factors. */
  1025. i__5 = nba;
  1026. for (ii = 1; ii <= i__5; ++ii) {
  1027. work[ii + kk * lds] = 1.;
  1028. }
  1029. scaloc = 1.;
  1030. }
  1031. }
  1032. scaloc *= work[j + kk * lds];
  1033. work[j + kk * lds] = scaloc;
  1034. }
  1035. /* Linear block updates */
  1036. if (notran) {
  1037. if (upper) {
  1038. ifirst = j - 1;
  1039. ilast = 1;
  1040. iinc = -1;
  1041. } else {
  1042. ifirst = j + 1;
  1043. ilast = nba;
  1044. iinc = 1;
  1045. }
  1046. } else {
  1047. if (upper) {
  1048. ifirst = j + 1;
  1049. ilast = nba;
  1050. iinc = 1;
  1051. } else {
  1052. ifirst = j - 1;
  1053. ilast = 1;
  1054. iinc = -1;
  1055. }
  1056. }
  1057. i__4 = ilast;
  1058. i__5 = iinc;
  1059. for (i__ = ifirst; i__5 < 0 ? i__ >= i__4 : i__ <= i__4; i__ +=
  1060. i__5) {
  1061. /* I1: row index of the first column in X( I, K ) */
  1062. /* I2: row index of the first column in X( I+1, K ) */
  1063. /* so the I2 - I1 is the row count of the block X( I, K ) */
  1064. i1 = (i__ - 1) * nb + 1;
  1065. /* Computing MIN */
  1066. i__6 = i__ * nb;
  1067. i2 = f2cmin(i__6,*n) + 1;
  1068. /* Prepare the linear update to be executed with GEMM. */
  1069. /* For each column, compute a consistent scaling, a */
  1070. /* scaling factor to survive the linear update, and */
  1071. /* rescale the column segments, if necesssary. Then */
  1072. /* the linear update is safely executed. */
  1073. i__6 = k2 - k1;
  1074. for (kk = 1; kk <= i__6; ++kk) {
  1075. rhs = k1 + kk - 1;
  1076. /* Compute consistent scaling */
  1077. /* Computing MIN */
  1078. d__1 = work[i__ + kk * lds], d__2 = work[j + kk * lds];
  1079. scamin = f2cmin(d__1,d__2);
  1080. /* Compute scaling factor to survive the linear update */
  1081. /* simulating consistent scaling. */
  1082. i__7 = i2 - i1;
  1083. bnrm = dlange_("I", &i__7, &c__1, &x[i1 + rhs * x_dim1],
  1084. ldx, w);
  1085. bnrm *= scamin / work[i__ + kk * lds];
  1086. xnrm[kk - 1] *= scamin / work[j + kk * lds];
  1087. anrm = work[awrk + i__ + (j - 1) * nba];
  1088. scaloc = dlarmm_(&anrm, &xnrm[kk - 1], &bnrm);
  1089. /* Simultaneously apply the robust update factor and the */
  1090. /* consistency scaling factor to B( I, KK ) and B( J, KK ). */
  1091. scal = scamin / work[i__ + kk * lds] * scaloc;
  1092. if (scal != 1.) {
  1093. i__7 = i2 - i1;
  1094. dscal_(&i__7, &scal, &x[i1 + rhs * x_dim1], &c__1);
  1095. work[i__ + kk * lds] = scamin * scaloc;
  1096. }
  1097. scal = scamin / work[j + kk * lds] * scaloc;
  1098. if (scal != 1.) {
  1099. i__7 = j2 - j1;
  1100. dscal_(&i__7, &scal, &x[j1 + rhs * x_dim1], &c__1);
  1101. work[j + kk * lds] = scamin * scaloc;
  1102. }
  1103. }
  1104. if (notran) {
  1105. /* B( I, K ) := B( I, K ) - A( I, J ) * X( J, K ) */
  1106. i__6 = i2 - i1;
  1107. i__7 = k2 - k1;
  1108. i__8 = j2 - j1;
  1109. dgemm_("N", "N", &i__6, &i__7, &i__8, &c_b35, &a[i1 + j1 *
  1110. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b36,
  1111. &x[i1 + k1 * x_dim1], ldx);
  1112. } else {
  1113. /* B( I, K ) := B( I, K ) - A( J, I )**T * X( J, K ) */
  1114. i__6 = i2 - i1;
  1115. i__7 = k2 - k1;
  1116. i__8 = j2 - j1;
  1117. dgemm_("T", "N", &i__6, &i__7, &i__8, &c_b35, &a[j1 + i1 *
  1118. a_dim1], lda, &x[j1 + k1 * x_dim1], ldx, &c_b36,
  1119. &x[i1 + k1 * x_dim1], ldx);
  1120. }
  1121. }
  1122. }
  1123. /* Reduce local scaling factors */
  1124. i__3 = k2 - k1;
  1125. for (kk = 1; kk <= i__3; ++kk) {
  1126. rhs = k1 + kk - 1;
  1127. i__2 = nba;
  1128. for (i__ = 1; i__ <= i__2; ++i__) {
  1129. /* Computing MIN */
  1130. d__1 = scale[rhs], d__2 = work[i__ + kk * lds];
  1131. scale[rhs] = f2cmin(d__1,d__2);
  1132. }
  1133. }
  1134. /* Realize consistent scaling */
  1135. i__3 = k2 - k1;
  1136. for (kk = 1; kk <= i__3; ++kk) {
  1137. rhs = k1 + kk - 1;
  1138. if (scale[rhs] != 1. && scale[rhs] != 0.) {
  1139. i__2 = nba;
  1140. for (i__ = 1; i__ <= i__2; ++i__) {
  1141. i1 = (i__ - 1) * nb + 1;
  1142. /* Computing MIN */
  1143. i__5 = i__ * nb;
  1144. i2 = f2cmin(i__5,*n) + 1;
  1145. scal = scale[rhs] / work[i__ + kk * lds];
  1146. if (scal != 1.) {
  1147. i__5 = i2 - i1;
  1148. dscal_(&i__5, &scal, &x[i1 + rhs * x_dim1], &c__1);
  1149. }
  1150. }
  1151. }
  1152. }
  1153. }
  1154. return;
  1155. /* End of DLATRS3 */
  1156. } /* dlatrs3_ */