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 28 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 int logical;
  53. typedef short int shortlogical;
  54. typedef char logical1;
  55. typedef char integer1;
  56. #define TRUE_ (1)
  57. #define FALSE_ (0)
  58. /* Extern is for use with -E */
  59. #ifndef Extern
  60. #define Extern extern
  61. #endif
  62. /* I/O stuff */
  63. typedef int flag;
  64. typedef int ftnlen;
  65. typedef int ftnint;
  66. /*external read, write*/
  67. typedef struct
  68. { flag cierr;
  69. ftnint ciunit;
  70. flag ciend;
  71. char *cifmt;
  72. ftnint cirec;
  73. } cilist;
  74. /*internal read, write*/
  75. typedef struct
  76. { flag icierr;
  77. char *iciunit;
  78. flag iciend;
  79. char *icifmt;
  80. ftnint icirlen;
  81. ftnint icirnum;
  82. } icilist;
  83. /*open*/
  84. typedef struct
  85. { flag oerr;
  86. ftnint ounit;
  87. char *ofnm;
  88. ftnlen ofnmlen;
  89. char *osta;
  90. char *oacc;
  91. char *ofm;
  92. ftnint orl;
  93. char *oblnk;
  94. } olist;
  95. /*close*/
  96. typedef struct
  97. { flag cerr;
  98. ftnint cunit;
  99. char *csta;
  100. } cllist;
  101. /*rewind, backspace, endfile*/
  102. typedef struct
  103. { flag aerr;
  104. ftnint aunit;
  105. } alist;
  106. /* inquire */
  107. typedef struct
  108. { flag inerr;
  109. ftnint inunit;
  110. char *infile;
  111. ftnlen infilen;
  112. ftnint *inex; /*parameters in standard's order*/
  113. ftnint *inopen;
  114. ftnint *innum;
  115. ftnint *innamed;
  116. char *inname;
  117. ftnlen innamlen;
  118. char *inacc;
  119. ftnlen inacclen;
  120. char *inseq;
  121. ftnlen inseqlen;
  122. char *indir;
  123. ftnlen indirlen;
  124. char *infmt;
  125. ftnlen infmtlen;
  126. char *inform;
  127. ftnint informlen;
  128. char *inunf;
  129. ftnlen inunflen;
  130. ftnint *inrecl;
  131. ftnint *innrec;
  132. char *inblank;
  133. ftnlen inblanklen;
  134. } inlist;
  135. #define VOID void
  136. union Multitype { /* for multiple entry points */
  137. integer1 g;
  138. shortint h;
  139. integer i;
  140. /* longint j; */
  141. real r;
  142. doublereal d;
  143. complex c;
  144. doublecomplex z;
  145. };
  146. typedef union Multitype Multitype;
  147. struct Vardesc { /* for Namelist */
  148. char *name;
  149. char *addr;
  150. ftnlen *dims;
  151. int type;
  152. };
  153. typedef struct Vardesc Vardesc;
  154. struct Namelist {
  155. char *name;
  156. Vardesc **vars;
  157. int nvars;
  158. };
  159. typedef struct Namelist Namelist;
  160. #define abs(x) ((x) >= 0 ? (x) : -(x))
  161. #define dabs(x) (fabs(x))
  162. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  163. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  164. #define dmin(a,b) (f2cmin(a,b))
  165. #define dmax(a,b) (f2cmax(a,b))
  166. #define bit_test(a,b) ((a) >> (b) & 1)
  167. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  168. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  169. #define abort_() { sig_die("Fortran abort routine called", 1); }
  170. #define c_abs(z) (cabsf(Cf(z)))
  171. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  172. #ifdef _MSC_VER
  173. #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]);}
  174. #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]);}
  175. #else
  176. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  177. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  178. #endif
  179. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  180. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  181. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  182. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  183. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  184. #define d_abs(x) (fabs(*(x)))
  185. #define d_acos(x) (acos(*(x)))
  186. #define d_asin(x) (asin(*(x)))
  187. #define d_atan(x) (atan(*(x)))
  188. #define d_atn2(x, y) (atan2(*(x),*(y)))
  189. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  190. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  191. #define d_cos(x) (cos(*(x)))
  192. #define d_cosh(x) (cosh(*(x)))
  193. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  194. #define d_exp(x) (exp(*(x)))
  195. #define d_imag(z) (cimag(Cd(z)))
  196. #define r_imag(z) (cimagf(Cf(z)))
  197. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  199. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  201. #define d_log(x) (log(*(x)))
  202. #define d_mod(x, y) (fmod(*(x), *(y)))
  203. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  204. #define d_nint(x) u_nint(*(x))
  205. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  206. #define d_sign(a,b) u_sign(*(a),*(b))
  207. #define r_sign(a,b) u_sign(*(a),*(b))
  208. #define d_sin(x) (sin(*(x)))
  209. #define d_sinh(x) (sinh(*(x)))
  210. #define d_sqrt(x) (sqrt(*(x)))
  211. #define d_tan(x) (tan(*(x)))
  212. #define d_tanh(x) (tanh(*(x)))
  213. #define i_abs(x) abs(*(x))
  214. #define i_dnnt(x) ((integer)u_nint(*(x)))
  215. #define i_len(s, n) (n)
  216. #define i_nint(x) ((integer)u_nint(*(x)))
  217. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  218. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  219. #define pow_si(B,E) spow_ui(*(B),*(E))
  220. #define pow_ri(B,E) spow_ui(*(B),*(E))
  221. #define pow_di(B,E) dpow_ui(*(B),*(E))
  222. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  223. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  224. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  225. #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++ = ' '; }
  226. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  227. #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]; }
  228. #define sig_die(s, kill) { exit(1); }
  229. #define s_stop(s, n) {exit(0);}
  230. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  231. #define z_abs(z) (cabs(Cd(z)))
  232. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  233. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  234. #define myexit_() break;
  235. #define mycycle() continue;
  236. #define myceiling(w) {ceil(w)}
  237. #define myhuge(w) {HUGE_VAL}
  238. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  239. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  240. /* procedure parameter types for -A and -C++ */
  241. #define F2C_proc_par_types 1
  242. #ifdef __cplusplus
  243. typedef logical (*L_fp)(...);
  244. #else
  245. typedef logical (*L_fp)();
  246. #endif
  247. static float spow_ui(float x, integer n) {
  248. float pow=1.0; unsigned long int u;
  249. if(n != 0) {
  250. if(n < 0) n = -n, x = 1/x;
  251. for(u = n; ; ) {
  252. if(u & 01) pow *= x;
  253. if(u >>= 1) x *= x;
  254. else break;
  255. }
  256. }
  257. return pow;
  258. }
  259. static double dpow_ui(double x, integer n) {
  260. double pow=1.0; unsigned long int u;
  261. if(n != 0) {
  262. if(n < 0) n = -n, x = 1/x;
  263. for(u = n; ; ) {
  264. if(u & 01) pow *= x;
  265. if(u >>= 1) x *= x;
  266. else break;
  267. }
  268. }
  269. return pow;
  270. }
  271. #ifdef _MSC_VER
  272. static _Fcomplex cpow_ui(complex x, integer n) {
  273. complex pow={1.0,0.0}; unsigned long int u;
  274. if(n != 0) {
  275. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  276. for(u = n; ; ) {
  277. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  278. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  279. else break;
  280. }
  281. }
  282. _Fcomplex p={pow.r, pow.i};
  283. return p;
  284. }
  285. #else
  286. static _Complex float cpow_ui(_Complex float x, integer n) {
  287. _Complex float pow=1.0; unsigned long int u;
  288. if(n != 0) {
  289. if(n < 0) n = -n, x = 1/x;
  290. for(u = n; ; ) {
  291. if(u & 01) pow *= x;
  292. if(u >>= 1) x *= x;
  293. else break;
  294. }
  295. }
  296. return pow;
  297. }
  298. #endif
  299. #ifdef _MSC_VER
  300. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  301. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  302. if(n != 0) {
  303. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  304. for(u = n; ; ) {
  305. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  306. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  307. else break;
  308. }
  309. }
  310. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  311. return p;
  312. }
  313. #else
  314. static _Complex double zpow_ui(_Complex double x, integer n) {
  315. _Complex double pow=1.0; unsigned long int u;
  316. if(n != 0) {
  317. if(n < 0) n = -n, x = 1/x;
  318. for(u = n; ; ) {
  319. if(u & 01) pow *= x;
  320. if(u >>= 1) x *= x;
  321. else break;
  322. }
  323. }
  324. return pow;
  325. }
  326. #endif
  327. static integer pow_ii(integer x, integer n) {
  328. integer pow; unsigned long int u;
  329. if (n <= 0) {
  330. if (n == 0 || x == 1) pow = 1;
  331. else if (x != -1) pow = x == 0 ? 1/x : 0;
  332. else n = -n;
  333. }
  334. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  335. u = n;
  336. for(pow = 1; ; ) {
  337. if(u & 01) pow *= x;
  338. if(u >>= 1) x *= x;
  339. else break;
  340. }
  341. }
  342. return pow;
  343. }
  344. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  345. {
  346. double m; integer i, mi;
  347. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  348. if (w[i-1]>m) mi=i ,m=w[i-1];
  349. return mi-s+1;
  350. }
  351. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  352. {
  353. float m; integer i, mi;
  354. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  355. if (w[i-1]>m) mi=i ,m=w[i-1];
  356. return mi-s+1;
  357. }
  358. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  359. integer n = *n_, incx = *incx_, incy = *incy_, i;
  360. #ifdef _MSC_VER
  361. _Fcomplex zdotc = {0.0, 0.0};
  362. if (incx == 1 && incy == 1) {
  363. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  364. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  365. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  370. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  371. }
  372. }
  373. pCf(z) = zdotc;
  374. }
  375. #else
  376. _Complex float zdotc = 0.0;
  377. if (incx == 1 && incy == 1) {
  378. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  379. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  380. }
  381. } else {
  382. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  383. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  384. }
  385. }
  386. pCf(z) = zdotc;
  387. }
  388. #endif
  389. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  390. integer n = *n_, incx = *incx_, incy = *incy_, i;
  391. #ifdef _MSC_VER
  392. _Dcomplex zdotc = {0.0, 0.0};
  393. if (incx == 1 && incy == 1) {
  394. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  395. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  396. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  397. }
  398. } else {
  399. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  400. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  401. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  402. }
  403. }
  404. pCd(z) = zdotc;
  405. }
  406. #else
  407. _Complex double zdotc = 0.0;
  408. if (incx == 1 && incy == 1) {
  409. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  410. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  411. }
  412. } else {
  413. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  414. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  415. }
  416. }
  417. pCd(z) = zdotc;
  418. }
  419. #endif
  420. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  421. integer n = *n_, incx = *incx_, incy = *incy_, i;
  422. #ifdef _MSC_VER
  423. _Fcomplex zdotc = {0.0, 0.0};
  424. if (incx == 1 && incy == 1) {
  425. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  426. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  427. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  428. }
  429. } else {
  430. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  431. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  432. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  433. }
  434. }
  435. pCf(z) = zdotc;
  436. }
  437. #else
  438. _Complex float zdotc = 0.0;
  439. if (incx == 1 && incy == 1) {
  440. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  441. zdotc += Cf(&x[i]) * Cf(&y[i]);
  442. }
  443. } else {
  444. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  445. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  446. }
  447. }
  448. pCf(z) = zdotc;
  449. }
  450. #endif
  451. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  452. integer n = *n_, incx = *incx_, incy = *incy_, i;
  453. #ifdef _MSC_VER
  454. _Dcomplex zdotc = {0.0, 0.0};
  455. if (incx == 1 && incy == 1) {
  456. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  457. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  458. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  459. }
  460. } else {
  461. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  462. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  463. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  464. }
  465. }
  466. pCd(z) = zdotc;
  467. }
  468. #else
  469. _Complex double zdotc = 0.0;
  470. if (incx == 1 && incy == 1) {
  471. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  472. zdotc += Cd(&x[i]) * Cd(&y[i]);
  473. }
  474. } else {
  475. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  476. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  477. }
  478. }
  479. pCd(z) = zdotc;
  480. }
  481. #endif
  482. /* -- translated by f2c (version 20000121).
  483. You must link the resulting object file with the libraries:
  484. -lf2c -lm (in that order)
  485. */
  486. /* Table of constant values */
  487. static integer c__1 = 1;
  488. static integer c_n1 = -1;
  489. /* > \brief \b IPARAM2STAGE */
  490. /* =========== DOCUMENTATION =========== */
  491. /* Online html documentation available at */
  492. /* http://www.netlib.org/lapack/explore-html/ */
  493. /* > \htmlonly */
  494. /* > Download IPARAM2STAGE + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/iparam2
  496. stage.F"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/iparam2
  499. stage.F"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/iparam2
  502. stage.F"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* INTEGER FUNCTION IPARAM2STAGE( ISPEC, NAME, OPTS, */
  508. /* NI, NBI, IBI, NXI ) */
  509. /* #if defined(_OPENMP) */
  510. /* use omp_lib */
  511. /* #endif */
  512. /* IMPLICIT NONE */
  513. /* CHARACTER*( * ) NAME, OPTS */
  514. /* INTEGER ISPEC, NI, NBI, IBI, NXI */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > This program sets problem and machine dependent parameters */
  521. /* > useful for xHETRD_2STAGE, xHETRD_HE2HB, xHETRD_HB2ST, */
  522. /* > xGEBRD_2STAGE, xGEBRD_GE2GB, xGEBRD_GB2BD */
  523. /* > and related subroutines for eigenvalue problems. */
  524. /* > It is called whenever ILAENV is called with 17 <= ISPEC <= 21. */
  525. /* > It is called whenever ILAENV2STAGE is called with 1 <= ISPEC <= 5 */
  526. /* > with a direct conversion ISPEC + 16. */
  527. /* > \endverbatim */
  528. /* Arguments: */
  529. /* ========== */
  530. /* > \param[in] ISPEC */
  531. /* > \verbatim */
  532. /* > ISPEC is integer scalar */
  533. /* > ISPEC specifies which tunable parameter IPARAM2STAGE should */
  534. /* > return. */
  535. /* > */
  536. /* > ISPEC=17: the optimal blocksize nb for the reduction to */
  537. /* > BAND */
  538. /* > */
  539. /* > ISPEC=18: the optimal blocksize ib for the eigenvectors */
  540. /* > singular vectors update routine */
  541. /* > */
  542. /* > ISPEC=19: The length of the array that store the Housholder */
  543. /* > representation for the second stage */
  544. /* > Band to Tridiagonal or Bidiagonal */
  545. /* > */
  546. /* > ISPEC=20: The workspace needed for the routine in input. */
  547. /* > */
  548. /* > ISPEC=21: For future release. */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[in] NAME */
  552. /* > \verbatim */
  553. /* > NAME is character string */
  554. /* > Name of the calling subroutine */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[in] OPTS */
  558. /* > \verbatim */
  559. /* > OPTS is CHARACTER*(*) */
  560. /* > The character options to the subroutine NAME, concatenated */
  561. /* > into a single character string. For example, UPLO = 'U', */
  562. /* > TRANS = 'T', and DIAG = 'N' for a triangular routine would */
  563. /* > be specified as OPTS = 'UTN'. */
  564. /* > \endverbatim */
  565. /* > */
  566. /* > \param[in] NI */
  567. /* > \verbatim */
  568. /* > NI is INTEGER which is the size of the matrix */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] NBI */
  572. /* > \verbatim */
  573. /* > NBI is INTEGER which is the used in the reduciton, */
  574. /* > (e.g., the size of the band), needed to compute workspace */
  575. /* > and LHOUS2. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] IBI */
  579. /* > \verbatim */
  580. /* > IBI is INTEGER which represent the IB of the reduciton, */
  581. /* > needed to compute workspace and LHOUS2. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] NXI */
  585. /* > \verbatim */
  586. /* > NXI is INTEGER needed in the future release. */
  587. /* > \endverbatim */
  588. /* Authors: */
  589. /* ======== */
  590. /* > \author Univ. of Tennessee */
  591. /* > \author Univ. of California Berkeley */
  592. /* > \author Univ. of Colorado Denver */
  593. /* > \author NAG Ltd. */
  594. /* > \date June 2016 */
  595. /* > \ingroup auxOTHERauxiliary */
  596. /* > \par Further Details: */
  597. /* ===================== */
  598. /* > */
  599. /* > \verbatim */
  600. /* > */
  601. /* > Implemented by Azzam Haidar. */
  602. /* > */
  603. /* > All detail are available on technical report, SC11, SC13 papers. */
  604. /* > */
  605. /* > Azzam Haidar, Hatem Ltaief, and Jack Dongarra. */
  606. /* > Parallel reduction to condensed forms for symmetric eigenvalue problems */
  607. /* > using aggregated fine-grained and memory-aware kernels. In Proceedings */
  608. /* > of 2011 International Conference for High Performance Computing, */
  609. /* > Networking, Storage and Analysis (SC '11), New York, NY, USA, */
  610. /* > Article 8 , 11 pages. */
  611. /* > http://doi.acm.org/10.1145/2063384.2063394 */
  612. /* > */
  613. /* > A. Haidar, J. Kurzak, P. Luszczek, 2013. */
  614. /* > An improved parallel singular value algorithm and its implementation */
  615. /* > for multicore hardware, In Proceedings of 2013 International Conference */
  616. /* > for High Performance Computing, Networking, Storage and Analysis (SC '13). */
  617. /* > Denver, Colorado, USA, 2013. */
  618. /* > Article 90, 12 pages. */
  619. /* > http://doi.acm.org/10.1145/2503210.2503292 */
  620. /* > */
  621. /* > A. Haidar, R. Solca, S. Tomov, T. Schulthess and J. Dongarra. */
  622. /* > A novel hybrid CPU-GPU generalized eigensolver for electronic structure */
  623. /* > calculations based on fine-grained memory aware tasks. */
  624. /* > International Journal of High Performance Computing Applications. */
  625. /* > Volume 28 Issue 2, Pages 196-209, May 2014. */
  626. /* > http://hpc.sagepub.com/content/28/2/196 */
  627. /* > */
  628. /* > \endverbatim */
  629. /* > */
  630. /* ===================================================================== */
  631. integer iparam2stage_(integer *ispec, char *name__, char *opts, integer *ni,
  632. integer *nbi, integer *ibi, integer *nxi)
  633. {
  634. /* System generated locals */
  635. integer ret_val, i__1, i__2, i__3;
  636. /* Local variables */
  637. char algo[4], prec[1], stag[6], vect[1];
  638. integer nthreads, i__;
  639. logical cprec, rprec;
  640. integer lhous, lwork, factoptnb, ib, ic, kd, iz;
  641. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  642. integer *, integer *, ftnlen, ftnlen);
  643. char subnam[14];
  644. integer lqoptnb, qroptnb;
  645. integer name_len;
  646. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  647. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  648. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  649. /* June 2016 */
  650. /* ================================================================ */
  651. /* Invalid value for ISPEC */
  652. if (*ispec < 17 || *ispec > 21) {
  653. ret_val = -1;
  654. return ret_val;
  655. }
  656. /* Get the number of threads */
  657. nthreads = 1;
  658. /* WRITE(*,*) 'IPARAM VOICI NTHREADS ISPEC ',NTHREADS, ISPEC */
  659. if (*ispec != 19) {
  660. /* Convert NAME to upper case if the first character is lower case. */
  661. ret_val = -1;
  662. // s_copy(subnam, name__, (ftnlen)12, name_len);
  663. strncpy(subnam,name__,13);
  664. subnam[13]='\0';
  665. {
  666. int i;
  667. for (i=0;i<13;i++) subnam[i]=toupper(subnam[i]);
  668. }
  669. #if 0
  670. ic = *(unsigned char *)subnam;
  671. iz = 'Z';
  672. if (iz == 90 || iz == 122) {
  673. /* ASCII character set */
  674. if (ic >= 97 && ic <= 122) {
  675. *(unsigned char *)subnam = (char) (ic - 32);
  676. for (i__ = 2; i__ <= 12; ++i__) {
  677. ic = *(unsigned char *)&subnam[i__ - 1];
  678. if (ic >= 97 && ic <= 122) {
  679. *(unsigned char *)&subnam[i__ - 1] = (char) (ic - 32);
  680. }
  681. /* L100: */
  682. }
  683. }
  684. } else if (iz == 233 || iz == 169) {
  685. /* EBCDIC character set */
  686. if (ic >= 129 && ic <= 137 || ic >= 145 && ic <= 153 || ic >= 162
  687. && ic <= 169) {
  688. *(unsigned char *)subnam = (char) (ic + 64);
  689. for (i__ = 2; i__ <= 12; ++i__) {
  690. ic = *(unsigned char *)&subnam[i__ - 1];
  691. if (ic >= 129 && ic <= 137 || ic >= 145 && ic <= 153 ||
  692. ic >= 162 && ic <= 169) {
  693. *(unsigned char *)&subnam[i__ - 1] = (char) (ic + 64);
  694. }
  695. /* L110: */
  696. }
  697. }
  698. } else if (iz == 218 || iz == 250) {
  699. /* Prime machines: ASCII+128 */
  700. if (ic >= 225 && ic <= 250) {
  701. *(unsigned char *)subnam = (char) (ic - 32);
  702. for (i__ = 2; i__ <= 12; ++i__) {
  703. ic = *(unsigned char *)&subnam[i__ - 1];
  704. if (ic >= 225 && ic <= 250) {
  705. *(unsigned char *)&subnam[i__ - 1] = (char) (ic - 32);
  706. }
  707. /* L120: */
  708. }
  709. }
  710. }
  711. #endif
  712. //fprintf(stderr,"iparam2stage, subnam gross #%s#\n",subnam);
  713. // *(unsigned char *)prec = *(unsigned char *)subnam;
  714. strncpy(prec,subnam,1);
  715. strncpy(algo, subnam+3,3);
  716. algo[3]='\0';
  717. strncpy(stag, subnam+7,5);
  718. stag[5]='\0';
  719. // s_copy(algo, subnam + 3, (ftnlen)3, (ftnlen)3);
  720. // s_copy(stag, subnam + 7, (ftnlen)5, (ftnlen)5);
  721. rprec = *(unsigned char *)prec == 'S' || *(unsigned char *)prec ==
  722. 'D';
  723. cprec = *(unsigned char *)prec == 'C' || *(unsigned char *)prec ==
  724. 'Z';
  725. /* Invalid value for PRECISION */
  726. //fprintf(stderr," prec %s algo %s stag %s\n",prec,algo,stag);
  727. if (! (rprec || cprec)) {
  728. ret_val = -1;
  729. return ret_val;
  730. }
  731. }
  732. /* WRITE(*,*),'RPREC,CPREC ',RPREC,CPREC, */
  733. /* $ ' ALGO ',ALGO,' STAGE ',STAG */
  734. if (*ispec == 17 || *ispec == 18) {
  735. //fprintf(stderr,"iparam2stage spec 17/18");
  736. /* ISPEC = 17, 18: block size KD, IB */
  737. /* Could be also dependent from N but for now it */
  738. /* depend only on sequential or parallel */
  739. if (nthreads > 4) {
  740. if (cprec) {
  741. kd = 128;
  742. ib = 32;
  743. } else {
  744. kd = 160;
  745. ib = 40;
  746. }
  747. } else if (nthreads > 1) {
  748. if (cprec) {
  749. kd = 64;
  750. ib = 32;
  751. } else {
  752. kd = 64;
  753. ib = 32;
  754. }
  755. } else {
  756. if (cprec) {
  757. kd = 16;
  758. ib = 16;
  759. } else {
  760. kd = 32;
  761. ib = 16;
  762. }
  763. }
  764. if (*ispec == 17) {
  765. ret_val = kd;
  766. }
  767. if (*ispec == 18) {
  768. ret_val = ib;
  769. }
  770. } else if (*ispec == 19) {
  771. //fprintf(stderr,"iparam2stage spec 19\n");
  772. /* ISPEC = 19: */
  773. /* LHOUS length of the Houselholder representation */
  774. /* matrix (V,T) of the second stage. should be >= 1. */
  775. /* Will add the VECT OPTION HERE next release */
  776. *(unsigned char *)vect = *(unsigned char *)opts;
  777. if (*(unsigned char *)vect == 'N') {
  778. /* Computing MAX */
  779. i__1 = 1, i__2 = *ni << 2;
  780. lhous = f2cmax(i__1,i__2);
  781. } else {
  782. /* This is not correct, it need to call the ALGO and the stage2 */
  783. /* Computing MAX */
  784. i__1 = 1, i__2 = *ni << 2;
  785. lhous = f2cmax(i__1,i__2) + *ibi;
  786. }
  787. if (lhous >= 0) {
  788. ret_val = lhous;
  789. } else {
  790. ret_val = -1;
  791. }
  792. } else if (*ispec == 20) {
  793. //fprintf(stderr,"iparam2stage spec 20\n");
  794. /* ISPEC = 20: (21 for future use) */
  795. /* LWORK length of the workspace for */
  796. /* either or both stages for TRD and BRD. should be >= 1. */
  797. /* TRD: */
  798. /* TRD_stage 1: = LT + LW + LS1 + LS2 */
  799. /* = LDT*KD + N*KD + N*MAX(KD,FACTOPTNB) + LDS2*KD */
  800. /* where LDT=LDS2=KD */
  801. /* = N*KD + N*f2cmax(KD,FACTOPTNB) + 2*KD*KD */
  802. /* TRD_stage 2: = (2NB+1)*N + KD*NTHREADS */
  803. /* TRD_both : = f2cmax(stage1,stage2) + AB ( AB=(KD+1)*N ) */
  804. /* = N*KD + N*f2cmax(KD+1,FACTOPTNB) */
  805. /* + f2cmax(2*KD*KD, KD*NTHREADS) */
  806. /* + (KD+1)*N */
  807. lwork = -1;
  808. char *subnam=malloc(7*sizeof(char));
  809. strncpy(subnam,prec,1);
  810. sprintf(subnam+1,"GEQRF\0");
  811. // *(unsigned char *)subnam = *(unsigned char *)prec;
  812. // s_copy(subnam + 1, "GEQRF", (ftnlen)5, (ftnlen)5);
  813. qroptnb = ilaenv_(&c__1, subnam, " ", ni, nbi, &c_n1, &c_n1, (ftnlen)
  814. 12, (ftnlen)1);
  815. sprintf(subnam+1,"GELQF\0");
  816. s_copy(subnam + 1, "GELQF", (ftnlen)5, (ftnlen)5);
  817. lqoptnb = ilaenv_(&c__1, subnam, " ", nbi, ni, &c_n1, &c_n1, (ftnlen)
  818. 12, (ftnlen)1);
  819. /* Could be QR or LQ for TRD and the f2cmax for BRD */
  820. factoptnb = f2cmax(qroptnb,lqoptnb);
  821. if (s_cmp(algo, "TRD", (ftnlen)3, (ftnlen)3) == 0) {
  822. if (s_cmp(stag, "2STAG", (ftnlen)5, (ftnlen)5) == 0) {
  823. /* Computing MAX */
  824. i__1 = *nbi + 1;
  825. /* Computing MAX */
  826. i__2 = (*nbi << 1) * *nbi, i__3 = *nbi * nthreads;
  827. lwork = *ni * *nbi + *ni * f2cmax(i__1,factoptnb) + f2cmax(i__2,
  828. i__3) + (*nbi + 1) * *ni;
  829. } else if (s_cmp(stag, "HE2HB", (ftnlen)5, (ftnlen)5) == 0 ||
  830. s_cmp(stag, "SY2SB", (ftnlen)5, (ftnlen)5) == 0) {
  831. lwork = *ni * *nbi + *ni * f2cmax(*nbi,factoptnb) + (*nbi << 1) *
  832. *nbi;
  833. } else if (s_cmp(stag, "HB2ST", (ftnlen)5, (ftnlen)5) == 0 ||
  834. s_cmp(stag, "SB2ST", (ftnlen)5, (ftnlen)5) == 0) {
  835. lwork = ((*nbi << 1) + 1) * *ni + *nbi * nthreads;
  836. }
  837. } else if (s_cmp(algo, "BRD", (ftnlen)3, (ftnlen)3) == 0) {
  838. if (s_cmp(stag, "2STAG", (ftnlen)5, (ftnlen)5) == 0) {
  839. /* Computing MAX */
  840. i__1 = *nbi + 1;
  841. /* Computing MAX */
  842. i__2 = (*nbi << 1) * *nbi, i__3 = *nbi * nthreads;
  843. lwork = (*ni << 1) * *nbi + *ni * f2cmax(i__1,factoptnb) + f2cmax(
  844. i__2,i__3) + (*nbi + 1) * *ni;
  845. } else if (s_cmp(stag, "GE2GB", (ftnlen)5, (ftnlen)5) == 0) {
  846. lwork = *ni * *nbi + *ni * f2cmax(*nbi,factoptnb) + (*nbi << 1) *
  847. *nbi;
  848. } else if (s_cmp(stag, "GB2BD", (ftnlen)5, (ftnlen)5) == 0) {
  849. lwork = (*nbi * 3 + 1) * *ni + *nbi * nthreads;
  850. }
  851. }
  852. lwork = f2cmax(1,lwork);
  853. if (lwork > 0) {
  854. ret_val = lwork;
  855. } else {
  856. ret_val = -1;
  857. }
  858. } else if (*ispec == 21) {
  859. //fprintf(stderr,"iparam2stage spec 21\n");
  860. /* ISPEC = 21 for future use */
  861. ret_val = *nxi;
  862. }
  863. /* ==== End of IPARAM2STAGE ==== */
  864. return ret_val;
  865. } /* iparam2stage_ */