I tried implementing the Example 3.17 from the MPI 3.0 specification document using as follows:
#include <assert.h>
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int myrank, size;
MPI_Status status;
MPI_Init(&argc, &argv );
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
assert(size == 3);
if (myrank == 0) {
/* code for process zero */
int i = 1;
MPI_Send(&i, 1, MPI_INTEGER, 2, 99, MPI_COMM_WORLD);
}
if (myrank == 1) {
/* code for process one */
double d = 3.14;
MPI_Send(&d, 1, MPI_REAL, 2, 99, MPI_COMM_WORLD);
}
if (myrank == 2) {
/* code for process two */
for (int i = 0; i < 2; i++) {
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
printf("Probe matched %lld bytes from source %d.\n",
status.count, status.MPI_SOURCE);
if (status.MPI_SOURCE == 0) {
int i;
MPI_Recv(&i, 1, MPI_INTEGER, 0, 99, MPI_COMM_WORLD, &status);
printf("Received integer '%d' from %d.\n", i, status.MPI_SOURCE);
} else {
double d;
MPI_Recv(&d, 1, MPI_REAL, 1, 99, MPI_COMM_WORLD, &status);
printf("Received real '%f' from %d.\n", d, status.MPI_SOURCE);
}
}
}
This example compiles without any warning with the MPICH-3.0.4 library. However, running:
Probe matched 4 bytes from source 1.
Received real '0.000000' from 1.
Probe matched 4 bytes from source 0.
Received integer '1' from 0.
Could someone please let me know what is the problem with my program? I failed to see a problem there. Thank you.
Best,
--Jiri Simsa