#include #include #include #include #include "mpi.h" int main(int argc, char** argv) { int meu_rank, np, tag=0; float a,b,c,d,x1,x2; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &meu_rank); MPI_Comm_size(MPI_COMM_WORLD,&np); a = 1; b = 6; c = -10; if (meu_rank == 0) { d = (b*b) - (4*a*c); if (d < 0 ) exit(0); else { MPI_Send(&d, 1, MPI_FLOAT, 1, tag, MPI_COMM_WORLD); MPI_Send(&d, 1, MPI_FLOAT, 2, tag, MPI_COMM_WORLD); } } else if(meu_rank == 1) { MPI_Recv(&d, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &status); x1 = ((-b) + sqrt(d))/(2*a); MPI_Send(&x1, 1, MPI_FLOAT, 3, tag, MPI_COMM_WORLD); } else if(meu_rank == 2) { MPI_Recv(&d, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &status); x2 = ((-b) - sqrt(d))/(2*a); MPI_Send(&x2, 1, MPI_FLOAT, 3, tag, MPI_COMM_WORLD); } else { MPI_Recv(&x1, 1, MPI_FLOAT, 1, tag, MPI_COMM_WORLD, &status); printf("O valor de x1 é %.2f\n", x1); MPI_Recv(&x2, 1, MPI_FLOAT, 2, tag, MPI_COMM_WORLD, &status); printf("O valor de x2 é %.2f\n", x2); } MPI_Finalize( ); }