Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove few tests which may never finish, and change one that used too much stack...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / nullproc.c
1 /*
2  *  Test for null proc handling with non-blocking routines
3  */
4
5
6 #include <stdio.h>
7 #include "mpi.h"
8
9 #if defined(NEEDS_STDLIB_PROTOTYPES)
10 #include "protofix.h"
11 #endif
12
13 int main( int argc, char *argv[] )
14 {
15    int             a[4];
16    int             i, nproc;
17    int             rank, right, left;
18    MPI_Status      status;
19    MPI_Request     req[4];
20    int             index, it, count, errcnt = 0;
21
22    /* start up */
23    MPI_Init(&argc, &argv);
24    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
25    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26
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;
30
31    /* initialize local matrix */
32    /* globally: a[i] = i, i = 1 .. 2*nproc */
33    /* locally : a[i] = 2*rank+i, i=1,2 */
34    a[0] = -1;
35    a[1] = 2*rank + 1; 
36    a[2] = 2*rank + 2; 
37    a[3] = -1;
38
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]);
44
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) {
52                errcnt ++;
53                fprintf( stderr, "Incorrect null status for left\n" );
54            }
55            MPI_Get_count( &status, MPI_INT, &count );
56            if (count != 0) {
57                errcnt ++;
58                fprintf( stderr, "Incorrect null status for left (count)\n" );
59            }
60        }
61        else if (index == 3 && right == MPI_PROC_NULL) {
62            if (status.MPI_TAG != MPI_ANY_TAG ||
63                status.MPI_SOURCE != MPI_PROC_NULL) {
64                errcnt ++;
65                fprintf( stderr, "Incorrect null status for right\n" );
66            }
67            MPI_Get_count( &status, MPI_INT, &count );
68            if (count != 0) {
69                errcnt ++;
70                fprintf( stderr, "Incorrect null status for right (count)\n" );
71            }
72        }
73    }
74    
75    /* Test results */
76    if (left == MPI_PROC_NULL) {
77        if (a[0] != -1) {
78            fprintf( stderr, "Expected -1, found %d in left partner\n", a[0] );
79            errcnt ++;
80        }
81    }
82    else {
83        if (a[0] != 2 * left + 2) {
84            fprintf( stderr, "Expected %d, found %d in left partner\n", 
85                     2 * left + 2, a[0] );
86            errcnt ++;
87        }
88    }
89
90    if (right == MPI_PROC_NULL) {
91        if (a[3] != -1) {
92            fprintf( stderr, "Expected -1, found %d in right partner\n", a[3] );
93            errcnt ++;
94        }
95    }
96    else {
97        if (a[3] != 2 * right + 1) {
98            fprintf( stderr, "Expected %d, found %d in right partner\n", 
99                     2 * right + 1, a[3] );
100            errcnt ++;
101        }
102    }
103
104    
105    i = errcnt;
106    MPI_Allreduce( &i, &errcnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
107    if (rank == 0) {
108        if (errcnt > 0) {
109            printf( "Found %d errors in the run \n", errcnt );
110        }
111        else
112            printf( "No errors in handling MPI_PROC_NULL\n" );
113    }
114    
115    /* clean up */
116    MPI_Finalize();
117    return 0;
118 }