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.

ctrsyl3.c 56 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define exponent(x)
  140. #define abs(x) ((x) >= 0 ? (x) : -(x))
  141. #define dabs(x) (fabs(x))
  142. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  143. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  144. #define dmin(a,b) (f2cmin(a,b))
  145. #define dmax(a,b) (f2cmax(a,b))
  146. #define bit_test(a,b) ((a) >> (b) & 1)
  147. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  148. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  149. #define abort_() { sig_die("Fortran abort routine called", 1); }
  150. #define c_abs(z) (cabsf(Cf(z)))
  151. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  152. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  153. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  154. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  155. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  156. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  157. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  158. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  159. #define d_abs(x) (fabs(*(x)))
  160. #define d_acos(x) (acos(*(x)))
  161. #define d_asin(x) (asin(*(x)))
  162. #define d_atan(x) (atan(*(x)))
  163. #define d_atn2(x, y) (atan2(*(x),*(y)))
  164. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  165. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  166. #define d_cos(x) (cos(*(x)))
  167. #define d_cosh(x) (cosh(*(x)))
  168. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  169. #define d_exp(x) (exp(*(x)))
  170. #define d_imag(z) (cimag(Cd(z)))
  171. #define r_imag(z) (cimag(Cf(z)))
  172. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  174. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  176. #define d_log(x) (log(*(x)))
  177. #define d_mod(x, y) (fmod(*(x), *(y)))
  178. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  179. #define d_nint(x) u_nint(*(x))
  180. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  181. #define d_sign(a,b) u_sign(*(a),*(b))
  182. #define r_sign(a,b) u_sign(*(a),*(b))
  183. #define d_sin(x) (sin(*(x)))
  184. #define d_sinh(x) (sinh(*(x)))
  185. #define d_sqrt(x) (sqrt(*(x)))
  186. #define d_tan(x) (tan(*(x)))
  187. #define d_tanh(x) (tanh(*(x)))
  188. #define i_abs(x) abs(*(x))
  189. #define i_dnnt(x) ((integer)u_nint(*(x)))
  190. #define i_len(s, n) (n)
  191. #define i_nint(x) ((integer)u_nint(*(x)))
  192. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  193. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  194. #define pow_si(B,E) spow_ui(*(B),*(E))
  195. #define pow_ri(B,E) spow_ui(*(B),*(E))
  196. #define pow_di(B,E) dpow_ui(*(B),*(E))
  197. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  198. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  199. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  200. #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++ = ' '; }
  201. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  202. #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]; }
  203. #define sig_die(s, kill) { exit(1); }
  204. #define s_stop(s, n) {exit(0);}
  205. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  206. #define z_abs(z) (cabs(Cd(z)))
  207. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  208. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  209. #define myexit_() break;
  210. #define mycycle_() continue;
  211. #define myceiling_(w) ceil(w)
  212. #define myhuge_(w) HUGE_VAL
  213. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  214. #define mymaxloc_(w,s,e,n) dmaxloc_(w,*(s),*(e),n)
  215. #define myexp_(w) my_expfunc(w)
  216. static int my_expfunc(float *x) {int e; (void)frexpf(*x,&e); return e;}
  217. /* procedure parameter types for -A and -C++ */
  218. #define F2C_proc_par_types 1
  219. #ifdef __cplusplus
  220. typedef logical (*L_fp)(...);
  221. #else
  222. typedef logical (*L_fp)();
  223. #endif
  224. static float spow_ui(float x, integer n) {
  225. float pow=1.0; unsigned long int u;
  226. if(n != 0) {
  227. if(n < 0) n = -n, x = 1/x;
  228. for(u = n; ; ) {
  229. if(u & 01) pow *= x;
  230. if(u >>= 1) x *= x;
  231. else break;
  232. }
  233. }
  234. return pow;
  235. }
  236. static double dpow_ui(double x, integer n) {
  237. double pow=1.0; unsigned long int u;
  238. if(n != 0) {
  239. if(n < 0) n = -n, x = 1/x;
  240. for(u = n; ; ) {
  241. if(u & 01) pow *= x;
  242. if(u >>= 1) x *= x;
  243. else break;
  244. }
  245. }
  246. return pow;
  247. }
  248. static _Complex float cpow_ui(_Complex float x, integer n) {
  249. _Complex 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 _Complex double zpow_ui(_Complex double x, integer n) {
  261. _Complex 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. static integer pow_ii(integer x, integer n) {
  273. integer pow; unsigned long int u;
  274. if (n <= 0) {
  275. if (n == 0 || x == 1) pow = 1;
  276. else if (x != -1) pow = x == 0 ? 1/x : 0;
  277. else n = -n;
  278. }
  279. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  280. u = n;
  281. for(pow = 1; ; ) {
  282. if(u & 01) pow *= x;
  283. if(u >>= 1) x *= x;
  284. else break;
  285. }
  286. }
  287. return pow;
  288. }
  289. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  290. {
  291. double m; integer i, mi;
  292. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  293. if (w[i-1]>m) mi=i ,m=w[i-1];
  294. return mi-s+1;
  295. }
  296. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  297. {
  298. float m; integer i, mi;
  299. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  300. if (w[i-1]>m) mi=i ,m=w[i-1];
  301. return mi-s+1;
  302. }
  303. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  304. integer n = *n_, incx = *incx_, incy = *incy_, i;
  305. _Complex float zdotc = 0.0;
  306. if (incx == 1 && incy == 1) {
  307. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  308. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  309. }
  310. } else {
  311. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  312. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  313. }
  314. }
  315. pCf(z) = zdotc;
  316. }
  317. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  318. integer n = *n_, incx = *incx_, incy = *incy_, i;
  319. _Complex double zdotc = 0.0;
  320. if (incx == 1 && incy == 1) {
  321. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  322. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  323. }
  324. } else {
  325. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  326. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  327. }
  328. }
  329. pCd(z) = zdotc;
  330. }
  331. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  332. integer n = *n_, incx = *incx_, incy = *incy_, i;
  333. _Complex float zdotc = 0.0;
  334. if (incx == 1 && incy == 1) {
  335. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  336. zdotc += Cf(&x[i]) * Cf(&y[i]);
  337. }
  338. } else {
  339. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  340. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  341. }
  342. }
  343. pCf(z) = zdotc;
  344. }
  345. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  346. integer n = *n_, incx = *incx_, incy = *incy_, i;
  347. _Complex double zdotc = 0.0;
  348. if (incx == 1 && incy == 1) {
  349. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  350. zdotc += Cd(&x[i]) * Cd(&y[i]);
  351. }
  352. } else {
  353. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  354. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  355. }
  356. }
  357. pCd(z) = zdotc;
  358. }
  359. #endif
  360. /* -- translated by f2c (version 20000121).
  361. You must link the resulting object file with the libraries:
  362. -lf2c -lm (in that order)
  363. */
  364. /* Table of constant values */
  365. static complex c_b1 = {1.f,0.f};
  366. static integer c__1 = 1;
  367. static integer c_n1 = -1;
  368. static real c_b18 = 2.f;
  369. static real c_b106 = 1.f;
  370. /* > \brief \b CTRSYL3 */
  371. /* Definition: */
  372. /* =========== */
  373. /* > \par Purpose */
  374. /* ============= */
  375. /* > */
  376. /* > \verbatim */
  377. /* > */
  378. /* > CTRSYL3 solves the complex Sylvester matrix equation: */
  379. /* > */
  380. /* > op(A)*X + X*op(B) = scale*C or */
  381. /* > op(A)*X - X*op(B) = scale*C, */
  382. /* > */
  383. /* > where op(A) = A or A**H, and A and B are both upper triangular. A is */
  384. /* > M-by-M and B is N-by-N; the right hand side C and the solution X are */
  385. /* > M-by-N; and scale is an output scale factor, set <= 1 to avoid */
  386. /* > overflow in X. */
  387. /* > */
  388. /* > This is the block version of the algorithm. */
  389. /* > \endverbatim */
  390. /* Arguments */
  391. /* ========= */
  392. /* > \param[in] TRANA */
  393. /* > \verbatim */
  394. /* > TRANA is CHARACTER*1 */
  395. /* > Specifies the option op(A): */
  396. /* > = 'N': op(A) = A (No transpose) */
  397. /* > = 'C': op(A) = A**H (Conjugate transpose) */
  398. /* > \endverbatim */
  399. /* > */
  400. /* > \param[in] TRANB */
  401. /* > \verbatim */
  402. /* > TRANB is CHARACTER*1 */
  403. /* > Specifies the option op(B): */
  404. /* > = 'N': op(B) = B (No transpose) */
  405. /* > = 'C': op(B) = B**H (Conjugate transpose) */
  406. /* > \endverbatim */
  407. /* > */
  408. /* > \param[in] ISGN */
  409. /* > \verbatim */
  410. /* > ISGN is INTEGER */
  411. /* > Specifies the sign in the equation: */
  412. /* > = +1: solve op(A)*X + X*op(B) = scale*C */
  413. /* > = -1: solve op(A)*X - X*op(B) = scale*C */
  414. /* > \endverbatim */
  415. /* > */
  416. /* > \param[in] M */
  417. /* > \verbatim */
  418. /* > M is INTEGER */
  419. /* > The order of the matrix A, and the number of rows in the */
  420. /* > matrices X and C. M >= 0. */
  421. /* > \endverbatim */
  422. /* > */
  423. /* > \param[in] N */
  424. /* > \verbatim */
  425. /* > N is INTEGER */
  426. /* > The order of the matrix B, and the number of columns in the */
  427. /* > matrices X and C. N >= 0. */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[in] A */
  431. /* > \verbatim */
  432. /* > A is COMPLEX array, dimension (LDA,M) */
  433. /* > The upper triangular matrix A. */
  434. /* > \endverbatim */
  435. /* > */
  436. /* > \param[in] LDA */
  437. /* > \verbatim */
  438. /* > LDA is INTEGER */
  439. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[in] B */
  443. /* > \verbatim */
  444. /* > B is COMPLEX array, dimension (LDB,N) */
  445. /* > The upper triangular matrix B. */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[in] LDB */
  449. /* > \verbatim */
  450. /* > LDB is INTEGER */
  451. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[in,out] C */
  455. /* > \verbatim */
  456. /* > C is COMPLEX array, dimension (LDC,N) */
  457. /* > On entry, the M-by-N right hand side matrix C. */
  458. /* > On exit, C is overwritten by the solution matrix X. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in] LDC */
  462. /* > \verbatim */
  463. /* > LDC is INTEGER */
  464. /* > The leading dimension of the array C. LDC >= f2cmax(1,M) */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[out] SCALE */
  468. /* > \verbatim */
  469. /* > SCALE is REAL */
  470. /* > The scale factor, scale, set <= 1 to avoid overflow in X. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[out] SWORK */
  474. /* > \verbatim */
  475. /* > SWORK is REAL array, dimension (MAX(2, ROWS), MAX(1,COLS)). */
  476. /* > On exit, if INFO = 0, SWORK(1) returns the optimal value ROWS */
  477. /* > and SWORK(2) returns the optimal COLS. */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[in] LDSWORK */
  481. /* > \verbatim */
  482. /* > LDSWORK is INTEGER */
  483. /* > LDSWORK >= MAX(2,ROWS), where ROWS = ((M + NB - 1) / NB + 1) */
  484. /* > and NB is the optimal block size. */
  485. /* > */
  486. /* > If LDSWORK = -1, then a workspace query is assumed; the routine */
  487. /* > only calculates the optimal dimensions of the SWORK matrix, */
  488. /* > returns these values as the first and second entry of the SWORK */
  489. /* > matrix, and no error message related LWORK is issued by XERBLA. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[out] INFO */
  493. /* > \verbatim */
  494. /* > INFO is INTEGER */
  495. /* > = 0: successful exit */
  496. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  497. /* > = 1: A and B have common or very close eigenvalues; perturbed */
  498. /* > values were used to solve the equation (but the matrices */
  499. /* > A and B are unchanged). */
  500. /* > \endverbatim */
  501. /* > \ingroup complexSYcomputational */
  502. /* ===================================================================== */
  503. /* References: */
  504. /* E. S. Quintana-Orti and R. A. Van De Geijn (2003). Formal derivation of */
  505. /* algorithms: The triangular Sylvester equation, ACM Transactions */
  506. /* on Mathematical Software (TOMS), volume 29, pages 218--243. */
  507. /* A. Schwarz and C. C. Kjelgaard Mikkelsen (2020). Robust Task-Parallel */
  508. /* Solution of the Triangular Sylvester Equation. Lecture Notes in */
  509. /* Computer Science, vol 12043, pages 82--92, Springer. */
  510. /* Contributor: */
  511. /* Angelika Schwarz, Umea University, Sweden. */
  512. /* ===================================================================== */
  513. /* Subroutine */ int ctrsyl3_(char *trana, char *tranb, integer *isgn,
  514. integer *m, integer *n, complex *a, integer *lda, complex *b, integer
  515. *ldb, complex *c__, integer *ldc, real *scale, real *swork, integer *
  516. ldswork, integer *info)
  517. {
  518. /* System generated locals */
  519. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, swork_dim1,
  520. swork_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  521. real r__1, r__2, r__3, r__4;
  522. complex q__1;
  523. /* Local variables */
  524. real scal;
  525. complex csgn;
  526. real anrm, bnrm, cnrm;
  527. integer awrk, bwrk;
  528. real *wnrm, xnrm;
  529. integer i__, j, k, l;
  530. extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *,
  531. integer *, complex *, complex *, integer *, complex *, integer *,
  532. complex *, complex *, integer *);
  533. extern logical lsame_(char *, char *);
  534. integer iinfo, i1, i2, j1, j2, k1, k2, l1, l2;
  535. // extern integer myexp_(real *);
  536. integer nb, jj, ll;
  537. extern real clange_(char *, integer *, integer *, complex *, integer *,
  538. real *);
  539. extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *,
  540. real *, integer *, integer *, complex *, integer *, integer *);
  541. real scaloc;
  542. extern real slamch_(char *);
  543. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  544. *);
  545. real scamin;
  546. extern /* Subroutine */ int xerbla_(char *, integer *);
  547. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  548. integer *, integer *, ftnlen, ftnlen);
  549. real bignum;
  550. extern real slarmm_(real *, real *, real *);
  551. logical notrna, notrnb;
  552. real smlnum;
  553. extern /* Subroutine */ int ctrsyl_(char *, char *, integer *, integer *,
  554. integer *, complex *, integer *, complex *, integer *, complex *,
  555. integer *, real *, integer *);
  556. logical lquery;
  557. integer nba, nbb;
  558. real buf, sgn;
  559. /* Decode and Test input parameters */
  560. /* Parameter adjustments */
  561. a_dim1 = *lda;
  562. a_offset = 1 + a_dim1 * 1;
  563. a -= a_offset;
  564. b_dim1 = *ldb;
  565. b_offset = 1 + b_dim1 * 1;
  566. b -= b_offset;
  567. c_dim1 = *ldc;
  568. c_offset = 1 + c_dim1 * 1;
  569. c__ -= c_offset;
  570. swork_dim1 = *ldswork;
  571. swork_offset = 1 + swork_dim1 * 1;
  572. swork -= swork_offset;
  573. /* Function Body */
  574. notrna = lsame_(trana, "N");
  575. notrnb = lsame_(tranb, "N");
  576. /* Use the same block size for all matrices. */
  577. /* Computing MAX */
  578. i__1 = 8, i__2 = ilaenv_(&c__1, "CTRSYL", "", m, n, &c_n1, &c_n1, (ftnlen)
  579. 6, (ftnlen)0);
  580. nb = f2cmax(i__1,i__2);
  581. /* Compute number of blocks in A and B */
  582. /* Computing MAX */
  583. i__1 = 1, i__2 = (*m + nb - 1) / nb;
  584. nba = f2cmax(i__1,i__2);
  585. /* Computing MAX */
  586. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  587. nbb = f2cmax(i__1,i__2);
  588. /* Compute workspace */
  589. *info = 0;
  590. lquery = *ldswork == -1;
  591. if (lquery) {
  592. *ldswork = 2;
  593. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  594. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  595. }
  596. /* Test the input arguments */
  597. if (! notrna && ! lsame_(trana, "C")) {
  598. *info = -1;
  599. } else if (! notrnb && ! lsame_(tranb, "C")) {
  600. *info = -2;
  601. } else if (*isgn != 1 && *isgn != -1) {
  602. *info = -3;
  603. } else if (*m < 0) {
  604. *info = -4;
  605. } else if (*n < 0) {
  606. *info = -5;
  607. } else if (*lda < f2cmax(1,*m)) {
  608. *info = -7;
  609. } else if (*ldb < f2cmax(1,*n)) {
  610. *info = -9;
  611. } else if (*ldc < f2cmax(1,*m)) {
  612. *info = -11;
  613. }
  614. if (*info != 0) {
  615. i__1 = -(*info);
  616. xerbla_("CTRSYL3", &i__1);
  617. return 0;
  618. } else if (lquery) {
  619. return 0;
  620. }
  621. /* Quick return if possible */
  622. *scale = 1.f;
  623. if (*m == 0 || *n == 0) {
  624. return 0;
  625. }
  626. wnrm = (real*)malloc(f2cmax(*m,*n)*sizeof(real));
  627. /* Use unblocked code for small problems or if insufficient */
  628. /* workspace is provided */
  629. if (f2cmin(nba,nbb) == 1 || *ldswork < f2cmax(nba,nbb)) {
  630. ctrsyl_(trana, tranb, isgn, m, n, &a[a_offset], lda, &b[b_offset],
  631. ldb, &c__[c_offset], ldc, scale, info);
  632. return 0;
  633. }
  634. /* Set constants to control overflow */
  635. smlnum = slamch_("S");
  636. bignum = 1.f / smlnum;
  637. /* Set local scaling factors. */
  638. i__1 = nbb;
  639. for (l = 1; l <= i__1; ++l) {
  640. i__2 = nba;
  641. for (k = 1; k <= i__2; ++k) {
  642. swork[k + l * swork_dim1] = 1.f;
  643. }
  644. }
  645. /* Fallback scaling factor to prevent flushing of SWORK( K, L ) to zero. */
  646. /* This scaling is to ensure compatibility with TRSYL and may get flushed. */
  647. buf = 1.f;
  648. /* Compute upper bounds of blocks of A and B */
  649. awrk = nbb;
  650. i__1 = nba;
  651. for (k = 1; k <= i__1; ++k) {
  652. k1 = (k - 1) * nb + 1;
  653. /* Computing MIN */
  654. i__2 = k * nb;
  655. k2 = f2cmin(i__2,*m) + 1;
  656. i__2 = nba;
  657. for (l = k; l <= i__2; ++l) {
  658. l1 = (l - 1) * nb + 1;
  659. /* Computing MIN */
  660. i__3 = l * nb;
  661. l2 = f2cmin(i__3,*m) + 1;
  662. if (notrna) {
  663. i__3 = k2 - k1;
  664. i__4 = l2 - l1;
  665. swork[k + (awrk + l) * swork_dim1] = clange_("I", &i__3, &
  666. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  667. } else {
  668. i__3 = k2 - k1;
  669. i__4 = l2 - l1;
  670. swork[l + (awrk + k) * swork_dim1] = clange_("1", &i__3, &
  671. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  672. }
  673. }
  674. }
  675. bwrk = nbb + nba;
  676. i__1 = nbb;
  677. for (k = 1; k <= i__1; ++k) {
  678. k1 = (k - 1) * nb + 1;
  679. /* Computing MIN */
  680. i__2 = k * nb;
  681. k2 = f2cmin(i__2,*n) + 1;
  682. i__2 = nbb;
  683. for (l = k; l <= i__2; ++l) {
  684. l1 = (l - 1) * nb + 1;
  685. /* Computing MIN */
  686. i__3 = l * nb;
  687. l2 = f2cmin(i__3,*n) + 1;
  688. if (notrnb) {
  689. i__3 = k2 - k1;
  690. i__4 = l2 - l1;
  691. swork[k + (bwrk + l) * swork_dim1] = clange_("I", &i__3, &
  692. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  693. } else {
  694. i__3 = k2 - k1;
  695. i__4 = l2 - l1;
  696. swork[l + (bwrk + k) * swork_dim1] = clange_("1", &i__3, &
  697. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  698. }
  699. }
  700. }
  701. sgn = (real) (*isgn);
  702. q__1.r = sgn, q__1.i = 0.f;
  703. csgn.r = q__1.r, csgn.i = q__1.i;
  704. if (notrna && notrnb) {
  705. /* Solve A*X + ISGN*X*B = scale*C. */
  706. /* The (K,L)th block of X is determined starting from */
  707. /* bottom-left corner column by column by */
  708. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  709. /* Where */
  710. /* M L-1 */
  711. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)]. */
  712. /* I=K+1 J=1 */
  713. /* Start loop over block rows (index = K) and block columns (index = L) */
  714. for (k = nba; k >= 1; --k) {
  715. /* K1: row index of the first row in X( K, L ) */
  716. /* K2: row index of the first row in X( K+1, L ) */
  717. /* so the K2 - K1 is the column count of the block X( K, L ) */
  718. k1 = (k - 1) * nb + 1;
  719. /* Computing MIN */
  720. i__1 = k * nb;
  721. k2 = f2cmin(i__1,*m) + 1;
  722. i__1 = nbb;
  723. for (l = 1; l <= i__1; ++l) {
  724. /* L1: column index of the first column in X( K, L ) */
  725. /* L2: column index of the first column in X( K, L + 1) */
  726. /* so that L2 - L1 is the row count of the block X( K, L ) */
  727. l1 = (l - 1) * nb + 1;
  728. /* Computing MIN */
  729. i__2 = l * nb;
  730. l2 = f2cmin(i__2,*n) + 1;
  731. i__2 = k2 - k1;
  732. i__3 = l2 - l1;
  733. ctrsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  734. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  735. c_dim1], ldc, &scaloc, &iinfo);
  736. *info = f2cmax(*info,iinfo);
  737. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  738. if (scaloc == 0.f) {
  739. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  740. /* is larger than the product of BIGNUM**2 and cannot be */
  741. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  742. /* Mark the computation as pointless. */
  743. buf = 0.f;
  744. } else {
  745. /* Use second scaling factor to prevent flushing to zero. */
  746. i__2 = myexp_(&scaloc);
  747. buf *= pow_ri(&c_b18, &i__2);
  748. }
  749. i__2 = nbb;
  750. for (jj = 1; jj <= i__2; ++jj) {
  751. i__3 = nba;
  752. for (ll = 1; ll <= i__3; ++ll) {
  753. /* Bound by BIGNUM to not introduce Inf. The value */
  754. /* is irrelevant; corresponding entries of the */
  755. /* solution will be flushed in consistency scaling. */
  756. /* Computing MIN */
  757. i__4 = myexp_(&scaloc);
  758. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  759. / pow_ri(&c_b18, &i__4);
  760. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  761. }
  762. }
  763. }
  764. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  765. ;
  766. i__2 = k2 - k1;
  767. i__3 = l2 - l1;
  768. xnrm = clange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  769. wnrm);
  770. for (i__ = k - 1; i__ >= 1; --i__) {
  771. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  772. i1 = (i__ - 1) * nb + 1;
  773. /* Computing MIN */
  774. i__2 = i__ * nb;
  775. i2 = f2cmin(i__2,*m) + 1;
  776. /* Compute scaling factor to survive the linear update */
  777. /* simulating consistent scaling. */
  778. i__2 = i2 - i1;
  779. i__3 = l2 - l1;
  780. cnrm = clange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  781. ldc, wnrm);
  782. /* Computing MIN */
  783. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  784. swork_dim1];
  785. scamin = f2cmin(r__1,r__2);
  786. cnrm *= scamin / swork[i__ + l * swork_dim1];
  787. xnrm *= scamin / swork[k + l * swork_dim1];
  788. anrm = swork[i__ + (awrk + k) * swork_dim1];
  789. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  790. if (scaloc * scamin == 0.f) {
  791. /* Use second scaling factor to prevent flushing to zero. */
  792. i__2 = myexp_(&scaloc);
  793. buf *= pow_ri(&c_b18, &i__2);
  794. i__2 = nbb;
  795. for (jj = 1; jj <= i__2; ++jj) {
  796. i__3 = nba;
  797. for (ll = 1; ll <= i__3; ++ll) {
  798. /* Computing MIN */
  799. i__4 = myexp_(&scaloc);
  800. r__1 = bignum, r__2 = swork[ll + jj *
  801. swork_dim1] / pow_ri(&c_b18, &i__4);
  802. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  803. }
  804. }
  805. i__2 = myexp_(&scaloc);
  806. scamin /= pow_ri(&c_b18, &i__2);
  807. i__2 = myexp_(&scaloc);
  808. scaloc /= pow_ri(&c_b18, &i__2);
  809. }
  810. cnrm *= scaloc;
  811. xnrm *= scaloc;
  812. /* Simultaneously apply the robust update factor and the */
  813. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  814. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  815. if (scal != 1.f) {
  816. i__2 = l2 - 1;
  817. for (jj = l1; jj <= i__2; ++jj) {
  818. i__3 = k2 - k1;
  819. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  820. c__1);
  821. }
  822. }
  823. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  824. if (scal != 1.f) {
  825. i__2 = l2 - 1;
  826. for (ll = l1; ll <= i__2; ++ll) {
  827. i__3 = i2 - i1;
  828. csscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  829. c__1);
  830. }
  831. }
  832. /* Record current scaling factor */
  833. swork[k + l * swork_dim1] = scamin * scaloc;
  834. swork[i__ + l * swork_dim1] = scamin * scaloc;
  835. i__2 = i2 - i1;
  836. i__3 = l2 - l1;
  837. i__4 = k2 - k1;
  838. q__1.r = -1.f, q__1.i = 0.f;
  839. cgemm_("N", "N", &i__2, &i__3, &i__4, &q__1, &a[i1 + k1 *
  840. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  841. &c__[i1 + l1 * c_dim1], ldc)
  842. ;
  843. }
  844. i__2 = nbb;
  845. for (j = l + 1; j <= i__2; ++j) {
  846. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  847. j1 = (j - 1) * nb + 1;
  848. /* Computing MIN */
  849. i__3 = j * nb;
  850. j2 = f2cmin(i__3,*n) + 1;
  851. /* Compute scaling factor to survive the linear update */
  852. /* simulating consistent scaling. */
  853. i__3 = k2 - k1;
  854. i__4 = j2 - j1;
  855. cnrm = clange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  856. ldc, wnrm);
  857. /* Computing MIN */
  858. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  859. swork_dim1];
  860. scamin = f2cmin(r__1,r__2);
  861. cnrm *= scamin / swork[k + j * swork_dim1];
  862. xnrm *= scamin / swork[k + l * swork_dim1];
  863. bnrm = swork[l + (bwrk + j) * swork_dim1];
  864. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  865. if (scaloc * scamin == 0.f) {
  866. /* Use second scaling factor to prevent flushing to zero. */
  867. i__3 = myexp_(&scaloc);
  868. buf *= pow_ri(&c_b18, &i__3);
  869. i__3 = nbb;
  870. for (jj = 1; jj <= i__3; ++jj) {
  871. i__4 = nba;
  872. for (ll = 1; ll <= i__4; ++ll) {
  873. /* Computing MIN */
  874. i__5 = myexp_(&scaloc);
  875. r__1 = bignum, r__2 = swork[ll + jj *
  876. swork_dim1] / pow_ri(&c_b18, &i__5);
  877. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  878. }
  879. }
  880. i__3 = myexp_(&scaloc);
  881. scamin /= pow_ri(&c_b18, &i__3);
  882. i__3 = myexp_(&scaloc);
  883. scaloc /= pow_ri(&c_b18, &i__3);
  884. }
  885. cnrm *= scaloc;
  886. xnrm *= scaloc;
  887. /* Simultaneously apply the robust update factor and the */
  888. /* consistency scaling factor to C( K, J ) and C( K, L). */
  889. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  890. if (scal != 1.f) {
  891. i__3 = l2 - 1;
  892. for (ll = l1; ll <= i__3; ++ll) {
  893. i__4 = k2 - k1;
  894. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  895. c__1);
  896. }
  897. }
  898. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  899. if (scal != 1.f) {
  900. i__3 = j2 - 1;
  901. for (jj = j1; jj <= i__3; ++jj) {
  902. i__4 = k2 - k1;
  903. csscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  904. c__1);
  905. }
  906. }
  907. /* Record current scaling factor */
  908. swork[k + l * swork_dim1] = scamin * scaloc;
  909. swork[k + j * swork_dim1] = scamin * scaloc;
  910. i__3 = k2 - k1;
  911. i__4 = j2 - j1;
  912. i__5 = l2 - l1;
  913. q__1.r = -csgn.r, q__1.i = -csgn.i;
  914. cgemm_("N", "N", &i__3, &i__4, &i__5, &q__1, &c__[k1 + l1
  915. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b1,
  916. &c__[k1 + j1 * c_dim1], ldc)
  917. ;
  918. }
  919. }
  920. }
  921. } else if (! notrna && notrnb) {
  922. /* Solve A**H *X + ISGN*X*B = scale*C. */
  923. /* The (K,L)th block of X is determined starting from */
  924. /* upper-left corner column by column by */
  925. /* A(K,K)**H*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  926. /* Where */
  927. /* K-1 L-1 */
  928. /* R(K,L) = SUM [A(I,K)**H*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)] */
  929. /* I=1 J=1 */
  930. /* Start loop over block rows (index = K) and block columns (index = L) */
  931. i__1 = nba;
  932. for (k = 1; k <= i__1; ++k) {
  933. /* K1: row index of the first row in X( K, L ) */
  934. /* K2: row index of the first row in X( K+1, L ) */
  935. /* so the K2 - K1 is the column count of the block X( K, L ) */
  936. k1 = (k - 1) * nb + 1;
  937. /* Computing MIN */
  938. i__2 = k * nb;
  939. k2 = f2cmin(i__2,*m) + 1;
  940. i__2 = nbb;
  941. for (l = 1; l <= i__2; ++l) {
  942. /* L1: column index of the first column in X( K, L ) */
  943. /* L2: column index of the first column in X( K, L + 1) */
  944. /* so that L2 - L1 is the row count of the block X( K, L ) */
  945. l1 = (l - 1) * nb + 1;
  946. /* Computing MIN */
  947. i__3 = l * nb;
  948. l2 = f2cmin(i__3,*n) + 1;
  949. i__3 = k2 - k1;
  950. i__4 = l2 - l1;
  951. ctrsyl_(trana, tranb, isgn, &i__3, &i__4, &a[k1 + k1 * a_dim1]
  952. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  953. c_dim1], ldc, &scaloc, &iinfo);
  954. *info = f2cmax(*info,iinfo);
  955. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  956. if (scaloc == 0.f) {
  957. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  958. /* is larger than the product of BIGNUM**2 and cannot be */
  959. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  960. /* Mark the computation as pointless. */
  961. buf = 0.f;
  962. } else {
  963. /* Use second scaling factor to prevent flushing to zero. */
  964. i__3 = myexp_(&scaloc);
  965. buf *= pow_ri(&c_b18, &i__3);
  966. }
  967. i__3 = nbb;
  968. for (jj = 1; jj <= i__3; ++jj) {
  969. i__4 = nba;
  970. for (ll = 1; ll <= i__4; ++ll) {
  971. /* Bound by BIGNUM to not introduce Inf. The value */
  972. /* is irrelevant; corresponding entries of the */
  973. /* solution will be flushed in consistency scaling. */
  974. /* Computing MIN */
  975. i__5 = myexp_(&scaloc);
  976. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  977. / pow_ri(&c_b18, &i__5);
  978. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  979. }
  980. }
  981. }
  982. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  983. ;
  984. i__3 = k2 - k1;
  985. i__4 = l2 - l1;
  986. xnrm = clange_("I", &i__3, &i__4, &c__[k1 + l1 * c_dim1], ldc,
  987. wnrm);
  988. i__3 = nba;
  989. for (i__ = k + 1; i__ <= i__3; ++i__) {
  990. /* C( I, L ) := C( I, L ) - A( K, I )**H * C( K, L ) */
  991. i1 = (i__ - 1) * nb + 1;
  992. /* Computing MIN */
  993. i__4 = i__ * nb;
  994. i2 = f2cmin(i__4,*m) + 1;
  995. /* Compute scaling factor to survive the linear update */
  996. /* simulating consistent scaling. */
  997. i__4 = i2 - i1;
  998. i__5 = l2 - l1;
  999. cnrm = clange_("I", &i__4, &i__5, &c__[i1 + l1 * c_dim1],
  1000. ldc, wnrm);
  1001. /* Computing MIN */
  1002. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1003. swork_dim1];
  1004. scamin = f2cmin(r__1,r__2);
  1005. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1006. xnrm *= scamin / swork[k + l * swork_dim1];
  1007. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1008. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1009. if (scaloc * scamin == 0.f) {
  1010. /* Use second scaling factor to prevent flushing to zero. */
  1011. i__4 = myexp_(&scaloc);
  1012. buf *= pow_ri(&c_b18, &i__4);
  1013. i__4 = nbb;
  1014. for (jj = 1; jj <= i__4; ++jj) {
  1015. i__5 = nba;
  1016. for (ll = 1; ll <= i__5; ++ll) {
  1017. /* Computing MIN */
  1018. i__6 = myexp_(&scaloc);
  1019. r__1 = bignum, r__2 = swork[ll + jj *
  1020. swork_dim1] / pow_ri(&c_b18, &i__6);
  1021. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1022. }
  1023. }
  1024. i__4 = myexp_(&scaloc);
  1025. scamin /= pow_ri(&c_b18, &i__4);
  1026. i__4 = myexp_(&scaloc);
  1027. scaloc /= pow_ri(&c_b18, &i__4);
  1028. }
  1029. cnrm *= scaloc;
  1030. xnrm *= scaloc;
  1031. /* Simultaneously apply the robust update factor and the */
  1032. /* consistency scaling factor to to C( I, L ) and C( K, L). */
  1033. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1034. if (scal != 1.f) {
  1035. i__4 = l2 - 1;
  1036. for (ll = l1; ll <= i__4; ++ll) {
  1037. i__5 = k2 - k1;
  1038. csscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1039. c__1);
  1040. }
  1041. }
  1042. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1043. if (scal != 1.f) {
  1044. i__4 = l2 - 1;
  1045. for (ll = l1; ll <= i__4; ++ll) {
  1046. i__5 = i2 - i1;
  1047. csscal_(&i__5, &scal, &c__[i1 + ll * c_dim1], &
  1048. c__1);
  1049. }
  1050. }
  1051. /* Record current scaling factor */
  1052. swork[k + l * swork_dim1] = scamin * scaloc;
  1053. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1054. i__4 = i2 - i1;
  1055. i__5 = l2 - l1;
  1056. i__6 = k2 - k1;
  1057. q__1.r = -1.f, q__1.i = 0.f;
  1058. cgemm_("C", "N", &i__4, &i__5, &i__6, &q__1, &a[k1 + i1 *
  1059. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1060. &c__[i1 + l1 * c_dim1], ldc)
  1061. ;
  1062. }
  1063. i__3 = nbb;
  1064. for (j = l + 1; j <= i__3; ++j) {
  1065. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  1066. j1 = (j - 1) * nb + 1;
  1067. /* Computing MIN */
  1068. i__4 = j * nb;
  1069. j2 = f2cmin(i__4,*n) + 1;
  1070. /* Compute scaling factor to survive the linear update */
  1071. /* simulating consistent scaling. */
  1072. i__4 = k2 - k1;
  1073. i__5 = j2 - j1;
  1074. cnrm = clange_("I", &i__4, &i__5, &c__[k1 + j1 * c_dim1],
  1075. ldc, wnrm);
  1076. /* Computing MIN */
  1077. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1078. swork_dim1];
  1079. scamin = f2cmin(r__1,r__2);
  1080. cnrm *= scamin / swork[k + j * swork_dim1];
  1081. xnrm *= scamin / swork[k + l * swork_dim1];
  1082. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1083. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1084. if (scaloc * scamin == 0.f) {
  1085. /* Use second scaling factor to prevent flushing to zero. */
  1086. i__4 = myexp_(&scaloc);
  1087. buf *= pow_ri(&c_b18, &i__4);
  1088. i__4 = nbb;
  1089. for (jj = 1; jj <= i__4; ++jj) {
  1090. i__5 = nba;
  1091. for (ll = 1; ll <= i__5; ++ll) {
  1092. /* Computing MIN */
  1093. i__6 = myexp_(&scaloc);
  1094. r__1 = bignum, r__2 = swork[ll + jj *
  1095. swork_dim1] / pow_ri(&c_b18, &i__6);
  1096. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1097. }
  1098. }
  1099. i__4 = myexp_(&scaloc);
  1100. scamin /= pow_ri(&c_b18, &i__4);
  1101. i__4 = myexp_(&scaloc);
  1102. scaloc /= pow_ri(&c_b18, &i__4);
  1103. }
  1104. cnrm *= scaloc;
  1105. xnrm *= scaloc;
  1106. /* Simultaneously apply the robust update factor and the */
  1107. /* consistency scaling factor to to C( K, J ) and C( K, L). */
  1108. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1109. if (scal != 1.f) {
  1110. i__4 = l2 - 1;
  1111. for (ll = l1; ll <= i__4; ++ll) {
  1112. i__5 = k2 - k1;
  1113. csscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1114. c__1);
  1115. }
  1116. }
  1117. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1118. if (scal != 1.f) {
  1119. i__4 = j2 - 1;
  1120. for (jj = j1; jj <= i__4; ++jj) {
  1121. i__5 = k2 - k1;
  1122. csscal_(&i__5, &scal, &c__[k1 + jj * c_dim1], &
  1123. c__1);
  1124. }
  1125. }
  1126. /* Record current scaling factor */
  1127. swork[k + l * swork_dim1] = scamin * scaloc;
  1128. swork[k + j * swork_dim1] = scamin * scaloc;
  1129. i__4 = k2 - k1;
  1130. i__5 = j2 - j1;
  1131. i__6 = l2 - l1;
  1132. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1133. cgemm_("N", "N", &i__4, &i__5, &i__6, &q__1, &c__[k1 + l1
  1134. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b1,
  1135. &c__[k1 + j1 * c_dim1], ldc)
  1136. ;
  1137. }
  1138. }
  1139. }
  1140. } else if (! notrna && ! notrnb) {
  1141. /* Solve A**H *X + ISGN*X*B**H = scale*C. */
  1142. /* The (K,L)th block of X is determined starting from */
  1143. /* top-right corner column by column by */
  1144. /* A(K,K)**H*X(K,L) + ISGN*X(K,L)*B(L,L)**H = C(K,L) - R(K,L) */
  1145. /* Where */
  1146. /* K-1 N */
  1147. /* R(K,L) = SUM [A(I,K)**H*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**H]. */
  1148. /* I=1 J=L+1 */
  1149. /* Start loop over block rows (index = K) and block columns (index = L) */
  1150. i__1 = nba;
  1151. for (k = 1; k <= i__1; ++k) {
  1152. /* K1: row index of the first row in X( K, L ) */
  1153. /* K2: row index of the first row in X( K+1, L ) */
  1154. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1155. k1 = (k - 1) * nb + 1;
  1156. /* Computing MIN */
  1157. i__2 = k * nb;
  1158. k2 = f2cmin(i__2,*m) + 1;
  1159. for (l = nbb; l >= 1; --l) {
  1160. /* L1: column index of the first column in X( K, L ) */
  1161. /* L2: column index of the first column in X( K, L + 1) */
  1162. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1163. l1 = (l - 1) * nb + 1;
  1164. /* Computing MIN */
  1165. i__2 = l * nb;
  1166. l2 = f2cmin(i__2,*n) + 1;
  1167. i__2 = k2 - k1;
  1168. i__3 = l2 - l1;
  1169. ctrsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  1170. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1171. c_dim1], ldc, &scaloc, &iinfo);
  1172. *info = f2cmax(*info,iinfo);
  1173. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1174. if (scaloc == 0.f) {
  1175. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1176. /* is larger than the product of BIGNUM**2 and cannot be */
  1177. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1178. /* Mark the computation as pointless. */
  1179. buf = 0.f;
  1180. } else {
  1181. /* Use second scaling factor to prevent flushing to zero. */
  1182. i__2 = myexp_(&scaloc);
  1183. buf *= pow_ri(&c_b18, &i__2);
  1184. }
  1185. i__2 = nbb;
  1186. for (jj = 1; jj <= i__2; ++jj) {
  1187. i__3 = nba;
  1188. for (ll = 1; ll <= i__3; ++ll) {
  1189. /* Bound by BIGNUM to not introduce Inf. The value */
  1190. /* is irrelevant; corresponding entries of the */
  1191. /* solution will be flushed in consistency scaling. */
  1192. /* Computing MIN */
  1193. i__4 = myexp_(&scaloc);
  1194. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1195. / pow_ri(&c_b18, &i__4);
  1196. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1197. }
  1198. }
  1199. }
  1200. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1201. ;
  1202. i__2 = k2 - k1;
  1203. i__3 = l2 - l1;
  1204. xnrm = clange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  1205. wnrm);
  1206. i__2 = nba;
  1207. for (i__ = k + 1; i__ <= i__2; ++i__) {
  1208. /* C( I, L ) := C( I, L ) - A( K, I )**H * C( K, L ) */
  1209. i1 = (i__ - 1) * nb + 1;
  1210. /* Computing MIN */
  1211. i__3 = i__ * nb;
  1212. i2 = f2cmin(i__3,*m) + 1;
  1213. /* Compute scaling factor to survive the linear update */
  1214. /* simulating consistent scaling. */
  1215. i__3 = i2 - i1;
  1216. i__4 = l2 - l1;
  1217. cnrm = clange_("I", &i__3, &i__4, &c__[i1 + l1 * c_dim1],
  1218. ldc, wnrm);
  1219. /* Computing MIN */
  1220. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1221. swork_dim1];
  1222. scamin = f2cmin(r__1,r__2);
  1223. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1224. xnrm *= scamin / swork[k + l * swork_dim1];
  1225. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1226. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1227. if (scaloc * scamin == 0.f) {
  1228. /* Use second scaling factor to prevent flushing to zero. */
  1229. i__3 = myexp_(&scaloc);
  1230. buf *= pow_ri(&c_b18, &i__3);
  1231. i__3 = nbb;
  1232. for (jj = 1; jj <= i__3; ++jj) {
  1233. i__4 = nba;
  1234. for (ll = 1; ll <= i__4; ++ll) {
  1235. /* Computing MIN */
  1236. i__5 = myexp_(&scaloc);
  1237. r__1 = bignum, r__2 = swork[ll + jj *
  1238. swork_dim1] / pow_ri(&c_b18, &i__5);
  1239. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1240. }
  1241. }
  1242. i__3 = myexp_(&scaloc);
  1243. scamin /= pow_ri(&c_b18, &i__3);
  1244. i__3 = myexp_(&scaloc);
  1245. scaloc /= pow_ri(&c_b18, &i__3);
  1246. }
  1247. cnrm *= scaloc;
  1248. xnrm *= scaloc;
  1249. /* Simultaneously apply the robust update factor and the */
  1250. /* consistency scaling factor to C( I, L ) and C( K, L). */
  1251. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1252. if (scal != 1.f) {
  1253. i__3 = l2 - 1;
  1254. for (ll = l1; ll <= i__3; ++ll) {
  1255. i__4 = k2 - k1;
  1256. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1257. c__1);
  1258. }
  1259. }
  1260. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1261. if (scal != 1.f) {
  1262. i__3 = l2 - 1;
  1263. for (ll = l1; ll <= i__3; ++ll) {
  1264. i__4 = i2 - i1;
  1265. csscal_(&i__4, &scal, &c__[i1 + ll * c_dim1], &
  1266. c__1);
  1267. }
  1268. }
  1269. /* Record current scaling factor */
  1270. swork[k + l * swork_dim1] = scamin * scaloc;
  1271. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1272. i__3 = i2 - i1;
  1273. i__4 = l2 - l1;
  1274. i__5 = k2 - k1;
  1275. q__1.r = -1.f, q__1.i = 0.f;
  1276. cgemm_("C", "N", &i__3, &i__4, &i__5, &q__1, &a[k1 + i1 *
  1277. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1278. &c__[i1 + l1 * c_dim1], ldc)
  1279. ;
  1280. }
  1281. i__2 = l - 1;
  1282. for (j = 1; j <= i__2; ++j) {
  1283. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**H */
  1284. j1 = (j - 1) * nb + 1;
  1285. /* Computing MIN */
  1286. i__3 = j * nb;
  1287. j2 = f2cmin(i__3,*n) + 1;
  1288. /* Compute scaling factor to survive the linear update */
  1289. /* simulating consistent scaling. */
  1290. i__3 = k2 - k1;
  1291. i__4 = j2 - j1;
  1292. cnrm = clange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  1293. ldc, wnrm);
  1294. /* Computing MIN */
  1295. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1296. swork_dim1];
  1297. scamin = f2cmin(r__1,r__2);
  1298. cnrm *= scamin / swork[k + j * swork_dim1];
  1299. xnrm *= scamin / swork[k + l * swork_dim1];
  1300. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1301. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1302. if (scaloc * scamin == 0.f) {
  1303. /* Use second scaling factor to prevent flushing to zero. */
  1304. i__3 = myexp_(&scaloc);
  1305. buf *= pow_ri(&c_b18, &i__3);
  1306. i__3 = nbb;
  1307. for (jj = 1; jj <= i__3; ++jj) {
  1308. i__4 = nba;
  1309. for (ll = 1; ll <= i__4; ++ll) {
  1310. /* Computing MIN */
  1311. i__5 = myexp_(&scaloc);
  1312. r__1 = bignum, r__2 = swork[ll + jj *
  1313. swork_dim1] / pow_ri(&c_b18, &i__5);
  1314. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1315. }
  1316. }
  1317. i__3 = myexp_(&scaloc);
  1318. scamin /= pow_ri(&c_b18, &i__3);
  1319. i__3 = myexp_(&scaloc);
  1320. scaloc /= pow_ri(&c_b18, &i__3);
  1321. }
  1322. cnrm *= scaloc;
  1323. xnrm *= scaloc;
  1324. /* Simultaneously apply the robust update factor and the */
  1325. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1326. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1327. if (scal != 1.f) {
  1328. i__3 = l2 - 1;
  1329. for (ll = l1; ll <= i__3; ++ll) {
  1330. i__4 = k2 - k1;
  1331. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1332. c__1);
  1333. }
  1334. }
  1335. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1336. if (scal != 1.f) {
  1337. i__3 = j2 - 1;
  1338. for (jj = j1; jj <= i__3; ++jj) {
  1339. i__4 = k2 - k1;
  1340. csscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1341. c__1);
  1342. }
  1343. }
  1344. /* Record current scaling factor */
  1345. swork[k + l * swork_dim1] = scamin * scaloc;
  1346. swork[k + j * swork_dim1] = scamin * scaloc;
  1347. i__3 = k2 - k1;
  1348. i__4 = j2 - j1;
  1349. i__5 = l2 - l1;
  1350. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1351. cgemm_("N", "C", &i__3, &i__4, &i__5, &q__1, &c__[k1 + l1
  1352. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b1,
  1353. &c__[k1 + j1 * c_dim1], ldc)
  1354. ;
  1355. }
  1356. }
  1357. }
  1358. } else if (notrna && ! notrnb) {
  1359. /* Solve A*X + ISGN*X*B**H = scale*C. */
  1360. /* The (K,L)th block of X is determined starting from */
  1361. /* bottom-right corner column by column by */
  1362. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)**H = C(K,L) - R(K,L) */
  1363. /* Where */
  1364. /* M N */
  1365. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**H]. */
  1366. /* I=K+1 J=L+1 */
  1367. /* Start loop over block rows (index = K) and block columns (index = L) */
  1368. for (k = nba; k >= 1; --k) {
  1369. /* K1: row index of the first row in X( K, L ) */
  1370. /* K2: row index of the first row in X( K+1, L ) */
  1371. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1372. k1 = (k - 1) * nb + 1;
  1373. /* Computing MIN */
  1374. i__1 = k * nb;
  1375. k2 = f2cmin(i__1,*m) + 1;
  1376. for (l = nbb; l >= 1; --l) {
  1377. /* L1: column index of the first column in X( K, L ) */
  1378. /* L2: column index of the first column in X( K, L + 1) */
  1379. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1380. l1 = (l - 1) * nb + 1;
  1381. /* Computing MIN */
  1382. i__1 = l * nb;
  1383. l2 = f2cmin(i__1,*n) + 1;
  1384. i__1 = k2 - k1;
  1385. i__2 = l2 - l1;
  1386. ctrsyl_(trana, tranb, isgn, &i__1, &i__2, &a[k1 + k1 * a_dim1]
  1387. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1388. c_dim1], ldc, &scaloc, &iinfo);
  1389. *info = f2cmax(*info,iinfo);
  1390. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1391. if (scaloc == 0.f) {
  1392. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1393. /* is larger than the product of BIGNUM**2 and cannot be */
  1394. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1395. /* Mark the computation as pointless. */
  1396. buf = 0.f;
  1397. } else {
  1398. /* Use second scaling factor to prevent flushing to zero. */
  1399. i__1 = myexp_(&scaloc);
  1400. buf *= pow_ri(&c_b18, &i__1);
  1401. }
  1402. i__1 = nbb;
  1403. for (jj = 1; jj <= i__1; ++jj) {
  1404. i__2 = nba;
  1405. for (ll = 1; ll <= i__2; ++ll) {
  1406. /* Bound by BIGNUM to not introduce Inf. The value */
  1407. /* is irrelevant; corresponding entries of the */
  1408. /* solution will be flushed in consistency scaling. */
  1409. /* Computing MIN */
  1410. i__3 = myexp_(&scaloc);
  1411. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1412. / pow_ri(&c_b18, &i__3);
  1413. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1414. }
  1415. }
  1416. }
  1417. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1418. ;
  1419. i__1 = k2 - k1;
  1420. i__2 = l2 - l1;
  1421. xnrm = clange_("I", &i__1, &i__2, &c__[k1 + l1 * c_dim1], ldc,
  1422. wnrm);
  1423. i__1 = k - 1;
  1424. for (i__ = 1; i__ <= i__1; ++i__) {
  1425. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  1426. i1 = (i__ - 1) * nb + 1;
  1427. /* Computing MIN */
  1428. i__2 = i__ * nb;
  1429. i2 = f2cmin(i__2,*m) + 1;
  1430. /* Compute scaling factor to survive the linear update */
  1431. /* simulating consistent scaling. */
  1432. i__2 = i2 - i1;
  1433. i__3 = l2 - l1;
  1434. cnrm = clange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  1435. ldc, wnrm);
  1436. /* Computing MIN */
  1437. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1438. swork_dim1];
  1439. scamin = f2cmin(r__1,r__2);
  1440. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1441. xnrm *= scamin / swork[k + l * swork_dim1];
  1442. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1443. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1444. if (scaloc * scamin == 0.f) {
  1445. /* Use second scaling factor to prevent flushing to zero. */
  1446. i__2 = myexp_(&scaloc);
  1447. buf *= pow_ri(&c_b18, &i__2);
  1448. i__2 = nbb;
  1449. for (jj = 1; jj <= i__2; ++jj) {
  1450. i__3 = nba;
  1451. for (ll = 1; ll <= i__3; ++ll) {
  1452. /* Computing MIN */
  1453. i__4 = myexp_(&scaloc);
  1454. r__1 = bignum, r__2 = swork[ll + jj *
  1455. swork_dim1] / pow_ri(&c_b18, &i__4);
  1456. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1457. }
  1458. }
  1459. i__2 = myexp_(&scaloc);
  1460. scamin /= pow_ri(&c_b18, &i__2);
  1461. i__2 = myexp_(&scaloc);
  1462. scaloc /= pow_ri(&c_b18, &i__2);
  1463. }
  1464. cnrm *= scaloc;
  1465. xnrm *= scaloc;
  1466. /* Simultaneously apply the robust update factor and the */
  1467. /* consistency scaling factor to C( I, L ) and C( K, L). */
  1468. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1469. if (scal != 1.f) {
  1470. i__2 = l2 - 1;
  1471. for (ll = l1; ll <= i__2; ++ll) {
  1472. i__3 = k2 - k1;
  1473. csscal_(&i__3, &scal, &c__[k1 + ll * c_dim1], &
  1474. c__1);
  1475. }
  1476. }
  1477. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1478. if (scal != 1.f) {
  1479. i__2 = l2 - 1;
  1480. for (ll = l1; ll <= i__2; ++ll) {
  1481. i__3 = i2 - i1;
  1482. csscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  1483. c__1);
  1484. }
  1485. }
  1486. /* Record current scaling factor */
  1487. swork[k + l * swork_dim1] = scamin * scaloc;
  1488. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1489. i__2 = i2 - i1;
  1490. i__3 = l2 - l1;
  1491. i__4 = k2 - k1;
  1492. q__1.r = -1.f, q__1.i = 0.f;
  1493. cgemm_("N", "N", &i__2, &i__3, &i__4, &q__1, &a[i1 + k1 *
  1494. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &c_b1,
  1495. &c__[i1 + l1 * c_dim1], ldc)
  1496. ;
  1497. }
  1498. i__1 = l - 1;
  1499. for (j = 1; j <= i__1; ++j) {
  1500. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**H */
  1501. j1 = (j - 1) * nb + 1;
  1502. /* Computing MIN */
  1503. i__2 = j * nb;
  1504. j2 = f2cmin(i__2,*n) + 1;
  1505. /* Compute scaling factor to survive the linear update */
  1506. /* simulating consistent scaling. */
  1507. i__2 = k2 - k1;
  1508. i__3 = j2 - j1;
  1509. cnrm = clange_("I", &i__2, &i__3, &c__[k1 + j1 * c_dim1],
  1510. ldc, wnrm);
  1511. /* Computing MIN */
  1512. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1513. swork_dim1];
  1514. scamin = f2cmin(r__1,r__2);
  1515. cnrm *= scamin / swork[k + j * swork_dim1];
  1516. xnrm *= scamin / swork[k + l * swork_dim1];
  1517. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1518. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1519. if (scaloc * scamin == 0.f) {
  1520. /* Use second scaling factor to prevent flushing to zero. */
  1521. i__2 = myexp_(&scaloc);
  1522. buf *= pow_ri(&c_b18, &i__2);
  1523. i__2 = nbb;
  1524. for (jj = 1; jj <= i__2; ++jj) {
  1525. i__3 = nba;
  1526. for (ll = 1; ll <= i__3; ++ll) {
  1527. /* Computing MIN */
  1528. i__4 = myexp_(&scaloc);
  1529. r__1 = bignum, r__2 = swork[ll + jj *
  1530. swork_dim1] / pow_ri(&c_b18, &i__4);
  1531. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1532. }
  1533. }
  1534. i__2 = myexp_(&scaloc);
  1535. scamin /= pow_ri(&c_b18, &i__2);
  1536. i__2 = myexp_(&scaloc);
  1537. scaloc /= pow_ri(&c_b18, &i__2);
  1538. }
  1539. cnrm *= scaloc;
  1540. xnrm *= scaloc;
  1541. /* Simultaneously apply the robust update factor and the */
  1542. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1543. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1544. if (scal != 1.f) {
  1545. i__2 = l2 - 1;
  1546. for (jj = l1; jj <= i__2; ++jj) {
  1547. i__3 = k2 - k1;
  1548. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1549. c__1);
  1550. }
  1551. }
  1552. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1553. if (scal != 1.f) {
  1554. i__2 = j2 - 1;
  1555. for (jj = j1; jj <= i__2; ++jj) {
  1556. i__3 = k2 - k1;
  1557. csscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1558. c__1);
  1559. }
  1560. }
  1561. /* Record current scaling factor */
  1562. swork[k + l * swork_dim1] = scamin * scaloc;
  1563. swork[k + j * swork_dim1] = scamin * scaloc;
  1564. i__2 = k2 - k1;
  1565. i__3 = j2 - j1;
  1566. i__4 = l2 - l1;
  1567. q__1.r = -csgn.r, q__1.i = -csgn.i;
  1568. cgemm_("N", "C", &i__2, &i__3, &i__4, &q__1, &c__[k1 + l1
  1569. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b1,
  1570. &c__[k1 + j1 * c_dim1], ldc)
  1571. ;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. free(wnrm);
  1577. /* Reduce local scaling factors */
  1578. *scale = swork[swork_dim1 + 1];
  1579. i__1 = nba;
  1580. for (k = 1; k <= i__1; ++k) {
  1581. i__2 = nbb;
  1582. for (l = 1; l <= i__2; ++l) {
  1583. /* Computing MIN */
  1584. r__1 = *scale, r__2 = swork[k + l * swork_dim1];
  1585. *scale = f2cmin(r__1,r__2);
  1586. }
  1587. }
  1588. if (*scale == 0.f) {
  1589. /* The magnitude of the largest entry of the solution is larger */
  1590. /* than the product of BIGNUM**2 and cannot be represented in the */
  1591. /* form (1/SCALE)*X if SCALE is REAL. Set SCALE to */
  1592. /* zero and give up. */
  1593. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1594. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1595. return 0;
  1596. }
  1597. /* Realize consistent scaling */
  1598. i__1 = nba;
  1599. for (k = 1; k <= i__1; ++k) {
  1600. k1 = (k - 1) * nb + 1;
  1601. /* Computing MIN */
  1602. i__2 = k * nb;
  1603. k2 = f2cmin(i__2,*m) + 1;
  1604. i__2 = nbb;
  1605. for (l = 1; l <= i__2; ++l) {
  1606. l1 = (l - 1) * nb + 1;
  1607. /* Computing MIN */
  1608. i__3 = l * nb;
  1609. l2 = f2cmin(i__3,*n) + 1;
  1610. scal = *scale / swork[k + l * swork_dim1];
  1611. if (scal != 1.f) {
  1612. i__3 = l2 - 1;
  1613. for (ll = l1; ll <= i__3; ++ll) {
  1614. i__4 = k2 - k1;
  1615. csscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &c__1);
  1616. }
  1617. }
  1618. }
  1619. }
  1620. if (buf != 1.f && buf > 0.f) {
  1621. /* Decrease SCALE as much as possible. */
  1622. /* Computing MIN */
  1623. r__1 = *scale / smlnum, r__2 = 1.f / buf;
  1624. scaloc = f2cmin(r__1,r__2);
  1625. buf *= scaloc;
  1626. *scale /= scaloc;
  1627. }
  1628. if (buf != 1.f && buf > 0.f) {
  1629. /* In case of overly aggressive scaling during the computation, */
  1630. /* flushing of the global scale factor may be prevented by */
  1631. /* undoing some of the scaling. This step is to ensure that */
  1632. /* this routine flushes only scale factors that TRSYL also */
  1633. /* flushes and be usable as a drop-in replacement. */
  1634. /* How much can the normwise largest entry be upscaled? */
  1635. /* Computing MAX */
  1636. i__1 = c_dim1 + 1;
  1637. r__3 = (r__1 = c__[i__1].r, abs(r__1)), r__4 = (r__2 = r_imag(&c__[
  1638. c_dim1 + 1]), abs(r__2));
  1639. scal = f2cmax(r__3,r__4);
  1640. i__1 = *m;
  1641. for (k = 1; k <= i__1; ++k) {
  1642. i__2 = *n;
  1643. for (l = 1; l <= i__2; ++l) {
  1644. /* Computing MAX */
  1645. i__3 = k + l * c_dim1;
  1646. r__3 = scal, r__4 = (r__1 = c__[i__3].r, abs(r__1)), r__3 =
  1647. f2cmax(r__3,r__4), r__4 = (r__2 = r_imag(&c__[k + l *
  1648. c_dim1]), abs(r__2));
  1649. scal = f2cmax(r__3,r__4);
  1650. }
  1651. }
  1652. /* Increase BUF as close to 1 as possible and apply scaling. */
  1653. /* Computing MIN */
  1654. r__1 = bignum / scal, r__2 = 1.f / buf;
  1655. scaloc = f2cmin(r__1,r__2);
  1656. buf *= scaloc;
  1657. clascl_("G", &c_n1, &c_n1, &c_b106, &scaloc, m, n, &c__[c_offset],
  1658. ldc, &iinfo);
  1659. }
  1660. /* Combine with buffer scaling factor. SCALE will be flushed if */
  1661. /* BUF is less than one here. */
  1662. *scale *= buf;
  1663. /* Restore workspace dimensions */
  1664. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1665. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1666. return 0;
  1667. /* End of CTRSYL3 */
  1668. } /* ctrsyl3_ */