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.

strsyl3.c 58 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  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 integer c__1 = 1;
  366. static integer c_n1 = -1;
  367. static real c_b19 = 2.f;
  368. static real c_b31 = -1.f;
  369. static real c_b32 = 1.f;
  370. /* > \brief \b STRSYL3 */
  371. /* Definition: */
  372. /* =========== */
  373. /* > \par Purpose */
  374. /* ============= */
  375. /* > */
  376. /* > \verbatim */
  377. /* > */
  378. /* > STRSYL3 solves the real 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**T, and A and B are both upper quasi- */
  384. /* > triangular. A is M-by-M and B is N-by-N; the right hand side C and */
  385. /* > the solution X are M-by-N; and scale is an output scale factor, set */
  386. /* > <= 1 to avoid overflow in X. */
  387. /* > */
  388. /* > A and B must be in Schur canonical form (as returned by SHSEQR), that */
  389. /* > is, block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; */
  390. /* > each 2-by-2 diagonal block has its diagonal elements equal and its */
  391. /* > off-diagonal elements of opposite sign. */
  392. /* > */
  393. /* > This is the block version of the algorithm. */
  394. /* > \endverbatim */
  395. /* Arguments */
  396. /* ========= */
  397. /* > \param[in] TRANA */
  398. /* > \verbatim */
  399. /* > TRANA is CHARACTER*1 */
  400. /* > Specifies the option op(A): */
  401. /* > = 'N': op(A) = A (No transpose) */
  402. /* > = 'T': op(A) = A**T (Transpose) */
  403. /* > = 'C': op(A) = A**H (Conjugate transpose = Transpose) */
  404. /* > \endverbatim */
  405. /* > */
  406. /* > \param[in] TRANB */
  407. /* > \verbatim */
  408. /* > TRANB is CHARACTER*1 */
  409. /* > Specifies the option op(B): */
  410. /* > = 'N': op(B) = B (No transpose) */
  411. /* > = 'T': op(B) = B**T (Transpose) */
  412. /* > = 'C': op(B) = B**H (Conjugate transpose = Transpose) */
  413. /* > \endverbatim */
  414. /* > */
  415. /* > \param[in] ISGN */
  416. /* > \verbatim */
  417. /* > ISGN is INTEGER */
  418. /* > Specifies the sign in the equation: */
  419. /* > = +1: solve op(A)*X + X*op(B) = scale*C */
  420. /* > = -1: solve op(A)*X - X*op(B) = scale*C */
  421. /* > \endverbatim */
  422. /* > */
  423. /* > \param[in] M */
  424. /* > \verbatim */
  425. /* > M is INTEGER */
  426. /* > The order of the matrix A, and the number of rows in the */
  427. /* > matrices X and C. M >= 0. */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[in] N */
  431. /* > \verbatim */
  432. /* > N is INTEGER */
  433. /* > The order of the matrix B, and the number of columns in the */
  434. /* > matrices X and C. N >= 0. */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in] A */
  438. /* > \verbatim */
  439. /* > A is REAL array, dimension (LDA,M) */
  440. /* > The upper quasi-triangular matrix A, in Schur canonical form. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in] LDA */
  444. /* > \verbatim */
  445. /* > LDA is INTEGER */
  446. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  447. /* > \endverbatim */
  448. /* > */
  449. /* > \param[in] B */
  450. /* > \verbatim */
  451. /* > B is REAL array, dimension (LDB,N) */
  452. /* > The upper quasi-triangular matrix B, in Schur canonical form. */
  453. /* > \endverbatim */
  454. /* > */
  455. /* > \param[in] LDB */
  456. /* > \verbatim */
  457. /* > LDB is INTEGER */
  458. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in,out] C */
  462. /* > \verbatim */
  463. /* > C is REAL array, dimension (LDC,N) */
  464. /* > On entry, the M-by-N right hand side matrix C. */
  465. /* > On exit, C is overwritten by the solution matrix X. */
  466. /* > \endverbatim */
  467. /* > */
  468. /* > \param[in] LDC */
  469. /* > \verbatim */
  470. /* > LDC is INTEGER */
  471. /* > The leading dimension of the array C. LDC >= f2cmax(1,M) */
  472. /* > \endverbatim */
  473. /* > */
  474. /* > \param[out] SCALE */
  475. /* > \verbatim */
  476. /* > SCALE is REAL */
  477. /* > The scale factor, scale, set <= 1 to avoid overflow in X. */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[out] IWORK */
  481. /* > \verbatim */
  482. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  483. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  484. /* > \endverbatim */
  485. /* > */
  486. /* > \param[in] LIWORK */
  487. /* > \verbatim */
  488. /* > IWORK is INTEGER */
  489. /* > The dimension of the array IWORK. LIWORK >= ((M + NB - 1) / NB + 1) */
  490. /* > + ((N + NB - 1) / NB + 1), where NB is the optimal block size. */
  491. /* > */
  492. /* > If LIWORK = -1, then a workspace query is assumed; the routine */
  493. /* > only calculates the optimal dimension of the IWORK array, */
  494. /* > returns this value as the first entry of the IWORK array, and */
  495. /* > no error message related to LIWORK is issued by XERBLA. */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[out] SWORK */
  499. /* > \verbatim */
  500. /* > SWORK is REAL array, dimension (MAX(2, ROWS), */
  501. /* > MAX(1,COLS)). */
  502. /* > On exit, if INFO = 0, SWORK(1) returns the optimal value ROWS */
  503. /* > and SWORK(2) returns the optimal COLS. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[in] LDSWORK */
  507. /* > \verbatim */
  508. /* > LDSWORK is INTEGER */
  509. /* > LDSWORK >= MAX(2,ROWS), where ROWS = ((M + NB - 1) / NB + 1) */
  510. /* > and NB is the optimal block size. */
  511. /* > */
  512. /* > If LDSWORK = -1, then a workspace query is assumed; the routine */
  513. /* > only calculates the optimal dimensions of the SWORK matrix, */
  514. /* > returns these values as the first and second entry of the SWORK */
  515. /* > matrix, and no error message related LWORK is issued by XERBLA. */
  516. /* > \endverbatim */
  517. /* > */
  518. /* > \param[out] INFO */
  519. /* > \verbatim */
  520. /* > INFO is INTEGER */
  521. /* > = 0: successful exit */
  522. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  523. /* > = 1: A and B have common or very close eigenvalues; perturbed */
  524. /* > values were used to solve the equation (but the matrices */
  525. /* > A and B are unchanged). */
  526. /* > \endverbatim */
  527. /* ===================================================================== */
  528. /* References: */
  529. /* E. S. Quintana-Orti and R. A. Van De Geijn (2003). Formal derivation of */
  530. /* algorithms: The triangular Sylvester equation, ACM Transactions */
  531. /* on Mathematical Software (TOMS), volume 29, pages 218--243. */
  532. /* A. Schwarz and C. C. Kjelgaard Mikkelsen (2020). Robust Task-Parallel */
  533. /* Solution of the Triangular Sylvester Equation. Lecture Notes in */
  534. /* Computer Science, vol 12043, pages 82--92, Springer. */
  535. /* Contributor: */
  536. /* Angelika Schwarz, Umea University, Sweden. */
  537. /* ===================================================================== */
  538. /* Subroutine */ int strsyl3_(char *trana, char *tranb, integer *isgn,
  539. integer *m, integer *n, real *a, integer *lda, real *b, integer *ldb,
  540. real *c__, integer *ldc, real *scale, integer *iwork, integer *liwork,
  541. real *swork, integer *ldswork, integer *info)
  542. {
  543. /* System generated locals */
  544. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, swork_dim1,
  545. swork_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  546. real r__1, r__2, r__3;
  547. /* Local variables */
  548. real scal, anrm, bnrm, cnrm;
  549. integer awrk, bwrk;
  550. logical skip;
  551. real *wnrm, xnrm;
  552. integer i__, j, k, l;
  553. extern logical lsame_(char *, char *);
  554. integer iinfo;
  555. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *),
  556. sgemm_(char *, char *, integer *, integer *, integer *, real *,
  557. real *, integer *, real *, integer *, real *, real *, integer *);
  558. integer i1, i2, j1, j2, k1, k2, l1;
  559. // extern integer myexp_(real *);
  560. integer l2, nb, pc, jj, ll;
  561. real scaloc;
  562. extern real slamch_(char *), slange_(char *, integer *, integer *,
  563. real *, integer *, real *);
  564. real scamin;
  565. extern /* Subroutine */ int xerbla_(char *, integer *);
  566. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  567. integer *, integer *, ftnlen, ftnlen);
  568. real bignum;
  569. extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
  570. real *, integer *, integer *, real *, integer *, integer *);
  571. extern real slarmm_(real *, real *, real *);
  572. logical notrna, notrnb;
  573. real smlnum;
  574. logical lquery;
  575. extern /* Subroutine */ int strsyl_(char *, char *, integer *, integer *,
  576. integer *, real *, integer *, real *, integer *, real *, integer *
  577. , real *, integer *);
  578. integer nba, nbb;
  579. real buf, sgn;
  580. /* Decode and Test input parameters */
  581. /* Parameter adjustments */
  582. a_dim1 = *lda;
  583. a_offset = 1 + a_dim1 * 1;
  584. a -= a_offset;
  585. b_dim1 = *ldb;
  586. b_offset = 1 + b_dim1 * 1;
  587. b -= b_offset;
  588. c_dim1 = *ldc;
  589. c_offset = 1 + c_dim1 * 1;
  590. c__ -= c_offset;
  591. --iwork;
  592. swork_dim1 = *ldswork;
  593. swork_offset = 1 + swork_dim1 * 1;
  594. swork -= swork_offset;
  595. /* Function Body */
  596. notrna = lsame_(trana, "N");
  597. notrnb = lsame_(tranb, "N");
  598. /* Use the same block size for all matrices. */
  599. /* Computing MAX */
  600. i__1 = 8, i__2 = ilaenv_(&c__1, "STRSYL", "", m, n, &c_n1, &c_n1, (ftnlen)
  601. 6, (ftnlen)0);
  602. nb = f2cmax(i__1,i__2);
  603. /* Compute number of blocks in A and B */
  604. /* Computing MAX */
  605. i__1 = 1, i__2 = (*m + nb - 1) / nb;
  606. nba = f2cmax(i__1,i__2);
  607. /* Computing MAX */
  608. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  609. nbb = f2cmax(i__1,i__2);
  610. /* Compute workspace */
  611. *info = 0;
  612. lquery = *liwork == -1 || *ldswork == -1;
  613. iwork[1] = nba + nbb + 2;
  614. if (lquery) {
  615. *ldswork = 2;
  616. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  617. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  618. }
  619. /* Test the input arguments */
  620. if (! notrna && ! lsame_(trana, "T") && ! lsame_(
  621. trana, "C")) {
  622. *info = -1;
  623. } else if (! notrnb && ! lsame_(tranb, "T") && !
  624. lsame_(tranb, "C")) {
  625. *info = -2;
  626. } else if (*isgn != 1 && *isgn != -1) {
  627. *info = -3;
  628. } else if (*m < 0) {
  629. *info = -4;
  630. } else if (*n < 0) {
  631. *info = -5;
  632. } else if (*lda < f2cmax(1,*m)) {
  633. *info = -7;
  634. } else if (*ldb < f2cmax(1,*n)) {
  635. *info = -9;
  636. } else if (*ldc < f2cmax(1,*m)) {
  637. *info = -11;
  638. } else if (! lquery && *liwork < iwork[1]) {
  639. *info = -14;
  640. } else if (! lquery && *ldswork < f2cmax(nba,nbb)) {
  641. *info = -16;
  642. }
  643. if (*info != 0) {
  644. i__1 = -(*info);
  645. xerbla_("STRSYL3", &i__1);
  646. return 0;
  647. } else if (lquery) {
  648. return 0;
  649. }
  650. /* Quick return if possible */
  651. *scale = 1.f;
  652. if (*m == 0 || *n == 0) {
  653. return 0;
  654. }
  655. /* Use unblocked code for small problems or if insufficient */
  656. /* workspaces are provided */
  657. if (f2cmin(nba,nbb) == 1 || *ldswork < f2cmax(nba,nbb) || *liwork < iwork[1]) {
  658. strsyl_(trana, tranb, isgn, m, n, &a[a_offset], lda, &b[b_offset],
  659. ldb, &c__[c_offset], ldc, scale, info);
  660. return 0;
  661. }
  662. /* REAL WNRM( MAX( M, N ) ) */
  663. wnrm=(real*)malloc (f2cmax(*m,*n)*sizeof(real));
  664. /* Set constants to control overflow */
  665. smlnum = slamch_("S");
  666. bignum = 1.f / smlnum;
  667. /* Partition A such that 2-by-2 blocks on the diagonal are not split */
  668. skip = FALSE_;
  669. i__1 = nba;
  670. for (i__ = 1; i__ <= i__1; ++i__) {
  671. iwork[i__] = (i__ - 1) * nb + 1;
  672. }
  673. iwork[nba + 1] = *m + 1;
  674. i__1 = nba;
  675. for (k = 1; k <= i__1; ++k) {
  676. l1 = iwork[k];
  677. l2 = iwork[k + 1] - 1;
  678. i__2 = l2;
  679. for (l = l1; l <= i__2; ++l) {
  680. if (skip) {
  681. skip = FALSE_;
  682. mycycle_();
  683. }
  684. if (l >= *m) {
  685. /* A( M, M ) is a 1-by-1 block */
  686. mycycle_();
  687. }
  688. if (a[l + (l + 1) * a_dim1] != 0.f && a[l + 1 + l * a_dim1] !=
  689. 0.f) {
  690. /* Check if 2-by-2 block is split */
  691. if (l + 1 == iwork[k + 1]) {
  692. ++iwork[k + 1];
  693. mycycle_();
  694. }
  695. skip = TRUE_;
  696. }
  697. }
  698. }
  699. iwork[nba + 1] = *m + 1;
  700. if (iwork[nba] >= iwork[nba + 1]) {
  701. iwork[nba] = iwork[nba + 1];
  702. --nba;
  703. }
  704. /* Partition B such that 2-by-2 blocks on the diagonal are not split */
  705. pc = nba + 1;
  706. skip = FALSE_;
  707. i__1 = nbb;
  708. for (i__ = 1; i__ <= i__1; ++i__) {
  709. iwork[pc + i__] = (i__ - 1) * nb + 1;
  710. }
  711. iwork[pc + nbb + 1] = *n + 1;
  712. i__1 = nbb;
  713. for (k = 1; k <= i__1; ++k) {
  714. l1 = iwork[pc + k];
  715. l2 = iwork[pc + k + 1] - 1;
  716. i__2 = l2;
  717. for (l = l1; l <= i__2; ++l) {
  718. if (skip) {
  719. skip = FALSE_;
  720. mycycle_();
  721. }
  722. if (l >= *n) {
  723. /* B( N, N ) is a 1-by-1 block */
  724. mycycle_();
  725. }
  726. if (b[l + (l + 1) * b_dim1] != 0.f && b[l + 1 + l * b_dim1] !=
  727. 0.f) {
  728. /* Check if 2-by-2 block is split */
  729. if (l + 1 == iwork[pc + k + 1]) {
  730. ++iwork[pc + k + 1];
  731. mycycle_();
  732. }
  733. skip = TRUE_;
  734. }
  735. }
  736. }
  737. iwork[pc + nbb + 1] = *n + 1;
  738. if (iwork[pc + nbb] >= iwork[pc + nbb + 1]) {
  739. iwork[pc + nbb] = iwork[pc + nbb + 1];
  740. --nbb;
  741. }
  742. /* Set local scaling factors - must never attain zero. */
  743. i__1 = nbb;
  744. for (l = 1; l <= i__1; ++l) {
  745. i__2 = nba;
  746. for (k = 1; k <= i__2; ++k) {
  747. swork[k + l * swork_dim1] = 1.f;
  748. }
  749. }
  750. /* Fallback scaling factor to prevent flushing of SWORK( K, L ) to zero. */
  751. /* This scaling is to ensure compatibility with TRSYL and may get flushed. */
  752. buf = 1.f;
  753. /* Compute upper bounds of blocks of A and B */
  754. awrk = nbb;
  755. i__1 = nba;
  756. for (k = 1; k <= i__1; ++k) {
  757. k1 = iwork[k];
  758. k2 = iwork[k + 1];
  759. i__2 = nba;
  760. for (l = k; l <= i__2; ++l) {
  761. l1 = iwork[l];
  762. l2 = iwork[l + 1];
  763. if (notrna) {
  764. i__3 = k2 - k1;
  765. i__4 = l2 - l1;
  766. swork[k + (awrk + l) * swork_dim1] = slange_("I", &i__3, &
  767. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  768. } else {
  769. i__3 = k2 - k1;
  770. i__4 = l2 - l1;
  771. swork[l + (awrk + k) * swork_dim1] = slange_("1", &i__3, &
  772. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  773. }
  774. }
  775. }
  776. bwrk = nbb + nba;
  777. i__1 = nbb;
  778. for (k = 1; k <= i__1; ++k) {
  779. k1 = iwork[pc + k];
  780. k2 = iwork[pc + k + 1];
  781. i__2 = nbb;
  782. for (l = k; l <= i__2; ++l) {
  783. l1 = iwork[pc + l];
  784. l2 = iwork[pc + l + 1];
  785. if (notrnb) {
  786. i__3 = k2 - k1;
  787. i__4 = l2 - l1;
  788. swork[k + (bwrk + l) * swork_dim1] = slange_("I", &i__3, &
  789. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  790. } else {
  791. i__3 = k2 - k1;
  792. i__4 = l2 - l1;
  793. swork[l + (bwrk + k) * swork_dim1] = slange_("1", &i__3, &
  794. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  795. }
  796. }
  797. }
  798. sgn = (real) (*isgn);
  799. if (notrna && notrnb) {
  800. /* Solve A*X + ISGN*X*B = scale*C. */
  801. /* The (K,L)th block of X is determined starting from */
  802. /* bottom-left corner column by column by */
  803. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  804. /* Where */
  805. /* M L-1 */
  806. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)]. */
  807. /* I=K+1 J=1 */
  808. /* Start loop over block rows (index = K) and block columns (index = L) */
  809. for (k = nba; k >= 1; --k) {
  810. /* K1: row index of the first row in X( K, L ) */
  811. /* K2: row index of the first row in X( K+1, L ) */
  812. /* so the K2 - K1 is the column count of the block X( K, L ) */
  813. k1 = iwork[k];
  814. k2 = iwork[k + 1];
  815. i__1 = nbb;
  816. for (l = 1; l <= i__1; ++l) {
  817. /* L1: column index of the first column in X( K, L ) */
  818. /* L2: column index of the first column in X( K, L + 1) */
  819. /* so that L2 - L1 is the row count of the block X( K, L ) */
  820. l1 = iwork[pc + l];
  821. l2 = iwork[pc + l + 1];
  822. i__2 = k2 - k1;
  823. i__3 = l2 - l1;
  824. strsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  825. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  826. c_dim1], ldc, &scaloc, &iinfo);
  827. *info = f2cmax(*info,iinfo);
  828. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  829. if (scaloc == 0.f) {
  830. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  831. /* is larger than the product of BIGNUM**2 and cannot be */
  832. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  833. /* Mark the computation as pointless. */
  834. buf = 0.f;
  835. } else {
  836. /* Use second scaling factor to prevent flushing to zero. */
  837. i__2 = myexp_(&scaloc);
  838. buf *= pow_ri(&c_b19, &i__2);
  839. }
  840. i__2 = nbb;
  841. for (jj = 1; jj <= i__2; ++jj) {
  842. i__3 = nba;
  843. for (ll = 1; ll <= i__3; ++ll) {
  844. /* Bound by BIGNUM to not introduce Inf. The value */
  845. /* is irrelevant; corresponding entries of the */
  846. /* solution will be flushed in consistency scaling. */
  847. /* Computing MIN */
  848. i__4 = myexp_(&scaloc);
  849. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  850. / pow_ri(&c_b19, &i__4);
  851. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  852. }
  853. }
  854. }
  855. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  856. ;
  857. i__2 = k2 - k1;
  858. i__3 = l2 - l1;
  859. xnrm = slange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  860. wnrm);
  861. for (i__ = k - 1; i__ >= 1; --i__) {
  862. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  863. i1 = iwork[i__];
  864. i2 = iwork[i__ + 1];
  865. /* Compute scaling factor to survive the linear update */
  866. /* simulating consistent scaling. */
  867. i__2 = i2 - i1;
  868. i__3 = l2 - l1;
  869. cnrm = slange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  870. ldc, wnrm);
  871. /* Computing MIN */
  872. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  873. swork_dim1];
  874. scamin = f2cmin(r__1,r__2);
  875. cnrm *= scamin / swork[i__ + l * swork_dim1];
  876. xnrm *= scamin / swork[k + l * swork_dim1];
  877. anrm = swork[i__ + (awrk + k) * swork_dim1];
  878. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  879. if (scaloc * scamin == 0.f) {
  880. /* Use second scaling factor to prevent flushing to zero. */
  881. i__2 = myexp_(&scaloc);
  882. buf *= pow_ri(&c_b19, &i__2);
  883. i__2 = nbb;
  884. for (jj = 1; jj <= i__2; ++jj) {
  885. i__3 = nba;
  886. for (ll = 1; ll <= i__3; ++ll) {
  887. /* Computing MIN */
  888. i__4 = myexp_(&scaloc);
  889. r__1 = bignum, r__2 = swork[ll + jj *
  890. swork_dim1] / pow_ri(&c_b19, &i__4);
  891. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  892. }
  893. }
  894. i__2 = myexp_(&scaloc);
  895. scamin /= pow_ri(&c_b19, &i__2);
  896. i__2 = myexp_(&scaloc);
  897. scaloc /= pow_ri(&c_b19, &i__2);
  898. }
  899. cnrm *= scaloc;
  900. xnrm *= scaloc;
  901. /* Simultaneously apply the robust update factor and the */
  902. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  903. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  904. if (scal != 1.f) {
  905. i__2 = l2 - 1;
  906. for (jj = l1; jj <= i__2; ++jj) {
  907. i__3 = k2 - k1;
  908. sscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  909. c__1);
  910. }
  911. }
  912. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  913. if (scal != 1.f) {
  914. i__2 = l2 - 1;
  915. for (ll = l1; ll <= i__2; ++ll) {
  916. i__3 = i2 - i1;
  917. sscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  918. c__1);
  919. }
  920. }
  921. /* Record current scaling factor */
  922. swork[k + l * swork_dim1] = scamin * scaloc;
  923. swork[i__ + l * swork_dim1] = scamin * scaloc;
  924. i__2 = i2 - i1;
  925. i__3 = l2 - l1;
  926. i__4 = k2 - k1;
  927. sgemm_("N", "N", &i__2, &i__3, &i__4, &c_b31, &a[i1 + k1 *
  928. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  929. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  930. }
  931. i__2 = nbb;
  932. for (j = l + 1; j <= i__2; ++j) {
  933. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  934. j1 = iwork[pc + j];
  935. j2 = iwork[pc + j + 1];
  936. /* Compute scaling factor to survive the linear update */
  937. /* simulating consistent scaling. */
  938. i__3 = k2 - k1;
  939. i__4 = j2 - j1;
  940. cnrm = slange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  941. ldc, wnrm);
  942. /* Computing MIN */
  943. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  944. swork_dim1];
  945. scamin = f2cmin(r__1,r__2);
  946. cnrm *= scamin / swork[k + j * swork_dim1];
  947. xnrm *= scamin / swork[k + l * swork_dim1];
  948. bnrm = swork[l + (bwrk + j) * swork_dim1];
  949. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  950. if (scaloc * scamin == 0.f) {
  951. /* Use second scaling factor to prevent flushing to zero. */
  952. i__3 = myexp_(&scaloc);
  953. buf *= pow_ri(&c_b19, &i__3);
  954. i__3 = nbb;
  955. for (jj = 1; jj <= i__3; ++jj) {
  956. i__4 = nba;
  957. for (ll = 1; ll <= i__4; ++ll) {
  958. /* Computing MIN */
  959. i__5 = myexp_(&scaloc);
  960. r__1 = bignum, r__2 = swork[ll + jj *
  961. swork_dim1] / pow_ri(&c_b19, &i__5);
  962. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  963. }
  964. }
  965. i__3 = myexp_(&scaloc);
  966. scamin /= pow_ri(&c_b19, &i__3);
  967. i__3 = myexp_(&scaloc);
  968. scaloc /= pow_ri(&c_b19, &i__3);
  969. }
  970. cnrm *= scaloc;
  971. xnrm *= scaloc;
  972. /* Simultaneously apply the robust update factor and the */
  973. /* consistency scaling factor to C( K, J ) and C( K, L). */
  974. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  975. if (scal != 1.f) {
  976. i__3 = l2 - 1;
  977. for (ll = l1; ll <= i__3; ++ll) {
  978. i__4 = k2 - k1;
  979. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  980. c__1);
  981. }
  982. }
  983. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  984. if (scal != 1.f) {
  985. i__3 = j2 - 1;
  986. for (jj = j1; jj <= i__3; ++jj) {
  987. i__4 = k2 - k1;
  988. sscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  989. c__1);
  990. }
  991. }
  992. /* Record current scaling factor */
  993. swork[k + l * swork_dim1] = scamin * scaloc;
  994. swork[k + j * swork_dim1] = scamin * scaloc;
  995. i__3 = k2 - k1;
  996. i__4 = j2 - j1;
  997. i__5 = l2 - l1;
  998. r__1 = -sgn;
  999. sgemm_("N", "N", &i__3, &i__4, &i__5, &r__1, &c__[k1 + l1
  1000. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b32,
  1001. &c__[k1 + j1 * c_dim1], ldc);
  1002. }
  1003. }
  1004. }
  1005. } else if (! notrna && notrnb) {
  1006. /* Solve A**T*X + ISGN*X*B = scale*C. */
  1007. /* The (K,L)th block of X is determined starting from */
  1008. /* upper-left corner column by column by */
  1009. /* A(K,K)**T*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  1010. /* Where */
  1011. /* K-1 L-1 */
  1012. /* R(K,L) = SUM [A(I,K)**T*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)] */
  1013. /* I=1 J=1 */
  1014. /* Start loop over block rows (index = K) and block columns (index = L) */
  1015. i__1 = nba;
  1016. for (k = 1; k <= i__1; ++k) {
  1017. /* K1: row index of the first row in X( K, L ) */
  1018. /* K2: row index of the first row in X( K+1, L ) */
  1019. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1020. k1 = iwork[k];
  1021. k2 = iwork[k + 1];
  1022. i__2 = nbb;
  1023. for (l = 1; l <= i__2; ++l) {
  1024. /* L1: column index of the first column in X( K, L ) */
  1025. /* L2: column index of the first column in X( K, L + 1) */
  1026. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1027. l1 = iwork[pc + l];
  1028. l2 = iwork[pc + l + 1];
  1029. i__3 = k2 - k1;
  1030. i__4 = l2 - l1;
  1031. strsyl_(trana, tranb, isgn, &i__3, &i__4, &a[k1 + k1 * a_dim1]
  1032. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1033. c_dim1], ldc, &scaloc, &iinfo);
  1034. *info = f2cmax(*info,iinfo);
  1035. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1036. if (scaloc == 0.f) {
  1037. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1038. /* is larger than the product of BIGNUM**2 and cannot be */
  1039. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1040. /* Mark the computation as pointless. */
  1041. buf = 0.f;
  1042. } else {
  1043. /* Use second scaling factor to prevent flushing to zero. */
  1044. i__3 = myexp_(&scaloc);
  1045. buf *= pow_ri(&c_b19, &i__3);
  1046. }
  1047. i__3 = nbb;
  1048. for (jj = 1; jj <= i__3; ++jj) {
  1049. i__4 = nba;
  1050. for (ll = 1; ll <= i__4; ++ll) {
  1051. /* Bound by BIGNUM to not introduce Inf. The value */
  1052. /* is irrelevant; corresponding entries of the */
  1053. /* solution will be flushed in consistency scaling. */
  1054. /* Computing MIN */
  1055. i__5 = myexp_(&scaloc);
  1056. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1057. / pow_ri(&c_b19, &i__5);
  1058. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1059. }
  1060. }
  1061. }
  1062. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1063. ;
  1064. i__3 = k2 - k1;
  1065. i__4 = l2 - l1;
  1066. xnrm = slange_("I", &i__3, &i__4, &c__[k1 + l1 * c_dim1], ldc,
  1067. wnrm);
  1068. i__3 = nba;
  1069. for (i__ = k + 1; i__ <= i__3; ++i__) {
  1070. /* C( I, L ) := C( I, L ) - A( K, I )**T * C( K, L ) */
  1071. i1 = iwork[i__];
  1072. i2 = iwork[i__ + 1];
  1073. /* Compute scaling factor to survive the linear update */
  1074. /* simulating consistent scaling. */
  1075. i__4 = i2 - i1;
  1076. i__5 = l2 - l1;
  1077. cnrm = slange_("I", &i__4, &i__5, &c__[i1 + l1 * c_dim1],
  1078. ldc, wnrm);
  1079. /* Computing MIN */
  1080. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1081. swork_dim1];
  1082. scamin = f2cmin(r__1,r__2);
  1083. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1084. xnrm *= scamin / swork[k + l * swork_dim1];
  1085. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1086. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1087. if (scaloc * scamin == 0.f) {
  1088. /* Use second scaling factor to prevent flushing to zero. */
  1089. i__4 = myexp_(&scaloc);
  1090. buf *= pow_ri(&c_b19, &i__4);
  1091. i__4 = nbb;
  1092. for (jj = 1; jj <= i__4; ++jj) {
  1093. i__5 = nba;
  1094. for (ll = 1; ll <= i__5; ++ll) {
  1095. /* Computing MIN */
  1096. i__6 = myexp_(&scaloc);
  1097. r__1 = bignum, r__2 = swork[ll + jj *
  1098. swork_dim1] / pow_ri(&c_b19, &i__6);
  1099. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1100. }
  1101. }
  1102. i__4 = myexp_(&scaloc);
  1103. scamin /= pow_ri(&c_b19, &i__4);
  1104. i__4 = myexp_(&scaloc);
  1105. scaloc /= pow_ri(&c_b19, &i__4);
  1106. }
  1107. cnrm *= scaloc;
  1108. xnrm *= scaloc;
  1109. /* Simultaneously apply the robust update factor and the */
  1110. /* consistency scaling factor to to C( I, L ) and C( K, L ). */
  1111. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1112. if (scal != 1.f) {
  1113. i__4 = l2 - 1;
  1114. for (ll = l1; ll <= i__4; ++ll) {
  1115. i__5 = k2 - k1;
  1116. sscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1117. c__1);
  1118. }
  1119. }
  1120. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1121. if (scal != 1.f) {
  1122. i__4 = l2 - 1;
  1123. for (ll = l1; ll <= i__4; ++ll) {
  1124. i__5 = i2 - i1;
  1125. sscal_(&i__5, &scal, &c__[i1 + ll * c_dim1], &
  1126. c__1);
  1127. }
  1128. }
  1129. /* Record current scaling factor */
  1130. swork[k + l * swork_dim1] = scamin * scaloc;
  1131. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1132. i__4 = i2 - i1;
  1133. i__5 = l2 - l1;
  1134. i__6 = k2 - k1;
  1135. sgemm_("T", "N", &i__4, &i__5, &i__6, &c_b31, &a[k1 + i1 *
  1136. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1137. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1138. }
  1139. i__3 = nbb;
  1140. for (j = l + 1; j <= i__3; ++j) {
  1141. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  1142. j1 = iwork[pc + j];
  1143. j2 = iwork[pc + j + 1];
  1144. /* Compute scaling factor to survive the linear update */
  1145. /* simulating consistent scaling. */
  1146. i__4 = k2 - k1;
  1147. i__5 = j2 - j1;
  1148. cnrm = slange_("I", &i__4, &i__5, &c__[k1 + j1 * c_dim1],
  1149. ldc, wnrm);
  1150. /* Computing MIN */
  1151. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1152. swork_dim1];
  1153. scamin = f2cmin(r__1,r__2);
  1154. cnrm *= scamin / swork[k + j * swork_dim1];
  1155. xnrm *= scamin / swork[k + l * swork_dim1];
  1156. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1157. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1158. if (scaloc * scamin == 0.f) {
  1159. /* Use second scaling factor to prevent flushing to zero. */
  1160. i__4 = myexp_(&scaloc);
  1161. buf *= pow_ri(&c_b19, &i__4);
  1162. i__4 = nbb;
  1163. for (jj = 1; jj <= i__4; ++jj) {
  1164. i__5 = nba;
  1165. for (ll = 1; ll <= i__5; ++ll) {
  1166. /* Computing MIN */
  1167. i__6 = myexp_(&scaloc);
  1168. r__1 = bignum, r__2 = swork[ll + jj *
  1169. swork_dim1] / pow_ri(&c_b19, &i__6);
  1170. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1171. }
  1172. }
  1173. i__4 = myexp_(&scaloc);
  1174. scamin /= pow_ri(&c_b19, &i__4);
  1175. i__4 = myexp_(&scaloc);
  1176. scaloc /= pow_ri(&c_b19, &i__4);
  1177. }
  1178. cnrm *= scaloc;
  1179. xnrm *= scaloc;
  1180. /* Simultaneously apply the robust update factor and the */
  1181. /* consistency scaling factor to to C( K, J ) and C( K, L ). */
  1182. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1183. if (scal != 1.f) {
  1184. i__4 = l2 - 1;
  1185. for (ll = l1; ll <= i__4; ++ll) {
  1186. i__5 = k2 - k1;
  1187. sscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1188. c__1);
  1189. }
  1190. }
  1191. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1192. if (scal != 1.f) {
  1193. i__4 = j2 - 1;
  1194. for (jj = j1; jj <= i__4; ++jj) {
  1195. i__5 = k2 - k1;
  1196. sscal_(&i__5, &scal, &c__[k1 + jj * c_dim1], &
  1197. c__1);
  1198. }
  1199. }
  1200. /* Record current scaling factor */
  1201. swork[k + l * swork_dim1] = scamin * scaloc;
  1202. swork[k + j * swork_dim1] = scamin * scaloc;
  1203. i__4 = k2 - k1;
  1204. i__5 = j2 - j1;
  1205. i__6 = l2 - l1;
  1206. r__1 = -sgn;
  1207. sgemm_("N", "N", &i__4, &i__5, &i__6, &r__1, &c__[k1 + l1
  1208. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b32,
  1209. &c__[k1 + j1 * c_dim1], ldc);
  1210. }
  1211. }
  1212. }
  1213. } else if (! notrna && ! notrnb) {
  1214. /* Solve A**T*X + ISGN*X*B**T = scale*C. */
  1215. /* The (K,L)th block of X is determined starting from */
  1216. /* top-right corner column by column by */
  1217. /* A(K,K)**T*X(K,L) + ISGN*X(K,L)*B(L,L)**T = C(K,L) - R(K,L) */
  1218. /* Where */
  1219. /* K-1 N */
  1220. /* R(K,L) = SUM [A(I,K)**T*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**T]. */
  1221. /* I=1 J=L+1 */
  1222. /* Start loop over block rows (index = K) and block columns (index = L) */
  1223. i__1 = nba;
  1224. for (k = 1; k <= i__1; ++k) {
  1225. /* K1: row index of the first row in X( K, L ) */
  1226. /* K2: row index of the first row in X( K+1, L ) */
  1227. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1228. k1 = iwork[k];
  1229. k2 = iwork[k + 1];
  1230. for (l = nbb; l >= 1; --l) {
  1231. /* L1: column index of the first column in X( K, L ) */
  1232. /* L2: column index of the first column in X( K, L + 1) */
  1233. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1234. l1 = iwork[pc + l];
  1235. l2 = iwork[pc + l + 1];
  1236. i__2 = k2 - k1;
  1237. i__3 = l2 - l1;
  1238. strsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  1239. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1240. c_dim1], ldc, &scaloc, &iinfo);
  1241. *info = f2cmax(*info,iinfo);
  1242. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1243. if (scaloc == 0.f) {
  1244. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1245. /* is larger than the product of BIGNUM**2 and cannot be */
  1246. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1247. /* Mark the computation as pointless. */
  1248. buf = 0.f;
  1249. } else {
  1250. /* Use second scaling factor to prevent flushing to zero. */
  1251. i__2 = myexp_(&scaloc);
  1252. buf *= pow_ri(&c_b19, &i__2);
  1253. }
  1254. i__2 = nbb;
  1255. for (jj = 1; jj <= i__2; ++jj) {
  1256. i__3 = nba;
  1257. for (ll = 1; ll <= i__3; ++ll) {
  1258. /* Bound by BIGNUM to not introduce Inf. The value */
  1259. /* is irrelevant; corresponding entries of the */
  1260. /* solution will be flushed in consistency scaling. */
  1261. /* Computing MIN */
  1262. i__4 = myexp_(&scaloc);
  1263. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1264. / pow_ri(&c_b19, &i__4);
  1265. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1266. }
  1267. }
  1268. }
  1269. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1270. ;
  1271. i__2 = k2 - k1;
  1272. i__3 = l2 - l1;
  1273. xnrm = slange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  1274. wnrm);
  1275. i__2 = nba;
  1276. for (i__ = k + 1; i__ <= i__2; ++i__) {
  1277. /* C( I, L ) := C( I, L ) - A( K, I )**T * C( K, L ) */
  1278. i1 = iwork[i__];
  1279. i2 = iwork[i__ + 1];
  1280. /* Compute scaling factor to survive the linear update */
  1281. /* simulating consistent scaling. */
  1282. i__3 = i2 - i1;
  1283. i__4 = l2 - l1;
  1284. cnrm = slange_("I", &i__3, &i__4, &c__[i1 + l1 * c_dim1],
  1285. ldc, wnrm);
  1286. /* Computing MIN */
  1287. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1288. swork_dim1];
  1289. scamin = f2cmin(r__1,r__2);
  1290. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1291. xnrm *= scamin / swork[k + l * swork_dim1];
  1292. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1293. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1294. if (scaloc * scamin == 0.f) {
  1295. /* Use second scaling factor to prevent flushing to zero. */
  1296. i__3 = myexp_(&scaloc);
  1297. buf *= pow_ri(&c_b19, &i__3);
  1298. i__3 = nbb;
  1299. for (jj = 1; jj <= i__3; ++jj) {
  1300. i__4 = nba;
  1301. for (ll = 1; ll <= i__4; ++ll) {
  1302. /* Computing MIN */
  1303. i__5 = myexp_(&scaloc);
  1304. r__1 = bignum, r__2 = swork[ll + jj *
  1305. swork_dim1] / pow_ri(&c_b19, &i__5);
  1306. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1307. }
  1308. }
  1309. i__3 = myexp_(&scaloc);
  1310. scamin /= pow_ri(&c_b19, &i__3);
  1311. i__3 = myexp_(&scaloc);
  1312. scaloc /= pow_ri(&c_b19, &i__3);
  1313. }
  1314. cnrm *= scaloc;
  1315. xnrm *= scaloc;
  1316. /* Simultaneously apply the robust update factor and the */
  1317. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  1318. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1319. if (scal != 1.f) {
  1320. i__3 = l2 - 1;
  1321. for (ll = l1; ll <= i__3; ++ll) {
  1322. i__4 = k2 - k1;
  1323. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1324. c__1);
  1325. }
  1326. }
  1327. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1328. if (scal != 1.f) {
  1329. i__3 = l2 - 1;
  1330. for (ll = l1; ll <= i__3; ++ll) {
  1331. i__4 = i2 - i1;
  1332. sscal_(&i__4, &scal, &c__[i1 + ll * c_dim1], &
  1333. c__1);
  1334. }
  1335. }
  1336. /* Record current scaling factor */
  1337. swork[k + l * swork_dim1] = scamin * scaloc;
  1338. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1339. i__3 = i2 - i1;
  1340. i__4 = l2 - l1;
  1341. i__5 = k2 - k1;
  1342. sgemm_("T", "N", &i__3, &i__4, &i__5, &c_b31, &a[k1 + i1 *
  1343. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1344. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1345. }
  1346. i__2 = l - 1;
  1347. for (j = 1; j <= i__2; ++j) {
  1348. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**T */
  1349. j1 = iwork[pc + j];
  1350. j2 = iwork[pc + j + 1];
  1351. /* Compute scaling factor to survive the linear update */
  1352. /* simulating consistent scaling. */
  1353. i__3 = k2 - k1;
  1354. i__4 = j2 - j1;
  1355. cnrm = slange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  1356. ldc, wnrm);
  1357. /* Computing MIN */
  1358. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1359. swork_dim1];
  1360. scamin = f2cmin(r__1,r__2);
  1361. cnrm *= scamin / swork[k + j * swork_dim1];
  1362. xnrm *= scamin / swork[k + l * swork_dim1];
  1363. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1364. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1365. if (scaloc * scamin == 0.f) {
  1366. /* Use second scaling factor to prevent flushing to zero. */
  1367. i__3 = myexp_(&scaloc);
  1368. buf *= pow_ri(&c_b19, &i__3);
  1369. i__3 = nbb;
  1370. for (jj = 1; jj <= i__3; ++jj) {
  1371. i__4 = nba;
  1372. for (ll = 1; ll <= i__4; ++ll) {
  1373. /* Computing MIN */
  1374. i__5 = myexp_(&scaloc);
  1375. r__1 = bignum, r__2 = swork[ll + jj *
  1376. swork_dim1] / pow_ri(&c_b19, &i__5);
  1377. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1378. }
  1379. }
  1380. i__3 = myexp_(&scaloc);
  1381. scamin /= pow_ri(&c_b19, &i__3);
  1382. i__3 = myexp_(&scaloc);
  1383. scaloc /= pow_ri(&c_b19, &i__3);
  1384. }
  1385. cnrm *= scaloc;
  1386. xnrm *= scaloc;
  1387. /* Simultaneously apply the robust update factor and the */
  1388. /* consistency scaling factor to C( K, J ) and C( K, L ). */
  1389. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1390. if (scal != 1.f) {
  1391. i__3 = l2 - 1;
  1392. for (ll = l1; ll <= i__3; ++ll) {
  1393. i__4 = k2 - k1;
  1394. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1395. c__1);
  1396. }
  1397. }
  1398. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1399. if (scal != 1.f) {
  1400. i__3 = j2 - 1;
  1401. for (jj = j1; jj <= i__3; ++jj) {
  1402. i__4 = k2 - k1;
  1403. sscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1404. c__1);
  1405. }
  1406. }
  1407. /* Record current scaling factor */
  1408. swork[k + l * swork_dim1] = scamin * scaloc;
  1409. swork[k + j * swork_dim1] = scamin * scaloc;
  1410. i__3 = k2 - k1;
  1411. i__4 = j2 - j1;
  1412. i__5 = l2 - l1;
  1413. r__1 = -sgn;
  1414. sgemm_("N", "T", &i__3, &i__4, &i__5, &r__1, &c__[k1 + l1
  1415. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b32,
  1416. &c__[k1 + j1 * c_dim1], ldc);
  1417. }
  1418. }
  1419. }
  1420. } else if (notrna && ! notrnb) {
  1421. /* Solve A*X + ISGN*X*B**T = scale*C. */
  1422. /* The (K,L)th block of X is determined starting from */
  1423. /* bottom-right corner column by column by */
  1424. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)**T = C(K,L) - R(K,L) */
  1425. /* Where */
  1426. /* M N */
  1427. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**T]. */
  1428. /* I=K+1 J=L+1 */
  1429. /* Start loop over block rows (index = K) and block columns (index = L) */
  1430. for (k = nba; k >= 1; --k) {
  1431. /* K1: row index of the first row in X( K, L ) */
  1432. /* K2: row index of the first row in X( K+1, L ) */
  1433. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1434. k1 = iwork[k];
  1435. k2 = iwork[k + 1];
  1436. for (l = nbb; l >= 1; --l) {
  1437. /* L1: column index of the first column in X( K, L ) */
  1438. /* L2: column index of the first column in X( K, L + 1) */
  1439. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1440. l1 = iwork[pc + l];
  1441. l2 = iwork[pc + l + 1];
  1442. i__1 = k2 - k1;
  1443. i__2 = l2 - l1;
  1444. strsyl_(trana, tranb, isgn, &i__1, &i__2, &a[k1 + k1 * a_dim1]
  1445. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1446. c_dim1], ldc, &scaloc, &iinfo);
  1447. *info = f2cmax(*info,iinfo);
  1448. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1449. if (scaloc == 0.f) {
  1450. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1451. /* is larger than the product of BIGNUM**2 and cannot be */
  1452. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1453. /* Mark the computation as pointless. */
  1454. buf = 0.f;
  1455. } else {
  1456. /* Use second scaling factor to prevent flushing to zero. */
  1457. i__1 = myexp_(&scaloc);
  1458. buf *= pow_ri(&c_b19, &i__1);
  1459. }
  1460. i__1 = nbb;
  1461. for (jj = 1; jj <= i__1; ++jj) {
  1462. i__2 = nba;
  1463. for (ll = 1; ll <= i__2; ++ll) {
  1464. /* Bound by BIGNUM to not introduce Inf. The value */
  1465. /* is irrelevant; corresponding entries of the */
  1466. /* solution will be flushed in consistency scaling. */
  1467. /* Computing MIN */
  1468. i__3 = myexp_(&scaloc);
  1469. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1470. / pow_ri(&c_b19, &i__3);
  1471. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1472. }
  1473. }
  1474. }
  1475. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1476. ;
  1477. i__1 = k2 - k1;
  1478. i__2 = l2 - l1;
  1479. xnrm = slange_("I", &i__1, &i__2, &c__[k1 + l1 * c_dim1], ldc,
  1480. wnrm);
  1481. i__1 = k - 1;
  1482. for (i__ = 1; i__ <= i__1; ++i__) {
  1483. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  1484. i1 = iwork[i__];
  1485. i2 = iwork[i__ + 1];
  1486. /* Compute scaling factor to survive the linear update */
  1487. /* simulating consistent scaling. */
  1488. i__2 = i2 - i1;
  1489. i__3 = l2 - l1;
  1490. cnrm = slange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  1491. ldc, wnrm);
  1492. /* Computing MIN */
  1493. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1494. swork_dim1];
  1495. scamin = f2cmin(r__1,r__2);
  1496. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1497. xnrm *= scamin / swork[k + l * swork_dim1];
  1498. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1499. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1500. if (scaloc * scamin == 0.f) {
  1501. /* Use second scaling factor to prevent flushing to zero. */
  1502. i__2 = myexp_(&scaloc);
  1503. buf *= pow_ri(&c_b19, &i__2);
  1504. i__2 = nbb;
  1505. for (jj = 1; jj <= i__2; ++jj) {
  1506. i__3 = nba;
  1507. for (ll = 1; ll <= i__3; ++ll) {
  1508. /* Computing MIN */
  1509. i__4 = myexp_(&scaloc);
  1510. r__1 = bignum, r__2 = swork[ll + jj *
  1511. swork_dim1] / pow_ri(&c_b19, &i__4);
  1512. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1513. }
  1514. }
  1515. i__2 = myexp_(&scaloc);
  1516. scamin /= pow_ri(&c_b19, &i__2);
  1517. i__2 = myexp_(&scaloc);
  1518. scaloc /= pow_ri(&c_b19, &i__2);
  1519. }
  1520. cnrm *= scaloc;
  1521. xnrm *= scaloc;
  1522. /* Simultaneously apply the robust update factor and the */
  1523. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  1524. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1525. if (scal != 1.f) {
  1526. i__2 = l2 - 1;
  1527. for (ll = l1; ll <= i__2; ++ll) {
  1528. i__3 = k2 - k1;
  1529. sscal_(&i__3, &scal, &c__[k1 + ll * c_dim1], &
  1530. c__1);
  1531. }
  1532. }
  1533. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1534. if (scal != 1.f) {
  1535. i__2 = l2 - 1;
  1536. for (ll = l1; ll <= i__2; ++ll) {
  1537. i__3 = i2 - i1;
  1538. sscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  1539. c__1);
  1540. }
  1541. }
  1542. /* Record current scaling factor */
  1543. swork[k + l * swork_dim1] = scamin * scaloc;
  1544. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1545. i__2 = i2 - i1;
  1546. i__3 = l2 - l1;
  1547. i__4 = k2 - k1;
  1548. sgemm_("N", "N", &i__2, &i__3, &i__4, &c_b31, &a[i1 + k1 *
  1549. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1550. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1551. }
  1552. i__1 = l - 1;
  1553. for (j = 1; j <= i__1; ++j) {
  1554. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**T */
  1555. j1 = iwork[pc + j];
  1556. j2 = iwork[pc + j + 1];
  1557. /* Compute scaling factor to survive the linear update */
  1558. /* simulating consistent scaling. */
  1559. i__2 = k2 - k1;
  1560. i__3 = j2 - j1;
  1561. cnrm = slange_("I", &i__2, &i__3, &c__[k1 + j1 * c_dim1],
  1562. ldc, wnrm);
  1563. /* Computing MIN */
  1564. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1565. swork_dim1];
  1566. scamin = f2cmin(r__1,r__2);
  1567. cnrm *= scamin / swork[k + j * swork_dim1];
  1568. xnrm *= scamin / swork[k + l * swork_dim1];
  1569. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1570. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1571. if (scaloc * scamin == 0.f) {
  1572. /* Use second scaling factor to prevent flushing to zero. */
  1573. i__2 = myexp_(&scaloc);
  1574. buf *= pow_ri(&c_b19, &i__2);
  1575. i__2 = nbb;
  1576. for (jj = 1; jj <= i__2; ++jj) {
  1577. i__3 = nba;
  1578. for (ll = 1; ll <= i__3; ++ll) {
  1579. /* Computing MIN */
  1580. i__4 = myexp_(&scaloc);
  1581. r__1 = bignum, r__2 = swork[ll + jj *
  1582. swork_dim1] / pow_ri(&c_b19, &i__4);
  1583. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1584. }
  1585. }
  1586. i__2 = myexp_(&scaloc);
  1587. scamin /= pow_ri(&c_b19, &i__2);
  1588. i__2 = myexp_(&scaloc);
  1589. scaloc /= pow_ri(&c_b19, &i__2);
  1590. }
  1591. cnrm *= scaloc;
  1592. xnrm *= scaloc;
  1593. /* Simultaneously apply the robust update factor and the */
  1594. /* consistency scaling factor to C( K, J ) and C( K, L ). */
  1595. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1596. if (scal != 1.f) {
  1597. i__2 = l2 - 1;
  1598. for (jj = l1; jj <= i__2; ++jj) {
  1599. i__3 = k2 - k1;
  1600. sscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1601. c__1);
  1602. }
  1603. }
  1604. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1605. if (scal != 1.f) {
  1606. i__2 = j2 - 1;
  1607. for (jj = j1; jj <= i__2; ++jj) {
  1608. i__3 = k2 - k1;
  1609. sscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1610. c__1);
  1611. }
  1612. }
  1613. /* Record current scaling factor */
  1614. swork[k + l * swork_dim1] = scamin * scaloc;
  1615. swork[k + j * swork_dim1] = scamin * scaloc;
  1616. i__2 = k2 - k1;
  1617. i__3 = j2 - j1;
  1618. i__4 = l2 - l1;
  1619. r__1 = -sgn;
  1620. sgemm_("N", "T", &i__2, &i__3, &i__4, &r__1, &c__[k1 + l1
  1621. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b32,
  1622. &c__[k1 + j1 * c_dim1], ldc);
  1623. }
  1624. }
  1625. }
  1626. }
  1627. free(wnrm);
  1628. /* Reduce local scaling factors */
  1629. *scale = swork[swork_dim1 + 1];
  1630. i__1 = nba;
  1631. for (k = 1; k <= i__1; ++k) {
  1632. i__2 = nbb;
  1633. for (l = 1; l <= i__2; ++l) {
  1634. /* Computing MIN */
  1635. r__1 = *scale, r__2 = swork[k + l * swork_dim1];
  1636. *scale = f2cmin(r__1,r__2);
  1637. }
  1638. }
  1639. if (*scale == 0.f) {
  1640. /* The magnitude of the largest entry of the solution is larger */
  1641. /* than the product of BIGNUM**2 and cannot be represented in the */
  1642. /* form (1/SCALE)*X if SCALE is REAL. Set SCALE to zero and give up. */
  1643. iwork[1] = nba + nbb + 2;
  1644. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1645. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1646. return 0;
  1647. }
  1648. /* Realize consistent scaling */
  1649. i__1 = nba;
  1650. for (k = 1; k <= i__1; ++k) {
  1651. k1 = iwork[k];
  1652. k2 = iwork[k + 1];
  1653. i__2 = nbb;
  1654. for (l = 1; l <= i__2; ++l) {
  1655. l1 = iwork[pc + l];
  1656. l2 = iwork[pc + l + 1];
  1657. scal = *scale / swork[k + l * swork_dim1];
  1658. if (scal != 1.f) {
  1659. i__3 = l2 - 1;
  1660. for (ll = l1; ll <= i__3; ++ll) {
  1661. i__4 = k2 - k1;
  1662. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &c__1);
  1663. }
  1664. }
  1665. }
  1666. }
  1667. if (buf != 1.f && buf > 0.f) {
  1668. /* Decrease SCALE as much as possible. */
  1669. /* Computing MIN */
  1670. r__1 = *scale / smlnum, r__2 = 1.f / buf;
  1671. scaloc = f2cmin(r__1,r__2);
  1672. buf *= scaloc;
  1673. *scale /= scaloc;
  1674. }
  1675. if (buf != 1.f && buf > 0.f) {
  1676. /* In case of overly aggressive scaling during the computation, */
  1677. /* flushing of the global scale factor may be prevented by */
  1678. /* undoing some of the scaling. This step is to ensure that */
  1679. /* this routine flushes only scale factors that TRSYL also */
  1680. /* flushes and be usable as a drop-in replacement. */
  1681. /* How much can the normwise largest entry be upscaled? */
  1682. scal = c__[c_dim1 + 1];
  1683. i__1 = *m;
  1684. for (k = 1; k <= i__1; ++k) {
  1685. i__2 = *n;
  1686. for (l = 1; l <= i__2; ++l) {
  1687. /* Computing MAX */
  1688. r__2 = scal, r__3 = (r__1 = c__[k + l * c_dim1], abs(r__1));
  1689. scal = f2cmax(r__2,r__3);
  1690. }
  1691. }
  1692. /* Increase BUF as close to 1 as possible and apply scaling. */
  1693. /* Computing MIN */
  1694. r__1 = bignum / scal, r__2 = 1.f / buf;
  1695. scaloc = f2cmin(r__1,r__2);
  1696. buf *= scaloc;
  1697. slascl_("G", &c_n1, &c_n1, &c_b32, &scaloc, m, n, &c__[c_offset], ldc,
  1698. &iwork[1]);
  1699. }
  1700. /* Combine with buffer scaling factor. SCALE will be flushed if */
  1701. /* BUF is less than one here. */
  1702. *scale *= buf;
  1703. /* Restore workspace dimensions */
  1704. iwork[1] = nba + nbb + 2;
  1705. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1706. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1707. return 0;
  1708. /* End of STRSYL3 */
  1709. } /* strsyl3_ */