Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove unwanted files
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / cancelibm.c
1 /****************************************************************************
2
3   MESSAGE PASSING INTERFACE TEST CASE SUITE
4   
5   Copyright IBM Corp. 1995
6         
7   IBM Corp. hereby grants a non-exclusive license to use, copy, modify, and
8   distribute this software for any purpose and without fee provided that the
9   above copyright notice and the following paragraphs appear in all copies.
10           
11   IBM Corp. makes no representation that the test cases comprising this
12   suite are correct or are an accurate representation of any standard.
13                 
14   In no event shall IBM be liable to any party for direct, indirect, special
15   incidental, or consequential damage arising out of the use of this software
16   even if IBM Corp. has been advised of the possibility of such damage.
17                   
18   IBM CORP. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT NOT LIMITED
19   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20   PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS AND IBM
21   CORP. HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
22   ENHANCEMENTS, OR MODIFICATIONS.
23                         
24   ****************************************************************************
25                           
26   These test cases reflect an interpretation of the MPI Standard.  They are
27   are, in most cases, unit tests of specific MPI behaviors.  If a user of any
28   test case from this set believes that the MPI Standard requires behavior
29   different than that implied by the test case we would appreciate feedback.
30   
31   Comments may be sent to:
32   Richard Treumann
33   treumann@kgn.ibm.com
34                                   
35   ****************************************************************************
36 */
37 #include <stdio.h>
38 #include "mpi.h"
39
40 int main(int argc, char *argv[])
41 {
42         int me, tasks, data, flag;
43         int err0 = 0;
44         int err1 = 0;
45         int errs, toterrs;
46         MPI_Request request;
47         MPI_Status status;
48
49         MPI_Init(&argc,&argv);
50         MPI_Comm_rank(MPI_COMM_WORLD,&me);
51         MPI_Comm_size(MPI_COMM_WORLD,&tasks);
52
53         if (tasks < 2) {
54             printf( "Cancel test requires at least 2 processes\n" );
55             MPI_Abort( MPI_COMM_WORLD, 1 );
56         }
57         
58         { int data[100000]; if (me == 0)  
59         {
60                 MPI_Irecv(data, 1, MPI_INT, 1, 1, MPI_COMM_WORLD,&request);
61                 MPI_Cancel(&request);
62                 MPI_Wait(&request,&status);
63                 MPI_Test_cancelled(&status,&flag);
64                 if (!flag) {
65                     err0++;
66                     printf("task %d ERROR: Receive request not cancelled!\n", me);
67                 }
68
69                 MPI_Issend(data, 100000, MPI_INT, 1, 1, MPI_COMM_WORLD,&request);
70                 MPI_Cancel(&request);
71                 for (flag = 0;; )  
72                 {
73                         MPI_Test(&request,&flag,&status);
74                         if (flag) break;
75                 }
76                 
77                 MPI_Test_cancelled(&status,&flag);
78                 if (!flag) {
79                     err0++;
80                     printf("task %d ERROR: Send request not cancelled! (1)\n", me);
81                 }
82         }}
83         
84         if (me == 0)  
85         {
86                 data = 5;
87                 MPI_Isend(&data, 1, MPI_INT, 1, 1, MPI_COMM_WORLD,&request);
88                 MPI_Cancel(&request);
89                 MPI_Wait(&request,&status);
90                 MPI_Test_cancelled(&status,&flag);
91                 if (!flag) {
92                     err0++;
93                     printf("task %d ERROR: Send request not cancelled! (2)\n", me);
94                 }
95                 MPI_Barrier(MPI_COMM_WORLD);
96                 status.MPI_TAG=MPI_SUCCESS;
97                 data = 6;
98                 MPI_Send(&data, 1, MPI_INT, 1, 5, MPI_COMM_WORLD);
99                 
100                 data = 7;
101                 MPI_Isend(&data, 1, MPI_INT, 1, 1, MPI_COMM_WORLD,&request);
102                 MPI_Barrier(MPI_COMM_WORLD);
103                 MPI_Cancel(&request);
104                 MPI_Wait(&request,&status);
105                 MPI_Test_cancelled(&status,&flag);
106                 if (flag) {
107                     err0++;
108                     printf("task %d ERROR: Send request cancelled!\n", me);
109                 }
110         } 
111         else if (me == 1) 
112         {
113             MPI_Barrier(MPI_COMM_WORLD);
114             data = 0;
115             MPI_Recv(&data, 1, MPI_INT, 0, 1, MPI_COMM_WORLD,&status);
116             if (data != 7) {
117                 err1++;
118                 printf("task %d ERROR: Send request not cancelled!\n", me);
119             }
120             
121             MPI_Recv(&data, 1, MPI_INT, 0, 5, MPI_COMM_WORLD,&status);
122             if (data != 6) {
123                 err1++;
124                 printf("task %d ERROR: Send request not cancelled!\n", me);
125             }
126             MPI_Barrier(MPI_COMM_WORLD);
127         }
128         else {
129             /* These are needed when the size of MPI_COMM_WORLD > 2 */
130             MPI_Barrier( MPI_COMM_WORLD );
131             MPI_Barrier( MPI_COMM_WORLD );
132         }
133         
134         errs = err0 + err1;
135         MPI_Reduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
136             
137         if ( errs ) {
138             printf( "Test failed with %d errors.\n", errs );
139         }
140         if (me == 0 && toterrs == 0) {
141             printf( " No Errors\n" );
142         }
143               
144         MPI_Finalize();
145         return 0;
146 }