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