PageRenderTime 68ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/wrfv2_fire/external/RSL_LITE/gen_comms.c

http://github.com/jbeezley/wrf-fire
C | 2448 lines | 2206 code | 166 blank | 76 comment | 833 complexity | a49569cce082a2ef413251e7875b6468 MD5 | raw file
Possible License(s): AGPL-1.0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #ifdef _WIN32
  5. #define index(X,Y) strchr(X,Y)
  6. #endif
  7. #include "protos.h"
  8. #include "registry.h"
  9. #include "data.h"
  10. /* For detecting variables that are members of a derived type */
  11. #define NULLCHARPTR (char *) 0
  12. static int parent_type;
  13. /* print actual and dummy arguments and declarations for 4D and i1 arrays */
  14. int print_4d_i1_decls ( FILE *fp , node_t *p, int ad /* 0=argument,1=declaration */, int du /* 0=dummy,1=actual */)
  15. {
  16. node_t * q ;
  17. node_t * dimd ;
  18. char fname[NAMELEN] ;
  19. char tmp[NAMELEN_LONG], tmp2[NAMELEN_LONG], tmp3[NAMELEN_LONG] ;
  20. char commuse[NAMELEN] ;
  21. int maxstenwidth, stenwidth ;
  22. char * t1, * t2 , *wordsize ;
  23. char varref[NAMELEN], moredims[80] ;
  24. char * pos1 , * pos2 ;
  25. char * dimspec ;
  26. char indices[NAMELEN], post[NAMELEN], memord[NAMELEN] ;
  27. int zdex, d ;
  28. set_mark( 0, Domain.fields ) ;
  29. strcpy( tmp, p->comm_define ) ;
  30. strcpy( commuse, p->use ) ;
  31. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  32. while ( t1 != NULL )
  33. {
  34. strcpy( tmp2 , t1 ) ;
  35. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  36. {
  37. fprintf(stderr,"unparseable description for halo %s\n", p->name ) ; continue ;
  38. }
  39. t2 = strtok_rentr(NULL,",", &pos2) ;
  40. while ( t2 != NULL )
  41. {
  42. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  43. { fprintf(stderr,"WARNING 1a : %s in halo spec %s (%s) is not defined in registry.\n",t2,p->name, commuse) ; }
  44. else
  45. {
  46. strcpy( varref, t2 ) ;
  47. if ( q->node_kind & FIELD && ! (q->node_kind & I1) ) {
  48. sprintf(varref,"grid%%%s",t2) ;
  49. }
  50. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") ) { ; }
  51. else if ( q->boundary_array ) { ; }
  52. else
  53. {
  54. if ( ! strcmp( q->type->name, "real") ) { wordsize = "RWORDSIZE" ; }
  55. else if ( ! strcmp( q->type->name, "integer") ) { wordsize = "IWORDSIZE" ; }
  56. else if ( ! strcmp( q->type->name, "doubleprecision") ) { wordsize = "DWORDSIZE" ; }
  57. if ( q->node_kind & FOURD )
  58. {
  59. node_t *member ;
  60. zdex = get_index_for_coord( q , COORD_Z ) ;
  61. if ( zdex >=1 && zdex <= 3 )
  62. {
  63. set_mem_order( q->members, memord , 3 ) ;
  64. if ( ad == 0 )
  65. /* actual or dummy argument */
  66. {
  67. /* explicit dummy or actual arguments for 4D arrays */
  68. if ( q->mark == 0 ) {
  69. fprintf(fp," num_%s, &\n",q->name) ;
  70. for ( d = 3 ; d < q->ndims ; d++ ) {
  71. char *colon, r[80],tx[80] ;
  72. strcpy(r,"") ;
  73. range_of_dimension(r,tx,d,q,du?"":"config_flags%") ;
  74. colon = index(tx,':') ; *colon = '\0' ;
  75. if ( du ) { /* dummy args */
  76. fprintf(fp,"%s_sdim%d,%s_edim%d, &\n",q->name,d-2,q->name,d-2) ;
  77. } else {
  78. fprintf(fp,"%s,%s,&\n",tx,colon+1) ;
  79. }
  80. }
  81. q->mark = 1 ;
  82. }
  83. fprintf(fp," %s, &\n",varref) ;
  84. }
  85. else
  86. {
  87. /* declaration of dummy arguments for 4D arrays */
  88. if ( q->mark == 0 ) {
  89. fprintf(fp," INTEGER, INTENT(IN) :: num_%s\n",q->name) ;
  90. for ( d = 3 ; d < q->ndims ; d++ ) {
  91. fprintf(fp," INTEGER, INTENT(IN) :: %s_sdim%d,%s_edim%d\n",q->name,d-2,q->name,d-2) ;
  92. }
  93. q->mark = 1 ;
  94. }
  95. strcpy(moredims,"") ;
  96. for ( d = 3 ; d < q->ndims ; d++ ) {
  97. char temp[80] ;
  98. sprintf(temp,",%s_sdim%d:%s_edim%d",q->name,d-2,q->name,d-2) ;
  99. strcat(moredims,temp) ;
  100. }
  101. strcat(moredims,",") ;
  102. fprintf(fp," %s, INTENT(INOUT) :: %s ( grid%%sm31:grid%%em31,grid%%sm32:grid%%em32,grid%%sm33:grid%%em33%snum_%s)\n",
  103. q->type->name , varref , moredims, q->name ) ;
  104. }
  105. }
  106. else
  107. {
  108. fprintf(stderr,"WARNING: %d some dimension info missing for 4d array %s\n",zdex,t2) ;
  109. }
  110. }
  111. else if ( q->node_kind & I1 )
  112. {
  113. if ( ad == 0 )
  114. {
  115. /* explicit dummy or actual arguments for i1 arrays */
  116. fprintf(fp," %s, &\n",varref) ;
  117. }
  118. else
  119. {
  120. /* declaration of dummy arguments for i1 arrays */
  121. strcpy(tmp3,"") ;
  122. dimspec=dimension_with_ranges( "grid%","(",-1,tmp3,q,")","" ) ;
  123. fprintf(fp," %s, INTENT(INOUT) :: %s %s\n", q->type->name , varref , dimspec ) ;
  124. }
  125. }
  126. }
  127. }
  128. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  129. }
  130. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  131. }
  132. }
  133. int print_call_or_def( FILE * fp , node_t *p, char * callorsub,
  134. char * commname, char * communicator,
  135. int need_config_flags )
  136. {
  137. fprintf(fp,"%s %s_sub ( grid, &\n",callorsub,commname) ;
  138. if (need_config_flags == 1)
  139. fprintf(fp," config_flags, &\n") ;
  140. print_4d_i1_decls( fp, p, 0, (!strcmp("CALL",callorsub))?0:1 );
  141. fprintf(fp," %s, &\n",communicator) ;
  142. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  143. fprintf(fp," ids, ide, jds, jde, kds, kde, &\n") ;
  144. fprintf(fp," ims, ime, jms, jme, kms, kme, &\n") ;
  145. fprintf(fp," ips, ipe, jps, jpe, kps, kpe )\n") ;
  146. return(0) ;
  147. }
  148. int print_decl( FILE * fp , node_t *p, char * communicator,
  149. int need_config_flags )
  150. {
  151. fprintf(fp," USE module_domain, ONLY:domain\n") ;
  152. fprintf(fp," USE module_configure, ONLY:grid_config_rec_type,in_use_for_config\n") ;
  153. fprintf(fp," USE module_state_description, ONLY:PARAM_FIRST_SCALAR\n") ;
  154. fprintf(fp," USE module_driver_constants\n") ;
  155. fprintf(fp," TYPE(domain) , INTENT(IN) :: grid\n") ;
  156. if (need_config_flags == 1)
  157. fprintf(fp," TYPE(grid_config_rec_type) , INTENT(IN) :: config_flags\n") ;
  158. print_4d_i1_decls( fp, p, 1, 0 );
  159. fprintf(fp," INTEGER , INTENT(IN) :: %s\n",communicator) ;
  160. fprintf(fp," INTEGER , INTENT(IN) :: mytask, ntasks, ntasks_x, ntasks_y\n") ;
  161. fprintf(fp," INTEGER , INTENT(IN) :: ids, ide, jds, jde, kds, kde\n") ;
  162. fprintf(fp," INTEGER , INTENT(IN) :: ims, ime, jms, jme, kms, kme\n") ;
  163. fprintf(fp," INTEGER , INTENT(IN) :: ips, ipe, jps, jpe, kps, kpe\n") ;
  164. fprintf(fp," INTEGER :: itrace\n") ;
  165. fprintf(fp," INTEGER :: rsl_sendw_p, rsl_sendbeg_p, rsl_recvw_p, rsl_recvbeg_p\n") ;
  166. fprintf(fp," INTEGER :: rsl_sendw_m, rsl_sendbeg_m, rsl_recvw_m, rsl_recvbeg_m\n") ;
  167. fprintf(fp," LOGICAL, EXTERNAL :: rsl_comm_iter\n") ;
  168. fprintf(fp," INTEGER :: idim1, idim2, idim3, idim4, idim5, idim6, idim7\n") ;
  169. }
  170. int print_body( FILE * fp, char * commname )
  171. {
  172. fprintf(fp," \n") ;
  173. fprintf(fp,"#ifdef DM_PARALLEL\n") ;
  174. fprintf(fp,"#include \"%s_inline.inc\"\n",commname) ;
  175. fprintf(fp,"#endif\n") ;
  176. fprintf(fp," \n") ;
  177. fprintf(fp," END SUBROUTINE %s_sub\n",commname) ;
  178. }
  179. int
  180. gen_halos ( char * dirname , char * incname , node_t * halos, int split )
  181. {
  182. node_t * p, * q ;
  183. node_t * dimd ;
  184. char commname[NAMELEN], subs_fname[NAMELEN] ;
  185. char fname[NAMELEN], fnamecall[NAMELEN], fnamesub[NAMELEN] ;
  186. char tmp[NAMELEN_LONG], tmp2[NAMELEN_LONG], tmp3[NAMELEN_LONG] ;
  187. char commuse[NAMELEN] ;
  188. #define MAX_VDIMS 100
  189. char vdims[MAX_VDIMS][2][80] ;
  190. char s[NAMELEN], e[NAMELEN] ;
  191. int vdimcurs ;
  192. int maxstenwidth_int, stenwidth ;
  193. char maxstenwidth[NAMELEN] ;
  194. FILE * fp ;
  195. FILE * fpcall ;
  196. FILE * fpsub ;
  197. char * t1, * t2 ;
  198. char * pos1 , * pos2 ;
  199. char indices[NAMELEN], post[NAMELEN] ;
  200. int zdex ;
  201. int n2dR, n3dR ;
  202. int n2dI, n3dI ;
  203. int n2dD, n3dD ;
  204. int n4d ;
  205. int i, foundvdim ;
  206. int subgrid ;
  207. int need_config_flags;
  208. #define MAX_4DARRAYS 1000
  209. char name_4d[MAX_4DARRAYS][NAMELEN] ;
  210. #define FRAC 4
  211. int num_halos, fraction, ihalo, j ;
  212. if ( dirname == NULL ) return(1) ;
  213. if ( split ) {
  214. for ( p = halos, num_halos=0 ; p != NULL ; p = p-> next ) { /* howmany deez guys? */
  215. if ( incname == NULL ) {
  216. strcpy( commname, p->name ) ;
  217. make_upper_case(commname) ;
  218. }
  219. else {
  220. strcpy( commname, incname ) ;
  221. }
  222. if ( !( !strcmp(commname,"HALO_INTERP_DOWN") || !strcmp(commname,"HALO_FORCE_DOWN" )
  223. || !strcmp(commname,"HALO_INTERP_UP" ) || !strcmp(commname,"HALO_INTERP_SMOOTH" ) ) ) {
  224. num_halos++ ;
  225. }
  226. }
  227. }
  228. ihalo = 0 ;
  229. for ( p = halos ; p != NULL ; p = p->next )
  230. {
  231. need_config_flags = 0; /* 0 = do not need, 1 = need */
  232. if ( incname == NULL ) {
  233. strcpy( commname, p->name ) ;
  234. make_upper_case(commname) ;
  235. }
  236. else {
  237. strcpy( commname, incname ) ;
  238. }
  239. if ( incname == NULL ) {
  240. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s_inline.inc",dirname,commname) ; }
  241. else { sprintf(fname,"%s_inline.inc",commname) ; }
  242. /* Generate call to custom routine that encapsulates inlined comm calls */
  243. if ( strlen(dirname) > 0 ) { sprintf(fnamecall,"%s/%s.inc",dirname,commname) ; }
  244. else { sprintf(fnamecall,"%s.inc",commname) ; }
  245. if ((fpcall = fopen( fnamecall , "w" )) == NULL )
  246. {
  247. fprintf(stderr,"WARNING: gen_halos in registry cannot open %s for writing\n",fnamecall ) ;
  248. continue ;
  249. }
  250. print_warning(fpcall,fnamecall) ;
  251. if ( !strcmp(commname,"HALO_INTERP_DOWN") || !strcmp(commname,"HALO_FORCE_DOWN")
  252. || !strcmp(commname,"HALO_INTERP_UP" ) || !strcmp(commname,"HALO_INTERP_SMOOTH") ) {
  253. sprintf(subs_fname, "REGISTRY_COMM_NESTING_DM_subs.inc" ) ;
  254. } else {
  255. if ( split ) {
  256. j = ihalo / ((num_halos+1)/FRAC+1) ; /* the compiler you save may be your own */
  257. sprintf(subs_fname, "REGISTRY_COMM_DM_%d_subs.inc", j ) ;
  258. ihalo++ ;
  259. } else {
  260. sprintf(subs_fname, "REGISTRY_COMM_DM_subs.inc" ) ;
  261. }
  262. }
  263. /* Generate definition of custom routine that encapsulates inlined comm calls */
  264. if ( strlen(dirname) > 0 ) { sprintf(fnamesub,"%s/%s",dirname,subs_fname) ; }
  265. else { sprintf(fnamesub,"%s",subs_fname) ; }
  266. if ((fpsub = fopen( fnamesub , "a" )) == NULL )
  267. {
  268. fprintf(stderr,"WARNING: gen_halos in registry cannot open %s for writing\n",fnamesub ) ;
  269. continue ;
  270. }
  271. print_warning(fpsub,fnamesub) ;
  272. }
  273. else {
  274. /* for now, retain original behavior when called from gen_shift */
  275. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s.inc",dirname,commname) ; }
  276. else { sprintf(fname,"%s.inc",commname) ; }
  277. }
  278. /* Generate inlined comm calls */
  279. if ((fp = fopen( fname , "w" )) == NULL )
  280. {
  281. fprintf(stderr,"WARNING: gen_halos in registry cannot open %s for writing\n",fname ) ;
  282. continue ;
  283. }
  284. /* get maximum stencil width */
  285. maxstenwidth_int = 0 ;
  286. strcpy( tmp, p->comm_define ) ;
  287. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  288. while ( t1 != NULL )
  289. {
  290. strcpy( tmp2 , t1 ) ;
  291. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  292. { fprintf(stderr,"unparseable description for halo %s\n", commname ) ; exit(1) ; }
  293. if ( !strcmp(t2,"SHW") ) {
  294. stenwidth = -99 ;
  295. maxstenwidth_int = -99 ; /* use a run-time computed stencil width based on nest ratio */
  296. break ; /* note that SHW is set internally by gen_shift, it should never be used in a Registry file */
  297. } else {
  298. stenwidth = atoi (t2) ;
  299. if ( stenwidth == 0 )
  300. { fprintf(stderr,"* unparseable description for halo %s\n", commname ) ; exit(1) ; }
  301. if ( stenwidth == 4 || stenwidth == 8 ) stenwidth = 1 ;
  302. else if ( stenwidth == 12 || stenwidth == 24 ) stenwidth = 2 ;
  303. else if ( stenwidth == 48 ) stenwidth = 3 ;
  304. else if ( stenwidth == 80 ) stenwidth = 4 ;
  305. else if ( stenwidth == 120 ) stenwidth = 5 ;
  306. else if ( stenwidth == 168 ) stenwidth = 6 ;
  307. else
  308. { fprintf(stderr,"%s: unknown stenci description or just too big: %d\n", commname, stenwidth ) ; exit(1) ; }
  309. if ( stenwidth > maxstenwidth_int ) maxstenwidth_int = stenwidth ;
  310. }
  311. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  312. }
  313. if ( maxstenwidth_int == -99 ) {
  314. sprintf(maxstenwidth,"grid%%parent_grid_ratio") ;
  315. } else {
  316. sprintf(maxstenwidth,"%d",maxstenwidth_int) ;
  317. }
  318. print_warning(fp,fname) ;
  319. fprintf(fp,"CALL wrf_debug(2,'calling %s')\n",fname) ;
  320. /* count up the number of 2d and 3d real arrays and their types */
  321. n2dR = 0 ; n3dR = 0 ;
  322. n2dI = 0 ; n3dI = 0 ;
  323. n2dD = 0 ; n3dD = 0 ;
  324. n4d = 0 ;
  325. vdimcurs = 0 ;
  326. subgrid = -1 ; /* watch to make sure we don't mix subgrid fields with non-subgrid fields in same halo */
  327. strcpy( tmp, p->comm_define ) ;
  328. strcpy( commuse, p->use ) ;
  329. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  330. for ( i = 0 ; i < MAX_4DARRAYS ; i++ ) strcpy(name_4d[i],"") ; /* truncate all of these */
  331. while ( t1 != NULL )
  332. {
  333. strcpy( tmp2 , t1 ) ;
  334. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  335. { fprintf(stderr,"unparseable description for halo %s\n", commname ) ; continue ; }
  336. t2 = strtok_rentr(NULL,",", &pos2) ;
  337. while ( t2 != NULL )
  338. {
  339. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  340. { fprintf(stderr,"WARNING 1 : %s in halo spec %s (%s) is not defined in registry.\n",t2,commname, commuse) ; }
  341. else
  342. {
  343. if ( subgrid == -1 ) { /* first one */
  344. subgrid = q->subgrid ;
  345. } else if ( subgrid != q->subgrid ) {
  346. fprintf(stderr,"SERIOUS WARNING: you are mixing subgrid fields with non-subgrid fields in halo %s\n",commname) ;
  347. }
  348. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") )
  349. { fprintf(stderr,"WARNING: only type 'real', 'doubleprecision', or 'integer' can be part of halo exchange. %s in %s is %s\n",t2,commname,q->type->name) ; }
  350. else if ( q->boundary_array )
  351. { fprintf(stderr,"WARNING: boundary array %s cannot be member of halo spec %s.\n",t2,commname) ; }
  352. else
  353. {
  354. /* 20061004 -- collect all the vertical dimensions so we can use a MAX
  355. on them when calling RSL_LITE_INIT_EXCH */
  356. if ( q->ndims == 3 || q->node_kind & FOURD ) {
  357. if ((dimd = get_dimnode_for_coord( q , COORD_Z )) != NULL ) {
  358. zdex = get_index_for_coord( q , COORD_Z ) ;
  359. if ( dimd->len_defined_how == DOMAIN_STANDARD ) {
  360. strcpy(s,"kps") ;
  361. strcpy(e,"kpe") ;
  362. }
  363. else if ( dimd->len_defined_how == NAMELIST ) {
  364. need_config_flags = 1;
  365. if ( !strcmp(dimd->assoc_nl_var_s,"1") ) {
  366. strcpy(s,"1") ;
  367. sprintf(e,"config_flags%%%s",dimd->assoc_nl_var_e) ;
  368. } else {
  369. sprintf(s,"config_flags%%%s",dimd->assoc_nl_var_s) ;
  370. sprintf(e,"config_flags%%%s",dimd->assoc_nl_var_e) ;
  371. }
  372. }
  373. else if ( dimd->len_defined_how == CONSTANT ) {
  374. sprintf(s,"%d",dimd->coord_start) ;
  375. sprintf(e,"%d",dimd->coord_end) ;
  376. }
  377. for ( i = 0, foundvdim = 0 ; i < vdimcurs ; i++ ) {
  378. if ( !strcmp( vdims[i][1], e ) ) {
  379. foundvdim = 1 ; break ;
  380. }
  381. }
  382. if ( ! foundvdim ) {
  383. if (vdimcurs < 100 ) {
  384. strcpy( vdims[vdimcurs][0], s ) ;
  385. strcpy( vdims[vdimcurs][1], e ) ;
  386. vdimcurs++ ;
  387. } else {
  388. fprintf(stderr,"REGISTRY ERROR: too many different vertical dimensions (> %d).\n", MAX_VDIMS ) ;
  389. fprintf(stderr,"That seems like a lot, but if you are sure, increase MAX_VDIMS\n" ) ;
  390. fprintf(stderr,"in external/RSL_LITE/gen_comms.c and recompile\n") ;
  391. exit(5) ;
  392. }
  393. }
  394. }
  395. }
  396. if ( q->node_kind & FOURD ) {
  397. if ( n4d < MAX_4DARRAYS ) {
  398. int d ;
  399. char temp[80], tx[80], r[10], *colon ;
  400. strcpy( name_4d[n4d], q->name ) ;
  401. for ( d = 3 ; d < q->ndims ; d++ ) {
  402. sprintf(temp,"*(%s_edim%d-%s_sdim%d+1)",q->name,d-2,q->name,d-2) ;
  403. strcat( name_4d[n4d],temp) ;
  404. }
  405. } else {
  406. fprintf(stderr,"REGISTRY ERROR: too many 4d arrays (> %d).\n", MAX_4DARRAYS ) ;
  407. fprintf(stderr,"That seems like a lot, but if you are sure, increase MAX_4DARRAYS\n" ) ;
  408. fprintf(stderr,"in external/RSL_LITE/gen_comms.c and recompile\n") ;
  409. exit(5) ;
  410. }
  411. n4d++ ;
  412. }
  413. else
  414. {
  415. if ( ! strcmp( q->type->name, "real") ) {
  416. if ( q->ndims == 3 ) { n3dR++ ; }
  417. else if ( q->ndims == 2 ) { n2dR++ ; }
  418. } else if ( ! strcmp( q->type->name, "integer") ) {
  419. if ( q->ndims == 3 ) { n3dI++ ; }
  420. else if ( q->ndims == 2 ) { n2dI++ ; }
  421. } else if ( ! strcmp( q->type->name, "doubleprecision") ) {
  422. if ( q->ndims == 3 ) { n3dD++ ; }
  423. else if ( q->ndims == 2 ) { n2dD++ ; }
  424. }
  425. }
  426. }
  427. }
  428. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  429. }
  430. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  431. }
  432. /* generate the stencil init statement for Y transfer */
  433. #if 0
  434. fprintf(fp,"CALL wrf_debug(3,'calling RSL_LITE_INIT_EXCH %s for Y %s')\n",maxstenwidth,fname) ;
  435. #endif
  436. if ( subgrid != 0 ) {
  437. fprintf(fp,"IF ( grid%%sr_y .GT. 0 ) THEN\n") ;
  438. }
  439. fprintf(fp,"CALL rsl_comm_iter_init(%s,jps,jpe)\n",maxstenwidth) ;
  440. fprintf(fp,"DO WHILE ( rsl_comm_iter( grid%%id , grid%%is_intermediate, %s , &\n", maxstenwidth ) ;
  441. fprintf(fp," 0 , jds,jde,jps,jpe, grid%%njds, grid%%njde , & \n" ) ;
  442. fprintf(fp," rsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, & \n" ) ;
  443. fprintf(fp," rsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p ))\n" ) ;
  444. fprintf(fp," CALL RSL_LITE_INIT_EXCH ( local_communicator, %s, 0, &\n",maxstenwidth) ;
  445. fprintf(fp," rsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, & \n" ) ;
  446. fprintf(fp," rsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, & \n" ) ;
  447. if ( n4d > 0 ) {
  448. fprintf(fp, " %d &\n", n3dR ) ;
  449. for ( i = 0 ; i < n4d ; i++ ) {
  450. fprintf(fp," + num_%s &\n", name_4d[i] ) ;
  451. }
  452. fprintf(fp," , %d, RWORDSIZE, &\n", n2dR ) ;
  453. } else {
  454. fprintf(fp," %d, %d, RWORDSIZE, &\n", n3dR, n2dR ) ;
  455. }
  456. fprintf(fp," %d, %d, IWORDSIZE, &\n", n3dI, n2dI ) ;
  457. fprintf(fp," %d, %d, DWORDSIZE, &\n", n3dD, n2dD ) ;
  458. fprintf(fp," 0, 0, LWORDSIZE, &\n" ) ;
  459. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n" ) ;
  460. if ( subgrid == 0 ) {
  461. fprintf(fp," ips, ipe, jps, jpe, kps, MAX(1,1&\n") ;
  462. for ( i = 0 ; i < vdimcurs ; i++ ) {
  463. fprintf(fp,",%s &\n",vdims[i][1] ) ;
  464. }
  465. fprintf(fp,"))\n") ;
  466. } else {
  467. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,kps,kpe)\n") ;
  468. }
  469. /* generate packs prior to stencil exchange in Y */
  470. gen_packs_halo( fp, p, maxstenwidth, 0, 0, "RSL_LITE_PACK", "local_communicator" ) ;
  471. /* generate stencil exchange in Y */
  472. fprintf(fp," CALL RSL_LITE_EXCH_Y ( local_communicator , mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  473. fprintf(fp," rsl_sendw_m, rsl_sendw_p, rsl_recvw_m, rsl_recvw_p )\n" ) ;
  474. /* generate unpacks after stencil exchange in Y */
  475. gen_packs_halo( fp, p, maxstenwidth, 0, 1 , "RSL_LITE_PACK", "local_communicator" ) ;
  476. fprintf(fp,"ENDDO\n") ;
  477. /* generate the stencil init statement for X transfer */
  478. fprintf(fp,"CALL rsl_comm_iter_init(%s,ips,ipe)\n",maxstenwidth) ;
  479. fprintf(fp,"DO WHILE ( rsl_comm_iter( grid%%id , grid%%is_intermediate, %s , &\n", maxstenwidth ) ;
  480. fprintf(fp," 1 , ids,ide,ips,ipe, grid%%nids, grid%%nide , & \n" ) ;
  481. fprintf(fp," rsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, & \n" ) ;
  482. fprintf(fp," rsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p ))\n" ) ;
  483. fprintf(fp," CALL RSL_LITE_INIT_EXCH ( local_communicator, %s, 1, &\n",maxstenwidth) ;
  484. fprintf(fp," rsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, & \n" ) ;
  485. fprintf(fp," rsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, & \n" ) ;
  486. if ( n4d > 0 ) {
  487. fprintf(fp, " %d &\n", n3dR ) ;
  488. for ( i = 0 ; i < n4d ; i++ ) {
  489. fprintf(fp," + num_%s &\n", name_4d[i] ) ;
  490. }
  491. fprintf(fp," , %d, RWORDSIZE, &\n", n2dR ) ;
  492. } else {
  493. fprintf(fp," %d, %d, RWORDSIZE, &\n", n3dR, n2dR ) ;
  494. }
  495. fprintf(fp," %d, %d, IWORDSIZE, &\n", n3dI, n2dI ) ;
  496. fprintf(fp," %d, %d, DWORDSIZE, &\n", n3dD, n2dD ) ;
  497. fprintf(fp," 0, 0, LWORDSIZE, &\n" ) ;
  498. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n" ) ;
  499. if ( subgrid == 0 ) {
  500. fprintf(fp," ips, ipe, jps, jpe, kps, MAX(1,1&\n") ;
  501. for ( i = 0 ; i < vdimcurs ; i++ ) {
  502. fprintf(fp,",%s &\n",vdims[i][1] ) ;
  503. }
  504. fprintf(fp,"))\n") ;
  505. } else {
  506. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,kps,kpe)\n") ;
  507. }
  508. /* generate packs prior to stencil exchange in X */
  509. gen_packs_halo( fp, p, maxstenwidth, 1, 0, "RSL_LITE_PACK", "local_communicator" ) ;
  510. /* generate stencil exchange in X */
  511. fprintf(fp," CALL RSL_LITE_EXCH_X ( local_communicator , mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  512. fprintf(fp," rsl_sendw_m, rsl_sendw_p, rsl_recvw_m, rsl_recvw_p )\n" ) ;
  513. /* generate unpacks after stencil exchange in X */
  514. gen_packs_halo( fp, p, maxstenwidth, 1, 1, "RSL_LITE_PACK", "local_communicator" ) ;
  515. fprintf(fp," ENDDO\n") ;
  516. if ( subgrid != 0 ) {
  517. fprintf(fp,"ENDIF\n") ;
  518. }
  519. close_the_file(fp) ;
  520. if ( incname == NULL ) {
  521. /* Finish call to custom routine that encapsulates inlined comm calls */
  522. print_call_or_def(fpcall, p, "CALL", commname, "local_communicator", need_config_flags );
  523. close_the_file(fpcall) ;
  524. /* Generate definition of custom routine that encapsulates inlined comm calls */
  525. print_call_or_def(fpsub, p, "SUBROUTINE", commname, "local_communicator", need_config_flags );
  526. print_decl(fpsub, p, "local_communicator", need_config_flags );
  527. print_body(fpsub, commname);
  528. close_the_file(fpsub) ;
  529. }
  530. }
  531. return(0) ;
  532. }
  533. gen_packs_halo ( FILE *fp , node_t *p, char *shw, int xy /* 0=y,1=x */ , int pu /* 0=pack,1=unpack */, char * packname, char * commname )
  534. {
  535. node_t * q ;
  536. node_t * dimd ;
  537. char fname[NAMELEN] ;
  538. char tmp[NAMELEN_LONG], tmp2[NAMELEN_LONG], tmp3[NAMELEN_LONG] ;
  539. char commuse[NAMELEN] ;
  540. int maxstenwidth, stenwidth ;
  541. char * t1, * t2 , *wordsize ;
  542. char varref[NAMELEN] ;
  543. char varname[NAMELEN] ;
  544. char * pos1 , * pos2 ;
  545. char indices[NAMELEN], post[NAMELEN], memord[NAMELEN] ;
  546. int xdex,ydex,zdex ;
  547. strcpy( tmp, p->comm_define ) ;
  548. strcpy( commuse, p->use ) ;
  549. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  550. while ( t1 != NULL )
  551. {
  552. strcpy( tmp2 , t1 ) ;
  553. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  554. { fprintf(stderr,"unparseable description for halo %s\n", p->name ) ; continue ; }
  555. t2 = strtok_rentr(NULL,",", &pos2) ;
  556. while ( t2 != NULL )
  557. {
  558. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  559. { fprintf(stderr,"WARNING 1b : %s in halo spec %s (%s) is not defined in registry.\n",t2,p->name, commuse) ; }
  560. else
  561. {
  562. strcpy( varname, t2 ) ;
  563. strcpy( varref, t2 ) ;
  564. if ( q->node_kind & FIELD && ! (q->node_kind & I1) ) {
  565. sprintf(varref,"grid%%%s",t2) ;
  566. }
  567. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") ) { ; }
  568. else if ( q->boundary_array ) { ; }
  569. else
  570. {
  571. if ( ! strcmp( q->type->name, "real") ) { wordsize = "RWORDSIZE" ; }
  572. else if ( ! strcmp( q->type->name, "integer") ) { wordsize = "IWORDSIZE" ; }
  573. else if ( ! strcmp( q->type->name, "doubleprecision") ) { wordsize = "DWORDSIZE" ; }
  574. if ( q->node_kind & FOURD )
  575. {
  576. node_t *member ;
  577. zdex = get_index_for_coord( q , COORD_Z ) ;
  578. if ( zdex >=1 && zdex <= 3 )
  579. {
  580. int d ;
  581. char * colon ;
  582. char moredims[80], tx[80], temp[10], r[80] ;
  583. set_mem_order( q->members, memord , 3 ) ;
  584. fprintf(fp,"DO itrace = PARAM_FIRST_SCALAR, num_%s\n",q->name ) ;
  585. strcpy(moredims,"") ;
  586. for ( d = q->ndims-1 ; d >= 3 ; d-- ) {
  587. fprintf(fp," DO idim%d = %s_sdim%d,%s_edim%d\n",d-2,q->name,d-2,q->name,d-2 ) ;
  588. }
  589. for ( d = 3 ; d < q->ndims ; d++ ) {
  590. strcpy(r,"") ;
  591. range_of_dimension( r, tx, d, q, "config_flags%" ) ;
  592. colon = index(tx,':') ; if ( colon != NULL ) *colon = ',' ;
  593. sprintf(temp,"idim%d",d-2) ;
  594. strcat(moredims,",") ; strcat(moredims,temp) ;
  595. }
  596. strcat(moredims,",") ;
  597. xdex = get_index_for_coord( q , COORD_X ) ;
  598. ydex = get_index_for_coord( q , COORD_Y ) ;
  599. fprintf(fp," IF ( SIZE(%s,%d)*SIZE(%s,%d) .GT. 1 ) THEN\n",varref,xdex+1,varref,ydex+1 ) ;
  600. fprintf(fp," CALL %s ( %s,&\n%s ( grid%%sm31,grid%%sm32,grid%%sm33%sitrace),%s,&\nrsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, &\nrsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, &\n%s, %d, %d, DATA_ORDER_%s, %d, &\n",
  601. packname, commname, varref , moredims, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  602. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  603. if ( !strcmp( packname, "RSL_LITE_PACK_SWAP" ) ||
  604. !strcmp( packname, "RSL_LITE_PACK_CYCLE" ) ) {
  605. fprintf(fp,"thisdomain_max_halo_width, &\n") ;
  606. }
  607. if ( q->subgrid == 0 ) {
  608. fprintf(fp,"ids, ide, jds, jde, kds, kde, &\n") ;
  609. fprintf(fp,"ims, ime, jms, jme, kms, kme, &\n") ;
  610. fprintf(fp,"ips, ipe, jps, jpe, kps, kpe )\n") ;
  611. } else {
  612. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  613. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,kms,kme,&\n") ;
  614. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,kps,kpe)\n") ;
  615. }
  616. fprintf(fp," ENDIF\n") ;
  617. for ( d = 3 ; d < q->ndims ; d++ ) {
  618. fprintf(fp," ENDDO ! idim%d \n",d-2 ) ;
  619. }
  620. fprintf(fp,"ENDDO\n") ;
  621. }
  622. else
  623. {
  624. fprintf(stderr,"WARNING: %d some dimension info missing for 4d array %s\n",zdex,t2) ;
  625. }
  626. }
  627. else
  628. {
  629. set_mem_order( q, memord , 3 ) ;
  630. if ( q->ndims == 3 ) {
  631. dimd = get_dimnode_for_coord( q , COORD_Z ) ;
  632. xdex = get_index_for_coord( q , COORD_X ) ;
  633. ydex = get_index_for_coord( q , COORD_Y ) ;
  634. zdex = get_index_for_coord( q , COORD_Z ) ;
  635. fprintf(fp,"IF ( SIZE(%s,%d)*SIZE(%s,%d) .GT. 1 ) THEN\n",varref,xdex+1,varref,ydex+1 ) ;
  636. if ( dimd != NULL )
  637. {
  638. char s[256], e[256] ;
  639. if ( dimd->len_defined_how == DOMAIN_STANDARD ) {
  640. fprintf(fp,"CALL %s ( %s,&\n %s, %s,&\nrsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, &\nrsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, &\n%s, %d, %d, DATA_ORDER_%s, %d, &\n",
  641. packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  642. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  643. if ( q->subgrid == 0 ) {
  644. fprintf(fp,"ids, ide, jds, jde, kds, kde, &\n") ;
  645. fprintf(fp,"ims, ime, jms, jme, kms, kme, &\n") ;
  646. fprintf(fp,"ips, ipe, jps, jpe, kps, kpe )\n") ;
  647. } else {
  648. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  649. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,kms,kme,&\n") ;
  650. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,kps,kpe)\n") ;
  651. }
  652. }
  653. else if ( dimd->len_defined_how == NAMELIST )
  654. {
  655. if ( !strcmp(dimd->assoc_nl_var_s,"1") ) {
  656. strcpy(s,"1") ;
  657. sprintf(e,"config_flags%%%s",dimd->assoc_nl_var_e) ;
  658. } else {
  659. sprintf(s,"config_flags%%%s",dimd->assoc_nl_var_s) ;
  660. sprintf(e,"config_flags%%%s",dimd->assoc_nl_var_e) ;
  661. }
  662. fprintf(fp,"CALL %s ( %s,&\n %s, %s,&\nrsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, &\nrsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, &\n%s, %d, %d, DATA_ORDER_%s, %d, &\n",
  663. packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  664. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  665. if ( q->subgrid == 0 ) {
  666. fprintf(fp,"ids, ide, jds, jde, %s, %s, &\n",s,e) ;
  667. fprintf(fp,"ims, ime, jms, jme, %s, %s, &\n",s,e) ;
  668. fprintf(fp,"ips, ipe, jps, jpe, %s, %s )\n",s,e) ;
  669. } else {
  670. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  671. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,%s,%s,&\n",s,e) ;
  672. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,%s,%s)\n",s,e) ;
  673. }
  674. }
  675. else if ( dimd->len_defined_how == CONSTANT )
  676. {
  677. fprintf(fp,"CALL %s ( %s,&\n %s, %s,&\nrsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, &\nrsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, &\n%s, %d, %d, DATA_ORDER_%s, %d, &\n",
  678. packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  679. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  680. if ( q->subgrid == 0 ) {
  681. fprintf(fp,"ids, ide, jds, jde, %d, %d, &\n",dimd->coord_start,dimd->coord_end) ;
  682. fprintf(fp,"ims, ime, jms, jme, %d, %d, &\n",dimd->coord_start,dimd->coord_end) ;
  683. fprintf(fp,"ips, ipe, jps, jpe, %d, %d )\n",dimd->coord_start,dimd->coord_end) ;
  684. } else {
  685. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  686. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,%d,%d,&\n",dimd->coord_start,dimd->coord_end) ;
  687. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,%d,%d)\n",dimd->coord_start,dimd->coord_end) ;
  688. }
  689. }
  690. }
  691. fprintf(fp,"ENDIF\n") ;
  692. } else if ( q->ndims == 2 ) {
  693. xdex = get_index_for_coord( q , COORD_X ) ;
  694. ydex = get_index_for_coord( q , COORD_Y ) ;
  695. fprintf(fp,"IF ( SIZE(%s,%d)*SIZE(%s,%d) .GT. 1 ) THEN\n",varref,xdex+1,varref,ydex+1 ) ;
  696. fprintf(fp,"CALL %s ( %s,&\n %s, %s,&\nrsl_sendbeg_m, rsl_sendw_m, rsl_sendbeg_p, rsl_sendw_p, &\nrsl_recvbeg_m, rsl_recvw_m, rsl_recvbeg_p, rsl_recvw_p, &\n%s, %d, %d, DATA_ORDER_%s, %d, &\n",
  697. packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  698. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  699. if ( q->subgrid == 0 ) {
  700. fprintf(fp,"ids, ide, jds, jde, 1 , 1 , &\n") ;
  701. fprintf(fp,"ims, ime, jms, jme, 1 , 1 , &\n") ;
  702. fprintf(fp,"ips, ipe, jps, jpe, 1 , 1 )\n") ;
  703. } else {
  704. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  705. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,1,1,&\n") ;
  706. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,1,1)\n") ;
  707. }
  708. fprintf(fp,"ENDIF\n") ;
  709. }
  710. }
  711. }
  712. }
  713. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  714. }
  715. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  716. }
  717. }
  718. gen_packs ( FILE *fp , node_t *p, int shw, int xy /* 0=y,1=x */ , int pu /* 0=pack,1=unpack */, char * packname, char * commname )
  719. {
  720. node_t * q ;
  721. node_t * dimd ;
  722. char fname[NAMELEN] ;
  723. char tmp[NAMELEN_LONG], tmp2[NAMELEN_LONG], tmp3[NAMELEN_LONG] ;
  724. char commuse[NAMELEN] ;
  725. int maxstenwidth, stenwidth ;
  726. char * t1, * t2 , *wordsize ;
  727. char varref[NAMELEN] ;
  728. char varname[NAMELEN] ;
  729. char * pos1 , * pos2 ;
  730. char indices[NAMELEN], post[NAMELEN], memord[NAMELEN] ;
  731. int xdex,ydex,zdex ;
  732. strcpy( tmp, p->comm_define ) ;
  733. strcpy( commuse, p->use ) ;
  734. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  735. while ( t1 != NULL )
  736. {
  737. strcpy( tmp2 , t1 ) ;
  738. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  739. { fprintf(stderr,"unparseable description for halo %s\n", p->name ) ; continue ; }
  740. t2 = strtok_rentr(NULL,",", &pos2) ;
  741. while ( t2 != NULL )
  742. {
  743. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  744. { fprintf(stderr,"WARNING 1b : %s in halo spec %s (%s) is not defined in registry.\n",t2,p->name, commuse) ; }
  745. else
  746. {
  747. strcpy( varname, t2 ) ;
  748. strcpy( varref, t2 ) ;
  749. if ( q->node_kind & FIELD && ! (q->node_kind & I1) ) {
  750. sprintf(varref,"grid%%%s",t2) ;
  751. }
  752. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") ) { ; }
  753. else if ( q->boundary_array ) { ; }
  754. else
  755. {
  756. if ( ! strcmp( q->type->name, "real") ) { wordsize = "RWORDSIZE" ; }
  757. else if ( ! strcmp( q->type->name, "integer") ) { wordsize = "IWORDSIZE" ; }
  758. else if ( ! strcmp( q->type->name, "doubleprecision") ) { wordsize = "DWORDSIZE" ; }
  759. if ( q->node_kind & FOURD )
  760. {
  761. node_t *member ;
  762. zdex = get_index_for_coord( q , COORD_Z ) ;
  763. if ( zdex >=1 && zdex <= 3 )
  764. {
  765. set_mem_order( q->members, memord , 3 ) ;
  766. fprintf(fp,"DO itrace = PARAM_FIRST_SCALAR, num_%s\n",q->name ) ;
  767. xdex = get_index_for_coord( q , COORD_X ) ;
  768. ydex = get_index_for_coord( q , COORD_Y ) ;
  769. fprintf(fp," IF ( SIZE(%s,%d)*SIZE(%s,%d) .GT. 1 ) THEN\n",varref,xdex+1,varref,ydex+1 ) ;
  770. fprintf(fp," CALL %s ( %s,&\n%s ( grid%%sm31,grid%%sm32,grid%%sm33,itrace), %d, %s, %d, %d, DATA_ORDER_%s, %d, &\n",
  771. packname, commname, varref , shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  772. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  773. if ( !strcmp( packname, "RSL_LITE_PACK_SWAP" ) ||
  774. !strcmp( packname, "RSL_LITE_PACK_CYCLE" ) ) {
  775. fprintf(fp,"thisdomain_max_halo_width, &\n") ;
  776. }
  777. if ( q->subgrid == 0 ) {
  778. fprintf(fp,"ids, ide, jds, jde, kds, kde, &\n") ;
  779. fprintf(fp,"ims, ime, jms, jme, kms, kme, &\n") ;
  780. fprintf(fp,"ips, ipe, jps, jpe, kps, kpe )\n") ;
  781. } else {
  782. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  783. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,kms,kme,&\n") ;
  784. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,kps,kpe)\n") ;
  785. }
  786. fprintf(fp," ENDIF\n") ;
  787. fprintf(fp,"ENDDO\n") ;
  788. }
  789. else
  790. {
  791. fprintf(stderr,"WARNING: %d some dimension info missing for 4d array %s\n",zdex,t2) ;
  792. }
  793. }
  794. else
  795. {
  796. set_mem_order( q, memord , 3 ) ;
  797. if ( q->ndims == 3 ) {
  798. dimd = get_dimnode_for_coord( q , COORD_Z ) ;
  799. xdex = get_index_for_coord( q , COORD_X ) ;
  800. ydex = get_index_for_coord( q , COORD_Y ) ;
  801. zdex = get_index_for_coord( q , COORD_Z ) ;
  802. fprintf(fp,"IF ( SIZE(%s,%d)*SIZE(%s,%d) .GT. 1 ) THEN\n",varref,xdex+1,varref,ydex+1 ) ;
  803. if ( dimd != NULL )
  804. {
  805. char s[256], e[256] ;
  806. if ( dimd->len_defined_how == DOMAIN_STANDARD ) {
  807. fprintf(fp,"CALL %s ( %s,&\n %s, %d, %s, %d, %d, DATA_ORDER_%s, %d, &\n", packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  808. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  809. if ( q->subgrid == 0 ) {
  810. fprintf(fp,"ids, ide, jds, jde, kds, kde, &\n") ;
  811. fprintf(fp,"ims, ime, jms, jme, kms, kme, &\n") ;
  812. fprintf(fp,"ips, ipe, jps, jpe, kps, kpe )\n") ;
  813. } else {
  814. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  815. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,kms,kme,&\n") ;
  816. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,kps,kpe)\n") ;
  817. }
  818. }
  819. else if ( dimd->len_defined_how == NAMELIST )
  820. {
  821. if ( !strcmp(dimd->assoc_nl_var_s,"1") ) {
  822. strcpy(s,"1") ;
  823. sprintf(e,"config_flags%%%s",dimd->assoc_nl_var_e) ;
  824. } else {
  825. sprintf(s,"config_flags%%%s",dimd->assoc_nl_var_s) ;
  826. sprintf(e,"config_flags%%%s",dimd->assoc_nl_var_e) ;
  827. }
  828. fprintf(fp,"CALL %s ( %s,&\n %s, %d, %s, %d, %d, DATA_ORDER_%s, %d, &\n", packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  829. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  830. if ( q->subgrid == 0 ) {
  831. fprintf(fp,"ids, ide, jds, jde, %s, %s, &\n",s,e) ;
  832. fprintf(fp,"ims, ime, jms, jme, %s, %s, &\n",s,e) ;
  833. fprintf(fp,"ips, ipe, jps, jpe, %s, %s )\n",s,e) ;
  834. } else {
  835. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  836. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,%s,%s,&\n",s,e) ;
  837. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,%s,%s)\n",s,e) ;
  838. }
  839. }
  840. else if ( dimd->len_defined_how == CONSTANT )
  841. {
  842. fprintf(fp,"CALL %s ( %s,&\n %s, %d, %s, %d, %d, DATA_ORDER_%s, %d, &\n", packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  843. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  844. if ( q->subgrid == 0 ) {
  845. fprintf(fp,"ids, ide, jds, jde, %d, %d, &\n",dimd->coord_start,dimd->coord_end) ;
  846. fprintf(fp,"ims, ime, jms, jme, %d, %d, &\n",dimd->coord_start,dimd->coord_end) ;
  847. fprintf(fp,"ips, ipe, jps, jpe, %d, %d )\n",dimd->coord_start,dimd->coord_end) ;
  848. } else {
  849. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  850. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,%d,%d,&\n",dimd->coord_start,dimd->coord_end) ;
  851. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,%d,%d)\n",dimd->coord_start,dimd->coord_end) ;
  852. }
  853. }
  854. }
  855. fprintf(fp,"ENDIF\n") ;
  856. } else if ( q->ndims == 2 ) {
  857. xdex = get_index_for_coord( q , COORD_X ) ;
  858. ydex = get_index_for_coord( q , COORD_Y ) ;
  859. fprintf(fp,"IF ( SIZE(%s,%d)*SIZE(%s,%d) .GT. 1 ) THEN\n",varref,xdex+1,varref,ydex+1 ) ;
  860. fprintf(fp,"CALL %s ( %s,&\n %s, %d, %s, %d, %d, DATA_ORDER_%s, %d, &\n", packname, commname, varref, shw, wordsize, xy, pu, memord, xy?(q->stag_x?1:0):(q->stag_y?1:0) ) ;
  861. fprintf(fp,"mytask, ntasks, ntasks_x, ntasks_y, &\n") ;
  862. if ( q->subgrid == 0 ) {
  863. fprintf(fp,"ids, ide, jds, jde, 1 , 1 , &\n") ;
  864. fprintf(fp,"ims, ime, jms, jme, 1 , 1 , &\n") ;
  865. fprintf(fp,"ips, ipe, jps, jpe, 1 , 1 )\n") ;
  866. } else {
  867. fprintf(fp,"ids, ide*grid%%sr_x, jds, jde*grid%%sr_y, kds, kde, &\n") ;
  868. fprintf(fp,"(ims-1)*grid%%sr_x+1,ime*grid%%sr_x,(jms-1)*grid%%sr_y+1,jme*grid%%sr_y,1,1,&\n") ;
  869. fprintf(fp,"(ips-1)*grid%%sr_x+1,ipe*grid%%sr_x,(jps-1)*grid%%sr_y+1,jpe*grid%%sr_y,1,1)\n") ;
  870. }
  871. fprintf(fp,"ENDIF\n") ;
  872. }
  873. }
  874. }
  875. }
  876. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  877. }
  878. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  879. }
  880. }
  881. int
  882. gen_periods ( char * dirname , node_t * periods )
  883. {
  884. node_t * p, * q ;
  885. node_t * dimd ;
  886. char commname[NAMELEN] ;
  887. char fname[NAMELEN], fnamecall[NAMELEN], fnamesub[NAMELEN] ;
  888. char tmp[NAMELEN], tmp2[NAMELEN], tmp3[NAMELEN] ;
  889. char commuse[NAMELEN] ;
  890. int maxperwidth, perwidth ;
  891. FILE * fp ;
  892. FILE * fpcall ;
  893. FILE * fpsub ;
  894. char * t1, * t2 ;
  895. char varref[NAMELEN] ;
  896. char * pos1 , * pos2 ;
  897. char indices[NAMELEN], post[NAMELEN] ;
  898. int zdex ;
  899. int n2dR, n3dR ;
  900. int n2dI, n3dI ;
  901. int n2dD, n3dD ;
  902. int n4d ;
  903. int i ;
  904. #define MAX_4DARRAYS 1000
  905. char name_4d[MAX_4DARRAYS][NAMELEN] ;
  906. if ( dirname == NULL ) return(1) ;
  907. /* Open and truncate REGISTRY_COMM_DM_PERIOD_subs.inc so file exists even if there are no periods. */
  908. if ( strlen(dirname) > 0 ) { sprintf(fnamesub,"%s/REGISTRY_COMM_DM_PERIOD_subs.inc",dirname) ; }
  909. else { sprintf(fnamesub,"REGISTRY_COMM_DM_PERIOD_subs.inc") ; }
  910. if ((fpsub = fopen( fnamesub , "w" )) == NULL )
  911. {
  912. fprintf(stderr,"WARNING: gen_periods in registry cannot open %s for writing\n",fnamesub ) ;
  913. }
  914. if ( fpsub != NULL ) {
  915. print_warning(fpsub,fnamesub) ;
  916. fclose(fpsub) ;
  917. }
  918. for ( p = periods ; p != NULL ; p = p->next )
  919. {
  920. strcpy( commname, p->name ) ;
  921. make_upper_case(commname) ;
  922. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s_inline.inc",dirname,commname) ; }
  923. else { sprintf(fname,"%s_inline.inc",commname) ; }
  924. /* Generate call to custom routine that encapsulates inlined comm calls */
  925. if ( strlen(dirname) > 0 ) { sprintf(fnamecall,"%s/%s.inc",dirname,commname) ; }
  926. else { sprintf(fnamecall,"%s.inc",commname) ; }
  927. if ((fpcall = fopen( fnamecall , "w" )) == NULL )
  928. {
  929. fprintf(stderr,"WARNING: gen_periods in registry cannot open %s for writing\n",fnamecall ) ;
  930. continue ;
  931. }
  932. print_warning(fpcall,fnamecall) ;
  933. print_call_or_def(fpcall, p, "CALL", commname, "local_communicator_periodic", 1 );
  934. close_the_file(fpcall) ;
  935. /* Generate definition of custom routine that encapsulates inlined comm calls */
  936. if ( strlen(dirname) > 0 ) { sprintf(fnamesub,"%s/REGISTRY_COMM_DM_PERIOD_subs.inc",dirname) ; }
  937. else { sprintf(fnamesub,"REGISTRY_COMM_DM_PERIOD_subs.inc") ; }
  938. if ((fpsub = fopen( fnamesub , "a" )) == NULL )
  939. {
  940. fprintf(stderr,"WARNING: gen_periods in registry cannot open %s for writing\n",fnamesub ) ;
  941. continue ;
  942. }
  943. print_call_or_def(fpsub, p, "SUBROUTINE", commname, "local_communicator_periodic", 1 );
  944. print_decl(fpsub, p, "local_communicator_periodic", 1 );
  945. print_body(fpsub, commname);
  946. close_the_file(fpsub) ;
  947. /* Generate inlined comm calls */
  948. if ((fp = fopen( fname , "w" )) == NULL )
  949. {
  950. fprintf(stderr,"WARNING: gen_periods in registry cannot open %s for writing\n",fname ) ;
  951. continue ;
  952. }
  953. /* get maximum period width */
  954. maxperwidth = 0 ;
  955. strcpy( tmp, p->comm_define ) ;
  956. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  957. while ( t1 != NULL )
  958. {
  959. strcpy( tmp2 , t1 ) ;
  960. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  961. { fprintf(stderr,"unparseable description for period %s\n", commname ) ; exit(1) ; }
  962. perwidth = atoi (t2) ;
  963. if ( perwidth > maxperwidth ) maxperwidth = perwidth ;
  964. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  965. }
  966. print_warning(fp,fname) ;
  967. fprintf(fp,"CALL wrf_debug(2,'calling %s')\n",fname) ;
  968. /* count up the number of 2d and 3d real arrays and their types */
  969. n2dR = 0 ; n3dR = 0 ;
  970. n2dI = 0 ; n3dI = 0 ;
  971. n2dD = 0 ; n3dD = 0 ;
  972. n4d = 0 ;
  973. strcpy( tmp, p->comm_define ) ;
  974. strcpy( commuse, p->use ) ;
  975. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  976. for ( i = 0 ; i < MAX_4DARRAYS ; i++ ) strcpy(name_4d[i],"") ; /* truncate all of these */
  977. while ( t1 != NULL )
  978. {
  979. strcpy( tmp2 , t1 ) ;
  980. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  981. { fprintf(stderr,"unparseable description for period %s\n", commname ) ; continue ; }
  982. t2 = strtok_rentr(NULL,",", &pos2) ;
  983. while ( t2 != NULL )
  984. {
  985. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  986. { fprintf(stderr,"WARNING 1 : %s in period spec %s (%s) is not defined in registry.\n",t2,commname, commuse) ; }
  987. else
  988. {
  989. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") )
  990. { fprintf(stderr,"WARNING: only type 'real', 'doubleprecision', or 'integer' can be part of period exchange. %s in %s is %s\n",t2,commname,q->type->name) ; }
  991. else if ( q->boundary_array )
  992. { fprintf(stderr,"WARNING: boundary array %s cannot be member of period spec %s.\n",t2,commname) ; }
  993. else
  994. {
  995. if ( q->node_kind & FOURD ) {
  996. if ( n4d < MAX_4DARRAYS ) {
  997. strcpy( name_4d[n4d], q->name ) ;
  998. } else {
  999. fprintf(stderr,"REGISTRY ERROR: too many 4d arrays (> %d).\n", MAX_4DARRAYS ) ;
  1000. fprintf(stderr,"That seems like a lot, but if you are sure, increase MAX_4DARRAYS\n" ) ;
  1001. fprintf(stderr,"in external/RSL_LITE/gen_comms.c and recompile\n") ;
  1002. exit(5) ;
  1003. }
  1004. n4d++ ;
  1005. }
  1006. else
  1007. {
  1008. if ( ! strcmp( q->type->name, "real") ) {
  1009. if ( q->ndims == 3 ) { n3dR++ ; }
  1010. else if ( q->ndims == 2 ) { n2dR++ ; }
  1011. } else if ( ! strcmp( q->type->name, "integer") ) {
  1012. if ( q->ndims == 3 ) { n3dI++ ; }
  1013. else if ( q->ndims == 2 ) { n2dI++ ; }
  1014. } else if ( ! strcmp( q->type->name, "doubleprecision") ) {
  1015. if ( q->ndims == 3 ) { n3dD++ ; }
  1016. else if ( q->ndims == 2 ) { n2dD++ ; }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  1022. }
  1023. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  1024. }
  1025. fprintf(fp,"IF ( config_flags%%periodic_x ) THEN\n") ;
  1026. /* generate the stencil init statement for X transfer */
  1027. fprintf(fp,"CALL RSL_LITE_INIT_PERIOD ( local_communicator_periodic, %d , &\n",maxperwidth) ;
  1028. if ( n4d > 0 ) {
  1029. fprintf(fp, " %d &\n", n3dR ) ;
  1030. for ( i = 0 ; i < n4d ; i++ ) {
  1031. fprintf(fp," + num_%s &\n", name_4d[i] ) ;
  1032. }
  1033. fprintf(fp," , %d, RWORDSIZE, &\n", n2dR ) ;
  1034. } else {
  1035. fprintf(fp," %d, %d, RWORDSIZE, &\n", n3dR, n2dR ) ;
  1036. }
  1037. fprintf(fp," %d, %d, IWORDSIZE, &\n", n3dI, n2dI ) ;
  1038. fprintf(fp," %d, %d, DWORDSIZE, &\n", n3dD, n2dD ) ;
  1039. fprintf(fp," 0, 0, LWORDSIZE, &\n" ) ;
  1040. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n" ) ;
  1041. fprintf(fp," ips, ipe, jps, jpe, kps, kpe )\n") ;
  1042. /* generate packs prior to exchange in X */
  1043. gen_packs( fp, p, maxperwidth, 1, 0, "RSL_LITE_PACK_PERIOD", "local_communicator_periodic" ) ;
  1044. /* generate exchange in X */
  1045. fprintf(fp," CALL RSL_LITE_EXCH_PERIOD_X ( local_communicator_periodic , mytask, ntasks, ntasks_x, ntasks_y )\n") ;
  1046. /* generate unpacks after exchange in X */
  1047. gen_packs( fp, p, maxperwidth, 1, 1, "RSL_LITE_PACK_PERIOD", "local_communicator_periodic" ) ;
  1048. fprintf(fp,"END IF\n") ;
  1049. fprintf(fp,"IF ( config_flags%%periodic_y ) THEN\n") ;
  1050. /* generate the init statement for Y transfer */
  1051. fprintf(fp,"CALL RSL_LITE_INIT_PERIOD ( local_communicator_periodic, %d , &\n",maxperwidth) ;
  1052. if ( n4d > 0 ) {
  1053. fprintf(fp, " %d &\n", n3dR ) ;
  1054. for ( i = 0 ; i < n4d ; i++ ) {
  1055. fprintf(fp," + num_%s &\n", name_4d[i] ) ;
  1056. }
  1057. fprintf(fp," , %d, RWORDSIZE, &\n", n2dR ) ;
  1058. } else {
  1059. fprintf(fp," %d, %d, RWORDSIZE, &\n", n3dR, n2dR ) ;
  1060. }
  1061. fprintf(fp," %d, %d, IWORDSIZE, &\n", n3dI, n2dI ) ;
  1062. fprintf(fp," %d, %d, DWORDSIZE, &\n", n3dD, n2dD ) ;
  1063. fprintf(fp," 0, 0, LWORDSIZE, &\n" ) ;
  1064. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n" ) ;
  1065. fprintf(fp," ips, ipe, jps, jpe, kps, kpe )\n") ;
  1066. /* generate packs prior to exchange in Y */
  1067. gen_packs( fp, p, maxperwidth, 0, 0, "RSL_LITE_PACK_PERIOD", "local_communicator_periodic" ) ;
  1068. /* generate exchange in Y */
  1069. fprintf(fp," CALL RSL_LITE_EXCH_PERIOD_Y ( local_communicator_periodic , mytask, ntasks, ntasks_x, ntasks_y )\n") ;
  1070. /* generate unpacks after exchange in Y */
  1071. gen_packs( fp, p, maxperwidth, 0, 1, "RSL_LITE_PACK_PERIOD", "local_communicator_periodic" ) ;
  1072. fprintf(fp,"END IF\n") ;
  1073. close_the_file(fp) ;
  1074. }
  1075. return(0) ;
  1076. }
  1077. int
  1078. gen_swaps ( char * dirname , node_t * swaps )
  1079. {
  1080. node_t * p, * q ;
  1081. node_t * dimd ;
  1082. char commname[NAMELEN] ;
  1083. char fname[NAMELEN] ;
  1084. char tmp[NAMELEN], tmp2[NAMELEN], tmp3[NAMELEN] ;
  1085. char commuse[NAMELEN] ;
  1086. FILE * fp ;
  1087. char * t1, * t2 ;
  1088. char * pos1 , * pos2 ;
  1089. char indices[NAMELEN], post[NAMELEN] ;
  1090. int zdex ;
  1091. int n2dR, n3dR ;
  1092. int n2dI, n3dI ;
  1093. int n2dD, n3dD ;
  1094. int n4d ;
  1095. int i, xy ;
  1096. #define MAX_4DARRAYS 1000
  1097. char name_4d[MAX_4DARRAYS][NAMELEN] ;
  1098. if ( dirname == NULL ) return(1) ;
  1099. for ( p = swaps ; p != NULL ; p = p->next )
  1100. {
  1101. strcpy( commname, p->name ) ;
  1102. make_upper_case(commname) ;
  1103. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s.inc",dirname,commname) ; }
  1104. else { sprintf(fname,"%s.inc",commname) ; }
  1105. if ((fp = fopen( fname , "w" )) == NULL )
  1106. {
  1107. fprintf(stderr,"WARNING: gen_swaps in registry cannot open %s for writing\n",fname ) ;
  1108. continue ;
  1109. }
  1110. print_warning(fp,fname) ;
  1111. for ( xy = 0 ; xy < 2 ; xy++ ) {
  1112. fprintf(fp,"CALL wrf_debug(2,'calling %s')\n",fname) ;
  1113. /* count up the number of 2d and 3d real arrays and their types */
  1114. n2dR = 0 ; n3dR = 0 ;
  1115. n2dI = 0 ; n3dI = 0 ;
  1116. n2dD = 0 ; n3dD = 0 ;
  1117. n4d = 0 ;
  1118. strcpy( tmp, p->comm_define ) ;
  1119. strcpy( commuse, p->use ) ;
  1120. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  1121. for ( i = 0 ; i < MAX_4DARRAYS ; i++ ) strcpy(name_4d[i],"") ; /* truncate all of these */
  1122. while ( t1 != NULL )
  1123. {
  1124. strcpy( tmp2 , t1 ) ;
  1125. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  1126. { fprintf(stderr,"unparseable description for period %s\n", commname ) ; continue ; }
  1127. t2 = strtok_rentr(NULL,",", &pos2) ;
  1128. while ( t2 != NULL )
  1129. {
  1130. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  1131. { fprintf(stderr,"WARNING 1 : %s in swap spec %s (%s) is not defined in registry.\n",t2,commname, commuse) ; }
  1132. else
  1133. {
  1134. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") )
  1135. { fprintf(stderr,"WARNING: only type 'real', 'doubleprecision', or 'integer' can be part of swaps exchange. %s in %s is %s\n",t2,commname,q->type->name) ; }
  1136. else if ( q->boundary_array )
  1137. { fprintf(stderr,"WARNING: boundary array %s cannot be member of swaps spec %s.\n",t2,commname) ; }
  1138. else
  1139. {
  1140. if ( q->node_kind & FOURD ) {
  1141. if ( n4d < MAX_4DARRAYS ) {
  1142. strcpy( name_4d[n4d], q->name ) ;
  1143. } else {
  1144. fprintf(stderr,"REGISTRY ERROR: too many 4d arrays (> %d).\n", MAX_4DARRAYS ) ;
  1145. fprintf(stderr,"That seems like a lot, but if you are sure, increase MAX_4DARRAYS\n" ) ;
  1146. fprintf(stderr,"in external/RSL_LITE/gen_comms.c and recompile\n") ;
  1147. exit(5) ;
  1148. }
  1149. n4d++ ;
  1150. }
  1151. else
  1152. {
  1153. if ( ! strcmp( q->type->name, "real") ) {
  1154. if ( q->ndims == 3 ) { n3dR++ ; }
  1155. else if ( q->ndims == 2 ) { n2dR++ ; }
  1156. } else if ( ! strcmp( q->type->name, "integer") ) {
  1157. if ( q->ndims == 3 ) { n3dI++ ; }
  1158. else if ( q->ndims == 2 ) { n2dI++ ; }
  1159. } else if ( ! strcmp( q->type->name, "doubleprecision") ) {
  1160. if ( q->ndims == 3 ) { n3dD++ ; }
  1161. else if ( q->ndims == 2 ) { n2dD++ ; }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  1167. }
  1168. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  1169. }
  1170. fprintf(fp,"IF ( config_flags%%swap_%c ) THEN\n",(xy==1)?'x':'y') ;
  1171. /* generate the init statement for X swap */
  1172. fprintf(fp,"CALL RSL_LITE_INIT_SWAP ( local_communicator, %d , &\n", xy ) ;
  1173. if ( n4d > 0 ) {
  1174. fprintf(fp, " %d &\n", n3dR ) ;
  1175. for ( i = 0 ; i < n4d ; i++ ) {
  1176. fprintf(fp," + num_%s &\n", name_4d[i] ) ;
  1177. }
  1178. fprintf(fp," , %d, RWORDSIZE, &\n", n2dR ) ;
  1179. } else {
  1180. fprintf(fp," %d, %d, RWORDSIZE, &\n", n3dR, n2dR ) ;
  1181. }
  1182. fprintf(fp," %d, %d, IWORDSIZE, &\n", n3dI, n2dI ) ;
  1183. fprintf(fp," %d, %d, DWORDSIZE, &\n", n3dD, n2dD ) ;
  1184. fprintf(fp," 0, 0, LWORDSIZE, &\n" ) ;
  1185. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n" ) ;
  1186. fprintf(fp," thisdomain_max_halo_width, &\n" ) ;
  1187. fprintf(fp," ids, ide, jds, jde, kds, kde, &\n") ;
  1188. fprintf(fp," ips, ipe, jps, jpe, kps, kpe )\n") ;
  1189. /* generate packs prior to stencil exchange */
  1190. gen_packs( fp, p, 1, xy, 0, "RSL_LITE_PACK_SWAP", "local_communicator" ) ;
  1191. /* generate stencil exchange in X */
  1192. fprintf(fp," CALL RSL_LITE_SWAP ( local_communicator , mytask, ntasks, ntasks_x, ntasks_y )\n") ;
  1193. /* generate unpacks after stencil exchange */
  1194. gen_packs( fp, p, 1, xy, 1, "RSL_LITE_PACK_SWAP", "local_communicator" ) ;
  1195. fprintf(fp,"END IF\n") ;
  1196. }
  1197. close_the_file(fp) ;
  1198. }
  1199. return(0) ;
  1200. }
  1201. int
  1202. gen_cycles ( char * dirname , node_t * cycles )
  1203. {
  1204. node_t * p, * q ;
  1205. node_t * dimd ;
  1206. char commname[NAMELEN] ;
  1207. char fname[NAMELEN] ;
  1208. char tmp[NAMELEN], tmp2[NAMELEN], tmp3[NAMELEN] ;
  1209. char commuse[NAMELEN] ;
  1210. FILE * fp ;
  1211. char * t1, * t2 ;
  1212. char * pos1 , * pos2 ;
  1213. char indices[NAMELEN], post[NAMELEN] ;
  1214. int zdex ;
  1215. int n2dR, n3dR ;
  1216. int n2dI, n3dI ;
  1217. int n2dD, n3dD ;
  1218. int n4d ;
  1219. int i, xy, inout ;
  1220. #define MAX_4DARRAYS 1000
  1221. char name_4d[MAX_4DARRAYS][NAMELEN] ;
  1222. if ( dirname == NULL ) return(1) ;
  1223. for ( p = cycles ; p != NULL ; p = p->next )
  1224. {
  1225. strcpy( commname, p->name ) ;
  1226. make_upper_case(commname) ;
  1227. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s.inc",dirname,commname) ; }
  1228. else { sprintf(fname,"%s.inc",commname) ; }
  1229. if ((fp = fopen( fname , "w" )) == NULL )
  1230. {
  1231. fprintf(stderr,"WARNING: gen_cycles in registry cannot open %s for writing\n",fname ) ;
  1232. continue ;
  1233. }
  1234. /* get inout */
  1235. inout = 0 ;
  1236. strcpy( tmp, p->comm_define ) ;
  1237. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  1238. strcpy( tmp2 , t1 ) ;
  1239. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  1240. { fprintf(stderr,"unparseable description for cycle %s\n", commname ) ; exit(1) ; }
  1241. inout = atoi (t2) ;
  1242. print_warning(fp,fname) ;
  1243. for ( xy = 0 ; xy < 2 ; xy++ ) {
  1244. fprintf(fp,"CALL wrf_debug(2,'calling %s')\n",fname) ;
  1245. /* count up the number of 2d and 3d real arrays and their types */
  1246. n2dR = 0 ; n3dR = 0 ;
  1247. n2dI = 0 ; n3dI = 0 ;
  1248. n2dD = 0 ; n3dD = 0 ;
  1249. n4d = 0 ;
  1250. strcpy( tmp, p->comm_define ) ;
  1251. strcpy( commuse, p->use ) ;
  1252. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  1253. for ( i = 0 ; i < MAX_4DARRAYS ; i++ ) strcpy(name_4d[i],"") ; /* truncate all of these */
  1254. while ( t1 != NULL )
  1255. {
  1256. strcpy( tmp2 , t1 ) ;
  1257. if (( t2 = strtok_rentr( tmp2 , ":" , &pos2 )) == NULL )
  1258. { fprintf(stderr,"unparseable description for period %s\n", commname ) ; continue ; }
  1259. t2 = strtok_rentr(NULL,",", &pos2) ;
  1260. while ( t2 != NULL )
  1261. {
  1262. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  1263. { fprintf(stderr,"WARNING 1 : %s in cycle spec %s (%s) is not defined in registry.\n",t2,commname, commuse) ; }
  1264. else
  1265. {
  1266. if ( strcmp( q->type->name, "real") && strcmp( q->type->name, "integer") && strcmp( q->type->name, "doubleprecision") )
  1267. { fprintf(stderr,"WARNING: only type 'real', 'doubleprecision', or 'integer' can be part of cycles exchange. %s in %s is %s\n",t2,commname,q->type->name) ; }
  1268. else if ( q->boundary_array )
  1269. { fprintf(stderr,"WARNING: boundary array %s cannot be member of cycles spec %s.\n",t2,commname) ; }
  1270. else
  1271. {
  1272. if ( q->node_kind & FOURD ) {
  1273. if ( n4d < MAX_4DARRAYS ) {
  1274. strcpy( name_4d[n4d], q->name ) ;
  1275. } else {
  1276. fprintf(stderr,"REGISTRY ERROR: too many 4d arrays (> %d).\n", MAX_4DARRAYS ) ;
  1277. fprintf(stderr,"That seems like a lot, but if you are sure, increase MAX_4DARRAYS\n" ) ;
  1278. fprintf(stderr,"in external/RSL_LITE/gen_comms.c and recompile\n") ;
  1279. exit(5) ;
  1280. }
  1281. n4d++ ;
  1282. }
  1283. else
  1284. {
  1285. if ( ! strcmp( q->type->name, "real") ) {
  1286. if ( q->ndims == 3 ) { n3dR++ ; }
  1287. else if ( q->ndims == 2 ) { n2dR++ ; }
  1288. } else if ( ! strcmp( q->type->name, "integer") ) {
  1289. if ( q->ndims == 3 ) { n3dI++ ; }
  1290. else if ( q->ndims == 2 ) { n2dI++ ; }
  1291. } else if ( ! strcmp( q->type->name, "doubleprecision") ) {
  1292. if ( q->ndims == 3 ) { n3dD++ ; }
  1293. else if ( q->ndims == 2 ) { n2dD++ ; }
  1294. }
  1295. }
  1296. }
  1297. }
  1298. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  1299. }
  1300. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  1301. }
  1302. fprintf(fp,"IF ( config_flags%%cycle_%c ) THEN\n",(xy==1)?'x':'y') ;
  1303. /* generate the init statement for X swap */
  1304. fprintf(fp,"CALL RSL_LITE_INIT_CYCLE ( local_communicator, %d , %d, &\n", xy, inout ) ;
  1305. if ( n4d > 0 ) {
  1306. fprintf(fp, " %d &\n", n3dR ) ;
  1307. for ( i = 0 ; i < n4d ; i++ ) {
  1308. fprintf(fp," + num_%s &\n", name_4d[i] ) ;
  1309. }
  1310. fprintf(fp," , %d, RWORDSIZE, &\n", n2dR ) ;
  1311. } else {
  1312. fprintf(fp," %d, %d, RWORDSIZE, &\n", n3dR, n2dR ) ;
  1313. }
  1314. fprintf(fp," %d, %d, IWORDSIZE, &\n", n3dI, n2dI ) ;
  1315. fprintf(fp," %d, %d, DWORDSIZE, &\n", n3dD, n2dD ) ;
  1316. fprintf(fp," 0, 0, LWORDSIZE, &\n" ) ;
  1317. fprintf(fp," mytask, ntasks, ntasks_x, ntasks_y, &\n" ) ;
  1318. fprintf(fp," thisdomain_max_halo_width, &\n") ;
  1319. fprintf(fp," ids, ide, jds, jde, kds, kde, &\n") ;
  1320. fprintf(fp," ips, ipe, jps, jpe, kps, kpe )\n") ;
  1321. /* generate packs prior to stencil exchange */
  1322. gen_packs( fp, p, inout, xy, 0, "RSL_LITE_PACK_CYCLE", "local_communicator" ) ;
  1323. /* generate stencil exchange in X */
  1324. fprintf(fp," CALL RSL_LITE_CYCLE ( local_communicator , mytask, ntasks, ntasks_x, ntasks_y )\n") ;
  1325. /* generate unpacks after stencil exchange */
  1326. gen_packs( fp, p, inout, xy, 1, "RSL_LITE_PACK_CYCLE", "local_communicator" ) ;
  1327. fprintf(fp,"END IF\n") ;
  1328. }
  1329. close_the_file(fp) ;
  1330. }
  1331. return(0) ;
  1332. }
  1333. int
  1334. gen_xposes ( char * dirname )
  1335. {
  1336. node_t * p, * q ;
  1337. char commname[NAMELEN] ;
  1338. char fname[NAMELEN] ;
  1339. char tmp[4096], tmp2[4096], tmp3[4096] ;
  1340. char commuse[4096] ;
  1341. FILE * fp ;
  1342. char * t1, * t2 ;
  1343. char * pos1 , * pos2 ;
  1344. char *xposedir[] = { "z2x" , "x2z" , "x2y" , "y2x" , "z2y" , "y2z" , 0L } ;
  1345. char ** x ;
  1346. char post[NAMELEN], varname[NAMELEN], memord[10] ;
  1347. char indices_z[NAMELEN], varref_z[NAMELEN] ;
  1348. char indices_x[NAMELEN], varref_x[NAMELEN] ;
  1349. char indices_y[NAMELEN], varref_y[NAMELEN] ;
  1350. if ( dirname == NULL ) return(1) ;
  1351. for ( p = Xposes ; p != NULL ; p = p->next )
  1352. {
  1353. for ( x = xposedir ; *x ; x++ )
  1354. {
  1355. strcpy( commname, p->name ) ;
  1356. make_upper_case(commname) ;
  1357. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s_%s.inc",dirname,commname, *x) ; }
  1358. else { sprintf(fname,"%s_%s.inc",commname,*x) ; }
  1359. if ((fp = fopen( fname , "w" )) == NULL )
  1360. {
  1361. fprintf(stderr,"WARNING: gen_halos in registry cannot open %s for writing\n",fname ) ;
  1362. continue ;
  1363. }
  1364. print_warning(fp,fname) ;
  1365. strcpy( tmp, p->comm_define ) ;
  1366. strcpy( commuse, p->use ) ;
  1367. t1 = strtok_rentr( tmp , ";" , &pos1 ) ;
  1368. while ( t1 != NULL )
  1369. {
  1370. strcpy( tmp2 , t1 ) ;
  1371. /* Z array */
  1372. t2 = strtok_rentr(tmp2,",", &pos2) ;
  1373. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  1374. { fprintf(stderr,"WARNING 3 : %s in xpose spec %s (%s) is not defined in registry.\n",t2,commname,commuse) ; goto skiperific ; }
  1375. strcpy( varref_z, t2 ) ;
  1376. if ( q->node_kind & FIELD && ! (q->node_kind & I1) ) {
  1377. sprintf(varref_z,"grid%%%s",t2) ;
  1378. }
  1379. if ( q->proc_orient != ALL_Z_ON_PROC )
  1380. { fprintf(stderr,"WARNING: %s in xpose spec %s is not ALL_Z_ON_PROC.\n",t2,commname) ; goto skiperific ; }
  1381. if ( q->ndims != 3 )
  1382. { fprintf(stderr,"WARNING: array %s must be 3D to be member of xpose spec %s.\n",t2,commname) ; goto skiperific ; }
  1383. if ( q->boundary_array )
  1384. { fprintf(stderr,"WARNING: boundary array %s cannot be member of xpose spec %s.\n",t2,commname) ; goto skiperific ; }
  1385. strcpy (indices_z,"");
  1386. if ( sw_deref_kludge && strchr (t2, '%') != NULLCHARPTR )
  1387. {
  1388. sprintf(post,")") ;
  1389. sprintf(indices_z, "%s",index_with_firstelem("(","",-1,tmp3,q,post)) ;
  1390. }
  1391. if ( q->node_kind & FOURD ) {
  1392. strcat( varref_z, "(grid%sm31,grid%sm32,grid%sm33,itrace )" ) ;
  1393. }
  1394. /* X array */
  1395. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  1396. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  1397. { fprintf(stderr,"WARNING 4 : %s in xpose spec %s (%s) is not defined in registry.\n",t2,commname,commuse) ; goto skiperific ; }
  1398. strcpy( varref_x, t2 ) ;
  1399. if ( q->node_kind & FIELD && ! (q->node_kind & I1) ) {
  1400. sprintf(varref_x,"grid%%%s",t2) ;
  1401. }
  1402. if ( q->proc_orient != ALL_X_ON_PROC )
  1403. { fprintf(stderr,"WARNING: %s in xpose spec %s is not ALL_X_ON_PROC.\n",t2,commname) ; goto skiperific ; }
  1404. if ( q->ndims != 3 )
  1405. { fprintf(stderr,"WARNING: array %s must be 3D to be member of xpose spec %s.\n",t2,commname) ; goto skiperific ; }
  1406. if ( q->boundary_array )
  1407. { fprintf(stderr,"WARNING: boundary array %s cannot be member of xpose spec %s.\n",t2,commname) ; goto skiperific ; }
  1408. strcpy (indices_x,"");
  1409. if ( sw_deref_kludge && strchr (t2, '%') != NULLCHARPTR )
  1410. {
  1411. sprintf(post,")") ;
  1412. sprintf(indices_x, "%s",index_with_firstelem("(","",-1,tmp3,q,post)) ;
  1413. }
  1414. if ( q->node_kind & FOURD ) {
  1415. strcat( varref_x, "(grid%sm31x,grid%sm32x,grid%sm33x,itrace )" ) ;
  1416. }
  1417. /* Y array */
  1418. t2 = strtok_rentr( NULL , "," , &pos2 ) ;
  1419. if ((q = get_entry_r( t2, commuse, Domain.fields )) == NULL )
  1420. { fprintf(stderr,"WARNING 5 : %s in xpose spec %s (%s)is not defined in registry.\n",t2,commname,commuse) ; goto skiperific ; }
  1421. strcpy( varref_y, t2 ) ;
  1422. if ( q->node_kind & FIELD && ! (q->node_kind & I1) ) {
  1423. sprintf(varref_y,"grid%%%s",t2) ;
  1424. }
  1425. if ( q->proc_orient != ALL_Y_ON_PROC )
  1426. { fprintf(stderr,"WARNING: %s in xpose spec %s is not ALL_Y_ON_PROC.\n",t2,commname) ; goto skiperific ; }
  1427. if ( q->ndims != 3 )
  1428. { fprintf(stderr,"WARNING: array %s must be 3D to be member of xpose spec %s.\n",t2,commname) ; goto skiperific ; }
  1429. if ( q->boundary_array )
  1430. { fprintf(stderr,"WARNING: boundary array %s cannot be member of xpose spec %s.\n",t2,commname) ; goto skiperific ; }
  1431. strcpy (indices_y,"");
  1432. if ( sw_deref_kludge && strchr (t2, '%') != NULLCHARPTR )
  1433. {
  1434. sprintf(post,")") ;
  1435. sprintf(indices_y, "%s",index_with_firstelem("(","",-1,tmp3,q,post)) ;
  1436. }
  1437. if ( q->node_kind & FOURD ) {
  1438. strcat( varref_y, "(grid%sm31y,grid%sm32y,grid%sm33y,itrace )" ) ;
  1439. }
  1440. t1 = strtok_rentr( NULL , ";" , &pos1 ) ;
  1441. }
  1442. set_mem_order( q, memord , 3 ) ;
  1443. if ( !strcmp( *x , "z2x" ) ) {
  1444. fprintf(fp," call trans_z2x ( ntasks_x, local_communicator_x, 1, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1445. fprintf(fp," %s, & ! variable in Z decomp\n" , varref_z ) ;
  1446. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1447. fprintf(fp," grid%%sp31, grid%%ep31, grid%%sp32, grid%%ep32, grid%%sp33, grid%%ep33, &\n" ) ;
  1448. fprintf(fp," grid%%sm31, grid%%em31, grid%%sm32, grid%%em32, grid%%sm33, grid%%em33, &\n" ) ;
  1449. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1450. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1451. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x ) \n" ) ;
  1452. } else if ( !strcmp( *x , "x2z" ) ) {
  1453. fprintf(fp," call trans_z2x ( ntasks_x, local_communicator_x, 0, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1454. fprintf(fp," %s, & ! variable in Z decomp\n" , varref_z ) ;
  1455. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1456. fprintf(fp," grid%%sp31, grid%%ep31, grid%%sp32, grid%%ep32, grid%%sp33, grid%%ep33, &\n" ) ;
  1457. fprintf(fp," grid%%sm31, grid%%em31, grid%%sm32, grid%%em32, grid%%sm33, grid%%em33, &\n" ) ;
  1458. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1459. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1460. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x ) \n" ) ;
  1461. } else if ( !strcmp( *x , "x2y" ) ) {
  1462. fprintf(fp," call trans_x2y ( ntasks_y, local_communicator_y, 1, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1463. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1464. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1465. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1466. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x, &\n" ) ;
  1467. fprintf(fp," %s, & ! variable in Y decomp\n" , varref_y ) ;
  1468. fprintf(fp," grid%%sp31y, grid%%ep31y, grid%%sp32y, grid%%ep32y, grid%%sp33y, grid%%ep33y, &\n" ) ;
  1469. fprintf(fp," grid%%sm31y, grid%%em31y, grid%%sm32y, grid%%em32y, grid%%sm33y, grid%%em33y ) \n" ) ;
  1470. } else if ( !strcmp( *x , "y2x" ) ) {
  1471. fprintf(fp," call trans_x2y ( ntasks_y, local_communicator_y, 0, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1472. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1473. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1474. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1475. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x, &\n" ) ;
  1476. fprintf(fp," %s, & ! variable in Y decomp\n" , varref_y ) ;
  1477. fprintf(fp," grid%%sp31y, grid%%ep31y, grid%%sp32y, grid%%ep32y, grid%%sp33y, grid%%ep33y, &\n" ) ;
  1478. fprintf(fp," grid%%sm31y, grid%%em31y, grid%%sm32y, grid%%em32y, grid%%sm33y, grid%%em33y ) \n" ) ;
  1479. } else if ( !strcmp( *x , "y2z" ) ) {
  1480. fprintf(fp," call trans_x2y ( ntasks_y, local_communicator_y, 0, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1481. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1482. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1483. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1484. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x, &\n" ) ;
  1485. fprintf(fp," %s, & ! variable in Y decomp\n" , varref_y ) ;
  1486. fprintf(fp," grid%%sp31y, grid%%ep31y, grid%%sp32y, grid%%ep32y, grid%%sp33y, grid%%ep33y, &\n" ) ;
  1487. fprintf(fp," grid%%sm31y, grid%%em31y, grid%%sm32y, grid%%em32y, grid%%sm33y, grid%%em33y ) \n" ) ;
  1488. fprintf(fp," call trans_z2x ( ntasks_x, local_communicator_x, 0, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1489. fprintf(fp," %s, & ! variable in Z decomp\n" , varref_z ) ;
  1490. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1491. fprintf(fp," grid%%sp31, grid%%ep31, grid%%sp32, grid%%ep32, grid%%sp33, grid%%ep33, &\n" ) ;
  1492. fprintf(fp," grid%%sm31, grid%%em31, grid%%sm32, grid%%em32, grid%%sm33, grid%%em33, &\n" ) ;
  1493. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1494. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1495. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x)\n" ) ;
  1496. } else if ( !strcmp( *x , "z2y" ) ) {
  1497. fprintf(fp," call trans_z2x ( ntasks_x, local_communicator_x, 1, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1498. fprintf(fp," %s, & ! variable in Z decomp\n" , varref_z ) ;
  1499. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1500. fprintf(fp," grid%%sp31, grid%%ep31, grid%%sp32, grid%%ep32, grid%%sp33, grid%%ep33, &\n" ) ;
  1501. fprintf(fp," grid%%sm31, grid%%em31, grid%%sm32, grid%%em32, grid%%sm33, grid%%em33, &\n" ) ;
  1502. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1503. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1504. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x )\n" ) ;
  1505. fprintf(fp," call trans_x2y ( ntasks_y, local_communicator_y, 1, RWORDSIZE, IWORDSIZE, DATA_ORDER_%s , &\n", memord ) ;
  1506. fprintf(fp," %s, & ! variable in X decomp\n" , varref_x ) ;
  1507. fprintf(fp," grid%%sd31, grid%%ed31, grid%%sd32, grid%%ed32, grid%%sd33, grid%%ed33, &\n" ) ;
  1508. fprintf(fp," grid%%sp31x, grid%%ep31x, grid%%sp32x, grid%%ep32x, grid%%sp33x, grid%%ep33x, &\n" ) ;
  1509. fprintf(fp," grid%%sm31x, grid%%em31x, grid%%sm32x, grid%%em32x, grid%%sm33x, grid%%em33x, &\n" ) ;
  1510. fprintf(fp," %s, & ! variable in Y decomp\n" , varref_y ) ;
  1511. fprintf(fp," grid%%sp31y, grid%%ep31y, grid%%sp32y, grid%%ep32y, grid%%sp33y, grid%%ep33y, &\n" ) ;
  1512. fprintf(fp," grid%%sm31y, grid%%em31y, grid%%sm32y, grid%%em32y, grid%%sm33y, grid%%em33y ) \n" ) ;
  1513. }
  1514. close_the_file(fp) ;
  1515. }
  1516. skiperific:
  1517. ;
  1518. }
  1519. return(0) ;
  1520. }
  1521. int
  1522. gen_comm_descrips ( char * dirname )
  1523. {
  1524. node_t * p ;
  1525. char * fn = "dm_comm_cpp_flags" ;
  1526. char commname[NAMELEN] ;
  1527. char fname[NAMELEN] ;
  1528. FILE * fp ;
  1529. int ncomm ;
  1530. if ( dirname == NULL ) return(1) ;
  1531. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
  1532. else { sprintf(fname,"%s",fn) ; }
  1533. if ((fp = fopen( fname , "w" )) == NULL )
  1534. {
  1535. fprintf(stderr,"WARNING: gen_comm_descrips in registry cannot open %s for writing\n",fname ) ;
  1536. }
  1537. return(0) ;
  1538. }
  1539. int
  1540. gen_shift ( char * dirname )
  1541. {
  1542. int i ;
  1543. FILE * fp ;
  1544. node_t *p, *q, *dimd ;
  1545. char **direction ;
  1546. char *directions[] = { "x", "y", 0L } ;
  1547. char fname[NAMELEN], vname[NAMELEN] ;
  1548. char indices[NAMELEN], post[NAMELEN], tmp3[NAMELEN] ;
  1549. char memord[NAMELEN] ;
  1550. int xdex,ydex,zdex ;
  1551. node_t Shift ;
  1552. int said_it = 0 ;
  1553. int said_it2 = 0 ;
  1554. for ( direction = directions ; *direction != NULL ; direction++ )
  1555. {
  1556. if ( dirname == NULL ) return(1) ;
  1557. if ( sw_unidir_shift_halo ) {
  1558. sprintf(fname,"shift_halo",*direction) ;
  1559. } else {
  1560. sprintf(fname,"shift_halo_%s_halo",*direction) ;
  1561. }
  1562. Shift.next = NULL ;
  1563. sprintf( Shift.use, "" ) ;
  1564. strcpy( Shift.comm_define, "SHW:" ) ;
  1565. strcpy( Shift.name , fname ) ;
  1566. if ( sw_move ) {
  1567. for ( p = Domain.fields ; p != NULL ; p = p->next ) {
  1568. if (( p->node_kind & (FIELD | FOURD) ) && p->ndims >= 2 && ! p->boundary_array )
  1569. {
  1570. /* special cases in WRF */
  1571. if ( !strcmp( p->name , "xf_ens" ) || !strcmp( p->name , "pr_ens" ) ||
  1572. !strcmp( p->name , "abstot" ) || !strcmp( p->name , "absnxt" ) ||
  1573. !strcmp( p->name , "emstot" ) || !strcmp( p->name , "obs_savwt" ) ) {
  1574. if ( sw_move && ! said_it ) { fprintf(stderr,"Info only - not an error: Moving nests not implemented for Grell Ens. Cumulus\n") ;
  1575. fprintf(stderr,"Info only - not an error: Moving nests not implemented for CAM radiation\n") ;
  1576. fprintf(stderr,"Info only - not an error: Moving nests not implemented for Observation Nudging\n") ;
  1577. said_it = 1 ; }
  1578. continue ;
  1579. }
  1580. /* make sure that the only things we are shifting are arrays that have a decomposed X and a Y dimension */
  1581. /* also make sure we don't shift or halo any transpose variables (ALL_X_ON_PROC or ALL_Y_ON_PROC) */
  1582. if ( get_dimnode_for_coord( p , COORD_X ) && get_dimnode_for_coord( p , COORD_Y ) &&
  1583. !(p->proc_orient == ALL_X_ON_PROC || p->proc_orient == ALL_Y_ON_PROC) ) {
  1584. if ( p->subgrid != 0 ) { /* moving nests not implemented for subgrid variables */
  1585. if ( sw_move && ! said_it2 ) { fprintf(stderr,"Info only - not an error: Moving nests not implemented for subgrid variables \n") ;
  1586. said_it2 = 1 ; }
  1587. continue ;
  1588. }
  1589. if ( p->type->type_type == SIMPLE )
  1590. {
  1591. for ( i = 1 ; i <= p->ntl ; i++ )
  1592. {
  1593. if ( p->ntl > 1 ) sprintf(vname,"%s_%d",p->name,i ) ;
  1594. else sprintf(vname,"%s",p->name ) ;
  1595. strcat( Shift.comm_define, vname ) ;
  1596. strcat( Shift.comm_define, "," ) ;
  1597. }
  1598. }
  1599. }
  1600. }
  1601. }
  1602. if ( strlen(Shift.comm_define) > 0 )Shift.comm_define[strlen(Shift.comm_define)-1] = '\0' ;
  1603. }
  1604. /* if unidir halo, then only generate on x pass */
  1605. if ( ! ( sw_unidir_shift_halo && !strcmp(*direction,"y" ) ) ) {
  1606. gen_halos( dirname , NULL, &Shift, 0 ) ;
  1607. }
  1608. sprintf(fname,"%s/shift_halo_%s.inc",dirname,*direction) ;
  1609. if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
  1610. /* now generate the shifts themselves */
  1611. if ( sw_move ) {
  1612. for ( p = Domain.fields ; p != NULL ; p = p->next )
  1613. {
  1614. /* special cases in WRF */
  1615. if ( !strcmp( p->name , "xf_ens" ) || !strcmp( p->name , "pr_ens" ) ||
  1616. !strcmp( p->name , "abstot" ) || !strcmp( p->name , "absnxt" ) ||
  1617. !strcmp( p->name , "emstot" ) || !strcmp( p->name , "obs_savwt" ) ) {
  1618. continue ;
  1619. }
  1620. /* do not shift transpose variables */
  1621. if ( p->proc_orient == ALL_X_ON_PROC || p->proc_orient == ALL_Y_ON_PROC ) continue ;
  1622. if (( p->node_kind & (FIELD | FOURD) ) && p->ndims >= 2 && ! p->boundary_array )
  1623. {
  1624. if ( p->type->type_type == SIMPLE )
  1625. {
  1626. for ( i = 1 ; i <= p->ntl ; i++ )
  1627. {
  1628. if ( p->ntl > 1 ) sprintf(vname,"%s_%d",p->name,i ) ;
  1629. else sprintf(vname,"%s",p->name ) ;
  1630. if ( p->node_kind & FOURD )
  1631. {
  1632. node_t *member ;
  1633. xdex = get_index_for_coord( p , COORD_X ) ;
  1634. ydex = get_index_for_coord( p , COORD_Y ) ;
  1635. zdex = get_index_for_coord( p , COORD_Z ) ;
  1636. if ( zdex >=1 && zdex <= 3 )
  1637. {
  1638. int d ;
  1639. char r[10], tx[80], temp[80], moredims[80], *colon ;
  1640. set_mem_order( p->members, memord , 3 ) ;
  1641. fprintf(fp, " DO itrace = PARAM_FIRST_SCALAR, num_%s\n", p->name ) ;
  1642. for ( d = p->ndims-1; d >= 3 ; d-- ) {
  1643. strcpy(r,"") ;
  1644. range_of_dimension( r, tx, d, p, "config_flags%") ;
  1645. colon = index(tx,':') ; *colon = ',' ;
  1646. fprintf(fp, " DO idim%d = %s\n", d-2, tx ) ;
  1647. }
  1648. strcpy(moredims,"") ;
  1649. for ( d = 3 ; d < p->ndims ; d++ ) {
  1650. sprintf(temp,"idim%d",d-2) ;
  1651. strcat(moredims,",") ; strcat(moredims,temp) ;
  1652. }
  1653. strcat(moredims,",") ;
  1654. if ( !strcmp( *direction, "x" ) )
  1655. {
  1656. char * stag = "" ;
  1657. stag = p->members->stag_x?"":"-1" ;
  1658. if ( !strncmp( memord , "XYZ", 3 ) ) {
  1659. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1660. fprintf(fp,"grid%%%s (ips:min(ide%s,ipe),jms:jme,:%sitrace) = grid%%%s (ips+px:min(ide%s,ipe)+px,jms:jme,:%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1661. fprintf(fp,"ENDIF\n") ;
  1662. } else if ( !strncmp( memord , "YXZ", 3 ) ) {
  1663. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1664. fprintf(fp,"grid%%%s (jms:jme,ips:min(ide%s,ipe),:%sitrace) = grid%%%s (jms:jme,ips+px:min(ide%s,ipe)+px,:%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1665. fprintf(fp,"ENDIF\n") ;
  1666. } else if ( !strncmp( memord , "XZY", 3 ) ) {
  1667. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1668. fprintf(fp,"grid%%%s (ips:min(ide%s,ipe),:,jms:jme%sitrace) = grid%%%s (ips+px:min(ide%s,ipe)+px,:,jms:jme%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1669. fprintf(fp,"ENDIF\n") ;
  1670. } else if ( !strncmp( memord , "YZX", 3 ) ) {
  1671. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1672. fprintf(fp,"grid%%%s (jms:jme,:,ips:min(ide%s,ipe)%sitrace) = grid%%%s (jms:jme,:,ips+px:min(ide%s,ipe)+px%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1673. fprintf(fp,"ENDIF\n") ;
  1674. } else if ( !strncmp( memord , "ZXY", 3 ) ) {
  1675. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1676. fprintf(fp,"grid%%%s (:,ips:min(ide%s,ipe),jms:jme%sitrace) = grid%%%s (:,ips+px:min(ide%s,ipe)+px,jms:jme%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1677. fprintf(fp,"ENDIF\n") ;
  1678. } else if ( !strncmp( memord , "ZYX", 3 ) ) {
  1679. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1680. fprintf(fp,"grid%%%s (:,jms:jme,ips:min(ide%s,ipe)%sitrace) = grid%%%s (:,jms:jme,ips+px:min(ide%s,ipe)+px%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1681. fprintf(fp,"ENDIF\n") ;
  1682. } else if ( !strncmp( memord , "XY", 2 ) ) {
  1683. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1684. fprintf(fp,"grid%%%s (ips:min(ide%s,ipe),jms:jme%sitrace) = grid%%%s (ips+px:min(ide%s,ipe)+px,jms:jme%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1685. fprintf(fp,"ENDIF\n") ;
  1686. } else if ( !strncmp( memord , "YX", 2 ) ) {
  1687. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1688. fprintf(fp,"grid%%%s (jms:jme,ips:min(ide%s,ipe)%sitrace) = grid%%%s (jms:jme,ips+px:min(ide%s,ipe)+px%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1689. fprintf(fp,"ENDIF\n") ;
  1690. }
  1691. }
  1692. else
  1693. {
  1694. char * stag = "" ;
  1695. stag = p->members->stag_y?"":"-1" ;
  1696. if ( !strncmp( memord , "XYZ", 3 ) ) {
  1697. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1698. fprintf(fp,"grid%%%s (ims:ime,jps:min(jde%s,jpe),:%sitrace) = grid%%%s (ims:ime,jps+py:min(jde%s,jpe)+py,:%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1699. fprintf(fp,"ENDIF\n") ;
  1700. } else if ( !strncmp( memord , "YXZ", 3 ) ) {
  1701. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1702. fprintf(fp,"grid%%%s (jps:min(jde%s,jpe),ims:ime,:%sitrace) = grid%%%s (jps+py:min(jde%s,jpe)+py,ims:ime,:%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1703. fprintf(fp,"ENDIF\n") ;
  1704. } else if ( !strncmp( memord , "XZY", 3 ) ) {
  1705. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1706. fprintf(fp,"grid%%%s (ims:ime,:,jps:min(jde%s,jpe)%sitrace) = grid%%%s (ims:ime,:,jps+py:min(jde%s,jpe)+py%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1707. fprintf(fp,"ENDIF\n") ;
  1708. } else if ( !strncmp( memord , "YZX", 3 ) ) {
  1709. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1710. fprintf(fp,"grid%%%s (jps:min(jde%s,jpe),:,ims:ime%sitrace) = grid%%%s (jps+py:min(jde%s,jpe)+py,:,ims:ime%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1711. fprintf(fp,"ENDIF\n") ;
  1712. } else if ( !strncmp( memord , "ZXY", 3 ) ) {
  1713. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1714. fprintf(fp,"grid%%%s (:,ims:ime,jps:min(jde%s,jpe)%sitrace) = grid%%%s (:,ims:ime,jps+py:min(jde%s,jpe)+py%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1715. fprintf(fp,"ENDIF\n") ;
  1716. } else if ( !strncmp( memord , "ZYX", 3 ) ) {
  1717. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1718. fprintf(fp,"grid%%%s (:,jps:min(jde%s,jpe),ims:ime%sitrace) = grid%%%s (:,jps+py:min(jde%s,jpe)+py,ims:ime%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1719. fprintf(fp,"ENDIF\n") ;
  1720. } else if ( !strncmp( memord , "XY", 2 ) ) {
  1721. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1722. fprintf(fp,"grid%%%s (ims:ime,jps:min(jde%s,jpe)%sitrace) = grid%%%s (ims:ime,jps+py:min(jde%s,jpe)+py%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1723. fprintf(fp,"ENDIF\n") ;
  1724. } else if ( !strncmp( memord , "YX", 2 ) ) {
  1725. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1726. fprintf(fp,"grid%%%s (jps:min(jde%s,jpe),ims:ime%sitrace) = grid%%%s (jps+py:min(jde%s,jpe)+py,ims:ime%sitrace)\n", vname, stag, moredims, vname, stag, moredims ) ;
  1727. fprintf(fp,"ENDIF\n") ;
  1728. }
  1729. }
  1730. for ( d = p->ndims-1; d >= 3 ; d-- ) {
  1731. fprintf(fp, " ENDDO\n" ) ;
  1732. }
  1733. fprintf(fp, " ENDDO\n" ) ;
  1734. }
  1735. else
  1736. {
  1737. fprintf(stderr,"WARNING: %d some dimension info missing for 4d array %s\n",zdex,t2) ;
  1738. }
  1739. }
  1740. else
  1741. {
  1742. xdex = get_index_for_coord( p , COORD_X ) ;
  1743. ydex = get_index_for_coord( p , COORD_Y ) ;
  1744. set_mem_order( p, memord , 3 ) ;
  1745. if ( !strcmp( *direction, "x" ) ) {
  1746. if ( !strcmp( memord , "XYZ" ) ) {
  1747. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1748. fprintf(fp,"grid%%%s (ips:min(ide%s,ipe),jms:jme,:) = grid%%%s (ips+px:min(ide%s,ipe)+px,jms:jme,:)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1749. fprintf(fp,"ENDIF\n") ;
  1750. } else if ( !strcmp( memord , "YXZ" ) ) {
  1751. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1752. fprintf(fp,"grid%%%s (jms:jme,ips:min(ide%s,ipe),:) = grid%%%s (jms:jme,ips+px:min(ide%s,ipe)+px,:)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1753. fprintf(fp,"ENDIF\n") ;
  1754. } else if ( !strcmp( memord , "XZY" ) ) {
  1755. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1756. fprintf(fp,"grid%%%s (ips:min(ide%s,ipe),:,jms:jme) = grid%%%s (ips+px:min(ide%s,ipe)+px,:,jms:jme)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1757. fprintf(fp,"ENDIF\n") ;
  1758. } else if ( !strcmp( memord , "YZX" ) ) {
  1759. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1760. fprintf(fp,"grid%%%s (jms:jme,:,ips:min(ide%s,ipe)) = grid%%%s (jms:jme,:,ips+px:min(ide%s,ipe)+px)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1761. fprintf(fp,"ENDIF\n") ;
  1762. } else if ( !strcmp( memord , "ZXY" ) ) {
  1763. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1764. fprintf(fp,"grid%%%s (:,ips:min(ide%s,ipe),jms:jme) = grid%%%s (:,ips+px:min(ide%s,ipe)+px,jms:jme)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1765. fprintf(fp,"ENDIF\n") ;
  1766. } else if ( !strcmp( memord , "ZYX" ) ) {
  1767. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1768. fprintf(fp,"grid%%%s (:,jms:jme,ips:min(ide%s,ipe)) = grid%%%s (:,jms:jme,ips+px:min(ide%s,ipe)+px)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1769. fprintf(fp,"ENDIF\n") ;
  1770. } else if ( !strcmp( memord , "XY" ) ) {
  1771. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1772. fprintf(fp,"grid%%%s (ips:min(ide%s,ipe),jms:jme) = grid%%%s (ips+px:min(ide%s,ipe)+px,jms:jme)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1773. fprintf(fp,"ENDIF\n") ;
  1774. } else if ( !strcmp( memord , "YX" ) ) {
  1775. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1776. fprintf(fp,"grid%%%s (jms:jme,ips:min(ide%s,ipe)) = grid%%%s (jms:jme,ips+px:min(ide%s,ipe)+px)\n", vname, p->stag_x?"":"-1", vname, p->stag_x?"":"-1" ) ;
  1777. fprintf(fp,"ENDIF\n") ;
  1778. }
  1779. } else {
  1780. if ( !strcmp( memord , "XYZ" ) ) {
  1781. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1782. fprintf(fp,"grid%%%s (ims:ime,jps:min(jde%s,jpe),:) = grid%%%s (ims:ime,jps+py:min(jde%s,jpe)+py,:)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1783. fprintf(fp,"ENDIF\n") ;
  1784. } else if ( !strcmp( memord , "YXZ" ) ) {
  1785. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1786. fprintf(fp,"grid%%%s (jps:min(jde%s,jpe),ims:ime,:) = grid%%%s (jps+py:min(jde%s,jpe)+py,ims:ime,:)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1787. fprintf(fp,"ENDIF\n") ;
  1788. } else if ( !strcmp( memord , "XZY" ) ) {
  1789. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1790. fprintf(fp,"grid%%%s (ims:ime,:,jps:min(jde%s,jpe)) = grid%%%s (ims:ime,:,jps+py:min(jde%s,jpe)+py)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1791. fprintf(fp,"ENDIF\n") ;
  1792. } else if ( !strcmp( memord , "YZX" ) ) {
  1793. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1794. fprintf(fp,"grid%%%s (jps:min(jde%s,jpe),:,ims:ime) = grid%%%s (jps+py:min(jde%s,jpe)+py,:,ims:ime)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1795. fprintf(fp,"ENDIF\n") ;
  1796. } else if ( !strcmp( memord , "ZXY" ) ) {
  1797. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1798. fprintf(fp,"grid%%%s (:,ims:ime,jps:min(jde%s,jpe)) = grid%%%s (:,ims:ime,jps+py:min(jde%s,jpe)+py)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1799. fprintf(fp,"ENDIF\n") ;
  1800. } else if ( !strcmp( memord , "ZYX" ) ) {
  1801. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1802. fprintf(fp,"grid%%%s (:,jps:min(jde%s,jpe),ims:ime) = grid%%%s (:,jps+py:min(jde%s,jpe)+py,ims:ime)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1803. fprintf(fp,"ENDIF\n") ;
  1804. } else if ( !strcmp( memord , "XY" ) ) {
  1805. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1806. fprintf(fp,"grid%%%s (ims:ime,jps:min(jde%s,jpe)) = grid%%%s (ims:ime,jps+py:min(jde%s,jpe)+py)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1807. fprintf(fp,"ENDIF\n") ;
  1808. } else if ( !strcmp( memord , "YX" ) ) {
  1809. fprintf(fp,"IF ( SIZE(grid%%%s,%d)*SIZE(grid%%%s,%d) .GT. 1 ) THEN\n",vname,xdex+1,vname,ydex+1) ;
  1810. fprintf(fp,"grid%%%s (jps:min(jde%s,jpe),ims:ime) = grid%%%s (jps+py:min(jde%s,jpe)+py,ims:ime)\n", vname, p->stag_y?"":"-1", vname, p->stag_y?"":"-1" ) ;
  1811. fprintf(fp,"ENDIF\n") ;
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. } /* if sw_move */
  1820. close_the_file(fp) ;
  1821. }
  1822. }
  1823. int
  1824. gen_datacalls ( char * dirname )
  1825. {
  1826. FILE * fp ;
  1827. char * fn = "data_calls.inc" ;
  1828. char fname[NAMELEN] ;
  1829. if ( dirname == NULL ) return(1) ;
  1830. if ( strlen(dirname) > 0 )
  1831. { sprintf(fname,"%s/%s",dirname,fn) ; }
  1832. else
  1833. { sprintf(fname,"%s",fn) ; }
  1834. if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
  1835. print_warning(fp,fname) ;
  1836. close_the_file(fp) ;
  1837. return(0) ;
  1838. }
  1839. /*****************/
  1840. /*****************/
  1841. gen_nest_packing ( char * dirname )
  1842. {
  1843. gen_nest_pack( dirname ) ;
  1844. gen_nest_unpack( dirname ) ;
  1845. }
  1846. #define PACKIT 1
  1847. #define UNPACKIT 2
  1848. int
  1849. gen_nest_pack ( char * dirname )
  1850. {
  1851. int i ;
  1852. FILE * fp ;
  1853. char * fnlst[] = { "nest_interpdown_pack.inc" , "nest_forcedown_pack.inc" , "nest_feedbackup_pack.inc", 0L } ;
  1854. int down_path[] = { INTERP_DOWN , FORCE_DOWN , INTERP_UP } ;
  1855. int ipath ;
  1856. char ** fnp ; char * fn ;
  1857. char * shw_str ;
  1858. char fname[NAMELEN] ;
  1859. node_t *node, *p, *dim ;
  1860. int xdex, ydex, zdex ;
  1861. char ddim[3][2][NAMELEN] ;
  1862. char mdim[3][2][NAMELEN] ;
  1863. char pdim[3][2][NAMELEN] ;
  1864. char vname[NAMELEN] ; char tag[NAMELEN], fourd_names[NAMELEN_LONG] ;
  1865. int d2, d3, sw ;
  1866. char *info_name ;
  1867. for ( fnp = fnlst , ipath = 0 ; *fnp ; fnp++ , ipath++ )
  1868. {
  1869. fn = *fnp ;
  1870. if ( dirname == NULL ) return(1) ;
  1871. if ( strlen(dirname) > 0 ) {
  1872. sprintf(fname,"%s/%s",dirname,fn) ;
  1873. } else {
  1874. sprintf(fname,"%s",fn) ;
  1875. }
  1876. if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
  1877. print_warning(fp,fname) ;
  1878. d2 = 0 ;
  1879. d3 = 0 ;
  1880. node = Domain.fields ;
  1881. count_fields ( node , &d2 , &d3 , fourd_names, down_path[ipath] ) ;
  1882. if ( d2 + d3 > 0 ) {
  1883. if ( down_path[ipath] == INTERP_UP )
  1884. {
  1885. info_name = "rsl_lite_to_parent_info" ;
  1886. sw = 0 ;
  1887. }
  1888. else
  1889. {
  1890. info_name = "rsl_lite_to_child_info" ;
  1891. sw = 1 ;
  1892. }
  1893. fprintf(fp,"msize = (%d + %s )* nlev + %d\n", d3, fourd_names, d2 ) ;
  1894. fprintf(fp,"CALL %s( local_communicator, msize*RWORDSIZE &\n",info_name ) ;
  1895. fprintf(fp," ,cips,cipe,cjps,cjpe &\n") ;
  1896. if (sw) fprintf(fp," ,iids,iide,ijds,ijde &\n") ;
  1897. fprintf(fp," ,nids,nide,njds,njde &\n") ;
  1898. if (sw) fprintf(fp," ,pgr , sw &\n") ;
  1899. fprintf(fp," ,ntasks_x,ntasks_y &\n") ;
  1900. fprintf(fp," ,thisdomain_max_halo_width &\n") ;
  1901. fprintf(fp," ,icoord,jcoord &\n") ;
  1902. fprintf(fp," ,idim_cd,jdim_cd &\n") ;
  1903. fprintf(fp," ,pig,pjg,retval )\n") ;
  1904. fprintf(fp,"DO while ( retval .eq. 1 )\n") ;
  1905. gen_nest_packunpack ( fp , Domain.fields, PACKIT, down_path[ipath] ) ;
  1906. fprintf(fp,"CALL %s( local_communicator, msize*RWORDSIZE &\n",info_name ) ;
  1907. fprintf(fp," ,cips,cipe,cjps,cjpe &\n") ;
  1908. if (sw) fprintf(fp," ,iids,iide,ijds,ijde &\n") ;
  1909. fprintf(fp," ,nids,nide,njds,njde &\n") ;
  1910. if (sw) fprintf(fp," ,pgr , sw &\n") ;
  1911. fprintf(fp," ,ntasks_x,ntasks_y &\n") ;
  1912. fprintf(fp," ,thisdomain_max_halo_width &\n") ;
  1913. fprintf(fp," ,icoord,jcoord &\n") ;
  1914. fprintf(fp," ,idim_cd,jdim_cd &\n") ;
  1915. fprintf(fp," ,pig,pjg,retval )\n") ;
  1916. fprintf(fp,"ENDDO\n") ;
  1917. }
  1918. close_the_file(fp) ;
  1919. }
  1920. return(0) ;
  1921. }
  1922. int
  1923. gen_nest_unpack ( char * dirname )
  1924. {
  1925. int i ;
  1926. FILE * fp ;
  1927. char * fnlst[] = { "nest_interpdown_unpack.inc" , "nest_forcedown_unpack.inc" , "nest_feedbackup_unpack.inc" , 0L } ;
  1928. int down_path[] = { INTERP_DOWN , FORCE_DOWN , INTERP_UP } ;
  1929. int ipath ;
  1930. char ** fnp ; char * fn ;
  1931. char fname[NAMELEN] ;
  1932. node_t *node, *p, *dim ;
  1933. int xdex, ydex, zdex ;
  1934. char ddim[3][2][NAMELEN] ;
  1935. char mdim[3][2][NAMELEN] ;
  1936. char pdim[3][2][NAMELEN] ;
  1937. char *info_name ;
  1938. char vname[NAMELEN] ; char tag[NAMELEN] ; char fourd_names[NAMELEN_LONG] ;
  1939. int d2, d3 ;
  1940. for ( fnp = fnlst , ipath = 0 ; *fnp ; fnp++ , ipath++ )
  1941. {
  1942. fn = *fnp ;
  1943. d2 = 0 ;
  1944. d3 = 0 ;
  1945. node = Domain.fields ;
  1946. if ( dirname == NULL ) return(1) ;
  1947. if ( strlen(dirname) > 0 )
  1948. { sprintf(fname,"%s/%s",dirname,fn) ; }
  1949. else
  1950. { sprintf(fname,"%s",fn) ; }
  1951. if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
  1952. print_warning(fp,fname) ;
  1953. count_fields ( node , &d2 , &d3 , fourd_names, down_path[ipath] ) ;
  1954. if ( d2 + d3 > 0 && strlen(fourd_names) > 0 ) {
  1955. if ( down_path[ipath] == INTERP_UP )
  1956. {
  1957. info_name = "rsl_lite_from_child_info" ;
  1958. }
  1959. else
  1960. {
  1961. info_name = "rsl_lite_from_parent_info" ;
  1962. }
  1963. fprintf(fp,"CALL %s(pig,pjg,retval)\n", info_name ) ;
  1964. fprintf(fp,"DO while ( retval .eq. 1 )\n") ;
  1965. gen_nest_packunpack ( fp , Domain.fields, UNPACKIT, down_path[ipath] ) ;
  1966. fprintf(fp,"CALL %s(pig,pjg,retval)\n", info_name ) ;
  1967. fprintf(fp,"ENDDO\n") ;
  1968. }
  1969. close_the_file(fp) ;
  1970. }
  1971. return(0) ;
  1972. }
  1973. int
  1974. gen_nest_packunpack ( FILE *fp , node_t * node , int dir, int down_path )
  1975. {
  1976. int i, d1 ;
  1977. node_t *p, *p1, *dim ;
  1978. int d2, d3, xdex, ydex, zdex ;
  1979. int nest_mask ;
  1980. char * grid ;
  1981. char ddim[3][2][NAMELEN] ;
  1982. char mdim[3][2][NAMELEN] ;
  1983. char pdim[3][2][NAMELEN] ;
  1984. char vname[NAMELEN], dexes[NAMELEN] ; char tag[NAMELEN] ;
  1985. char tx[80], moredims[80], temp[80], r[10], *colon ;
  1986. char c, d ;
  1987. for ( p1 = node ; p1 != NULL ; p1 = p1->next )
  1988. {
  1989. if ( p1->node_kind & FOURD )
  1990. {
  1991. if ( p1->members->next )
  1992. nest_mask = p1->members->next->nest_mask ;
  1993. else
  1994. continue ;
  1995. }
  1996. else
  1997. {
  1998. nest_mask = p1->nest_mask ;
  1999. }
  2000. p = p1 ;
  2001. if ( nest_mask & down_path )
  2002. {
  2003. if ( p->node_kind & FOURD ) {
  2004. if ( p->members->next->ntl > 1 ) sprintf(tag,"_2") ;
  2005. else sprintf(tag,"") ;
  2006. set_dim_strs ( p->members , ddim , mdim , pdim , "c", 0 ) ;
  2007. zdex = get_index_for_coord( p->members , COORD_Z ) ;
  2008. xdex = get_index_for_coord( p->members , COORD_X ) ;
  2009. ydex = get_index_for_coord( p->members , COORD_Y ) ;
  2010. } else {
  2011. if ( p->ntl > 1 ) sprintf(tag,"_2") ;
  2012. else sprintf(tag,"") ;
  2013. set_dim_strs ( p , ddim , mdim , pdim , "c", 0 ) ;
  2014. zdex = get_index_for_coord( p , COORD_Z ) ;
  2015. xdex = get_index_for_coord( p , COORD_X ) ;
  2016. ydex = get_index_for_coord( p , COORD_Y ) ;
  2017. }
  2018. if ( down_path == INTERP_UP )
  2019. {
  2020. c = ( dir == PACKIT )?'n':'p' ;
  2021. d = ( dir == PACKIT )?'2':'1' ;
  2022. } else {
  2023. c = ( dir == UNPACKIT )?'n':'p' ;
  2024. d = ( dir == UNPACKIT )?'2':'1' ;
  2025. }
  2026. if ( zdex >= 0 ) {
  2027. if ( xdex == 0 && zdex == 1 && ydex == 2 ) sprintf(dexes,"pig,k,pjg") ;
  2028. else if ( zdex == 0 && xdex == 1 && ydex == 2 ) sprintf(dexes,"k,pig,pjg") ;
  2029. else if ( xdex == 0 && ydex == 1 && zdex == 2 ) sprintf(dexes,"pig,pjg,k") ;
  2030. } else {
  2031. if ( xdex == 0 && ydex == 1 ) sprintf(dexes,"pig,pjg") ;
  2032. if ( ydex == 0 && xdex == 1 ) sprintf(dexes,"pjg,pig") ;
  2033. }
  2034. /* construct variable name */
  2035. if ( p->node_kind & FOURD )
  2036. {
  2037. strcpy(moredims,"") ;
  2038. for ( d1 = 3 ; d1 < p->ndims ; d1++ ) {
  2039. sprintf(temp,"idim%d",d1-2) ;
  2040. strcat(moredims,",") ; strcat(moredims,temp) ;
  2041. }
  2042. strcat(moredims,",") ;
  2043. sprintf(vname,"%s%s(%s%sitrace)",p->name,tag,dexes,moredims) ;
  2044. }
  2045. else
  2046. {
  2047. sprintf(vname,"%s%s(%s)",p->name,tag,dexes) ;
  2048. }
  2049. grid = "grid%" ;
  2050. if ( p->node_kind & FOURD )
  2051. {
  2052. grid = "" ;
  2053. fprintf(fp,"DO itrace = PARAM_FIRST_SCALAR, num_%s\n", p->name) ;
  2054. for ( d1 = p->ndims-1 ; d1 >= 3 ; d1-- ) {
  2055. strcpy(r,"") ;
  2056. range_of_dimension(r, tx, d1, p, "config_flags%" ) ;
  2057. colon = index( tx, ':' ) ; *colon = ',' ;
  2058. fprintf(fp,"DO idim%d = %s \n", d1-2, tx) ;
  2059. }
  2060. } else {
  2061. /* note that in the case if dir != UNPACKIT and down_path == INTERP_UP the data
  2062. structure being used is intermediate_grid, not grid. However, intermediate_grid
  2063. and grid share the same id (see module_dm.F) so it will not make a difference. */
  2064. #if 0
  2065. fprintf(fp,"IF ( in_use_for_config(grid%%id,'%s%s') ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c\n",p->name,tag) ;
  2066. #else
  2067. fprintf(fp,"IF ( SIZE(%s%s%s) .GT. 1 ) THEN ! okay for intermediate_grid too. see comment in gen_comms.c\n",grid,p->name,tag) ;
  2068. #endif
  2069. }
  2070. if ( dir == UNPACKIT )
  2071. {
  2072. if ( down_path == INTERP_UP )
  2073. {
  2074. char *sjl = "" ;
  2075. if ( !strcmp( p->interpu_fcn_name ,"nmm_vfeedback") ) sjl = "_v" ; /* KLUDGE FOR NCEP NESTING 20071217 */
  2076. if ( zdex >= 0 ) {
  2077. fprintf(fp,"CALL rsl_lite_from_child_msg(((%s)-(%s)+1)*RWORDSIZE,xv) ;\n",ddim[zdex][1], ddim[zdex][0] ) ;
  2078. } else {
  2079. fprintf(fp,"CALL rsl_lite_from_child_msg(RWORDSIZE,xv)\n" ) ;
  2080. }
  2081. fprintf(fp,"IF ( cd_feedback_mask%s( pig, ips_save, ipe_save , pjg, jps_save, jpe_save, %s, %s ) ) THEN\n",
  2082. sjl ,
  2083. p->stag_x?".TRUE.":".FALSE." ,p->stag_y?".TRUE.":".FALSE." ) ;
  2084. if ( zdex >= 0 ) {
  2085. fprintf(fp,"DO k = %s,%s\nNEST_INFLUENCE(%s%s,xv(k))\nENDDO\n", ddim[zdex][0], ddim[zdex][1], grid, vname ) ;
  2086. } else {
  2087. fprintf(fp,"NEST_INFLUENCE(%s%s,xv(1))\n", grid, vname ) ;
  2088. }
  2089. fprintf(fp,"ENDIF\n") ;
  2090. }
  2091. else
  2092. {
  2093. if ( zdex >= 0 ) {
  2094. fprintf(fp,"CALL rsl_lite_from_parent_msg(((%s)-(%s)+1)*RWORDSIZE,xv)\nDO k = %s,%s\n%s%s = xv(k)\nENDDO\n",
  2095. ddim[zdex][1], ddim[zdex][0], ddim[zdex][0], ddim[zdex][1], grid, vname) ;
  2096. } else {
  2097. fprintf(fp,"CALL rsl_lite_from_parent_msg(RWORDSIZE,xv)\n%s%s = xv(1)\n", grid, vname) ;
  2098. }
  2099. }
  2100. }
  2101. else
  2102. {
  2103. if ( down_path == INTERP_UP )
  2104. {
  2105. if ( zdex >= 0 ) {
  2106. fprintf(fp,"DO k = %s,%s\nxv(k)= intermediate_grid%%%s\nENDDO\nCALL rsl_lite_to_parent_msg(((%s)-(%s)+1)*RWORDSIZE,xv)\n",
  2107. ddim[zdex][0], ddim[zdex][1], vname, ddim[zdex][1], ddim[zdex][0] ) ;
  2108. } else {
  2109. fprintf(fp,"xv(1)= intermediate_grid%%%s\nCALL rsl_lite_to_parent_msg(RWORDSIZE,xv)\n", vname) ;
  2110. }
  2111. }
  2112. else
  2113. {
  2114. if ( zdex >= 0 ) {
  2115. fprintf(fp,"DO k = %s,%s\nxv(k)= %s%s\nENDDO\nCALL rsl_lite_to_child_msg(((%s)-(%s)+1)*RWORDSIZE,xv)\n",
  2116. ddim[zdex][0], ddim[zdex][1], grid, vname, ddim[zdex][1], ddim[zdex][0] ) ;
  2117. } else {
  2118. fprintf(fp,"xv(1)=%s%s\nCALL rsl_lite_to_child_msg(RWORDSIZE,xv)\n", grid, vname) ;
  2119. }
  2120. }
  2121. }
  2122. if ( p->node_kind & FOURD )
  2123. {
  2124. for ( d1 = p->ndims-1 ; d1 >= 3 ; d1-- ) {
  2125. fprintf(fp,"ENDDO\n") ;
  2126. }
  2127. fprintf(fp,"ENDDO\n") ;
  2128. }
  2129. else
  2130. {
  2131. fprintf(fp,"ENDIF\n") ; /* in_use_for_config */
  2132. }
  2133. }
  2134. }
  2135. return(0) ;
  2136. }
  2137. /*****************/
  2138. /* STOPPED HERE -- need to include the extra dimensions in the count */
  2139. int
  2140. count_fields ( node_t * node , int * d2 , int * d3 , char * fourd_names, int down_path )
  2141. {
  2142. node_t * p ;
  2143. int zdex ;
  2144. char temp[80], r[10], tx[80], *colon ;
  2145. int d ;
  2146. strcpy(fourd_names,"") ; /* only works if non-recursive, but that is ifdefd out below */
  2147. /* count up the total number of levels from all fields */
  2148. for ( p = node ; p != NULL ; p = p->next )
  2149. {
  2150. if ( p->node_kind == FOURD )
  2151. {
  2152. #if 0
  2153. count_fields( p->members , d2 , d3 , down_path ) ; /* RECURSE */
  2154. #else
  2155. if ( strlen(fourd_names) > 0 ) strcat(fourd_names," & \n + ") ;
  2156. sprintf(temp,"((num_%s - PARAM_FIRST_SCALAR + 1)",p->name) ;
  2157. strcat(fourd_names,temp) ;
  2158. for ( d = 3 ; d < p->ndims ; d++ ) {
  2159. strcpy(r,"") ;
  2160. range_of_dimension(r,tx,d,p,"config_flags%") ;
  2161. colon = index(tx,':') ; *colon = '\0' ;
  2162. sprintf(temp," &\n *((%s)-(%s)+1)",colon+1,tx) ;
  2163. strcat(fourd_names,temp) ;
  2164. }
  2165. strcat(fourd_names,")") ;
  2166. #endif
  2167. }
  2168. else
  2169. {
  2170. if ( p->nest_mask & down_path )
  2171. {
  2172. if ( p->node_kind == FOURD )
  2173. zdex = get_index_for_coord( p->members , COORD_Z ) ;
  2174. else
  2175. zdex = get_index_for_coord( p , COORD_Z ) ;
  2176. if ( zdex < 0 ) {
  2177. (*d2)++ ; /* if no zdex then only 2 d */
  2178. } else {
  2179. (*d3)++ ; /* if has a zdex then 3 d */
  2180. }
  2181. }
  2182. }
  2183. }
  2184. return(0) ;
  2185. }
  2186. /*****************/
  2187. /*****************/
  2188. int
  2189. gen_debug ( char * dirname )
  2190. {
  2191. int i ;
  2192. FILE * fp ;
  2193. node_t *p, *q, *dimd ;
  2194. char **direction ;
  2195. char *directions[] = { "x", "y", 0L } ;
  2196. char fname[NAMELEN], vname[NAMELEN] ;
  2197. char indices[NAMELEN], post[NAMELEN], tmp3[NAMELEN] ;
  2198. int zdex ;
  2199. node_t Shift ;
  2200. int said_it = 0 ;
  2201. int said_it2 = 0 ;
  2202. if ( dirname == NULL ) return(1) ;
  2203. if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/debuggal.inc",dirname) ; }
  2204. else { sprintf(fname,"debuggal.inc") ; }
  2205. if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
  2206. /* now generate the shifts themselves */
  2207. for ( p = Domain.fields ; p != NULL ; p = p->next )
  2208. {
  2209. /* special cases in WRF */
  2210. if ( !strcmp( p->name , "xf_ens" ) || !strcmp( p->name , "pr_ens" ) ||
  2211. !strcmp( p->name , "abstot" ) || !strcmp( p->name , "absnxt" ) ||
  2212. !strcmp( p->name , "emstot" ) || !strcmp( p->name , "obs_savwt" ) ) {
  2213. continue ;
  2214. }
  2215. if (( p->node_kind & (FIELD | FOURD) ) && p->ndims >= 2 && ! p->boundary_array )
  2216. {
  2217. if ( p->type->type_type == SIMPLE )
  2218. {
  2219. for ( i = 1 ; i <= p->ntl ; i++ )
  2220. {
  2221. if ( p->ntl > 1 ) sprintf(vname,"%s_%d",p->name,i ) ;
  2222. else sprintf(vname,"%s",p->name ) ;
  2223. if ( p->node_kind & FOURD )
  2224. {
  2225. #if 0
  2226. node_t *member ;
  2227. zdex = get_index_for_coord( p , COORD_Z ) ;
  2228. if ( zdex >=1 && zdex <= 3 && strncmp(vname,"fdda",4) )
  2229. {
  2230. fprintf(fp, " DO itrace = PARAM_FIRST_SCALAR, num_%s\n", p->name ) ;
  2231. fprintf(fp, " write(0,*) AAA_AAA,BBB_BBB, '%s ', itrace , %s ( IDEBUG,KDEBUG,JDEBUG,itrace)\n", vname, vname ) ;
  2232. fprintf(fp, " ENDDO\n" ) ;
  2233. }
  2234. else
  2235. {
  2236. fprintf(stderr,"WARNING: %d some dimension info missing for 4d array %s\n",zdex,t2) ;
  2237. }
  2238. #endif
  2239. }
  2240. else
  2241. {
  2242. if ( p->ndims == 3 ) {
  2243. fprintf(fp, " write(0,*) AAA_AAA,BBB_BBB, '%s ', grid%%%s ( IDEBUG,KDEBUG,JDEBUG)\n", vname, vname ) ;
  2244. } else if ( p->ndims == 2 ) {
  2245. fprintf(fp, " write(0,*) AAA_AAA,BBB_BBB, '%s ', grid%%%s ( IDEBUG,JDEBUG)\n", vname, vname ) ;
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. }
  2252. close_the_file(fp) ;
  2253. }
  2254. /*****************/
  2255. /*****************/
  2256. int
  2257. gen_comms ( char * dirname )
  2258. {
  2259. FILE *fpsub ;
  2260. if ( sw_dm_parallel )
  2261. fprintf(stderr,"ADVISORY: RSL_LITE version of gen_comms is linked in with registry program.\n") ;
  2262. /* truncate this file if it exists */
  2263. if ((fpsub = fopen( "inc/REGISTRY_COMM_NESTING_DM_subs.inc" , "w" )) != NULL ) fclose(fpsub) ;
  2264. if ((fpsub = fopen( "inc/REGISTRY_COMM_DM_subs.inc" , "w" )) != NULL ) fclose(fpsub) ;
  2265. if ((fpsub = fopen( "inc/REGISTRY_COMM_DM_0_subs.inc" , "w" )) != NULL ) fclose(fpsub) ;
  2266. if ((fpsub = fopen( "inc/REGISTRY_COMM_DM_1_subs.inc" , "w" )) != NULL ) fclose(fpsub) ;
  2267. if ((fpsub = fopen( "inc/REGISTRY_COMM_DM_2_subs.inc" , "w" )) != NULL ) fclose(fpsub) ;
  2268. if ((fpsub = fopen( "inc/REGISTRY_COMM_DM_3_subs.inc" , "w" )) != NULL ) fclose(fpsub) ;
  2269. gen_halos( "inc" , NULL, Halos, 1 ) ;
  2270. gen_shift( "inc" ) ;
  2271. gen_periods( "inc", Periods ) ;
  2272. gen_swaps( "inc", Swaps ) ;
  2273. gen_cycles( "inc", Cycles ) ;
  2274. gen_xposes( "inc" ) ;
  2275. gen_comm_descrips( "inc" ) ;
  2276. gen_datacalls( "inc" ) ;
  2277. gen_nest_packing( "inc" ) ;
  2278. #if 0
  2279. gen_debug( "inc" ) ;
  2280. #endif
  2281. return(0) ;
  2282. }