Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free memory.
[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         MTEST_VG_MEM_INIT(buf, n);
41         if (!buf) {
42             fprintf(stderr, "Unable to allocate %d bytes\n", n);
43             MPI_Abort(MPI_COMM_WORLD, 1);
44         }
45
46         if (rank == source) {
47             MTestPrintfMsg(1, "(%d) About to create isend and cancel\n", cs);
48             MPI_Isend(buf, n, MPI_CHAR, dest, cs + n + 1, comm, &req);
49             MPI_Barrier(comm);
50             MPI_Cancel(&req);
51             MPI_Wait(&req, &status);
52             MTestPrintfMsg(1, "Completed wait on isend\n");
53             MPI_Test_cancelled(&status, &flag);
54             if (flag) {
55                 errs++;
56                 printf("Cancelled a matched Isend request (msg size = %d)!\n", n);
57                 fflush(stdout);
58             }
59             else {
60                 n = 0;
61             }
62             /* Send the size, zero for not cancelled (success) */
63             MPI_Send(&n, 1, MPI_INT, dest, 123, comm);
64         }
65         else if (rank == dest) {
66             MPI_Recv(buf, n, MPI_CHAR, source, cs + n + 1, comm, &status);
67             MPI_Barrier(comm);
68             MPI_Recv(&n, 1, MPI_INT, source, 123, comm, &status);
69         }
70         else {
71             MPI_Barrier(comm);
72         }
73
74         MPI_Barrier(comm);
75         free(buf);
76     }
77
78     MTest_Finalize(errs);
79     MPI_Finalize();
80     return 0;
81 }