6 # define O_CREAT _O_CREAT
9 # define O_WRONLY _O_WRONLY
12 # define O_TRUNC _O_TRUNC
18 #ifdef NCEP_DEBUG_MULTIDIR
19 // # include <errno.h>
22 #define STANDARD_ERROR 2
24 #define STANDARD_OUTPUT 1
33 #define ORIG_RSL_CUTOFF 10000
35 void RSL_LITE_ERROR_DUP1 ( int *me
, int *size
)
42 /* redirect standard out and standard error based on compile options*/
44 #ifndef NCEP_DEBUG_MULTIDIR
45 gethostname( hostname
, 256 ) ;
47 /* redirect standard out*/
49 if ( *size
< ORIG_RSL_CUTOFF
)
51 sprintf(filename
,"rsl.out.%04d",*me
) ;
55 sprintf(filename
,"rsl.out.%08d",*me
) ;
60 if ( *size
< ORIG_RSL_CUTOFF
)
62 sprintf(filename
,"rsl.out.%04d",*me
) ;
65 sprintf(filename
,"rsl.out.%08d",*me
) ;
70 sprintf(filename
,"/dev/null") ;
73 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
75 perror("error_dup: cannot open rsl.out.nnnn") ;
76 fprintf(stderr
,"...sending output to standard output and continuing.\n") ;
79 if( dup2( newfd
, STANDARD_OUTPUT
) < 0 )
81 perror("error_dup: dup2 fails to change output descriptor") ;
82 fprintf(stderr
,"...sending output to standard output and continuing.\n") ;
87 /* redirect standard error */
88 # if defined( _WIN32 )
89 if ( *me
!= 0 ) { /* stderr from task 0 should come to screen on windows because it is buffered if redirected */
92 if ( *size
< ORIG_RSL_CUTOFF
)
94 sprintf(filename
,"rsl.error.%04d",*me
) ;
98 sprintf(filename
,"rsl.error.%08d",*me
) ;
103 if ( *size
< ORIG_RSL_CUTOFF
)
105 sprintf(filename
,"rsl.error.%04d",*me
) ;
108 sprintf(filename
,"rsl.error.%08d",*me
) ;
113 sprintf(filename
,"/dev/null") ;
116 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
118 perror("error_dup: cannot open rsl.error.log") ;
119 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
122 if( dup2( newfd
, STANDARD_ERROR
) < 0 )
124 perror("error_dup: dup2 fails to change error descriptor") ;
125 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
129 fprintf( stdout
, "taskid: %d hostname: %s\n",*me
,hostname
) ;
130 fprintf( stderr
, "taskid: %d hostname: %s\n",*me
,hostname
) ;
131 # if defined( _WIN32 )
135 # ifndef NCEP_DEBUG_GLOBALSTDOUT
137 /*create TASKOUTPUT directory to contain separate task owned output directories*/
139 /* let task 0 create the subdirectory path for the task directories */
143 sprintf(dirname
, "%s","TASKOUTPUT");
144 rc
= mkdir(dirname
, 0777);
145 if ( rc
!= 0 && errno
==EEXIST
) rc
=0;
148 /* If TASKOUTPUT directory is not created then return */
150 MPI_Bcast(&rc
, 1, MPI_INTEGER
, 0, MPI_COMM_WORLD
);
154 perror("mkdir error");
155 fprintf(stderr
, "mkdir failed for directory %s on task %d. Sending error/output to stderr/stdout for all tasks and continuing.\n", dirname
, *me
);
163 /* TASKOUTPUT directory exists, continue with task specific directory */
165 if ( *size
< ORIG_RSL_CUTOFF
)
167 sprintf(dirname
, "TASKOUTPUT/%04d", *me
);
171 sprintf(dirname
, "TASKOUTPUT/%08d", *me
);
173 rc
=mkdir(dirname
, 0777);
174 if ( rc
!=0 && errno
!=EEXIST
) {
175 perror("mkdir error");
176 fprintf(stderr
, "mkdir failed for directory %s on task %d. Sending error/output to stderr/stdout and continuing.\n", dirname
, *me
);
180 /* Each tasks creates/opens its own output and error files */
182 if ( *size
< ORIG_RSL_CUTOFF
)
184 sprintf(filename
, "%s/%04d/rsl.out.%04d","TASKOUTPUT",*me
,*me
) ;
188 sprintf(filename
, "%s/%08d/rsl.out.%08d","TASKOUTPUT",*me
,*me
) ;
191 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
193 perror("error_dup: cannot open ./TASKOUTPUT/nnnn/rsl.out.nnnn") ;
194 fprintf(stderr
,"...sending output to standard output and continuing.\n")
198 if( dup2( newfd
, STANDARD_OUTPUT
) < 0 )
200 perror("error_dup: dup2 fails to change output descriptor") ;
201 fprintf(stderr
,"...sending output to standard output and continuing.\n");
206 if ( *size
< ORIG_RSL_CUTOFF
)
208 sprintf(filename
, "%s/%04d/rsl.error.%04d","TASKOUTPUT",*me
,*me
) ;
212 sprintf(filename
, "%s/%08d/rsl.error.%08d","TASKOUTPUT",*me
,*me
) ;
214 if ((newfd
= open( filename
, O_CREAT
| O_WRONLY
| O_TRUNC
, 0666 )) < 0 )
216 perror("error_dup: cannot open ./TASKOUTPUT/nnnn/rsl.error.nnnn") ;
217 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
220 if( dup2( newfd
, STANDARD_ERROR
) < 0 )
222 perror("error_dup: dup2 fails to change error descriptor") ;
223 fprintf(stderr
,"...sending error to standard error and continuing.\n") ;
228 /* Each task writes to global standard error and standard out */
237 /* Windows doesn't have a gethostid function so add a stub.
238 TODO: Create a version that will work on Windows. */
246 RSL_LITE_GET_HOSTNAME ( char * hn
, int * size
, int *n
, int *hostid
)
251 if ( gethostname(temp
,512) ) return(1) ;
253 for ( p
= temp
, q
= hn
, i
= 0 ; *p
&& i
< *size
&& i
< 512 ; i
++ , p
++ , q
++ ) { *q
= *p
; }
259 BYTE_BCAST ( char * buf
, int * size
, int * Fcomm
)
262 MPI_Comm
*comm
, dummy_comm
;
265 *comm
= MPI_Comm_f2c( *Fcomm
) ;
267 if (*size
% sizeof(int) == 0) {
268 MPI_Bcast ( buf
, *size
/sizeof(int), MPI_INT
, 0, *comm
) ;
270 MPI_Bcast ( buf
, *size
, MPI_BYTE
, 0, *comm
) ;
273 MPI_Bcast ( buf
, *size
, MPI_BYTE
, 0, *comm
) ;
278 BYTE_BCAST_FROM_ROOT ( char * buf
, int * size
, int *root
, int * Fcomm
)
281 MPI_Comm
*comm
, dummy_comm
;
284 *comm
= MPI_Comm_f2c( *Fcomm
) ;
286 if (*size
% sizeof(int) == 0) {
287 MPI_Bcast ( buf
, *size
/sizeof(int), MPI_INT
, *root
, *comm
) ;
289 MPI_Bcast ( buf
, *size
, MPI_BYTE
, *root
, *comm
) ;
292 MPI_Bcast ( buf
, *size
, MPI_BYTE
, *root
, *comm
) ;
297 static int yp_curs
, ym_curs
, xp_curs
, xm_curs
;
298 static int yp_curs_recv
, ym_curs_recv
, xp_curs_recv
, xm_curs_recv
;
302 int * shw0
, int * xy0
,
303 int *sendbegm0
, int * sendwm0
, int * sendbegp0
, int * sendwp0
,
304 int *recvbegm0
, int * recvwm0
, int * recvbegp0
, int * recvwp0
,
305 int * n3dR0
, int *n2dR0
, int * typesizeR0
,
306 int * n3dI0
, int *n2dI0
, int * typesizeI0
,
307 int * n3dD0
, int *n2dD0
, int * typesizeD0
,
308 int * n3dL0
, int *n2dL0
, int * typesizeL0
,
309 int * me0
, int * np0
, int * np_x0
, int * np_y0
,
310 int * ips0
, int * ipe0
, int * jps0
, int * jpe0
, int * kps0
, int * kpe0
)
312 int n3dR
, n2dR
, typesizeR
;
313 int n3dI
, n2dI
, typesizeI
;
314 int n3dD
, n2dD
, typesizeD
;
315 int n3dL
, n2dL
, typesizeL
;
317 int sendbegm
, sendwm
, sendbegp
, sendwp
;
318 int recvbegm
, recvwm
, recvbegp
, recvwp
;
319 int me
, np
, np_x
, np_y
;
320 int ips
, ipe
, jps
, jpe
, kps
, kpe
;
324 int nbytes_x_recv
= 0, nbytes_y_recv
= 0 ;
327 MPI_Comm comm
, *comm0
, dummy_comm
;
329 comm0
= &dummy_comm
;
330 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
332 shw
= *shw0
; /* logical half-width of stencil */
333 xy
= *xy0
; /* 0 = y , 1 = x */
334 sendbegm
= *sendbegm0
; /* send index of sten copy (edge = 1), lower/left */
335 sendwm
= *sendwm0
; /* send width of sten copy counting towards edge, lower/left */
336 sendbegp
= *sendbegp0
; /* send index of sten copy (edge = 1), upper/right */
337 sendwp
= *sendwp0
; /* send width of sten copy counting towards edge, upper/right */
338 recvbegm
= *recvbegm0
; /* recv index of sten copy (edge = 1), lower/left */
339 recvwm
= *recvwm0
; /* recv width of sten copy counting towards edge, lower/left */
340 recvbegp
= *recvbegp0
; /* recv index of sten copy (edge = 1), upper/right */
341 recvwp
= *recvwp0
; /* recv width of sten copy counting towards edge, upper/right */
342 n3dR
= *n3dR0
; n2dR
= *n2dR0
; typesizeR
= *typesizeR0
;
343 n3dI
= *n3dI0
; n2dI
= *n2dI0
; typesizeI
= *typesizeI0
;
344 n3dD
= *n3dD0
; n2dD
= *n2dD0
; typesizeD
= *typesizeD0
;
345 n3dL
= *n3dL0
; n2dL
= *n2dL0
; typesizeL
= *typesizeL0
;
346 me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
347 ips
= *ips0
-1 ; ipe
= *ipe0
-1 ; jps
= *jps0
-1 ; jpe
= *jpe0
-1 ; kps
= *kps0
-1 ; kpe
= *kpe0
-1 ;
349 yp_curs_recv
= 0 ; ym_curs_recv
= 0 ;
350 xp_curs_recv
= 0 ; xm_curs_recv
= 0 ;
352 if ( xy
== 0 && np_y
> 1 ) {
353 nbytes
= typesizeR
*(ipe
-ips
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
354 typesizeI
*(ipe
-ips
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
355 typesizeD
*(ipe
-ips
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
356 typesizeL
*(ipe
-ips
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
358 typesizeR
*(ipe
-ips
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
359 typesizeI
*(ipe
-ips
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
360 typesizeD
*(ipe
-ips
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
361 typesizeL
*(ipe
-ips
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
362 MPI_Cart_shift ( *comm0
, 0, 1, &ym
, &yp
) ;
363 if ( yp
!= MPI_PROC_NULL
) {
364 buffer_for_proc ( yp
, nbytes_y_recv
, RSL_RECVBUF
) ;
365 buffer_for_proc ( yp
, nbytes
, RSL_SENDBUF
) ;
367 if ( ym
!= MPI_PROC_NULL
) {
368 buffer_for_proc ( ym
, nbytes_y_recv
, RSL_RECVBUF
) ;
369 buffer_for_proc ( ym
, nbytes
, RSL_SENDBUF
) ;
372 if ( xy
== 1 && np_x
> 1 ) {
373 nbytes
= typesizeR
*(jpe
-jps
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
374 typesizeI
*(jpe
-jps
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
375 typesizeD
*(jpe
-jps
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
376 typesizeL
*(jpe
-jps
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
378 typesizeR
*(jpe
-jps
+1+2*shw
)*shw
*(n3dR
*(kpe
-kps
+1)+n2dR
) +
379 typesizeI
*(jpe
-jps
+1+2*shw
)*shw
*(n3dI
*(kpe
-kps
+1)+n2dI
) +
380 typesizeD
*(jpe
-jps
+1+2*shw
)*shw
*(n3dD
*(kpe
-kps
+1)+n2dD
) +
381 typesizeL
*(jpe
-jps
+1+2*shw
)*shw
*(n3dL
*(kpe
-kps
+1)+n2dL
) ;
382 MPI_Cart_shift ( *comm0
, 1, 1, &xm
, &xp
) ;
383 if ( xp
!= MPI_PROC_NULL
) {
384 buffer_for_proc ( xp
, nbytes_x_recv
, RSL_RECVBUF
) ;
385 buffer_for_proc ( xp
, nbytes
, RSL_SENDBUF
) ;
387 if ( xm
!= MPI_PROC_NULL
) {
388 buffer_for_proc ( xm
, nbytes_x_recv
, RSL_RECVBUF
) ;
389 buffer_for_proc ( xm
, nbytes
, RSL_SENDBUF
) ;
393 yp_curs
= 0 ; ym_curs
= 0 ; xp_curs
= 0 ; xm_curs
= 0 ;
394 yp_curs_recv
= nbytes_y_recv
; ym_curs_recv
= nbytes_y_recv
;
395 xp_curs_recv
= nbytes_x_recv
; xm_curs_recv
= nbytes_x_recv
;
398 RSL_LITE_PACK ( int * Fcomm0
, char * buf
, int * shw0
,
399 int * sendbegm0
, int * sendwm0
, int * sendbegp0
, int * sendwp0
,
400 int * recvbegm0
, int * recvwm0
, int * recvbegp0
, int * recvwp0
,
401 int * typesize0
, int * xy0
, int * pu0
, int * imemord
, int * xstag0
, /* not used */
402 int *me0
, int * np0
, int * np_x0
, int * np_y0
,
403 int * ids0
, int * ide0
, int * jds0
, int * jde0
, int * kds0
, int * kde0
,
404 int * ims0
, int * ime0
, int * jms0
, int * jme0
, int * kms0
, int * kme0
,
405 int * ips0
, int * ipe0
, int * jps0
, int * jpe0
, int * kps0
, int * kpe0
)
407 int me
, np
, np_x
, np_y
;
408 int sendbegm
, sendwm
, sendbegp
, sendwp
;
409 int recvbegm
, recvwm
, recvbegp
, recvwp
;
411 int ids
, ide
, jds
, jde
, kds
, kde
;
412 int ims
, ime
, jms
, jme
, kms
, kme
;
413 int ips
, ipe
, jps
, jpe
, kps
, kpe
;
414 int xy
; /* y = 0 , x = 1 */
415 int pu
; /* pack = 0 , unpack = 1 */
416 register int i
, j
, k
, t
;
418 register int i2
,i3
,i4
,i_offset
;
424 register int *pi
, *qi
;
427 MPI_Comm comm
, *comm0
, dummy_comm
;
428 int js
, je
, ks
, ke
, is
, ie
, wcount
;
430 comm0
= &dummy_comm
;
431 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
433 shw
= *shw0
; /* logical half-width of stencil */
434 sendbegm
= *sendbegm0
; /* send index of sten copy (edge = 1), lower/left */
435 sendwm
= *sendwm0
; /* send width of sten copy counting towards edge, lower/left */
436 sendbegp
= *sendbegp0
; /* send index of sten copy (edge = 1), upper/right */
437 sendwp
= *sendwp0
; /* send width of sten copy counting towards edge, upper/right */
438 recvbegm
= *recvbegm0
; /* recv index of sten copy (edge = 1), lower/left */
439 recvwm
= *recvwm0
; /* recv width of sten copy counting towards edge, lower/left */
440 recvbegp
= *recvbegp0
; /* recv index of sten copy (edge = 1), upper/right */
441 recvwp
= *recvwp0
; /* recv width of sten copy counting towards edge, upper/right */
442 me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
443 typesize
= *typesize0
;
444 ids
= *ids0
-1 ; ide
= *ide0
-1 ; jds
= *jds0
-1 ; jde
= *jde0
-1 ; kds
= *kds0
-1 ; kde
= *kde0
-1 ;
445 ims
= *ims0
-1 ; ime
= *ime0
-1 ; jms
= *jms0
-1 ; jme
= *jme0
-1 ; kms
= *kms0
-1 ; kme
= *kme0
-1 ;
446 ips
= *ips0
-1 ; ipe
= *ipe0
-1 ; jps
= *jps0
-1 ; jpe
= *jpe0
-1 ; kps
= *kps0
-1 ; kpe
= *kpe0
-1 ;
450 /* need to adapt for other memory orders */
452 #define RANGE(S1,E1,S2,E2,S3,E3,S4,E4) (((E1)-(S1)+1)*((E2)-(S2)+1)*((E3)-(S3)+1)*((E4)-(S4)+1))
453 #define IMAX(A) (((A)>ids)?(A):ids)
454 #define IMIN(A) (((A)<ide)?(A):ide)
455 #define JMAX(A) (((A)>jds)?(A):jds)
456 #define JMIN(A) (((A)<jde)?(A):jde)
458 da_buf
= ( pu
== 0 ) ? RSL_SENDBUF
: RSL_RECVBUF
;
460 if ( ips
<= ipe
&& jps
<= jpe
) {
462 if ( np_y
> 1 && xy
== 0 ) {
463 MPI_Cart_shift( *comm0
, 0, 1, &ym
, &yp
) ;
464 if ( yp
!= MPI_PROC_NULL
&& jpe
<= jde
&& jde
!= jpe
) {
465 p
= buffer_for_proc( yp
, 0 , da_buf
) ;
468 je
= jpe
- sendbegp
+ 1 ; js
= je
- sendwp
+ 1 ;
469 ks
= kps
; ke
= kpe
;
470 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
471 nbytes
= buffer_size_for_proc( yp
, da_buf
) ;
472 if ( yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
474 fprintf(stderr
,"memory overwrite in rsl_lite_pack, Y pack up, %d > %d\n",
475 yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
477 MPI_Abort(MPI_COMM_WORLD
, 99) ;
479 if ( typesize
== 8 ) {
480 F_PACK_LINT ( buf
, p
+yp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
481 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
482 yp_curs
+= wcount
*typesize
;
484 else if ( typesize
== 4 ) {
485 F_PACK_INT ( buf
, p
+yp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
486 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
487 yp_curs
+= wcount
*typesize
;
491 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
497 js
= jpe
+recvbegp
; je
= js
+ recvwp
- 1 ;
498 ks
= kps
; ke
= kpe
;
499 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
500 if ( typesize
== 8 ) {
501 F_UNPACK_LINT ( p
+yp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
502 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
503 yp_curs
+= wcount
*typesize
;
505 else if ( typesize
== 4 ) {
506 F_UNPACK_INT ( p
+yp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
507 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
508 yp_curs
+= wcount
*typesize
;
512 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
518 if ( ym
!= MPI_PROC_NULL
&& jps
>= jds
&& jps
!= jds
) {
519 p
= buffer_for_proc( ym
, 0 , da_buf
) ;
522 js
= jps
+sendbegm
-1 ; je
= js
+ sendwm
-1 ;
523 ks
= kps
; ke
= kpe
;
524 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
525 nbytes
= buffer_size_for_proc( ym
, da_buf
) ;
526 if ( ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
528 fprintf(stderr
,"memory overwrite in rsl_lite_pack, Y pack dn, %d > %d\n",
529 ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
531 MPI_Abort(MPI_COMM_WORLD
, 99) ;
533 if ( typesize
== 8 ) {
534 F_PACK_LINT ( buf
, p
+ym_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
535 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
536 ym_curs
+= wcount
*typesize
;
538 else if ( typesize
== 4 ) {
539 F_PACK_INT ( buf
, p
+ym_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
540 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
541 ym_curs
+= wcount
*typesize
;
545 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
551 je
= jps
-recvbegm
; js
= je
- recvwm
+ 1 ;
552 ks
= kps
; ke
= kpe
;
553 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
554 if ( typesize
== 8 ) {
555 F_UNPACK_LINT ( p
+ym_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
556 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
557 ym_curs
+= wcount
*typesize
;
559 else if ( typesize
== 4 ) {
560 F_UNPACK_INT ( p
+ym_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
561 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
562 ym_curs
+= wcount
*typesize
;
566 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
574 if ( np_x
> 1 && xy
== 1 ) {
575 MPI_Cart_shift( *comm0
, 1, 1, &xm
, &xp
) ;
576 if ( xp
!= MPI_PROC_NULL
&& ipe
<= ide
&& ide
!= ipe
) {
577 p
= buffer_for_proc( xp
, 0 , da_buf
) ;
580 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
581 ks
= kps
; ke
= kpe
;
582 ie
= ipe
- sendbegp
+ 1 ; is
= ie
- sendwp
+ 1 ;
583 nbytes
= buffer_size_for_proc( xp
, da_buf
) ;
584 if ( xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
) > nbytes
) {
586 fprintf(stderr
,"memory overwrite in rsl_lite_pack, X pack right, %d > %d\n",
587 xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
), nbytes
) ;
589 MPI_Abort(MPI_COMM_WORLD
, 99) ;
591 if ( typesize
== 8 ) {
592 F_PACK_LINT ( buf
, p
+xp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
593 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
594 xp_curs
+= wcount
*typesize
;
596 else if ( typesize
== 4 ) {
597 F_PACK_INT ( buf
, p
+xp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
598 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
599 xp_curs
+= wcount
*typesize
;
603 fprintf(stderr
,"A internal error: %s %d\n",__FILE__
,__LINE__
) ;
609 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
610 ks
= kps
; ke
= kpe
;
611 is
= ipe
+recvbegp
; ie
= is
+ recvwp
- 1 ;
612 if ( typesize
== 8 ) {
613 F_UNPACK_LINT ( p
+xp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
614 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
615 xp_curs
+= wcount
*typesize
;
617 else if ( typesize
== 4 ) {
618 F_UNPACK_INT ( p
+xp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
619 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
620 xp_curs
+= wcount
*typesize
;
624 fprintf(stderr
,"B internal error: %s %d\n",__FILE__
,__LINE__
) ;
625 fprintf(stderr
," stenbeg %d stenw %d \n",is
,ie
) ;
626 fprintf(stderr
," is %d ie %d \n",is
,ie
) ;
632 if ( xm
!= MPI_PROC_NULL
&& ips
>= ids
&& ids
!= ips
) {
633 p
= buffer_for_proc( xm
, 0 , da_buf
) ;
636 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
637 ks
= kps
; ke
= kpe
;
638 is
= ips
+sendbegm
-1 ; ie
= is
+ sendwm
-1 ;
639 nbytes
= buffer_size_for_proc( xm
, da_buf
) ;
640 if ( xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
) > nbytes
) {
642 fprintf(stderr
,"memory overwrite in rsl_lite_pack, X left , %d > %d\n",
643 xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
), nbytes
) ;
645 MPI_Abort(MPI_COMM_WORLD
, 99) ;
647 if ( typesize
== 8 ) {
648 F_PACK_LINT ( buf
, p
+xm_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
649 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
650 xm_curs
+= wcount
*typesize
;
652 else if ( typesize
== 4 ) {
653 F_PACK_INT ( buf
, p
+xm_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
654 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
655 xm_curs
+= wcount
*typesize
;
659 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
665 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
666 ks
= kps
; ke
= kpe
;
667 ie
= ips
-recvbegm
; is
= ie
- recvwm
+ 1 ;
668 if ( typesize
== 8 ) {
669 F_UNPACK_LINT ( p
+xm_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
670 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
671 xm_curs
+= wcount
*typesize
;
673 else if ( typesize
== 4 ) {
674 F_UNPACK_INT ( p
+xm_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
675 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
676 xm_curs
+= wcount
*typesize
;
680 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
693 RSL_LITE_PACK_AD ( int * Fcomm0
, char * buf
, int * shw0
,
694 int * sendbegm0
, int * sendwm0
, int * sendbegp0
, int * sendwp0
,
695 int * recvbegm0
, int * recvwm0
, int * recvbegp0
, int * recvwp0
,
696 int * typesize0
, int * xy0
, int * pu0
, int * imemord
, int * xstag0
, /* not used */
697 int *me0
, int * np0
, int * np_x0
, int * np_y0
,
698 int * ids0
, int * ide0
, int * jds0
, int * jde0
, int * kds0
, int * kde0
,
699 int * ims0
, int * ime0
, int * jms0
, int * jme0
, int * kms0
, int * kme0
,
700 int * ips0
, int * ipe0
, int * jps0
, int * jpe0
, int * kps0
, int * kpe0
)
702 int me
, np
, np_x
, np_y
;
703 int sendbegm
, sendwm
, sendbegp
, sendwp
;
704 int recvbegm
, recvwm
, recvbegp
, recvwp
;
706 int ids
, ide
, jds
, jde
, kds
, kde
;
707 int ims
, ime
, jms
, jme
, kms
, kme
;
708 int ips
, ipe
, jps
, jpe
, kps
, kpe
;
709 int xy
; /* y = 0 , x = 1 */
710 int pu
; /* pack = 0 , unpack = 1 */
711 register int i
, j
, k
, t
;
713 register int i2
,i3
,i4
,i_offset
;
719 register int *pi
, *qi
;
722 MPI_Comm comm
, *comm0
, dummy_comm
;
723 int js
, je
, ks
, ke
, is
, ie
, wcount
;
725 comm0
= &dummy_comm
;
726 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
728 shw
= *shw0
; /* logical half-width of stencil */
729 sendbegm
= *sendbegm0
; /* send index of sten copy (edge = 1), lower/left */
730 sendwm
= *sendwm0
; /* send width of sten copy counting towards edge, lower/left */
731 sendbegp
= *sendbegp0
; /* send index of sten copy (edge = 1), upper/right */
732 sendwp
= *sendwp0
; /* send width of sten copy counting towards edge, upper/right */
733 recvbegm
= *recvbegm0
; /* recv index of sten copy (edge = 1), lower/left */
734 recvwm
= *recvwm0
; /* recv width of sten copy counting towards edge, lower/left */
735 recvbegp
= *recvbegp0
; /* recv index of sten copy (edge = 1), upper/right */
736 recvwp
= *recvwp0
; /* recv width of sten copy counting towards edge, upper/right */
737 me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
738 typesize
= *typesize0
;
739 ids
= *ids0
-1 ; ide
= *ide0
-1 ; jds
= *jds0
-1 ; jde
= *jde0
-1 ; kds
= *kds0
-1 ; kde
= *kde0
-1 ;
740 ims
= *ims0
-1 ; ime
= *ime0
-1 ; jms
= *jms0
-1 ; jme
= *jme0
-1 ; kms
= *kms0
-1 ; kme
= *kme0
-1 ;
741 ips
= *ips0
-1 ; ipe
= *ipe0
-1 ; jps
= *jps0
-1 ; jpe
= *jpe0
-1 ; kps
= *kps0
-1 ; kpe
= *kpe0
-1 ;
745 /* need to adapt for other memory orders */
747 #define RANGE(S1,E1,S2,E2,S3,E3,S4,E4) (((E1)-(S1)+1)*((E2)-(S2)+1)*((E3)-(S3)+1)*((E4)-(S4)+1))
748 #define IMAX(A) (((A)>ids)?(A):ids)
749 #define IMIN(A) (((A)<ide)?(A):ide)
750 #define JMAX(A) (((A)>jds)?(A):jds)
751 #define JMIN(A) (((A)<jde)?(A):jde)
753 da_buf
= ( pu
== 0 ) ? RSL_SENDBUF
: RSL_RECVBUF
;
755 if ( ips
<= ipe
&& jps
<= jpe
) {
757 if ( np_y
> 1 && xy
== 0 ) {
758 MPI_Cart_shift( *comm0
, 0, 1, &ym
, &yp
) ;
759 if ( yp
!= MPI_PROC_NULL
&& jpe
<= jde
&& jde
!= jpe
) {
760 p
= buffer_for_proc( yp
, 0 , da_buf
) ;
763 je
= jpe
- sendbegp
+ 1 ; js
= je
- sendwp
+ 1 ;
764 ks
= kps
; ke
= kpe
;
765 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
766 nbytes
= buffer_size_for_proc( yp
, da_buf
) ;
767 if ( yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
769 fprintf(stderr
,"memory overwrite in rsl_lite_pack_ad, Y pack up, %d > %d\n",
770 yp_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
772 MPI_Abort(MPI_COMM_WORLD
, 99) ;
774 if ( typesize
== 8 ) {
775 F_UNPACK_LINT_AD ( p
+yp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
776 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
777 yp_curs
+= wcount
*typesize
;
779 else if ( typesize
== 4 ) {
780 F_UNPACK_INT_AD ( p
+yp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
781 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
782 yp_curs
+= wcount
*typesize
;
786 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
792 js
= jpe
+recvbegp
; je
= js
+ recvwp
- 1 ;
793 ks
= kps
; ke
= kpe
;
794 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
795 if ( typesize
== 8 ) {
796 F_PACK_LINT_AD ( buf
, p
+yp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
797 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
798 yp_curs
+= wcount
*typesize
;
800 else if ( typesize
== 4 ) {
801 F_PACK_INT_AD ( buf
, p
+yp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
802 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
803 yp_curs
+= wcount
*typesize
;
807 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
813 if ( ym
!= MPI_PROC_NULL
&& jps
>= jds
&& jps
!= jds
) {
814 p
= buffer_for_proc( ym
, 0 , da_buf
) ;
817 js
= jps
+sendbegm
-1 ; je
= js
+ sendwm
-1 ;
818 ks
= kps
; ke
= kpe
;
819 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
820 nbytes
= buffer_size_for_proc( ym
, da_buf
) ;
821 if ( ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
) > nbytes
) {
823 fprintf(stderr
,"memory overwrite in rsl_lite_pack_ad, Y pack dn, %d > %d\n",
824 ym_curs
+ RANGE( js
, je
, kps
, kpe
, ips
-shw
, ipe
+shw
, 1, typesize
), nbytes
) ;
826 MPI_Abort(MPI_COMM_WORLD
, 99) ;
828 if ( typesize
== 8 ) {
829 F_UNPACK_LINT_AD ( p
+ym_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
830 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
831 ym_curs
+= wcount
*typesize
;
833 else if ( typesize
== 4 ) {
834 F_UNPACK_INT_AD ( p
+ym_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
835 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
836 ym_curs
+= wcount
*typesize
;
840 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
846 je
= jps
-recvbegm
; js
= je
- recvwm
+ 1 ;
847 ks
= kps
; ke
= kpe
;
848 is
= IMAX(ips
-shw
) ; ie
= IMIN(ipe
+shw
) ;
849 if ( typesize
== 8 ) {
850 F_PACK_LINT_AD ( buf
, p
+ym_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
851 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
852 ym_curs
+= wcount
*typesize
;
854 else if ( typesize
== 4 ) {
855 F_PACK_INT_AD ( buf
, p
+ym_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
856 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
857 ym_curs
+= wcount
*typesize
;
861 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
869 if ( np_x
> 1 && xy
== 1 ) {
870 MPI_Cart_shift( *comm0
, 1, 1, &xm
, &xp
) ;
871 if ( xp
!= MPI_PROC_NULL
&& ipe
<= ide
&& ide
!= ipe
) {
872 p
= buffer_for_proc( xp
, 0 , da_buf
) ;
875 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
876 ks
= kps
; ke
= kpe
;
877 ie
= ipe
- sendbegp
+ 1 ; is
= ie
- sendwp
+ 1 ;
878 nbytes
= buffer_size_for_proc( xp
, da_buf
) ;
879 if ( xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
) > nbytes
) {
881 fprintf(stderr
,"memory overwrite in rsl_lite_pack, X pack right, %d > %d\n",
882 xp_curs
+ RANGE( js
, je
, kps
, kpe
, ipe
-shw
+1, ipe
, 1, typesize
), nbytes
) ;
884 MPI_Abort(MPI_COMM_WORLD
, 99) ;
886 if ( typesize
== 8 ) {
887 F_UNPACK_LINT_AD ( p
+xp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
888 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
889 xp_curs
+= wcount
*typesize
;
891 else if ( typesize
== 4 ) {
892 F_UNPACK_INT_AD ( p
+xp_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
893 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
894 xp_curs
+= wcount
*typesize
;
898 fprintf(stderr
,"A internal error: %s %d\n",__FILE__
,__LINE__
) ;
904 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
905 ks
= kps
; ke
= kpe
;
906 is
= ipe
+recvbegp
; ie
= is
+ recvwp
- 1 ;
907 if ( typesize
== 8 ) {
908 F_PACK_LINT_AD ( buf
, p
+xp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
909 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
910 xp_curs
+= wcount
*typesize
;
912 else if ( typesize
== 4 ) {
913 F_PACK_INT_AD ( buf
, p
+xp_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
914 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
915 xp_curs
+= wcount
*typesize
;
919 fprintf(stderr
,"B internal error: %s %d\n",__FILE__
,__LINE__
) ;
920 fprintf(stderr
," stenbeg %d stenw %d \n",is
,ie
) ;
921 fprintf(stderr
," is %d ie %d \n",is
,ie
) ;
927 if ( xm
!= MPI_PROC_NULL
&& ips
>= ids
&& ids
!= ips
) {
928 p
= buffer_for_proc( xm
, 0 , da_buf
) ;
931 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
932 ks
= kps
; ke
= kpe
;
933 is
= ips
+sendbegm
-1 ; ie
= is
+ sendwm
-1 ;
934 nbytes
= buffer_size_for_proc( xm
, da_buf
) ;
935 if ( xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
) > nbytes
) {
937 fprintf(stderr
,"memory overwrite in rsl_lite_pack_ad, X left , %d > %d\n",
938 xm_curs
+ RANGE( js
, je
, kps
, kpe
, ips
, ips
+shw
-1, 1, typesize
), nbytes
) ;
940 MPI_Abort(MPI_COMM_WORLD
, 99) ;
942 if ( typesize
== 8 ) {
943 F_UNPACK_LINT_AD ( p
+xm_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
944 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
945 xm_curs
+= wcount
*typesize
;
947 else if ( typesize
== 4 ) {
948 F_UNPACK_INT_AD ( p
+xm_curs
, buf
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
949 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
950 xm_curs
+= wcount
*typesize
;
954 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
960 js
= JMAX(jps
-shw
) ; je
= JMIN(jpe
+shw
) ;
961 ks
= kps
; ke
= kpe
;
962 ie
= ips
-recvbegm
; is
= ie
- recvwm
+ 1 ;
963 if ( typesize
== 8 ) {
964 F_PACK_LINT_AD ( buf
, p
+xm_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
965 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
966 xm_curs
+= wcount
*typesize
;
968 else if ( typesize
== 4 ) {
969 F_PACK_INT_AD ( buf
, p
+xm_curs
, imemord
, &js
, &je
, &ks
, &ke
, &is
, &ie
,
970 &jms
,&jme
,&kms
,&kme
,&ims
,&ime
, &wcount
) ;
971 xm_curs
+= wcount
*typesize
;
975 fprintf(stderr
,"internal error: %s %d\n",__FILE__
,__LINE__
) ;
988 static MPI_Request yp_recv
, ym_recv
, yp_send
, ym_send
;
989 static MPI_Request xp_recv
, xm_recv
, xp_send
, xm_send
;
992 RSL_LITE_EXCH_Y ( int * Fcomm0
, int *me0
, int * np0
, int * np_x0
, int * np_y0
,
993 int * sendw_m
, int * sendw_p
, int * recvw_m
, int * recvw_p
)
995 int me
, np
, np_x
, np_y
;
996 int yp
, ym
, xp
, xm
, ierr
;
999 MPI_Comm comm
, *comm0
, dummy_comm
;
1001 comm0
= &dummy_comm
;
1002 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
1003 comm
= *comm0
; me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
1005 MPI_Cart_shift( *comm0
, 0, 1, &ym
, &yp
) ;
1006 if ( yp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) {
1007 ierr
=MPI_Irecv ( buffer_for_proc( yp
, yp_curs_recv
, RSL_RECVBUF
), yp_curs_recv
, MPI_CHAR
, yp
, me
, comm
, &yp_recv
) ;
1009 if ( ym
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) {
1010 ierr
=MPI_Irecv ( buffer_for_proc( ym
, ym_curs_recv
, RSL_RECVBUF
), ym_curs_recv
, MPI_CHAR
, ym
, me
, comm
, &ym_recv
) ;
1012 if ( yp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) {
1013 ierr
=MPI_Isend ( buffer_for_proc( yp
, 0, RSL_SENDBUF
), yp_curs
, MPI_CHAR
, yp
, yp
, comm
, &yp_send
) ;
1015 if ( ym
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) {
1016 ierr
=MPI_Isend ( buffer_for_proc( ym
, 0, RSL_SENDBUF
), ym_curs
, MPI_CHAR
, ym
, ym
, comm
, &ym_send
) ;
1018 if ( yp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) { MPI_Wait( &yp_recv
, &stat
) ; }
1019 if ( ym
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) { MPI_Wait( &ym_recv
, &stat
) ; }
1020 if ( yp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) { MPI_Wait( &yp_send
, &stat
) ; }
1021 if ( ym
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) { MPI_Wait( &ym_send
, &stat
) ; }
1023 yp_curs
= 0 ; ym_curs
= 0 ; xp_curs
= 0 ; xm_curs
= 0 ;
1024 yp_curs_recv
= 0 ; ym_curs_recv
= 0 ;
1025 xp_curs_recv
= 0 ; xm_curs_recv
= 0 ;
1029 RSL_LITE_EXCH_X ( int * Fcomm0
, int *me0
, int * np0
, int * np_x0
, int * np_y0
,
1030 int * sendw_m
, int * sendw_p
, int * recvw_m
, int * recvw_p
)
1032 int me
, np
, np_x
, np_y
;
1033 int yp
, ym
, xp
, xm
;
1036 MPI_Comm comm
, *comm0
, dummy_comm
;
1038 comm0
= &dummy_comm
;
1039 *comm0
= MPI_Comm_f2c( *Fcomm0
) ;
1040 comm
= *comm0
; me
= *me0
; np
= *np0
; np_x
= *np_x0
; np_y
= *np_y0
;
1042 MPI_Cart_shift( *comm0
, 1, 1, &xm
, &xp
) ;
1043 if ( xp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) {
1044 MPI_Irecv ( buffer_for_proc( xp
, xp_curs_recv
, RSL_RECVBUF
), xp_curs_recv
, MPI_CHAR
, xp
, me
, comm
, &xp_recv
) ;
1046 if ( xm
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) {
1047 MPI_Irecv ( buffer_for_proc( xm
, xm_curs_recv
, RSL_RECVBUF
), xm_curs_recv
, MPI_CHAR
, xm
, me
, comm
, &xm_recv
) ;
1049 if ( xp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) {
1050 MPI_Isend ( buffer_for_proc( xp
, 0, RSL_SENDBUF
), xp_curs
, MPI_CHAR
, xp
, xp
, comm
, &xp_send
) ;
1052 if ( xm
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) {
1053 MPI_Isend ( buffer_for_proc( xm
, 0, RSL_SENDBUF
), xm_curs
, MPI_CHAR
, xm
, xm
, comm
, &xm_send
) ;
1055 if ( xp
!= MPI_PROC_NULL
&& *recvw_p
> 0 ) { MPI_Wait( &xp_recv
, &stat
) ; }
1056 if ( xm
!= MPI_PROC_NULL
&& *recvw_m
> 0 ) { MPI_Wait( &xm_recv
, &stat
) ; }
1057 if ( xp
!= MPI_PROC_NULL
&& *sendw_p
> 0 ) { MPI_Wait( &xp_send
, &stat
) ; }
1058 if ( xm
!= MPI_PROC_NULL
&& *sendw_m
> 0 ) { MPI_Wait( &xm_send
, &stat
) ; }
1060 yp_curs
= 0 ; ym_curs
= 0 ; xp_curs
= 0 ; xm_curs
= 0 ;
1061 yp_curs_recv
= 0 ; ym_curs_recv
= 0 ;
1062 xp_curs_recv
= 0 ; xm_curs_recv
= 0 ;
1066 #if !defined( MS_SUA) && !defined(_WIN32)
1067 #include <sys/time.h>
1068 RSL_INTERNAL_MILLICLOCK ()
1071 struct timezone tzp
;
1072 int isec
; /* seconds */
1073 int usec
; /* microseconds */
1075 gettimeofday( &tb
, &tzp
) ;
1078 msecs
= 1000 * isec
+ usec
/ 1000 ;
1081 RSL_INTERNAL_MICROCLOCK ()
1084 struct timezone tzp
;
1085 int isec
; /* seconds */
1086 int usec
; /* microseconds */
1088 gettimeofday( &tb
, &tzp
) ;
1091 msecs
= 1000000 * isec
+ usec
;