1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2006 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
10 #include <string.h> /* For memset */
12 int main(int argc, char *argv[])
16 int *buf0, *buf1, *buf2;
17 int rank, size, src, dest, flag, errs = 0;
21 MTest_Init(&argc, &argv);
23 MPI_Comm_size(MPI_COMM_WORLD, &size);
25 fprintf(stderr, "Must run with at least 2 processes\n");
26 MPI_Abort(MPI_COMM_WORLD, 1);
28 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32 comm = MPI_COMM_WORLD;
35 buf0 = (int *) malloc(n0 * sizeof(int));
36 buf1 = (int *) malloc(n1 * sizeof(int));
37 buf2 = (int *) malloc(n2 * sizeof(int));
38 if (!buf0 || !buf1 || !buf2) {
39 fprintf(stderr, "Unable to allocate buffers of size %d\n", n0 * (int) sizeof(int));
40 MPI_Abort(MPI_COMM_WORLD, 1);
42 memset(buf0, -1, n0 * sizeof(int));
43 memset(buf1, -1, n0 * sizeof(int));
44 memset(buf2, -1, n0 * sizeof(int));
47 MPI_Irecv(buf0, n0, MPI_INT, src, 0, comm, &r[0]);
48 MPI_Irecv(buf1, n1, MPI_INT, src, 1, comm, &r[1]);
49 MPI_Irecv(buf2, n2, MPI_INT, src, 2, comm, &r[2]);
55 memset(s, -1, sizeof(s));
57 MPI_Test_cancelled(&s[0], &flag);
60 printf("request 0 was cancelled!\n");
62 MPI_Test_cancelled(&s[1], &flag);
65 printf("request 1 was not cancelled!\n");
67 MPI_Test_cancelled(&s[2], &flag);
70 printf("request 2 was cancelled!\n");
78 MPI_Send(buf0, n0, MPI_INT, dest, 0, comm);
79 MPI_Isend(buf2, n2, MPI_INT, dest, 2, comm, &r[1]);
80 MPI_Isend(buf1, n1, MPI_INT, dest, 4, comm, &r[0]);
82 memset(s, -3, sizeof(s));
85 MPI_Testall(2, r, &tflag, s);
87 MPI_Test_cancelled(&s[0], &flag);
90 printf("send request 0 was not cancelled!\n");
92 MPI_Test_cancelled(&s[1], &flag);
95 printf("send request 1 was cancelled!\n");
99 /* If all requests are not complete, then neither r nor s
101 if ((s[0].MPI_ERROR) != -3) {
103 printf("Send request status 0 modified. s[0].MPI_ERROR = %d\n", s[0].MPI_ERROR);
105 if ((s[1].MPI_ERROR) != -3) {
107 printf("Send request status 1 modified. s[1].MPI_ERROR = %d\n", s[1].MPI_ERROR);
112 MPI_Testall(2, r, &tflag, s);
114 MPI_Test_cancelled(&s[0], &flag);
117 printf("send request 0 was not cancelled!\n");
119 MPI_Test_cancelled(&s[1], &flag);
122 printf("send request 1 was cancelled!\n");
125 if (rank != src && rank != dest) {
131 MTest_Finalize(errs);