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