Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
handle nested datatypes in smpi (structs of vectors for example), which previously...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / cancelmessages.c
1 /*
2  * This file tests to see if short,eager,and rndv messages can all be 
3  * successfully cancelled.  If they cannot be cancelled, then the 
4  * program still must successfully complete.
5  */
6
7 #include "mpi.h"
8 #include <stdio.h>
9
10 #if defined(NEEDS_STDLIB_PROTOTYPES)
11 #include "protofix.h"
12 #endif
13
14 int main( int argc, char *argv[] )
15 {
16
17     double       sbuf[20000];
18 #ifdef FOO
19     double rbuf[20000];
20 #endif
21     int          rank;
22     int          n, flag, size;
23     int          err = 0;
24     int          verbose = 0;
25     MPI_Status   status;
26     MPI_Request  req;
27
28     MPI_Init( &argc, &argv );
29     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
30     MPI_Comm_size( MPI_COMM_WORLD, &size );
31
32     if (size < 2) {
33         printf( "Cancel test requires at least 2 processes\n" );
34         MPI_Abort( MPI_COMM_WORLD, 1 );
35     }
36
37     /* Short Message Test */
38     n = 200;
39
40     if (rank == 1) { /* begin if rank = 1 */
41         MPI_Isend( sbuf, n, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &req );
42         MPI_Cancel(&req); 
43         MPI_Wait(&req, &status);
44         MPI_Test_cancelled(&status, &flag);
45         if (!flag) {
46             err++;
47             printf( "Cancelling a short message failed where it should succeed.\n" );
48         }
49         else if (verbose)
50         {
51             printf("Cancelling a short message succeeded.\n");
52         }
53     }  /* end if rank == 1 */
54
55 #ifdef FOO
56 /* Note that MPI-2 specifies that status.MPI_ERROR is only set by
57    multiple completion (e.g., MPI_Waitsome) and not by test_cancelled.
58 */
59     MPI_Barrier(MPI_COMM_WORLD); 
60
61     if (rank == 0) {  /* begin if rank == 0 */
62         MPI_Recv( rbuf, n, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &status);
63     }  /* end if rank = 0 */
64     else if (rank == 1) { /* begin if rank = 1 */
65         MPI_Isend( sbuf, n, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &req );
66         MPI_Cancel(&req); 
67         MPI_Wait(&req, &status);
68         MPI_Test_cancelled(&status, &flag);
69         if (!flag && status.MPI_ERROR != MPI_SUCCESS) {
70             err++;
71             printf( "Cancel of a send returned an error in the status field.\n" );
72         }
73           /* end if status.MPI_ERROR */
74     }  /* end if rank == 1 */
75 #endif
76
77     MPI_Barrier(MPI_COMM_WORLD);
78
79     /* Eager Message Test */
80     n = 3000;
81
82     if (rank == 1) { /* begin if rank = 1 */
83         MPI_Isend( sbuf, n, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &req );
84         MPI_Cancel(&req);
85         MPI_Wait(&req, &status);
86         MPI_Test_cancelled(&status, &flag);
87         if (!flag) {
88             err++;
89             printf( "Cancelling an eager message (3000 doubles) failed where it should succeed.\n" );
90         }
91         else if (verbose)
92         {
93             printf("Cancelling an eager message (3000 doubles) succeeded.\n");
94         }
95     }  /* end if rank == 1 */
96
97 #ifdef FOO
98     MPI_Barrier(MPI_COMM_WORLD); 
99
100     if (rank == 0) {  /* begin if rank == 0 */
101         MPI_Irecv(rbuf, n, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &req );
102         MPI_Wait( &req, &status);
103     }  /* end if rank = 0 */
104     else if (rank == 1) { /* begin if rank = 1 */
105         MPI_Isend( sbuf, n, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &req );
106         MPI_Cancel(&req);
107         MPI_Wait(&req, &status);
108         MPI_Test_cancelled(&status, &flag);
109         if (!flag && status.MPI_ERROR != MPI_SUCCESS) {
110             err++;
111             printf( "Cancel of a send returned an error in the status field.\n" );
112         }
113         /* end if status.MPI_ERROR */
114     }  /* end if rank == 1 */
115 #endif
116
117     MPI_Barrier(MPI_COMM_WORLD);
118
119     /* Rndv Message Test */
120     n = 20000;
121
122     if (rank == 1) { /* begin if rank = 1 */
123         MPI_Isend( sbuf, n, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &req );
124         MPI_Cancel(&req);
125         MPI_Wait(&req, &status);
126         MPI_Test_cancelled(&status, &flag);
127         if (!flag) {
128             err++;
129             printf( "Cancelling a rendezvous message failed (20000 doubles) where it should succeed.\n" );
130         }
131         else if (verbose)
132         {
133             printf("Cancelling an rendezvous message (20000 doubles) succeeded.\n");
134         }
135     }  /* end if rank == 1 */
136
137 #ifdef FOO
138     MPI_Barrier(MPI_COMM_WORLD); 
139
140     if (rank == 0) {  /* begin if rank == 0 */
141         MPI_Irecv(rbuf, n, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, &req );
142         MPI_Wait( &req, &status); 
143     }  /* end if rank = 0 */
144     else if (rank == 1) { /* begin if rank = 1 */
145         MPI_Isend( sbuf, n, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD, &req );
146         MPI_Cancel(&req);
147         MPI_Wait(&req, &status);
148         MPI_Test_cancelled(&status, &flag);
149         if (!flag && status.MPI_ERROR != MPI_SUCCESS) {
150             err++;
151             printf( "Cancel of a send returned an error in the status field.\n" );
152         }
153         /* end if status.MPI_ERROR */
154     }  /* end if rank == 1 */
155 #endif
156
157     MPI_Barrier(MPI_COMM_WORLD); 
158
159     if (rank == 1) {  /* begin if rank = 1 */
160         if (err) {
161             printf( "Test failed with %d errors.\n", err );
162         }
163         else {
164             printf( " No Errors\n" );
165         }
166     }
167
168     MPI_Finalize( );
169
170     return 0;
171 }