#include #include #include int main(int argc, char** argv) { MPI_Init(&argc, &argv); int world_rank, world_size; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); MPI_Comm_size(MPI_COMM_WORLD, &world_size); int token; // Create a wave of communication from the first to the last process if (world_rank != 0) { MPI_Recv(&token, 1, MPI_INT, world_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Process %d received token %d from process %d\n", world_rank, token, world_rank - 1); } else { // Start the wave token = -1; } MPI_Barrier(MPI_COMM_WORLD); if (world_rank != world_size - 1) { token++; MPI_Send(&token, 1, MPI_INT, world_rank + 1, 0, MPI_COMM_WORLD); printf("Process %d sent token %d to process %d\n", world_rank, token, world_rank + 1); } // Create a wave of confirmation back from the last to the first process if (world_rank != world_size - 1) { MPI_Recv(&token, 1, MPI_INT, world_rank + 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Process %d received confirmation %d from process %d\n", world_rank, token, world_rank + 1); } MPI_Barrier(MPI_COMM_WORLD); if (world_rank != 0) { MPI_Send(&token, 1, MPI_INT, world_rank - 1, 0, MPI_COMM_WORLD); printf("Process %d sent confirmation %d to process %d\n", world_rank, token, world_rank - 1); } MPI_Finalize(); return 0; }