#include #include int main (int argc, char *argv[]) { MPI_Status stat; int me, np, tag=313; double value; MPI_Init (&argc, &argv);/* starts MPI */ MPI_Comm_rank (MPI_COMM_WORLD, &me);/* get current process id */ MPI_Comm_size (MPI_COMM_WORLD, &np);/* get number of processes */ if ( me==0 ) { value = 0.125; if ( np > 1 ) MPI_Send( &value, 1, MPI_DOUBLE, 1, tag, MPI_COMM_WORLD ); else printf("Master is the only task. Value=%lf\n",value); } else { if ( me == np-1 ) { MPI_Recv( &value, 1, MPI_DOUBLE, me-1, tag, MPI_COMM_WORLD, &stat ); printf("Task #%d is the last one. Value=%lf\n",me,value); } else { MPI_Recv( &value, 1, MPI_DOUBLE, me-1, tag, MPI_COMM_WORLD, &stat ); MPI_Send( &value, 1, MPI_DOUBLE, me+1, tag, MPI_COMM_WORLD ); } } MPI_Finalize(); return 0; }