2
* Test for null proc handling with non-blocking routines
9
#if defined(NEEDS_STDLIB_PROTOTYPES)
13
int main( int argc, char *argv[] )
17
int rank, right, left;
20
int index, it, count, errcnt = 0;
23
MPI_Init(&argc, &argv);
24
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
25
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27
/* set up processor chain (Apps should use Cart_create/shift) */
28
left = (rank == 0) ? MPI_PROC_NULL : rank - 1;
29
right = (rank == nproc - 1) ? MPI_PROC_NULL : rank + 1;
31
/* initialize local matrix */
32
/* globally: a[i] = i, i = 1 .. 2*nproc */
33
/* locally : a[i] = 2*rank+i, i=1,2 */
39
/* start all receives and sends */
40
MPI_Irecv(&a[0], 1, MPI_INT, left, 1, MPI_COMM_WORLD, &req[0]);
41
MPI_Irecv(&a[3], 1, MPI_INT, right, 0, MPI_COMM_WORLD, &req[3]);
42
MPI_Isend(&a[1], 1, MPI_INT, left, 0, MPI_COMM_WORLD, &req[1]);
43
MPI_Isend(&a[2], 1, MPI_INT, right, 1, MPI_COMM_WORLD, &req[2]);
45
for (it=0; it<4; it++) {
46
status.MPI_SOURCE = nproc;
47
status.MPI_TAG = nproc;
48
MPI_Waitany( 4, req, &index, &status );
49
if (index == 0 && left == MPI_PROC_NULL) {
50
if (status.MPI_TAG != MPI_ANY_TAG ||
51
status.MPI_SOURCE != MPI_PROC_NULL) {
53
fprintf( stderr, "Incorrect null status for left\n" );
55
MPI_Get_count( &status, MPI_INT, &count );
58
fprintf( stderr, "Incorrect null status for left (count)\n" );
61
else if (index == 3 && right == MPI_PROC_NULL) {
62
if (status.MPI_TAG != MPI_ANY_TAG ||
63
status.MPI_SOURCE != MPI_PROC_NULL) {
65
fprintf( stderr, "Incorrect null status for right\n" );
67
MPI_Get_count( &status, MPI_INT, &count );
70
fprintf( stderr, "Incorrect null status for right (count)\n" );
76
if (left == MPI_PROC_NULL) {
78
fprintf( stderr, "Expected -1, found %d in left partner\n", a[0] );
83
if (a[0] != 2 * left + 2) {
84
fprintf( stderr, "Expected %d, found %d in left partner\n",
90
if (right == MPI_PROC_NULL) {
92
fprintf( stderr, "Expected -1, found %d in right partner\n", a[3] );
97
if (a[3] != 2 * right + 1) {
98
fprintf( stderr, "Expected %d, found %d in right partner\n",
99
2 * right + 1, a[3] );
106
MPI_Allreduce( &i, &errcnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
109
printf( "Found %d errors in the run \n", errcnt );
112
printf( "No errors in handling MPI_PROC_NULL\n" );