#include #include // stolen from the tutorial, but modified. using namespace std; int main(int argc, char * argv[]) { MPI_Init(&argc , &argv); int world_rank; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); int world_size; MPI_Comm_size(MPI_COMM_WORLD, &world_size); int number; if (world_rank == 0) { number = 2; for(int i = 1; i < world_size; ++i) { number *= number; cout << "Sending " << number << " to " << i << endl; MPI_Send(&number, 1, MPI_INT, i, 0, MPI_COMM_WORLD); } } else { MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); cout << "Process " << world_rank << " received number " << number << " from process 0" << endl; } MPI_Finalize(); return 0; }