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.

ztrsyl3.c 60 kB

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