/* // The root node sends out a message process 1. Process 1 send back to Process 0. */ #include //for input/output #include //for mpi routines #define BUFSIZE 64 //The size of the messege being passed main( int argc, char** argv) { int my_rank; //the rank of this process int n_processes; //the total number of processes char buf[BUFSIZE]; //a buffer for the messege int tag=0; //not important here int count; MPI_Status status; //not important here MPI_Init(&argc, &argv); //Initializing mpi MPI_Comm_size(MPI_COMM_WORLD, &n_processes);//Getting # of processes MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); //Getting my rank if( my_rank == 0 ) { //send to the next node */ printf("Hello world! I am %d of %d, sending to Proc %d\n", my_rank, n_processes, my_rank+1); MPI_Send(buf, BUFSIZE, MPI_CHAR, my_rank+1, tag, MPI_COMM_WORLD); //recieve from the last node */ MPI_Recv(buf, BUFSIZE, MPI_CHAR, n_processes-1, tag, MPI_COMM_WORLD, &status); MPI_Get_count(&status, MPI_CHAR, &count); printf("Hello world! I am %d of %d, recv %d entries from proc 1\n", my_rank, n_processes, count); } else { //recieve from proc 0 MPI_Recv(buf, BUFSIZE, MPI_CHAR, 0, tag, MPI_COMM_WORLD, &status); MPI_Get_count(&status, MPI_CHAR, &count); printf("Hello world! I am %d of %d, recv %d entries from Proc 0\n", my_rank, n_processes, count); //send to the next node printf("Hello world! I am %d of %d, sending to Proc 0\n", my_rank, n_processes); MPI_Send(buf, BUFSIZE, MPI_CHAR, 0, tag, MPI_COMM_WORLD); } MPI_Finalize(); //Finalize MPI return 0; }