#include #include int main( int argc, char ** argv ) { int rank, size; MPI_Init( 0, 0 ); MPI_Comm_size( MPI_COMM_WORLD, &size ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); int sendbuf = rank, recvbuf, probeflag; int excessProbesNeeded = 0; for ( int i = 0; i < 10; ++i ) { for ( int otherrank = 0; otherrank < size; ++otherrank ) { if ( otherrank != rank ) { MPI_Send( &sendbuf, 1, MPI_INT, otherrank, 0, MPI_COMM_WORLD ); } } MPI_Barrier( MPI_COMM_WORLD ); for ( int otherrank = 0; otherrank < size; ++otherrank ) { if ( otherrank == rank ) { continue; } probeflag = 0; int failedBeforeThisTime = 0; while( probeflag == 0 ) { MPI_Iprobe( otherrank, MPI_ANY_TAG, MPI_COMM_WORLD, &probeflag, MPI_STATUS_IGNORE ); if ( !probeflag ) { ++excessProbesNeeded; if ( !failedBeforeThisTime ) { printf( "Probe failed on %d from %d (iteration %d)\n", rank, otherrank, i ); ++failedBeforeThisTime; } } } if ( otherrank != rank ) { MPI_Recv( &recvbuf, 1, MPI_INT, otherrank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE ); } } } int totalExcess = 0; MPI_Reduce( &excessProbesNeeded, &totalExcess, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ); if ( rank == 0 ) { printf( "Excess probes needed: %d\n", totalExcess ); } MPI_Finalize(); }