MPI Trapezoid Rule Lab
From Education
Background
Tonight's MPI lab will let you explore the message passing interface a little more. This time you'll be on your own for creating skeleton code - so refer back to Hello World for help!
The Trapezoid Rule is one way of estimating the area under a curve, also known as the definite integral. It does this by approximating a line to serve as the curve and then calculating the area of the trapezoid that is formed. To make more accurate estimates, the area under the curve is first subdivided into smaller areas. This is shown to the right.
Your Task
Your task is to implement a parallel version of the Trapezoid Rule and estimate the area under the curve described by:
Pi / 4 to Pi / 2 for the equation f(x) = log(x) / sin(x)
A Few Hints
- The area of a trapezoid is equal to (b-a) f(a) + f(b) / 2
- If each of the processes knows the starting and ending points, there doesn't need to be any communication prior to calculating the final result.
- You could use MPI_Reduce.
- If you have difficulty with the trapezoidal rule, there are lots of implementations that Google knows about.
- If you would like to use a starting code that uses a different function, a different approximation method (rectangles), and another set of suggestions, then look no further
If you finish early, try changing the equation and then taking the boundaries as command-line arguments, and then using an MPI function to (hint) broadcast that value to each of the processes.