[mpich-discuss] Problem reproducing an example from the MPI standard
Pavan Balaji
balaji at mcs.anl.gov
Sat Jun 22 12:02:19 CDT 2013
The example is correct, since it's in Fortran. Your conversion to C is
incorrect. You probably want to use MPI_DOUBLE instead of MPI_REAL, and
MPI_INT instead of MPI_INTEGER.
-- Pavan
On 06/22/2013 11:49 AM, Jiri Simsa wrote:
> Hi,
>
> 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);
> }
> }
> }
> MPI_Finalize();
> return 0;
> }
>
> This example compiles without any warning with the MPICH-3.0.4 library.
> However, running:
>
> $ mpiexec -n 3 ./example
>
> leads to the following output:
>
> 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
>
>
> _______________________________________________
> discuss mailing list discuss at mpich.org
> To manage subscription options or unsubscribe:
> https://lists.mpich.org/mailman/listinfo/discuss
>
--
Pavan Balaji
http://www.mcs.anl.gov/~balaji
More information about the discuss
mailing list