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.

iparam2stage.c 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include <complex.h>
  7. #ifdef complex
  8. #undef complex
  9. #endif
  10. #ifdef I
  11. #undef I
  12. #endif
  13. #if defined(_WIN64)
  14. typedef long long BLASLONG;
  15. typedef unsigned long long BLASULONG;
  16. #else
  17. typedef long BLASLONG;
  18. typedef unsigned long BLASULONG;
  19. #endif
  20. #ifdef LAPACK_ILP64
  21. typedef BLASLONG blasint;
  22. #if defined(_WIN64)
  23. #define blasabs(x) llabs(x)
  24. #else
  25. #define blasabs(x) labs(x)
  26. #endif
  27. #else
  28. typedef int blasint;
  29. #define blasabs(x) abs(x)
  30. #endif
  31. typedef blasint integer;
  32. typedef unsigned int uinteger;
  33. typedef char *address;
  34. typedef short int shortint;
  35. typedef float real;
  36. typedef double doublereal;
  37. typedef struct { real r, i; } complex;
  38. typedef struct { doublereal r, i; } doublecomplex;
  39. #ifdef _MSC_VER
  40. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  41. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  42. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  43. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  44. #else
  45. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  47. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  48. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  49. #endif
  50. #define pCf(z) (*_pCf(z))
  51. #define pCd(z) (*_pCd(z))
  52. typedef blasint logical;
  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]/df(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. /* procedure parameter types for -A and -C++ */
  240. #ifdef __cplusplus
  241. typedef logical (*L_fp)(...);
  242. #else
  243. typedef logical (*L_fp)();
  244. #endif
  245. static float spow_ui(float x, integer n) {
  246. float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static double dpow_ui(double x, integer n) {
  258. double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. #ifdef _MSC_VER
  270. static _Fcomplex cpow_ui(complex x, integer n) {
  271. complex pow={1.0,0.0}; unsigned long int u;
  272. if(n != 0) {
  273. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  274. for(u = n; ; ) {
  275. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  276. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  277. else break;
  278. }
  279. }
  280. _Fcomplex p={pow.r, pow.i};
  281. return p;
  282. }
  283. #else
  284. static _Complex float cpow_ui(_Complex float x, integer n) {
  285. _Complex float pow=1.0; unsigned long int u;
  286. if(n != 0) {
  287. if(n < 0) n = -n, x = 1/x;
  288. for(u = n; ; ) {
  289. if(u & 01) pow *= x;
  290. if(u >>= 1) x *= x;
  291. else break;
  292. }
  293. }
  294. return pow;
  295. }
  296. #endif
  297. #ifdef _MSC_VER
  298. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  299. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  300. if(n != 0) {
  301. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  302. for(u = n; ; ) {
  303. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  304. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  305. else break;
  306. }
  307. }
  308. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  309. return p;
  310. }
  311. #else
  312. static _Complex double zpow_ui(_Complex double x, integer n) {
  313. _Complex double pow=1.0; unsigned long int u;
  314. if(n != 0) {
  315. if(n < 0) n = -n, x = 1/x;
  316. for(u = n; ; ) {
  317. if(u & 01) pow *= x;
  318. if(u >>= 1) x *= x;
  319. else break;
  320. }
  321. }
  322. return pow;
  323. }
  324. #endif
  325. static integer pow_ii(integer x, integer n) {
  326. integer pow; unsigned long int u;
  327. if (n <= 0) {
  328. if (n == 0 || x == 1) pow = 1;
  329. else if (x != -1) pow = x == 0 ? 1/x : 0;
  330. else n = -n;
  331. }
  332. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  333. u = n;
  334. for(pow = 1; ; ) {
  335. if(u & 01) pow *= x;
  336. if(u >>= 1) x *= x;
  337. else break;
  338. }
  339. }
  340. return pow;
  341. }
  342. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  343. {
  344. double m; integer i, mi;
  345. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  346. if (w[i-1]>m) mi=i ,m=w[i-1];
  347. return mi-s+1;
  348. }
  349. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  350. {
  351. float m; integer i, mi;
  352. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  353. if (w[i-1]>m) mi=i ,m=w[i-1];
  354. return mi-s+1;
  355. }
  356. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  357. integer n = *n_, incx = *incx_, incy = *incy_, i;
  358. #ifdef _MSC_VER
  359. _Fcomplex zdotc = {0.0, 0.0};
  360. if (incx == 1 && incy == 1) {
  361. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  362. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  363. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  364. }
  365. } else {
  366. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  367. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  368. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  369. }
  370. }
  371. pCf(z) = zdotc;
  372. }
  373. #else
  374. _Complex float zdotc = 0.0;
  375. if (incx == 1 && incy == 1) {
  376. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  377. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  378. }
  379. } else {
  380. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  381. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  382. }
  383. }
  384. pCf(z) = zdotc;
  385. }
  386. #endif
  387. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  388. integer n = *n_, incx = *incx_, incy = *incy_, i;
  389. #ifdef _MSC_VER
  390. _Dcomplex zdotc = {0.0, 0.0};
  391. if (incx == 1 && incy == 1) {
  392. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  393. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  394. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  395. }
  396. } else {
  397. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  398. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  399. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  400. }
  401. }
  402. pCd(z) = zdotc;
  403. }
  404. #else
  405. _Complex double zdotc = 0.0;
  406. if (incx == 1 && incy == 1) {
  407. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  408. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  409. }
  410. } else {
  411. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  412. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  413. }
  414. }
  415. pCd(z) = zdotc;
  416. }
  417. #endif
  418. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  419. integer n = *n_, incx = *incx_, incy = *incy_, i;
  420. #ifdef _MSC_VER
  421. _Fcomplex zdotc = {0.0, 0.0};
  422. if (incx == 1 && incy == 1) {
  423. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  424. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  425. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  426. }
  427. } else {
  428. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  429. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  430. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  431. }
  432. }
  433. pCf(z) = zdotc;
  434. }
  435. #else
  436. _Complex float zdotc = 0.0;
  437. if (incx == 1 && incy == 1) {
  438. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  439. zdotc += Cf(&x[i]) * Cf(&y[i]);
  440. }
  441. } else {
  442. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  443. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  444. }
  445. }
  446. pCf(z) = zdotc;
  447. }
  448. #endif
  449. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  450. integer n = *n_, incx = *incx_, incy = *incy_, i;
  451. #ifdef _MSC_VER
  452. _Dcomplex zdotc = {0.0, 0.0};
  453. if (incx == 1 && incy == 1) {
  454. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  455. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  456. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  457. }
  458. } else {
  459. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  460. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  461. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  462. }
  463. }
  464. pCd(z) = zdotc;
  465. }
  466. #else
  467. _Complex double zdotc = 0.0;
  468. if (incx == 1 && incy == 1) {
  469. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  470. zdotc += Cd(&x[i]) * Cd(&y[i]);
  471. }
  472. } else {
  473. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  474. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  475. }
  476. }
  477. pCd(z) = zdotc;
  478. }
  479. #endif
  480. /* -- translated by f2c (version 20000121).
  481. You must link the resulting object file with the libraries:
  482. -lf2c -lm (in that order)
  483. */
  484. /* Table of constant values */
  485. static integer c__1 = 1;
  486. static integer c_n1 = -1;
  487. /* > \brief \b IPARAM2STAGE */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download IPARAM2STAGE + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/iparam2
  494. stage.F"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/iparam2
  497. stage.F"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/iparam2
  500. stage.F"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* INTEGER FUNCTION IPARAM2STAGE( ISPEC, NAME, OPTS, */
  506. /* NI, NBI, IBI, NXI ) */
  507. /* #if defined(_OPENMP) */
  508. /* use omp_lib */
  509. /* #endif */
  510. /* IMPLICIT NONE */
  511. /* CHARACTER*( * ) NAME, OPTS */
  512. /* INTEGER ISPEC, NI, NBI, IBI, NXI */
  513. /* > \par Purpose: */
  514. /* ============= */
  515. /* > */
  516. /* > \verbatim */
  517. /* > */
  518. /* > This program sets problem and machine dependent parameters */
  519. /* > useful for xHETRD_2STAGE, xHETRD_HE2HB, xHETRD_HB2ST, */
  520. /* > xGEBRD_2STAGE, xGEBRD_GE2GB, xGEBRD_GB2BD */
  521. /* > and related subroutines for eigenvalue problems. */
  522. /* > It is called whenever ILAENV is called with 17 <= ISPEC <= 21. */
  523. /* > It is called whenever ILAENV2STAGE is called with 1 <= ISPEC <= 5 */
  524. /* > with a direct conversion ISPEC + 16. */
  525. /* > \endverbatim */
  526. /* Arguments: */
  527. /* ========== */
  528. /* > \param[in] ISPEC */
  529. /* > \verbatim */
  530. /* > ISPEC is integer scalar */
  531. /* > ISPEC specifies which tunable parameter IPARAM2STAGE should */
  532. /* > return. */
  533. /* > */
  534. /* > ISPEC=17: the optimal blocksize nb for the reduction to */
  535. /* > BAND */
  536. /* > */
  537. /* > ISPEC=18: the optimal blocksize ib for the eigenvectors */
  538. /* > singular vectors update routine */
  539. /* > */
  540. /* > ISPEC=19: The length of the array that store the Housholder */
  541. /* > representation for the second stage */
  542. /* > Band to Tridiagonal or Bidiagonal */
  543. /* > */
  544. /* > ISPEC=20: The workspace needed for the routine in input. */
  545. /* > */
  546. /* > ISPEC=21: For future release. */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[in] NAME */
  550. /* > \verbatim */
  551. /* > NAME is character string */
  552. /* > Name of the calling subroutine */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] OPTS */
  556. /* > \verbatim */
  557. /* > OPTS is CHARACTER*(*) */
  558. /* > The character options to the subroutine NAME, concatenated */
  559. /* > into a single character string. For example, UPLO = 'U', */
  560. /* > TRANS = 'T', and DIAG = 'N' for a triangular routine would */
  561. /* > be specified as OPTS = 'UTN'. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] NI */
  565. /* > \verbatim */
  566. /* > NI is INTEGER which is the size of the matrix */
  567. /* > \endverbatim */
  568. /* > */
  569. /* > \param[in] NBI */
  570. /* > \verbatim */
  571. /* > NBI is INTEGER which is the used in the reduciton, */
  572. /* > (e.g., the size of the band), needed to compute workspace */
  573. /* > and LHOUS2. */
  574. /* > \endverbatim */
  575. /* > */
  576. /* > \param[in] IBI */
  577. /* > \verbatim */
  578. /* > IBI is INTEGER which represent the IB of the reduciton, */
  579. /* > needed to compute workspace and LHOUS2. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] NXI */
  583. /* > \verbatim */
  584. /* > NXI is INTEGER needed in the future release. */
  585. /* > \endverbatim */
  586. /* Authors: */
  587. /* ======== */
  588. /* > \author Univ. of Tennessee */
  589. /* > \author Univ. of California Berkeley */
  590. /* > \author Univ. of Colorado Denver */
  591. /* > \author NAG Ltd. */
  592. /* > \date June 2016 */
  593. /* > \ingroup auxOTHERauxiliary */
  594. /* > \par Further Details: */
  595. /* ===================== */
  596. /* > */
  597. /* > \verbatim */
  598. /* > */
  599. /* > Implemented by Azzam Haidar. */
  600. /* > */
  601. /* > All detail are available on technical report, SC11, SC13 papers. */
  602. /* > */
  603. /* > Azzam Haidar, Hatem Ltaief, and Jack Dongarra. */
  604. /* > Parallel reduction to condensed forms for symmetric eigenvalue problems */
  605. /* > using aggregated fine-grained and memory-aware kernels. In Proceedings */
  606. /* > of 2011 International Conference for High Performance Computing, */
  607. /* > Networking, Storage and Analysis (SC '11), New York, NY, USA, */
  608. /* > Article 8 , 11 pages. */
  609. /* > http://doi.acm.org/10.1145/2063384.2063394 */
  610. /* > */
  611. /* > A. Haidar, J. Kurzak, P. Luszczek, 2013. */
  612. /* > An improved parallel singular value algorithm and its implementation */
  613. /* > for multicore hardware, In Proceedings of 2013 International Conference */
  614. /* > for High Performance Computing, Networking, Storage and Analysis (SC '13). */
  615. /* > Denver, Colorado, USA, 2013. */
  616. /* > Article 90, 12 pages. */
  617. /* > http://doi.acm.org/10.1145/2503210.2503292 */
  618. /* > */
  619. /* > A. Haidar, R. Solca, S. Tomov, T. Schulthess and J. Dongarra. */
  620. /* > A novel hybrid CPU-GPU generalized eigensolver for electronic structure */
  621. /* > calculations based on fine-grained memory aware tasks. */
  622. /* > International Journal of High Performance Computing Applications. */
  623. /* > Volume 28 Issue 2, Pages 196-209, May 2014. */
  624. /* > http://hpc.sagepub.com/content/28/2/196 */
  625. /* > */
  626. /* > \endverbatim */
  627. /* > */
  628. /* ===================================================================== */
  629. integer iparam2stage_(integer *ispec, char *name__, char *opts, integer *ni,
  630. integer *nbi, integer *ibi, integer *nxi)
  631. {
  632. /* System generated locals */
  633. integer ret_val, i__1, i__2, i__3;
  634. /* Local variables */
  635. char algo[4], prec[1], stag[6], vect[1];
  636. integer nthreads, i__;
  637. logical cprec, rprec;
  638. integer lhous, lwork, factoptnb, ib, ic, kd, iz;
  639. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  640. integer *, integer *, ftnlen, ftnlen);
  641. char subnam[14];
  642. integer lqoptnb, qroptnb;
  643. integer name_len;
  644. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  645. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  646. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  647. /* June 2016 */
  648. /* ================================================================ */
  649. /* Invalid value for ISPEC */
  650. if (*ispec < 17 || *ispec > 21) {
  651. ret_val = -1;
  652. return ret_val;
  653. }
  654. /* Get the number of threads */
  655. nthreads = 1;
  656. /* WRITE(*,*) 'IPARAM VOICI NTHREADS ISPEC ',NTHREADS, ISPEC */
  657. if (*ispec != 19) {
  658. /* Convert NAME to upper case if the first character is lower case. */
  659. ret_val = -1;
  660. // s_copy(subnam, name__, (ftnlen)12, name_len);
  661. strncpy(subnam,name__,13);
  662. subnam[13]='\0';
  663. {
  664. int i;
  665. for (i=0;i<13;i++) subnam[i]=toupper(subnam[i]);
  666. }
  667. #if 0
  668. ic = *(unsigned char *)subnam;
  669. iz = 'Z';
  670. if (iz == 90 || iz == 122) {
  671. /* ASCII character set */
  672. if (ic >= 97 && ic <= 122) {
  673. *(unsigned char *)subnam = (char) (ic - 32);
  674. for (i__ = 2; i__ <= 12; ++i__) {
  675. ic = *(unsigned char *)&subnam[i__ - 1];
  676. if (ic >= 97 && ic <= 122) {
  677. *(unsigned char *)&subnam[i__ - 1] = (char) (ic - 32);
  678. }
  679. /* L100: */
  680. }
  681. }
  682. } else if (iz == 233 || iz == 169) {
  683. /* EBCDIC character set */
  684. if (ic >= 129 && ic <= 137 || ic >= 145 && ic <= 153 || ic >= 162
  685. && ic <= 169) {
  686. *(unsigned char *)subnam = (char) (ic + 64);
  687. for (i__ = 2; i__ <= 12; ++i__) {
  688. ic = *(unsigned char *)&subnam[i__ - 1];
  689. if (ic >= 129 && ic <= 137 || ic >= 145 && ic <= 153 ||
  690. ic >= 162 && ic <= 169) {
  691. *(unsigned char *)&subnam[i__ - 1] = (char) (ic + 64);
  692. }
  693. /* L110: */
  694. }
  695. }
  696. } else if (iz == 218 || iz == 250) {
  697. /* Prime machines: ASCII+128 */
  698. if (ic >= 225 && ic <= 250) {
  699. *(unsigned char *)subnam = (char) (ic - 32);
  700. for (i__ = 2; i__ <= 12; ++i__) {
  701. ic = *(unsigned char *)&subnam[i__ - 1];
  702. if (ic >= 225 && ic <= 250) {
  703. *(unsigned char *)&subnam[i__ - 1] = (char) (ic - 32);
  704. }
  705. /* L120: */
  706. }
  707. }
  708. }
  709. #endif
  710. //fprintf(stderr,"iparam2stage, subnam gross #%s#\n",subnam);
  711. // *(unsigned char *)prec = *(unsigned char *)subnam;
  712. strncpy(prec,subnam,1);
  713. strncpy(algo, subnam+3,3);
  714. algo[3]='\0';
  715. strncpy(stag, subnam+7,5);
  716. stag[5]='\0';
  717. // s_copy(algo, subnam + 3, (ftnlen)3, (ftnlen)3);
  718. // s_copy(stag, subnam + 7, (ftnlen)5, (ftnlen)5);
  719. rprec = *(unsigned char *)prec == 'S' || *(unsigned char *)prec ==
  720. 'D';
  721. cprec = *(unsigned char *)prec == 'C' || *(unsigned char *)prec ==
  722. 'Z';
  723. /* Invalid value for PRECISION */
  724. //fprintf(stderr," prec %s algo %s stag %s\n",prec,algo,stag);
  725. if (! (rprec || cprec)) {
  726. ret_val = -1;
  727. return ret_val;
  728. }
  729. }
  730. /* WRITE(*,*),'RPREC,CPREC ',RPREC,CPREC, */
  731. /* $ ' ALGO ',ALGO,' STAGE ',STAG */
  732. if (*ispec == 17 || *ispec == 18) {
  733. //fprintf(stderr,"iparam2stage spec 17/18");
  734. /* ISPEC = 17, 18: block size KD, IB */
  735. /* Could be also dependent from N but for now it */
  736. /* depend only on sequential or parallel */
  737. if (nthreads > 4) {
  738. if (cprec) {
  739. kd = 128;
  740. ib = 32;
  741. } else {
  742. kd = 160;
  743. ib = 40;
  744. }
  745. } else if (nthreads > 1) {
  746. if (cprec) {
  747. kd = 64;
  748. ib = 32;
  749. } else {
  750. kd = 64;
  751. ib = 32;
  752. }
  753. } else {
  754. if (cprec) {
  755. kd = 16;
  756. ib = 16;
  757. } else {
  758. kd = 32;
  759. ib = 16;
  760. }
  761. }
  762. if (*ispec == 17) {
  763. ret_val = kd;
  764. }
  765. if (*ispec == 18) {
  766. ret_val = ib;
  767. }
  768. } else if (*ispec == 19) {
  769. //fprintf(stderr,"iparam2stage spec 19\n");
  770. /* ISPEC = 19: */
  771. /* LHOUS length of the Houselholder representation */
  772. /* matrix (V,T) of the second stage. should be >= 1. */
  773. /* Will add the VECT OPTION HERE next release */
  774. *(unsigned char *)vect = *(unsigned char *)opts;
  775. if (*(unsigned char *)vect == 'N') {
  776. /* Computing MAX */
  777. i__1 = 1, i__2 = *ni << 2;
  778. lhous = f2cmax(i__1,i__2);
  779. } else {
  780. /* This is not correct, it need to call the ALGO and the stage2 */
  781. /* Computing MAX */
  782. i__1 = 1, i__2 = *ni << 2;
  783. lhous = f2cmax(i__1,i__2) + *ibi;
  784. }
  785. if (lhous >= 0) {
  786. ret_val = lhous;
  787. } else {
  788. ret_val = -1;
  789. }
  790. } else if (*ispec == 20) {
  791. //fprintf(stderr,"iparam2stage spec 20\n");
  792. /* ISPEC = 20: (21 for future use) */
  793. /* LWORK length of the workspace for */
  794. /* either or both stages for TRD and BRD. should be >= 1. */
  795. /* TRD: */
  796. /* TRD_stage 1: = LT + LW + LS1 + LS2 */
  797. /* = LDT*KD + N*KD + N*MAX(KD,FACTOPTNB) + LDS2*KD */
  798. /* where LDT=LDS2=KD */
  799. /* = N*KD + N*f2cmax(KD,FACTOPTNB) + 2*KD*KD */
  800. /* TRD_stage 2: = (2NB+1)*N + KD*NTHREADS */
  801. /* TRD_both : = f2cmax(stage1,stage2) + AB ( AB=(KD+1)*N ) */
  802. /* = N*KD + N*f2cmax(KD+1,FACTOPTNB) */
  803. /* + f2cmax(2*KD*KD, KD*NTHREADS) */
  804. /* + (KD+1)*N */
  805. lwork = -1;
  806. char *subnam=malloc(7*sizeof(char));
  807. strncpy(subnam,prec,1);
  808. sprintf(subnam+1,"GEQRF\0");
  809. // *(unsigned char *)subnam = *(unsigned char *)prec;
  810. // s_copy(subnam + 1, "GEQRF", (ftnlen)5, (ftnlen)5);
  811. qroptnb = ilaenv_(&c__1, subnam, " ", ni, nbi, &c_n1, &c_n1, (ftnlen)
  812. 12, (ftnlen)1);
  813. sprintf(subnam+1,"GELQF\0");
  814. s_copy(subnam + 1, "GELQF", (ftnlen)5, (ftnlen)5);
  815. lqoptnb = ilaenv_(&c__1, subnam, " ", nbi, ni, &c_n1, &c_n1, (ftnlen)
  816. 12, (ftnlen)1);
  817. /* Could be QR or LQ for TRD and the f2cmax for BRD */
  818. factoptnb = f2cmax(qroptnb,lqoptnb);
  819. if (s_cmp(algo, "TRD", (ftnlen)3, (ftnlen)3) == 0) {
  820. if (s_cmp(stag, "2STAG", (ftnlen)5, (ftnlen)5) == 0) {
  821. /* Computing MAX */
  822. i__1 = *nbi + 1;
  823. /* Computing MAX */
  824. i__2 = (*nbi << 1) * *nbi, i__3 = *nbi * nthreads;
  825. lwork = *ni * *nbi + *ni * f2cmax(i__1,factoptnb) + f2cmax(i__2,
  826. i__3) + (*nbi + 1) * *ni;
  827. } else if (s_cmp(stag, "HE2HB", (ftnlen)5, (ftnlen)5) == 0 ||
  828. s_cmp(stag, "SY2SB", (ftnlen)5, (ftnlen)5) == 0) {
  829. lwork = *ni * *nbi + *ni * f2cmax(*nbi,factoptnb) + (*nbi << 1) *
  830. *nbi;
  831. } else if (s_cmp(stag, "HB2ST", (ftnlen)5, (ftnlen)5) == 0 ||
  832. s_cmp(stag, "SB2ST", (ftnlen)5, (ftnlen)5) == 0) {
  833. lwork = ((*nbi << 1) + 1) * *ni + *nbi * nthreads;
  834. }
  835. } else if (s_cmp(algo, "BRD", (ftnlen)3, (ftnlen)3) == 0) {
  836. if (s_cmp(stag, "2STAG", (ftnlen)5, (ftnlen)5) == 0) {
  837. /* Computing MAX */
  838. i__1 = *nbi + 1;
  839. /* Computing MAX */
  840. i__2 = (*nbi << 1) * *nbi, i__3 = *nbi * nthreads;
  841. lwork = (*ni << 1) * *nbi + *ni * f2cmax(i__1,factoptnb) + f2cmax(
  842. i__2,i__3) + (*nbi + 1) * *ni;
  843. } else if (s_cmp(stag, "GE2GB", (ftnlen)5, (ftnlen)5) == 0) {
  844. lwork = *ni * *nbi + *ni * f2cmax(*nbi,factoptnb) + (*nbi << 1) *
  845. *nbi;
  846. } else if (s_cmp(stag, "GB2BD", (ftnlen)5, (ftnlen)5) == 0) {
  847. lwork = (*nbi * 3 + 1) * *ni + *nbi * nthreads;
  848. }
  849. }
  850. lwork = f2cmax(1,lwork);
  851. if (lwork > 0) {
  852. ret_val = lwork;
  853. } else {
  854. ret_val = -1;
  855. }
  856. } else if (*ispec == 21) {
  857. //fprintf(stderr,"iparam2stage spec 21\n");
  858. /* ISPEC = 21 for future use */
  859. ret_val = *nxi;
  860. }
  861. /* ==== End of IPARAM2STAGE ==== */
  862. return ret_val;
  863. } /* iparam2stage_ */