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.
11 /* Test Ibsend and Request_free */
12 int main(int argc, char *argv[])
14 MPI_Comm comm = MPI_COMM_WORLD;
15 int dest = 1, src = 0, tag = 1;
19 int errs = 0, rank, size;
22 MTest_Init(&argc, &argv);
23 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24 MPI_Comm_size(MPI_COMM_WORLD, &size);
25 if (src >= size || dest >= size) {
29 fprintf(stderr, "This program requires %d processes\n", r - 1);
30 MPI_Abort(MPI_COMM_WORLD, 1);
36 MPI_Barrier(MPI_COMM_WORLD);
38 /* According to the standard, we must use the PACK_SIZE length of each
39 * message in the computation of the message buffer size */
40 MPI_Pack_size(5, MPI_INT, comm, &s1);
41 bufsize = MPI_BSEND_OVERHEAD + s1 + 2000;
42 buf = (char *) malloc(bufsize);
43 MPI_Buffer_attach(buf, bufsize);
45 MTestPrintfMsg(10, "About create and free Isend request\n");
47 MPI_Isend(&smsg[0], 1, MPI_INT, dest, tag, comm, &r);
49 if (r != MPI_REQUEST_NULL) {
51 fprintf(stderr, "Request not set to NULL after request free\n");
53 MTestPrintfMsg(10, "About create and free Ibsend request\n");
55 MPI_Ibsend(&smsg[1], 1, MPI_INT, dest, tag + 1, comm, &r);
57 if (r != MPI_REQUEST_NULL) {
59 fprintf(stderr, "Request not set to NULL after request free\n");
61 MTestPrintfMsg(10, "About create and free Issend request\n");
63 MPI_Issend(&smsg[2], 1, MPI_INT, dest, tag + 2, comm, &r);
65 if (r != MPI_REQUEST_NULL) {
67 fprintf(stderr, "Request not set to NULL after request free\n");
69 MTestPrintfMsg(10, "About create and free Irsend request\n");
71 MPI_Irsend(&smsg[3], 1, MPI_INT, dest, tag + 3, comm, &r);
73 if (r != MPI_REQUEST_NULL) {
75 fprintf(stderr, "Request not set to NULL after request free\n");
78 MPI_Isend(&smsg[4], 1, MPI_INT, dest, tag + 4, comm, &r);
79 MPI_Wait(&r, MPI_STATUS_IGNORE);
81 /* We can't guarantee that messages arrive until the detach */
82 MPI_Buffer_detach(&bbuf, &bsize);
90 for (i = 0; i < 5; i++) {
91 MPI_Irecv(&rmsg[i], 1, MPI_INT, src, tag + i, comm, &r[i]);
93 if (rank != src) /* Just in case rank == src */
94 MPI_Barrier(MPI_COMM_WORLD);
96 for (i = 0; i < 4; i++) {
97 MPI_Wait(&r[i], MPI_STATUS_IGNORE);
98 if (rmsg[i] != 10 + i) {
100 fprintf(stderr, "message %d (%d) should be %d\n", i, rmsg[i], 10 + i);
103 /* The MPI standard says that there is no way to use MPI_Request_free
104 * safely with receive requests. A strict MPI implementation may
105 * choose to consider these erroreous (an IBM MPI implementation
107 #ifdef USE_STRICT_MPI
108 MPI_Wait(&r[4], MPI_STATUS_IGNORE);
110 MTestPrintfMsg(10, "About free Irecv request\n");
111 MPI_Request_free(&r[4]);
115 if (rank != dest && rank != src) {
116 MPI_Barrier(MPI_COMM_WORLD);
120 MTest_Finalize(errs);