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.

clatrs3.c 39 kB

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