Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the compilation of MPICH3 tests with the absolute paranoid flags (enable_maintainer)
[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, i, MPI_COMM_WORLD, &req[i]);
44         }
45         /* Now, cancel them in a more interesting order, to ensure that the
46          * queue operation work properly */
47         MPI_Cancel(&req[2]);
48         MPI_Wait(&req[2], &status);
49         MTestPrintfMsg(1, "Completed wait on irecv[2]\n");
50         MPI_Test_cancelled(&status, &flag);
51         if (!flag) {
52             errs++;
53             printf("Failed to cancel a Irecv[2] request\n");
54             fflush(stdout);
55         }
56         MPI_Cancel(&req[3]);
57         MPI_Wait(&req[3], &status);
58         MTestPrintfMsg(1, "Completed wait on irecv[3]\n");
59         MPI_Test_cancelled(&status, &flag);
60         if (!flag) {
61             errs++;
62             printf("Failed to cancel a Irecv[3] request\n");
63             fflush(stdout);
64         }
65         MPI_Cancel(&req[0]);
66         MPI_Wait(&req[0], &status);
67         MTestPrintfMsg(1, "Completed wait on irecv[0]\n");
68         MPI_Test_cancelled(&status, &flag);
69         if (!flag) {
70             errs++;
71             printf("Failed to cancel a Irecv[0] request\n");
72             fflush(stdout);
73         }
74         MPI_Wait(&req[1], &status);
75         MPI_Test_cancelled(&status, &flag);
76         if (flag) {
77             errs++;
78             printf("Incorrectly cancelled Irecv[1]\n");
79             fflush(stdout);
80         }
81         for (i = 0; i < 4; i++) {
82             free(bufs[i]);
83         }
84     }
85
86     MTest_Finalize(errs);
87     MPI_Finalize();
88     return 0;
89 }