#include #include #include #include #include #include "MPI2.h" using namespace std; int num_procs, my_proc; MPI_Request r; MPI_Status status; int main (int argc, char **argv) { MPI_Init (&argc,&argv); MPI_Comm_size (MPI_COMM_WORLD,&num_procs); MPI_Comm_rank (MPI_COMM_WORLD,&my_proc); srand (time (NULL)+my_proc); //Give each processor a different random seed if (my_proc==0) { cout << "Enter a string: "; string s; getline (cin,s); const char *A = s.c_str(); MPI_Isend (A,strlen(A)+1,MPI_CHAR,1,42,MPI_COMM_WORLD,&r); } else if (my_proc==num_procs-1) { char sc[100]; MPI_Recv (sc,sizeof sc,MPI_CHAR,MPI_ANY_SOURCE,42,MPI_COMM_WORLD,&status); string rs (sc); cout << my_proc << " received a message from " <