#include #include #include #include "mpi.h" main(int argc, char* argv[]) { int i; double t,t_start, t_end; int my_rank; int p; MPI_Status status; double x,y,random_max; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); MPI_Comm_size(MPI_COMM_WORLD,&p); if (argc < 2) { fprintf(stderr,"Usage: %s message\n",argv[0]); exit(1); } t_start = MPI_Wtime(); srandom(69978+my_rank); /* we want different random numbers in each processor */ random_max = 2147483648.0; x = ((double) random() / random_max); printf("The message from process %d is <%s>\n",my_rank,argv[1]); printf("and x in process %d is %lf\n",my_rank,x); if (my_rank > 0) { MPI_Send(&x,1,MPI_DOUBLE, 0, /* destination */ 0, /* tag */ MPI_COMM_WORLD); } else { for (i=1;i