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 );
35 MPI_Barrier( MPI_COMM_WORLD );
37 /* According to the standard, we must use the PACK_SIZE length of each
38 message in the computation of the message buffer size */
39 MPI_Pack_size( 5, MPI_INT, comm, &s1 );
40 bufsize = MPI_BSEND_OVERHEAD + s1 + 2000;
41 buf = (char *)malloc( bufsize );
42 MPI_Buffer_attach( buf, bufsize );
44 MTestPrintfMsg( 10, "About create and free Isend request\n" );
46 MPI_Isend( &smsg[0], 1, MPI_INT, dest, tag, comm, &r );
47 MPI_Request_free( &r );
48 if (r != MPI_REQUEST_NULL) {
50 fprintf( stderr, "Request not set to NULL after request free\n" );
52 MTestPrintfMsg( 10, "About create and free Ibsend request\n" );
54 MPI_Ibsend( &smsg[1], 1, MPI_INT, dest, tag+1, comm, &r );
55 MPI_Request_free( &r );
56 if (r != MPI_REQUEST_NULL) {
58 fprintf( stderr, "Request not set to NULL after request free\n" );
60 MTestPrintfMsg( 10, "About create and free Issend request\n" );
62 MPI_Issend( &smsg[2], 1, MPI_INT, dest, tag+2, comm, &r );
63 MPI_Request_free( &r );
64 if (r != MPI_REQUEST_NULL) {
66 fprintf( stderr, "Request not set to NULL after request free\n" );
68 MTestPrintfMsg( 10, "About create and free Irsend request\n" );
70 MPI_Irsend( &smsg[3], 1, MPI_INT, dest, tag+3, comm, &r );
71 MPI_Request_free( &r );
72 if (r != MPI_REQUEST_NULL) {
74 fprintf( stderr, "Request not set to NULL after request free\n" );
77 MPI_Isend( &smsg[4], 1, MPI_INT, dest, tag+4, comm, &r );
78 MPI_Wait( &r, MPI_STATUS_IGNORE );
80 /* We can't guarantee that messages arrive until the detach */
81 MPI_Buffer_detach( &bbuf, &bsize );
89 MPI_Irecv( &rmsg[i], 1, MPI_INT, src, tag+i, comm, &r[i] );
91 if (rank != src) /* Just in case rank == src */
92 MPI_Barrier( MPI_COMM_WORLD );
95 MPI_Wait( &r[i], MPI_STATUS_IGNORE );
96 if (rmsg[i] != 10+i) {
98 fprintf( stderr, "message %d (%d) should be %d\n", i, rmsg[i], 10+i );
101 /* The MPI standard says that there is no way to use MPI_Request_free
102 safely with receive requests. A strict MPI implementation may
103 choose to consider these erroreous (an IBM MPI implementation
105 #ifdef USE_STRICT_MPI
106 MPI_Wait( &r[4], MPI_STATUS_IGNORE );
108 MTestPrintfMsg( 10, "About free Irecv request\n" );
109 MPI_Request_free( &r[4] );
113 if (rank != dest && rank != src) {
114 MPI_Barrier( MPI_COMM_WORLD );
118 MTest_Finalize( errs );