Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b027f0b6d83c57eb17e0344997df13aad5f95749
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / scancel2.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 send cancel (failure) calls";
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;
22     static int bufsizes[4] = { 1, 100, 10000, 1000000 };
23     char *buf;
24     int  cs, flag, n;
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     MTestPrintfMsg( 1, "Starting scancel test\n" );
36
37     for (cs=0; cs<4; cs++) {
38         n = bufsizes[cs];
39         buf = (char *)malloc( n );
40         if (!buf) {
41             fprintf( stderr, "Unable to allocate %d bytes\n", n );
42             MPI_Abort( MPI_COMM_WORLD, 1 );
43         }
44
45         if (rank == source) {
46             MTestPrintfMsg( 1, "(%d) About to create isend and cancel\n",cs );
47             MPI_Isend( buf, n, MPI_CHAR, dest, cs+n+1, comm, &req );
48             MPI_Barrier( comm );
49             MPI_Cancel( &req );
50             MPI_Wait( &req, &status );
51             MTestPrintfMsg( 1, "Completed wait on isend\n" );
52             MPI_Test_cancelled( &status, &flag );
53             if (flag) {
54                 errs ++;
55                 printf( "Cancelled a matched Isend request (msg size = %d)!\n",
56                         n );
57                 fflush(stdout);
58             }
59             else
60             {
61                 n = 0;
62             }
63             /* Send the size, zero for not cancelled (success) */
64             MPI_Send( &n, 1, MPI_INT, dest, 123, comm );
65         }
66         else if (rank == dest)
67         {
68             MPI_Recv( buf, n, MPI_CHAR, source, cs+n+1, comm, &status );
69             MPI_Barrier( comm );
70             MPI_Recv( &n, 1, MPI_INT, source, 123, comm, &status );
71         }
72         else {
73             MPI_Barrier( comm );
74         }
75
76         MPI_Barrier( comm );
77         free( buf );
78     }
79
80     MTest_Finalize( errs );
81     MPI_Finalize();
82     return 0;
83 }