Parallel Implementation
/* Let the system do what it needs to start up MPI*/
/* Get my process rank */
MPI_Comm_rank(MPI_COMM_WORLD,
/* Find out how many processes are being used */
MPI_Comm_size(MPI_COMM_WORLD, &p);
h = (b-a)/n; /* h is the same for all processes */
local_n = n/p; /* So is the number of trapezoids */
/* Length of each process' interval of
* integration = local_n*h. So my interval
local_a = a + my_rank*local_n*h;
local_b = local_a + local_n*h;
integral = Trap(local_a, local_b, local_n, h);
/* sum the integrals calculated by each process */
for (source = 1; source < p; source++) {
MPI_Recv(&integral, 1, MPI_FLOAT, source,
tag, MPI_COMM_WORLD, &status);
total = total + integral;
MPI_Send(&integral, 1, MPI_FLOAT, dest,
printf("With n = %d trapezoids, our estimate\n",
printf("of the integral from %f to %f = %f\n",