What is the final value printed if the the program below is executed with 5 MPI processes?
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main (int argc, char** argv)
{
int value=0;
int size, rank;
MPI_Status s;
MPI_Init (&argc, &argv);
MPI_Comm_size (MPI_COMM_WORLD, &size);
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
if (rank==2)
{
for (int i=0; i<size; i++)
{
if (i!=2)
{
int v;
MPI_Recv(&v, 1, MPI_INT, i, 42, MPI_COMM_WORLD, &s);
value+=v;
}
}
printf("Final value is %i\n",value);
MPI_Send(&value, 1, MPI_INT, 2, 42, MPI_COMM_WORLD);
}
MPI_Finalize();
}
I can't seem to figure it out and I can't run it, it just get blocked ?