2 This is a test of MPI_Test to receive a message of known length (used as a
10 int main( int argc, char **argv )
12 int data, to, from, tag, maxlen, np, myid, flag, dest, src;
16 MPI_Init( &argc, &argv );
17 MPI_Comm_rank( MPI_COMM_WORLD, &myid );
18 MPI_Comm_size( MPI_COMM_WORLD, &np );
20 /* dest writes out the received stats; for the output to be
21 consistant (with the final check), it should be procees 0 */
22 if (argc > 1 && argv[1] && strcmp( "-alt", argv[1] ) == 0) {
36 printf( "About to send\n" );
38 MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
42 printf( "About to send 'done'\n" );
44 MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
50 from = MPI_ANY_SOURCE;
51 MPI_Irecv( &data, 1, MPI_INT, from, tag, MPI_COMM_WORLD,
53 /* Should really use MPI_Wait, but functionally this will work
54 (it is less efficient, however) */
56 MPI_Test( &request, &flag, &status );
58 if (status.MPI_TAG == 2001) {
60 printf( "Received terminate message\n" );
64 if (status.MPI_TAG == 2000) {
65 MPI_Get_count( &status, MPI_INT, &maxlen );
67 fprintf( stderr, "Should have received one integer; got %d\n",
73 "Did not receive correct data: %d instead of %d\n",
79 MPI_Barrier( MPI_COMM_WORLD );