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.

dtrsyl3.c 58 kB

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