1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 static char MTEST_Descrip[] = "Test the handling of BSend operations when a detach occurs before the bsend data has been sent.";
16 int main(int argc, char *argv[])
19 int rank, size, source, dest;
20 unsigned char *buf, *bufp;
22 int i, msgsize, bufsize, outsize;
23 unsigned char *msg1, *msg2, *msg3;
25 MPI_Status status1, status2, status3;
27 MTest_Init(&argc, &argv);
29 /* The following illustrates the use of the routines to
30 * run through a selection of communicators and datatypes.
31 * Use subsets of these for tests that do not involve combinations
32 * of communicators, datatypes, and counts of datatypes */
34 msg1 = (unsigned char *) malloc(3 * msgsize);
35 msg2 = msg1 + msgsize;
36 msg3 = msg2 + msgsize;
37 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
38 if (comm == MPI_COMM_NULL)
40 /* Determine the sender and receiver */
41 MPI_Comm_rank(comm, &rank);
42 MPI_Comm_size(comm, &size);
46 /* Here is the test: The sender */
48 /* Get a bsend buffer. Make it large enough that the Bsend
49 * internals will (probably) not use a eager send for the data.
50 * Have three such messages */
51 bufsize = 3 * (MPI_BSEND_OVERHEAD + msgsize);
52 buf = (unsigned char *) malloc(bufsize);
54 fprintf(stderr, "Unable to allocate a buffer of %d bytes\n", bufsize);
55 MPI_Abort(MPI_COMM_WORLD, 1);
58 MPI_Buffer_attach(buf, bufsize);
60 /* Initialize the buffers */
61 for (i = 0; i < msgsize; i++) {
62 msg1[i] = 0xff ^ (i & 0xff);
63 msg2[i] = 0xff ^ (3 * i & 0xff);
64 msg3[i] = 0xff ^ (5 * i & 0xff);
67 /* Initiate the bsends */
68 MPI_Bsend(msg1, msgsize, MPI_UNSIGNED_CHAR, dest, 0, comm);
69 MPI_Bsend(msg2, msgsize, MPI_UNSIGNED_CHAR, dest, 0, comm);
70 MPI_Bsend(msg3, msgsize, MPI_UNSIGNED_CHAR, dest, 0, comm);
72 /* Synchronize with our partner */
73 MPI_Sendrecv(NULL, 0, MPI_UNSIGNED_CHAR, dest, 10,
74 NULL, 0, MPI_UNSIGNED_CHAR, dest, 10, comm, MPI_STATUS_IGNORE);
76 /* Detach the buffers. There should be pending operations */
77 MPI_Buffer_detach(&bufp, &outsize);
79 fprintf(stderr, "Wrong buffer returned\n");
82 if (outsize != bufsize) {
83 fprintf(stderr, "Wrong buffer size returned\n");
88 else if (rank == dest) {
91 /* Clear the message buffers */
92 for (i = 0; i < msgsize; i++) {
98 /* Wait for the synchronize */
99 MPI_Sendrecv(NULL, 0, MPI_UNSIGNED_CHAR, source, 10,
100 NULL, 0, MPI_UNSIGNED_CHAR, source, 10, comm, MPI_STATUS_IGNORE);
103 tstart = MPI_Wtime();
104 while (MPI_Wtime() - tstart < 2.0);
106 /* Now receive the messages */
107 MPI_Recv(msg1, msgsize, MPI_UNSIGNED_CHAR, source, 0, comm, &status1);
108 MPI_Recv(msg2, msgsize, MPI_UNSIGNED_CHAR, source, 0, comm, &status2);
109 MPI_Recv(msg3, msgsize, MPI_UNSIGNED_CHAR, source, 0, comm, &status3);
111 /* Check that we have the correct data */
112 for (i = 0; i < msgsize; i++) {
113 if (msg1[i] != (0xff ^ (i & 0xff))) {
115 fprintf(stderr, "msg1[%d] = %d\n", i, msg1[i]);
119 if (msg2[i] != (0xff ^ (3 * i & 0xff))) {
121 fprintf(stderr, "msg2[%d] = %d\n", i, msg2[i]);
125 if (msg3[i] != (0xff ^ (5 * i & 0xff))) {
127 fprintf(stderr, "msg2[%d] = %d\n", i, msg2[i]);
136 MTestFreeComm(&comm);
140 MTest_Finalize(errs);