/* Jonathan Hauenstein - University of Notre Dame Center for Applied Mathematics Minicourse on Parallel Computing April 24, May 1, May 8, 2008 Sample programs are designed for educational use */ #include "trapezoid_dyn.h" #include int main(int argc, char **argv) { int i, my_id, num_proc, totalTrap = 0; MPI_Status status; double total = 0; // initialize MPI MPI_Init(&argc, &argv); // find unique id MPI_Comm_rank(MPI_COMM_WORLD, &my_id); // find the number of processes running MPI_Comm_size(MPI_COMM_WORLD, &num_proc); if (my_id == 0) { // find the number of trapezoids the user wants to use printf("Please enter the number of trapezoids to use: "); scanf("%d", &totalTrap); // quick error checking if (totalTrap <= 0) { printf("The number of trapezoids was not read in properly. This program will terminate!\n\n"); MPI_Abort(MPI_COMM_WORLD, 1); } // farm out the work to the other processes total = head_trapezoid(totalTrap, -1, 1, num_proc); // find 2*total and print ans total *= 2; printf("Using %d trapezoids, the approximation to pi is %.15f.\n\n", totalTrap, total); } else { // perform the trapezoid calculations worker_trapezoid(my_id, num_proc); } // finalize MPI MPI_Finalize(); return 0; }