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) continue;
39 /* Determine the sender and receiver */
40 MPI_Comm_rank( comm, &rank );
41 MPI_Comm_size( comm, &size );
45 /* Here is the test: The sender */
47 /* Get a bsend buffer. Make it large enough that the Bsend
48 internals will (probably) not use a eager send for the data.
49 Have three such messages */
50 bufsize = 3 * (MPI_BSEND_OVERHEAD + msgsize);
51 buf = (unsigned char *)malloc( bufsize );
53 fprintf( stderr, "Unable to allocate a buffer of %d bytes\n",
55 MPI_Abort( MPI_COMM_WORLD, 1 );
59 MPI_Buffer_attach( buf, bufsize );
61 /* Initialize the buffers */
62 for (i=0; i<msgsize; i++) {
63 msg1[i] = 0xff ^ (i & 0xff);
64 msg2[i] = 0xff ^ (3*i & 0xff);
65 msg3[i] = 0xff ^ (5*i & 0xff);
68 /* Initiate the bsends */
69 MPI_Bsend( msg1, msgsize, MPI_CHAR, dest, 0, comm );
70 MPI_Bsend( msg2, msgsize, MPI_CHAR, dest, 0, comm );
71 MPI_Bsend( msg3, msgsize, MPI_CHAR, dest, 0, comm );
73 /* Synchronize with our partner */
74 MPI_Sendrecv( 0, 0, MPI_CHAR, dest, 10,
75 0, 0, MPI_CHAR, dest, 10, comm, MPI_STATUS_IGNORE );
77 /* Detach the buffers. There should be pending operations */
78 MPI_Buffer_detach ( &bufp, &outsize );
80 fprintf( stderr, "Wrong buffer returned\n" );
83 if (outsize != bufsize) {
84 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( 0, 0, MPI_CHAR, source, 10,
100 0, 0, MPI_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_CHAR, source, 0, comm, &status1 );
108 MPI_Recv( msg2, msgsize, MPI_CHAR, source, 0, comm, &status2 );
109 MPI_Recv( msg3, msgsize, MPI_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 );