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) {
27 if (dest > r) r = dest;
28 fprintf( stderr, "This program requires %d processes\n", r-1 );
29 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 );
48 MPI_Request_free( &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 );
56 MPI_Request_free( &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 );
64 MPI_Request_free( &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 );
72 MPI_Request_free( &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 MPI_Irecv( &rmsg[i], 1, MPI_INT, src, tag+i, comm, &r[i] );
92 if (rank != src) /* Just in case rank == src */
93 MPI_Barrier( MPI_COMM_WORLD );
96 MPI_Wait( &r[i], MPI_STATUS_IGNORE );
97 if (rmsg[i] != 10+i) {
99 fprintf( stderr, "message %d (%d) should be %d\n", i, rmsg[i], 10+i );
102 /* The MPI standard says that there is no way to use MPI_Request_free
103 safely with receive requests. A strict MPI implementation may
104 choose to consider these erroreous (an IBM MPI implementation
106 #ifdef USE_STRICT_MPI
107 MPI_Wait( &r[4], MPI_STATUS_IGNORE );
109 MTestPrintfMsg( 10, "About free Irecv request\n" );
110 MPI_Request_free( &r[4] );
114 if (rank != dest && rank != src) {
115 MPI_Barrier( MPI_COMM_WORLD );
119 MTest_Finalize( errs );