2 This is a test of probe to receive a message of unknown length
10 int main( int argc, char **argv )
12 int data, to, from, tag, maxlen, np, myid, src, dest;
15 MPI_Init( &argc, &argv );
16 MPI_Comm_rank( MPI_COMM_WORLD, &myid );
17 MPI_Comm_size( MPI_COMM_WORLD, &np );
19 /* dest writes out the received stats; for the output to be
20 consistant (with the final check), it should be procees 0 */
21 if (argc > 1 && argv[1] && strcmp( "-alt", argv[1] ) == 0) {
34 printf( "About to send\n" );
36 MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
40 from = MPI_ANY_SOURCE;
41 MPI_Probe( from, tag, MPI_COMM_WORLD, &status );
42 MPI_Get_count( &status, MPI_INT, &maxlen );
43 /* Here I'd normally allocate space; I'll just check that it is ok */
45 printf( "Error; size = %d\n", maxlen );
47 printf( "About to receive\n" );
49 MPI_Recv( &data, 1, MPI_INT, status.MPI_SOURCE, status.MPI_TAG,
50 MPI_COMM_WORLD, &status );
52 MPI_Barrier( MPI_COMM_WORLD );