2
This is a test of probe to receive a message of unknown type (used as a
10
int main( int argc, char **argv )
12
int data, to, from, tag, maxlen, np, myid, flag, dest, src;
13
MPI_Status status, status1;
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 );
39
printf( "About to send 'done'\n" );
41
MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
47
from = MPI_ANY_SOURCE;
48
/* Should really use MPI_Probe, but functionally this will work
49
(it is less efficient, however) */
51
MPI_Iprobe( from, tag, MPI_COMM_WORLD, &flag, &status );
53
if (status.MPI_TAG == 2001) {
55
printf( "Received terminate message\n" );
57
/* Actually need to receive it ... */
58
MPI_Recv( &data, 1, MPI_INT, status.MPI_SOURCE,
59
status.MPI_TAG, MPI_COMM_WORLD, &status1 );
62
if (status.MPI_TAG == 2000) {
63
MPI_Get_count( &status, MPI_INT, &maxlen );
65
printf( "Error; size = %d\n", maxlen );
67
printf( "About to receive\n" );
69
MPI_Recv( &data, 1, MPI_INT, status.MPI_SOURCE,
70
status.MPI_TAG, MPI_COMM_WORLD, &status1 );
74
MPI_Barrier( MPI_COMM_WORLD );