#include #include int main(int argc, char** argv) { // Initialize the MPI environment MPI_Init(NULL, NULL); // Get the rank of the process int world_rank; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); // Define the coefficients and the value of x int coefficients[3] = {1, 2, 1}; // Coefficients for x^2, x, and constant term int x = 2; // The value of x // Each process performs its part of the calculation int local_result = 0; if (world_rank == 0) { // First process calculates ax^2 local_result = coefficients[0] * x * x; } else if (world_rank == 1) { // Second process calculates bx local_result = coefficients[1] * x; } else if (world_rank == 2) { // Third process calculates c local_result = coefficients[2]; } // Pipeline to sum up the results int sum = 0; if (world_rank != 0) { MPI_Recv(&sum, 1, MPI_INT, world_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } sum += local_result; if (world_rank != 2) { MPI_Send(&sum, 1, MPI_INT, world_rank + 1, 0, MPI_COMM_WORLD); } // The last process prints the final result if (world_rank == 2) { printf("The result of the polynomial is %d\n", sum); } // Finalize the MPI environment MPI_Finalize(); return 0; }