MPI Lab10 Parallel Programming Application 2
Numerical Integration Using the Trapezoidal Rule

(this assignment is from Parallel Programming with MPI by Pacheco)

Assignment
Utilize parallel programming techniques to calculate the area under a curve using the trapezoidal approximation rule.

The Trapezoidal Rule

An approach to estimating the area under a curve, or integral is to partition the region into regular geometric shapes and then add the areas of the shapes. In the trapezoidal rule, the regular shapes are trapezoids. We are finding the area under a curve from x=a to x=b, and the values of the function are f(a) and f(b).

The bases of the trapezoids in this example are all chosen to have the same length, h. If there are n trapezoids, the base of each will be h = (b - a)/n. The base of the left most trapezoid is the length of the interval [a, a+h]; the base of the next trapezoid is [a + h, a + 2h]; the next is [a + 2h, a + 3h]; etc. The base of the ith trapezoid is [a + (i - 1)h, a + ih]. In this example, xi denotes a + ih, i = 0, ..., n. The length of the left side of the ith trapezoid is f(xi-1), and its right side is f(xi). The area of the ith trapezoid is

(1/2)h[f(xi-1) + f(xi)]

The area of the entire approximation is the sum of the areas of the trapezoids:

(1/2)h[f(x0) + f(x1)] + (1/2)h[f(x1) + f(x2)] + ... + (1/2)h[f(xn-1) + f(xn)]
= h/2[f(x0) + 2f(x1) + 2f(x2) + ... + f(xn)]
= [f(x0)/2 + f(xn)/2 + f(x1) + f(x2) + ... + f(xn-1)]h.

FIRST PART:

Before writing a parallel version of a program, familiarize yourself with this example integral.c serial version. You can use either Fortran or C to write your own version, or you can use this version. Confirm that the program works by test runs with various limit values and function values.

SECOND PART:

Write a parallel version of the trapezoidal approximation problem. Example shell to start with: integralMPI.c. Each process calculates the area under its fractional part of the curve. Divide the curve in the x direction. For example, if there are 4 processes and the curve is plotted from x=0 to x=8, then process 0 calculates the area under the curve from x=0 to x=2, process 1 from x=2 to x=4, etc. Process n calculates the area from x=rank*(totalX/numprocesses) to x = (rank+1)*(totalX/numprocesses).