6 # define O_CREAT _O_CREAT
9 # define O_WRONLY _O_WRONLY
12 # define O_TRUNC _O_TRUNC
20 #ifdef NCEP_DEBUG_MULTIDIR
21 // # include <errno.h>
24 #define STANDARD_ERROR 2
26 #define STANDARD_OUTPUT 1
35 #define ORIG_RSL_CUTOFF 10000
37 void RSL_LITE_ERROR_DUP1 ( int *me
, int *size
)
44 /* redirect standard out and standard error based on compile options*/
46 #ifndef NCEP_DEBUG_MULTIDIR
47 gethostname( hostname
, 256 ) ;
49 /* redirect standard out*/
51 if ( *size
< ORIG_RSL_CUTOFF
)
53 sprintf(filename
,"rsl.out.%04d",*me
) ;
57 sprintf(filename
,"rsl.out.%08d",*me
) ;
62 if ( *size
< ORIG_RSL_CUTOFF
)
64 sprintf(filename
,"rsl.out.%04d",*me
) ;
67 sprintf(filename
,"rsl.out.%08d",*me
) ;
72 sprintf(filename
,"/dev/null") ;
75 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
77 perror("error_dup: cannot open rsl.out.nnnn") ;
78 fprintf(stderr
,"...sending output to standard output and continuing.\n") ;
81 if( dup2( newfd
, STANDARD_OUTPUT
) < 0 )
83 perror("error_dup: dup2 fails to change output descriptor") ;
84 fprintf(stderr
,"...sending output to standard output and continuing.\n") ;
89 /* redirect standard error */
90 # if defined( _WIN32 )
91 if ( *me
!= 0 ) { /* stderr from task 0 should come to screen on windows because it is buffered if redirected */
94 if ( *size
< ORIG_RSL_CUTOFF
)
96 sprintf(filename
,"rsl.error.%04d",*me
) ;
100 sprintf(filename
,"rsl.error.%08d",*me
) ;
105 if ( *size
< ORIG_RSL_CUTOFF
)
107 sprintf(filename
,"rsl.error.%04d",*me
) ;
110 sprintf(filename
,"rsl.error.%08d",*me
) ;
115 sprintf(filename
,"/dev/null") ;
118 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
120 perror("error_dup: cannot open rsl.error.log") ;
121 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
124 if( dup2( newfd
, STANDARD_ERROR
) < 0 )
126 perror("error_dup: dup2 fails to change error descriptor") ;
127 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
131 fprintf( stdout
, "taskid: %d hostname: %s\n",*me
,hostname
) ;
132 fprintf( stderr
, "taskid: %d hostname: %s\n",*me
,hostname
) ;
133 # if defined( _WIN32 )
137 # ifndef NCEP_DEBUG_GLOBALSTDOUT
139 /*create TASKOUTPUT directory to contain separate task owned output directories*/
141 /* let task 0 create the subdirectory path for the task directories */
145 sprintf(dirname
, "%s","TASKOUTPUT");
146 rc
= mkdir(dirname
, 0777);
147 if ( rc
!= 0 && errno
==EEXIST
) rc
=0;
150 /* If TASKOUTPUT directory is not created then return */
152 MPI_Bcast(&rc
, 1, MPI_INTEGER
, 0, MPI_COMM_WORLD
);
156 perror("mkdir error");
157 fprintf(stderr
, "mkdir failed for directory %s on task %d. Sending error/output to stderr/stdout for all tasks and continuing.\n", dirname
, *me
);
165 /* TASKOUTPUT directory exists, continue with task specific directory */
167 if ( *size
< ORIG_RSL_CUTOFF
)
169 sprintf(dirname
, "TASKOUTPUT/%04d", *me
);
173 sprintf(dirname
, "TASKOUTPUT/%08d", *me
);
175 rc
=mkdir(dirname
, 0777);
176 if ( rc
!=0 && errno
!=EEXIST
) {
177 perror("mkdir error");
178 fprintf(stderr
, "mkdir failed for directory %s on task %d. Sending error/output to stderr/stdout and continuing.\n", dirname
, *me
);
182 /* Each tasks creates/opens its own output and error files */
184 if ( *size
< ORIG_RSL_CUTOFF
)
186 sprintf(filename
, "%s/%04d/rsl.out.%04d","TASKOUTPUT",*me
,*me
) ;
190 sprintf(filename
, "%s/%08d/rsl.out.%08d","TASKOUTPUT",*me
,*me
) ;
193 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
195 perror("error_dup: cannot open ./TASKOUTPUT/nnnn/rsl.out.nnnn") ;
196 fprintf(stderr
,"...sending output to standard output and continuing.\n")
200 if( dup2( newfd
, STANDARD_OUTPUT
) < 0 )
202 perror("error_dup: dup2 fails to change output descriptor") ;
203 fprintf(stderr
,"...sending output to standard output and continuing.\n");
208 if ( *size
< ORIG_RSL_CUTOFF
)
210 sprintf(filename
, "%s/%04d/rsl.error.%04d","TASKOUTPUT",*me
,*me
) ;
214 sprintf(filename
, "%s/%08d/rsl.error.%08d","TASKOUTPUT",*me
,*me
) ;
216 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
218 perror("error_dup: cannot open ./TASKOUTPUT/nnnn/rsl.error.nnnn") ;
219 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
222 if( dup2( newfd
, STANDARD_ERROR
) < 0 )
224 perror("error_dup: dup2 fails to change error descriptor") ;
225 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
230 /* Each task writes to global standard error and standard out */
239 /* Windows doesn't have a gethostid function so add a stub.
240 TODO: Create a version that will work on Windows. */
249 RSL_LITE_GET_HOSTNAME ( char * hn
, int * size
, int *n
, int *hostid
)
254 if ( gethostname(temp
,512) ) return(1) ;
256 for ( p
= temp
, q
= hn
, i
= 0 ; *p
&& i
< *size
&& i
< 512 ; i
++ , p
++ , q
++ ) { *q
= *p
; }
263 BYTE_BCAST ( char * buf
, int * size
, int * Fcomm
)
266 MPI_Comm
*comm
, dummy_comm
;
269 *comm
= MPI_Comm_f2c( *Fcomm
) ;
271 if (*size
% sizeof(int) == 0) {
272 MPI_Bcast ( buf
, *size
/sizeof(int), MPI_INT
, 0, *comm
) ;
274 MPI_Bcast ( buf
, *size
, MPI_BYTE
, 0, *comm
) ;
277 MPI_Bcast ( buf
, *size
, MPI_BYTE
, 0, *comm
) ;
283 BYTE_BCAST_FROM_ROOT ( char * buf
, int * size
, int *root
, int * Fcomm
)
286 MPI_Comm
*comm
, dummy_comm
;
289 *comm
= MPI_Comm_f2c( *Fcomm
) ;
291 if (*size
% sizeof(int) == 0) {
292 MPI_Bcast ( buf
, *size
/sizeof(int), MPI_INT
, *root
, *comm
) ;
294 MPI_Bcast ( buf
, *size
, MPI_BYTE
, *root
, *comm
) ;
297 MPI_Bcast ( buf
, *size
, MPI_BYTE
, *root
, *comm
) ;
302 static int yp_curs
, ym_curs
, xp_curs
, xm_curs
;
303 static int yp_curs_recv
, ym_curs_recv
, xp_curs_recv
, xm_curs_recv
;
308 int * shw0
, int * xy0
,
309 int *sendbegm0
, int * sendwm0
, int * sendbegp0
, int * sendwp0
,
310 int *recvbegm0
, int * recvwm0
, int * recvbegp0
, int * recvwp0
,
311 int * n3dR0
, int *n2dR0
, int * typesizeR0
,
312 int * n3dI0
, int *n2dI0
, int * typesizeI0
,
313 int * n3dD0
, int *n2dD0
, int * typesizeD0
,
314 int * n3dL0
, int *n2dL0
, int * typesizeL0
,
315 int * me0
, int * np0
, int * np_x0
, int * np_y0
,
316 int * ips0
, int * ipe0
, int * jps0
, int * jpe0
, int * kps0
, int * kpe0
)
318 int n3dR
, n2dR
, typesizeR
;
319 int n3dI
, n2dI
, typesizeI
;
320 int n3dD
, n2dD
, typesizeD
;
321 int n3dL
, n2dL
, typesizeL
;
323 int sendbegm
, sendwm
, sendbegp
, sendwp
;
324 int recvbegm
, recvwm
, recvbegp
, recvwp
;
325 int me
, np
, np_x
, np_y
;
326 int ips
, ipe
, jps
, jpe
, kps
, kpe
;
330 int nbytes_x_recv
= 0, nbytes_y_recv
= 0 ;
333 MPI_Comm comm
, *comm0
, dummy_comm
;
335 comm0
= &dummy_comm
;
336 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
338 shw
= *shw0
; /* logical half-width of stencil */
339 xy
= *xy0
; /* 0 = y , 1 = x */
340 sendbegm
= *sendbegm0
; /* send index of sten copy (edge = 1), lower/left */
341 sendwm
= *sendwm0
; /* send width of sten copy counting towards edge, lower/left */
342 sendbegp
= *sendbegp0
; /* send index of sten copy (edge = 1), upper/right */
343 sendwp
= *sendwp0
; /* send width of sten copy counting towards edge, upper/right */
344 recvbegm
= *recvbegm0
; /* recv index of sten copy (edge = 1), lower/left */
345 recvwm
= *recvwm0
; /* recv width of sten copy counting towards edge, lower/left */
346 recvbegp
= *recvbegp0
; /* recv index of sten copy (edge = 1), upper/right */
347 recvwp
= *recvwp0
; /* recv width of sten copy counting towards edge, upper/right */
348 n3dR
= *n3dR0
; n2dR
= *n2dR0
; typesizeR
= *typesizeR0
;
349 n3dI
= *n3dI0
; n2dI
= *n2dI0
; typesizeI
= *typesizeI0
;
350 n3dD
= *n3dD0
; n2dD
= *n2dD0
; typesizeD
= *typesizeD0
;
351 n3dL
= *n3dL0
; n2dL
= *n2dL0
; typesizeL
= *typesizeL0
;
352 me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
353 ips
= *ips0
-1 ; ipe
= *ipe0
-1 ; jps
= *jps0
-1 ; jpe
= *jpe0
-1 ; kps
= *kps0
-1 ; kpe
= *kpe0
-1 ;
355 yp_curs_recv
= 0 ; ym_curs_recv
= 0 ;
356 xp_curs_recv
= 0 ; xm_curs_recv
= 0 ;
358 if ( xy
== 0 && np_y
> 1 ) {
359 nbytes
= typesizeR
*(ipe
-ips
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
360 typesizeI
*(ipe
-ips
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
361 typesizeD
*(ipe
-ips
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
362 typesizeL
*(ipe
-ips
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
364 typesizeR
*(ipe
-ips
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
365 typesizeI
*(ipe
-ips
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
366 typesizeD
*(ipe
-ips
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
367 typesizeL
*(ipe
-ips
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
368 MPI_Cart_shift ( *comm0
, 0, 1, &ym
, &yp
) ;
369 if ( yp
!= MPI_PROC_NULL
) {
370 buffer_for_proc ( yp
, nbytes_y_recv
, RSL_RECVBUF
) ;
371 buffer_for_proc ( yp
, nbytes
, RSL_SENDBUF
) ;
373 if ( ym
!= MPI_PROC_NULL
) {
374 buffer_for_proc ( ym
, nbytes_y_recv
, RSL_RECVBUF
) ;
375 buffer_for_proc ( ym
, nbytes
, RSL_SENDBUF
) ;
378 if ( xy
== 1 && np_x
> 1 ) {
379 nbytes
= typesizeR
*(jpe
-jps
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
380 typesizeI
*(jpe
-jps
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
381 typesizeD
*(jpe
-jps
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
382 typesizeL
*(jpe
-jps
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
384 typesizeR
*(jpe
-jps
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
385 typesizeI
*(jpe
-jps
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
386 typesizeD
*(jpe
-jps
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
387 typesizeL
*(jpe
-jps
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
388 MPI_Cart_shift ( *comm0
, 1, 1, &xm
, &xp
) ;
389 if ( xp
!= MPI_PROC_NULL
) {
390 buffer_for_proc ( xp
, nbytes_x_recv
, RSL_RECVBUF
) ;
391 buffer_for_proc ( xp
, nbytes
, RSL_SENDBUF
) ;
393 if ( xm
!= MPI_PROC_NULL
) {
394 buffer_for_proc ( xm
, nbytes_x_recv
, RSL_RECVBUF
) ;
395 buffer_for_proc ( xm
, nbytes
, RSL_SENDBUF
) ;
399 yp_curs
= 0 ; ym_curs
= 0 ; xp_curs
= 0 ; xm_curs
= 0 ;
400 yp_curs_recv
= nbytes_y_recv
; ym_curs_recv
= nbytes_y_recv
;
401 xp_curs_recv
= nbytes_x_recv
; xm_curs_recv
= nbytes_x_recv
;
405 RSL_LITE_PACK ( int * Fcomm0
, char * buf
, int * shw0
,
406 int * sendbegm0
, int * sendwm0
, int * sendbegp0
, int * sendwp0
,
407 int * recvbegm0
, int * recvwm0
, int * recvbegp0
, int * recvwp0
,
408 int * typesize0
, int * xy0
, int * pu0
, int * imemord
, int * xstag0
, /* not used */
409 int *me0
, int * np0
, int * np_x0
, int * np_y0
,
410 int * ids0
, int * ide0
, int * jds0
, int * jde0
, int * kds0
, int * kde0
,
411 int * ims0
, int * ime0
, int * jms0
, int * jme0
, int * kms0
, int * kme0
,
412 int * ips0
, int * ipe0
, int * jps0
, int * jpe0
, int * kps0
, int * kpe0
)
414 int me
, np
, np_x
, np_y
;
415 int sendbegm
, sendwm
, sendbegp
, sendwp
;
416 int recvbegm
, recvwm
, recvbegp
, recvwp
;
418 int ids
, ide
, jds
, jde
, kds
, kde
;
419 int ims
, ime
, jms
, jme
, kms
, kme
;
420 int ips
, ipe
, jps
, jpe
, kps
, kpe
;
421 int xy
; /* y = 0 , x = 1 */
422 int pu
; /* pack = 0 , unpack = 1 */
423 register int i
, j
, k
, t
;
425 register int i2
,i3
,i4
,i_offset
;
431 register int *pi
, *qi
;
434 MPI_Comm comm
, *comm0
, dummy_comm
;
435 int js
, je
, ks
, ke
, is
, ie
, wcount
;
437 comm0
= &dummy_comm
;
438 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
440 shw
= *shw0
; /* logical half-width of stencil */
441 sendbegm
= *sendbegm0
; /* send index of sten copy (edge = 1), lower/left */
442 sendwm
= *sendwm0
; /* send width of sten copy counting towards edge, lower/left */
443 sendbegp
= *sendbegp0
; /* send index of sten copy (edge = 1), upper/right */
444 sendwp
= *sendwp0
; /* send width of sten copy counting towards edge, upper/right */
445 recvbegm
= *recvbegm0
; /* recv index of sten copy (edge = 1), lower/left */
446 recvwm
= *recvwm0
; /* recv width of sten copy counting towards edge, lower/left */
447 recvbegp
= *recvbegp0
; /* recv index of sten copy (edge = 1), upper/right */
448 recvwp
= *recvwp0
; /* recv width of sten copy counting towards edge, upper/right */
449 me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
450 typesize
= *typesize0
;
451 ids
= *ids0
-1 ; ide
= *ide0
-1 ; jds
= *jds0
-1 ; jde
= *jde0
-1 ; kds
= *kds0
-1 ; kde
= *kde0
-1 ;
452 ims
= *ims0
-1 ; ime
= *ime0
-1 ; jms
= *jms0
-1 ; jme
= *jme0
-1 ; kms
= *kms0
-1 ; kme
= *kme0
-1 ;
453 ips
= *ips0
-1 ; ipe
= *ipe0
-1 ; jps
= *jps0
-1 ; jpe
= *jpe0
-1 ; kps
= *kps0
-1 ; kpe
= *kpe0
-1 ;
457 /* need to adapt for other memory orders */
459 #define RANGE(S1,E1,S2,E2,S3,E3,S4,E4) (((E1)-(S1)+1)*((E2)-(S2)+1)*((E3)-(S3)+1)*((E4)-(S4)+1))
460 #define IMAX(A) (((A)>ids)?(A):ids)
461 #define IMIN(A) (((A)<ide)?(A):ide)
462 #define JMAX(A) (((A)>jds)?(A):jds)
463 #define JMIN(A) (((A)<jde)?(A):jde)
465 da_buf
= ( pu
== 0 ) ? RSL_SENDBUF
: RSL_RECVBUF
;
467 if ( ips
<= ipe
&& jps
<= jpe
) {
469 if ( np_y
> 1 && xy
== 0 ) {
470 MPI_Cart_shift( *comm0
, 0, 1, &ym
, &yp
) ;
471 if ( yp
!= MPI_PROC_NULL
&& jpe
<= jde
&& jde
!= jpe
) {
472 p
= buffer_for_proc( yp
, 0 , da_buf
) ;
475 je
= jpe
- sendbegp
+ 1 ; js
= je
- sendwp
+ 1 ;
476 ks
= kps
; ke
= kpe
;
477 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
478 nbytes
= buffer_size_for_proc( yp
, da_buf
) ;
479 if ( yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
481 fprintf(stderr
,"memory overwrite in rsl_lite_pack, Y pack up, %d > %d\n",
482 yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
484 MPI_Abort(MPI_COMM_WORLD
, 99) ;
486 if ( typesize
== 8 ) {
487 F_PACK_LINT ( (long *)buf
, (long *)(p
+yp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
488 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
489 yp_curs
+= wcount
*typesize
;
491 else if ( typesize
== 4 ) {
492 F_PACK_INT ( (int * )buf
, (int * )(p
+yp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
493 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
494 yp_curs
+= wcount
*typesize
;
498 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
504 js
= jpe
+recvbegp
; je
= js
+ recvwp
- 1 ;
505 ks
= kps
; ke
= kpe
;
506 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
507 if ( typesize
== 8 ) {
508 F_UNPACK_LINT ( (long *)(p
+yp_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
509 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
510 yp_curs
+= wcount
*typesize
;
512 else if ( typesize
== 4 ) {
513 F_UNPACK_INT ( (int * )(p
+yp_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
514 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
515 yp_curs
+= wcount
*typesize
;
519 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
525 if ( ym
!= MPI_PROC_NULL
&& jps
>= jds
&& jps
!= jds
) {
526 p
= buffer_for_proc( ym
, 0 , da_buf
) ;
529 js
= jps
+sendbegm
-1 ; je
= js
+ sendwm
-1 ;
530 ks
= kps
; ke
= kpe
;
531 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
532 nbytes
= buffer_size_for_proc( ym
, da_buf
) ;
533 if ( ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
535 fprintf(stderr
,"memory overwrite in rsl_lite_pack, Y pack dn, %d > %d\n",
536 ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
538 MPI_Abort(MPI_COMM_WORLD
, 99) ;
540 if ( typesize
== 8 ) {
541 F_PACK_LINT ( (long *)buf
, (long *)(p
+ym_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
542 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
543 ym_curs
+= wcount
*typesize
;
545 else if ( typesize
== 4 ) {
546 F_PACK_INT ( (int * )buf
, (int * )(p
+ym_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
547 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
548 ym_curs
+= wcount
*typesize
;
552 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
558 je
= jps
-recvbegm
; js
= je
- recvwm
+ 1 ;
559 ks
= kps
; ke
= kpe
;
560 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
561 if ( typesize
== 8 ) {
562 F_UNPACK_LINT ( (long *)(p
+ym_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
563 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
564 ym_curs
+= wcount
*typesize
;
566 else if ( typesize
== 4 ) {
567 F_UNPACK_INT ( (int * )(p
+ym_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
568 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
569 ym_curs
+= wcount
*typesize
;
573 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
581 if ( np_x
> 1 && xy
== 1 ) {
582 MPI_Cart_shift( *comm0
, 1, 1, &xm
, &xp
) ;
583 if ( xp
!= MPI_PROC_NULL
&& ipe
<= ide
&& ide
!= ipe
) {
584 p
= buffer_for_proc( xp
, 0 , da_buf
) ;
587 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
588 ks
= kps
; ke
= kpe
;
589 ie
= ipe
- sendbegp
+ 1 ; is
= ie
- sendwp
+ 1 ;
590 nbytes
= buffer_size_for_proc( xp
, da_buf
) ;
591 if ( xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
) > nbytes
) {
593 fprintf(stderr
,"memory overwrite in rsl_lite_pack, X pack right, %d > %d\n",
594 xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
), nbytes
) ;
596 MPI_Abort(MPI_COMM_WORLD
, 99) ;
598 if ( typesize
== 8 ) {
599 F_PACK_LINT ( (long *)buf
, (long *)(p
+xp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
600 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
601 xp_curs
+= wcount
*typesize
;
603 else if ( typesize
== 4 ) {
604 F_PACK_INT ( (int * )buf
, (int * )(p
+xp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
605 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
606 xp_curs
+= wcount
*typesize
;
610 fprintf(stderr
,"A internal error: %s %d\n",__FILE__
,__LINE__
) ;
616 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
617 ks
= kps
; ke
= kpe
;
618 is
= ipe
+recvbegp
; ie
= is
+ recvwp
- 1 ;
619 if ( typesize
== 8 ) {
620 F_UNPACK_LINT ( (long *)(p
+xp_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
621 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
622 xp_curs
+= wcount
*typesize
;
624 else if ( typesize
== 4 ) {
625 F_UNPACK_INT ( (int * )(p
+xp_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
626 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
627 xp_curs
+= wcount
*typesize
;
631 fprintf(stderr
,"B internal error: %s %d\n",__FILE__
,__LINE__
) ;
632 fprintf(stderr
," stenbeg %d stenw %d \n",is
,ie
) ;
633 fprintf(stderr
," is %d ie %d \n",is
,ie
) ;
639 if ( xm
!= MPI_PROC_NULL
&& ips
>= ids
&& ids
!= ips
) {
640 p
= buffer_for_proc( xm
, 0 , da_buf
) ;
643 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
644 ks
= kps
; ke
= kpe
;
645 is
= ips
+sendbegm
-1 ; ie
= is
+ sendwm
-1 ;
646 nbytes
= buffer_size_for_proc( xm
, da_buf
) ;
647 if ( xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
) > nbytes
) {
649 fprintf(stderr
,"memory overwrite in rsl_lite_pack, X left , %d > %d\n",
650 xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
), nbytes
) ;
652 MPI_Abort(MPI_COMM_WORLD
, 99) ;
654 if ( typesize
== 8 ) {
655 F_PACK_LINT ( (long *)buf
, (long *)(p
+xm_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
656 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
657 xm_curs
+= wcount
*typesize
;
659 else if ( typesize
== 4 ) {
660 F_PACK_INT ( (int * )buf
, (int * )(p
+xm_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
661 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
662 xm_curs
+= wcount
*typesize
;
666 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
672 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
673 ks
= kps
; ke
= kpe
;
674 ie
= ips
-recvbegm
; is
= ie
- recvwm
+ 1 ;
675 if ( typesize
== 8 ) {
676 F_UNPACK_LINT ( (long *)(p
+xm_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
677 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
678 xm_curs
+= wcount
*typesize
;
680 else if ( typesize
== 4 ) {
681 F_UNPACK_INT ( (int * )(p
+xm_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
682 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
683 xm_curs
+= wcount
*typesize
;
687 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
701 RSL_LITE_PACK_AD ( int * Fcomm0
, char * buf
, int * shw0
,
702 int * sendbegm0
, int * sendwm0
, int * sendbegp0
, int * sendwp0
,
703 int * recvbegm0
, int * recvwm0
, int * recvbegp0
, int * recvwp0
,
704 int * typesize0
, int * xy0
, int * pu0
, int * imemord
, int * xstag0
, /* not used */
705 int *me0
, int * np0
, int * np_x0
, int * np_y0
,
706 int * ids0
, int * ide0
, int * jds0
, int * jde0
, int * kds0
, int * kde0
,
707 int * ims0
, int * ime0
, int * jms0
, int * jme0
, int * kms0
, int * kme0
,
708 int * ips0
, int * ipe0
, int * jps0
, int * jpe0
, int * kps0
, int * kpe0
)
710 int me
, np
, np_x
, np_y
;
711 int sendbegm
, sendwm
, sendbegp
, sendwp
;
712 int recvbegm
, recvwm
, recvbegp
, recvwp
;
714 int ids
, ide
, jds
, jde
, kds
, kde
;
715 int ims
, ime
, jms
, jme
, kms
, kme
;
716 int ips
, ipe
, jps
, jpe
, kps
, kpe
;
717 int xy
; /* y = 0 , x = 1 */
718 int pu
; /* pack = 0 , unpack = 1 */
719 register int i
, j
, k
, t
;
721 register int i2
,i3
,i4
,i_offset
;
727 register int *pi
, *qi
;
730 MPI_Comm comm
, *comm0
, dummy_comm
;
731 int js
, je
, ks
, ke
, is
, ie
, wcount
;
733 comm0
= &dummy_comm
;
734 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
736 shw
= *shw0
; /* logical half-width of stencil */
737 sendbegm
= *sendbegm0
; /* send index of sten copy (edge = 1), lower/left */
738 sendwm
= *sendwm0
; /* send width of sten copy counting towards edge, lower/left */
739 sendbegp
= *sendbegp0
; /* send index of sten copy (edge = 1), upper/right */
740 sendwp
= *sendwp0
; /* send width of sten copy counting towards edge, upper/right */
741 recvbegm
= *recvbegm0
; /* recv index of sten copy (edge = 1), lower/left */
742 recvwm
= *recvwm0
; /* recv width of sten copy counting towards edge, lower/left */
743 recvbegp
= *recvbegp0
; /* recv index of sten copy (edge = 1), upper/right */
744 recvwp
= *recvwp0
; /* recv width of sten copy counting towards edge, upper/right */
745 me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
746 typesize
= *typesize0
;
747 ids
= *ids0
-1 ; ide
= *ide0
-1 ; jds
= *jds0
-1 ; jde
= *jde0
-1 ; kds
= *kds0
-1 ; kde
= *kde0
-1 ;
748 ims
= *ims0
-1 ; ime
= *ime0
-1 ; jms
= *jms0
-1 ; jme
= *jme0
-1 ; kms
= *kms0
-1 ; kme
= *kme0
-1 ;
749 ips
= *ips0
-1 ; ipe
= *ipe0
-1 ; jps
= *jps0
-1 ; jpe
= *jpe0
-1 ; kps
= *kps0
-1 ; kpe
= *kpe0
-1 ;
753 /* need to adapt for other memory orders */
755 #define RANGE(S1,E1,S2,E2,S3,E3,S4,E4) (((E1)-(S1)+1)*((E2)-(S2)+1)*((E3)-(S3)+1)*((E4)-(S4)+1))
756 #define IMAX(A) (((A)>ids)?(A):ids)
757 #define IMIN(A) (((A)<ide)?(A):ide)
758 #define JMAX(A) (((A)>jds)?(A):jds)
759 #define JMIN(A) (((A)<jde)?(A):jde)
761 da_buf
= ( pu
== 0 ) ? RSL_SENDBUF
: RSL_RECVBUF
;
763 if ( ips
<= ipe
&& jps
<= jpe
) {
765 if ( np_y
> 1 && xy
== 0 ) {
766 MPI_Cart_shift( *comm0
, 0, 1, &ym
, &yp
) ;
767 if ( yp
!= MPI_PROC_NULL
&& jpe
<= jde
&& jde
!= jpe
) {
768 p
= buffer_for_proc( yp
, 0 , da_buf
) ;
771 je
= jpe
- sendbegp
+ 1 ; js
= je
- sendwp
+ 1 ;
772 ks
= kps
; ke
= kpe
;
773 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
774 nbytes
= buffer_size_for_proc( yp
, da_buf
) ;
775 if ( yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
777 fprintf(stderr
,"memory overwrite in rsl_lite_pack_ad, Y pack up, %d > %d\n",
778 yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
780 MPI_Abort(MPI_COMM_WORLD
, 99) ;
782 if ( typesize
== 8 ) {
783 F_UNPACK_LINT_AD ( (long *)(p
+yp_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
784 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
785 yp_curs
+= wcount
*typesize
;
787 else if ( typesize
== 4 ) {
788 F_UNPACK_INT_AD ( (int * )(p
+yp_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
789 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
790 yp_curs
+= wcount
*typesize
;
794 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
800 js
= jpe
+recvbegp
; je
= js
+ recvwp
- 1 ;
801 ks
= kps
; ke
= kpe
;
802 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
803 if ( typesize
== 8 ) {
804 F_PACK_LINT_AD ( (long *)buf
, (long *)(p
+yp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
805 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
806 yp_curs
+= wcount
*typesize
;
808 else if ( typesize
== 4 ) {
809 F_PACK_INT_AD ( (int * )buf
, (int * )(p
+yp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
810 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
811 yp_curs
+= wcount
*typesize
;
815 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
821 if ( ym
!= MPI_PROC_NULL
&& jps
>= jds
&& jps
!= jds
) {
822 p
= buffer_for_proc( ym
, 0 , da_buf
) ;
825 js
= jps
+sendbegm
-1 ; je
= js
+ sendwm
-1 ;
826 ks
= kps
; ke
= kpe
;
827 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
828 nbytes
= buffer_size_for_proc( ym
, da_buf
) ;
829 if ( ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
831 fprintf(stderr
,"memory overwrite in rsl_lite_pack_ad, Y pack dn, %d > %d\n",
832 ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
834 MPI_Abort(MPI_COMM_WORLD
, 99) ;
836 if ( typesize
== 8 ) {
837 F_UNPACK_LINT_AD ( (long *)(p
+ym_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
838 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
839 ym_curs
+= wcount
*typesize
;
841 else if ( typesize
== 4 ) {
842 F_UNPACK_INT_AD ( (int * )(p
+ym_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
843 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
844 ym_curs
+= wcount
*typesize
;
848 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
854 je
= jps
-recvbegm
; js
= je
- recvwm
+ 1 ;
855 ks
= kps
; ke
= kpe
;
856 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
857 if ( typesize
== 8 ) {
858 F_PACK_LINT_AD ( (long *)buf
, (long *)(p
+ym_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
859 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
860 ym_curs
+= wcount
*typesize
;
862 else if ( typesize
== 4 ) {
863 F_PACK_INT_AD ( (int * )buf
, (int * )(p
+ym_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
864 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
865 ym_curs
+= wcount
*typesize
;
869 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
877 if ( np_x
> 1 && xy
== 1 ) {
878 MPI_Cart_shift( *comm0
, 1, 1, &xm
, &xp
) ;
879 if ( xp
!= MPI_PROC_NULL
&& ipe
<= ide
&& ide
!= ipe
) {
880 p
= buffer_for_proc( xp
, 0 , da_buf
) ;
883 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
884 ks
= kps
; ke
= kpe
;
885 ie
= ipe
- sendbegp
+ 1 ; is
= ie
- sendwp
+ 1 ;
886 nbytes
= buffer_size_for_proc( xp
, da_buf
) ;
887 if ( xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
) > nbytes
) {
889 fprintf(stderr
,"memory overwrite in rsl_lite_pack, X pack right, %d > %d\n",
890 xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
), nbytes
) ;
892 MPI_Abort(MPI_COMM_WORLD
, 99) ;
894 if ( typesize
== 8 ) {
895 F_UNPACK_LINT_AD ( (long *)(p
+xp_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
896 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
897 xp_curs
+= wcount
*typesize
;
899 else if ( typesize
== 4 ) {
900 F_UNPACK_INT_AD ( (int * )(p
+xp_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
901 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
902 xp_curs
+= wcount
*typesize
;
906 fprintf(stderr
,"A internal error: %s %d\n",__FILE__
,__LINE__
) ;
912 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
913 ks
= kps
; ke
= kpe
;
914 is
= ipe
+recvbegp
; ie
= is
+ recvwp
- 1 ;
915 if ( typesize
== 8 ) {
916 F_PACK_LINT_AD ( (long *)buf
, (long *)(p
+xp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
917 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
918 xp_curs
+= wcount
*typesize
;
920 else if ( typesize
== 4 ) {
921 F_PACK_INT_AD ( (int * )buf
, (int * )(p
+xp_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
922 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
923 xp_curs
+= wcount
*typesize
;
927 fprintf(stderr
,"B internal error: %s %d\n",__FILE__
,__LINE__
) ;
928 fprintf(stderr
," stenbeg %d stenw %d \n",is
,ie
) ;
929 fprintf(stderr
," is %d ie %d \n",is
,ie
) ;
935 if ( xm
!= MPI_PROC_NULL
&& ips
>= ids
&& ids
!= ips
) {
936 p
= buffer_for_proc( xm
, 0 , da_buf
) ;
939 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
940 ks
= kps
; ke
= kpe
;
941 is
= ips
+sendbegm
-1 ; ie
= is
+ sendwm
-1 ;
942 nbytes
= buffer_size_for_proc( xm
, da_buf
) ;
943 if ( xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
) > nbytes
) {
945 fprintf(stderr
,"memory overwrite in rsl_lite_pack_ad, X left , %d > %d\n",
946 xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
), nbytes
) ;
948 MPI_Abort(MPI_COMM_WORLD
, 99) ;
950 if ( typesize
== 8 ) {
951 F_UNPACK_LINT_AD ( (long *)(p
+xm_curs
), (long *)buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
952 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
953 xm_curs
+= wcount
*typesize
;
955 else if ( typesize
== 4 ) {
956 F_UNPACK_INT_AD ( (int * )(p
+xm_curs
), (int * )buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
957 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
958 xm_curs
+= wcount
*typesize
;
962 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
968 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
969 ks
= kps
; ke
= kpe
;
970 ie
= ips
-recvbegm
; is
= ie
- recvwm
+ 1 ;
971 if ( typesize
== 8 ) {
972 F_PACK_LINT_AD ( (long *)buf
, (long *)(p
+xm_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
973 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
974 xm_curs
+= wcount
*typesize
;
976 else if ( typesize
== 4 ) {
977 F_PACK_INT_AD ( (int * )buf
, (int * )(p
+xm_curs
), imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
978 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
979 xm_curs
+= wcount
*typesize
;
983 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
996 static MPI_Request yp_recv
, ym_recv
, yp_send
, ym_send
;
997 static MPI_Request xp_recv
, xm_recv
, xp_send
, xm_send
;
1001 RSL_LITE_EXCH_Y ( int * Fcomm0
, int *me0
, int * np0
, int * np_x0
, int * np_y0
,
1002 int * sendw_m
, int * sendw_p
, int * recvw_m
, int * recvw_p
)
1004 int me
, np
, np_x
, np_y
;
1005 int yp
, ym
, xp
, xm
, ierr
;
1008 MPI_Comm comm
, *comm0
, dummy_comm
;
1010 comm0
= &dummy_comm
;
1011 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
1012 comm
= *comm0
; me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
1014 MPI_Cart_shift( *comm0
, 0, 1, &ym
, &yp
) ;
1015 if ( yp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) {
1016 ierr
=MPI_Irecv ( buffer_for_proc( yp
, yp_curs_recv
, RSL_RECVBUF
), yp_curs_recv
, MPI_CHAR
, yp
, me
, comm
, &yp_recv
) ;
1018 if ( ym
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) {
1019 ierr
=MPI_Irecv ( buffer_for_proc( ym
, ym_curs_recv
, RSL_RECVBUF
), ym_curs_recv
, MPI_CHAR
, ym
, me
, comm
, &ym_recv
) ;
1021 if ( yp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) {
1022 ierr
=MPI_Isend ( buffer_for_proc( yp
, 0, RSL_SENDBUF
), yp_curs
, MPI_CHAR
, yp
, yp
, comm
, &yp_send
) ;
1024 if ( ym
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) {
1025 ierr
=MPI_Isend ( buffer_for_proc( ym
, 0, RSL_SENDBUF
), ym_curs
, MPI_CHAR
, ym
, ym
, comm
, &ym_send
) ;
1027 if ( yp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) { MPI_Wait( &yp_recv
, &stat
) ; }
1028 if ( ym
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) { MPI_Wait( &ym_recv
, &stat
) ; }
1029 if ( yp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) { MPI_Wait( &yp_send
, &stat
) ; }
1030 if ( ym
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) { MPI_Wait( &ym_send
, &stat
) ; }
1032 yp_curs
= 0 ; ym_curs
= 0 ; xp_curs
= 0 ; xm_curs
= 0 ;
1033 yp_curs_recv
= 0 ; ym_curs_recv
= 0 ;
1034 xp_curs_recv
= 0 ; xm_curs_recv
= 0 ;
1039 RSL_LITE_EXCH_X ( int * Fcomm0
, int *me0
, int * np0
, int * np_x0
, int * np_y0
,
1040 int * sendw_m
, int * sendw_p
, int * recvw_m
, int * recvw_p
)
1042 int me
, np
, np_x
, np_y
;
1043 int yp
, ym
, xp
, xm
;
1046 MPI_Comm comm
, *comm0
, dummy_comm
;
1048 comm0
= &dummy_comm
;
1049 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
1050 comm
= *comm0
; me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
1052 MPI_Cart_shift( *comm0
, 1, 1, &xm
, &xp
) ;
1053 if ( xp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) {
1054 MPI_Irecv ( buffer_for_proc( xp
, xp_curs_recv
, RSL_RECVBUF
), xp_curs_recv
, MPI_CHAR
, xp
, me
, comm
, &xp_recv
) ;
1056 if ( xm
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) {
1057 MPI_Irecv ( buffer_for_proc( xm
, xm_curs_recv
, RSL_RECVBUF
), xm_curs_recv
, MPI_CHAR
, xm
, me
, comm
, &xm_recv
) ;
1059 if ( xp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) {
1060 MPI_Isend ( buffer_for_proc( xp
, 0, RSL_SENDBUF
), xp_curs
, MPI_CHAR
, xp
, xp
, comm
, &xp_send
) ;
1062 if ( xm
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) {
1063 MPI_Isend ( buffer_for_proc( xm
, 0, RSL_SENDBUF
), xm_curs
, MPI_CHAR
, xm
, xm
, comm
, &xm_send
) ;
1065 if ( xp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) { MPI_Wait( &xp_recv
, &stat
) ; }
1066 if ( xm
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) { MPI_Wait( &xm_recv
, &stat
) ; }
1067 if ( xp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) { MPI_Wait( &xp_send
, &stat
) ; }
1068 if ( xm
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) { MPI_Wait( &xm_send
, &stat
) ; }
1070 yp_curs
= 0 ; ym_curs
= 0 ; xp_curs
= 0 ; xm_curs
= 0 ;
1071 yp_curs_recv
= 0 ; ym_curs_recv
= 0 ;
1072 xp_curs_recv
= 0 ; xm_curs_recv
= 0 ;
1076 #if !defined( MS_SUA) && !defined(_WIN32)
1077 #include <sys/time.h>
1079 RSL_INTERNAL_MILLICLOCK ()
1082 struct timezone tzp
;
1083 int isec
; /* seconds */
1084 int usec
; /* microseconds */
1086 gettimeofday( &tb
, &tzp
) ;
1089 msecs
= 1000 * isec
+ usec
/ 1000 ;
1093 RSL_INTERNAL_MICROCLOCK ()
1096 struct timezone tzp
;
1097 int isec
; /* seconds */
1098 int usec
; /* microseconds */
1100 gettimeofday( &tb
, &tzp
) ;
1103 msecs
= 1000000 * isec
+ usec
;