Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'hypervisor' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid...
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / rcancel.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2003 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Test of various receive cancel calls, with multiple requests to cancel";
13 */
14
15 int main( int argc, char *argv[] )
16 {
17     int errs = 0;
18     int rank, size, source, dest;
19     MPI_Comm      comm;
20     MPI_Status    status;
21     MPI_Request   req[4];
22     static int bufsizes[4] = { 1, 100, 10000, 1000000 };
23     char *bufs[4];
24     int  flag, i;
25
26     MTest_Init( &argc, &argv );
27
28     comm = MPI_COMM_WORLD;
29     MPI_Comm_rank( comm, &rank );
30     MPI_Comm_size( comm, &size );
31
32     source = 0;
33     dest   = size - 1;
34
35     if (rank == source) {
36         MPI_Send( MPI_BOTTOM, 0, MPI_CHAR, dest, 1, MPI_COMM_WORLD );
37     }
38     else if (rank == dest) {
39         /* Create 3 requests to cancel, plus one to use.  
40            Then receive one message and exit */ 
41         for (i=0; i<4; i++) {
42             bufs[i] = (char *) malloc( bufsizes[i] );
43             MPI_Irecv( bufs[i], bufsizes[i], MPI_CHAR, source, 
44                        i, MPI_COMM_WORLD, &req[i] );
45         }
46         /* Now, cancel them in a more interesting order, to ensure that the
47            queue operation work properly */
48         MPI_Cancel( &req[2] );
49         MPI_Wait( &req[2], &status );
50         MTestPrintfMsg( 1, "Completed wait on irecv[2]\n" );
51         MPI_Test_cancelled( &status, &flag );
52         if (!flag) {
53             errs ++;
54             printf( "Failed to cancel a Irecv[2] request\n" );
55             fflush(stdout);
56         }
57         MPI_Cancel( &req[3] );
58         MPI_Wait( &req[3], &status );
59         MTestPrintfMsg( 1, "Completed wait on irecv[3]\n" );
60         MPI_Test_cancelled( &status, &flag );
61         if (!flag) {
62             errs ++;
63             printf( "Failed to cancel a Irecv[3] request\n" );
64             fflush(stdout);
65         }
66         MPI_Cancel( &req[0] );
67         MPI_Wait( &req[0], &status );
68         MTestPrintfMsg( 1, "Completed wait on irecv[0]\n" );
69         MPI_Test_cancelled( &status, &flag );
70         if (!flag) {
71             errs ++;
72             printf( "Failed to cancel a Irecv[0] request\n" );
73             fflush(stdout);
74         }
75         MPI_Wait( &req[1], &status );
76         MPI_Test_cancelled( &status, &flag );
77         if (flag) {
78             errs ++;
79             printf( "Incorrectly cancelled Irecv[1]\n" ); fflush(stdout);
80         }
81     }
82
83     MTest_Finalize( errs );
84     MPI_Finalize();
85     return 0;
86 }