1 /****************************************************************************
3 MESSAGE PASSING INTERFACE TEST CASE SUITE
5 Copyright IBM Corp. 1995
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.
11 IBM Corp. makes no representation that the test cases comprising this
12 suite are correct or are an accurate representation of any standard.
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.
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.
24 ****************************************************************************
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.
31 Comments may be sent to:
35 ****************************************************************************
40 * This is a modified version that:
41 * Uses a shorter message (in case the implementation uses eager delivery
42 * even with synchronous send)
43 * Allows control of which process is executing the Issend and which the
44 * receive (to simplify debugging)
49 int main(int argc, char *argv[])
51 int me, tasks, data, flag;
55 int master = 1, worker = 0;
59 MPI_Init(&argc,&argv);
60 MPI_Comm_rank(MPI_COMM_WORLD,&me);
61 MPI_Comm_size(MPI_COMM_WORLD,&tasks);
64 printf( "Cancel test requires at least 2 processes\n" );
65 MPI_Abort( MPI_COMM_WORLD, 1 );
68 /* The original test sent 10000 elements with Issend. This
69 one uses less data but keeps the array the same size */
70 { int data[100000]; if (me == master)
72 MPI_Irecv(data, 1, MPI_INT, worker, 1, MPI_COMM_WORLD,&request);
74 MPI_Wait(&request,&status);
75 MPI_Test_cancelled(&status,&flag);
78 printf("task %d ERROR: Receive request not cancelled!\n", me);
81 /* This is short enough to use eager but because it is
82 a Synchronous send, it must still be possible to
83 cancel it, even when it is a short message */
84 MPI_Issend(data, 100, MPI_INT, worker, 1, MPI_COMM_WORLD,&request);
88 MPI_Test(&request,&flag,&status);
92 MPI_Test_cancelled(&status,&flag);
95 printf("task %d ERROR: Send request not cancelled! (1)\n", me);
102 MPI_Isend(&data, 1, MPI_INT, worker, 1, MPI_COMM_WORLD,&request);
103 MPI_Cancel(&request);
104 MPI_Wait(&request,&status);
105 MPI_Test_cancelled(&status,&flag);
108 printf("task %d ERROR: Send request not cancelled! (2)\n", me);
110 MPI_Barrier(MPI_COMM_WORLD);
111 status.MPI_TAG=MPI_SUCCESS;
113 MPI_Send(&data, 1, MPI_INT, worker, 5, MPI_COMM_WORLD);
115 MPI_Isend(&data, 1, MPI_INT, worker, 1, MPI_COMM_WORLD,&request);
116 MPI_Barrier(MPI_COMM_WORLD);
117 MPI_Cancel(&request);
118 MPI_Wait(&request,&status);
119 MPI_Test_cancelled(&status,&flag);
122 printf("task %d ERROR: Send request cancelled!\n", me);
125 else if (me == worker)
127 MPI_Barrier(MPI_COMM_WORLD);
129 MPI_Recv(&data, 1, MPI_INT, master, 1, MPI_COMM_WORLD,&status);
132 printf("task %d ERROR: Send request not cancelled!\n", me);
135 MPI_Recv(&data, 1, MPI_INT, master, 5, MPI_COMM_WORLD,&status);
138 printf("task %d ERROR: Send request not cancelled!\n", me);
140 MPI_Barrier(MPI_COMM_WORLD);
143 /* These are needed when the size of MPI_COMM_WORLD > 2 */
144 MPI_Barrier( MPI_COMM_WORLD );
145 MPI_Barrier( MPI_COMM_WORLD );
149 MPI_Reduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
152 printf( "Test failed with %d errors.\n", errs );
154 if (me == 0 && toterrs == 0) {
155 printf( " No Errors\n" );