For this homework, you are to write a program to solve a wave equation using either C/MPI or Java/MPI. Whichever language you pick this week, next week's problem will be to translate your solution to the other language.
Let us consider the problem of a vibrating string which has fixed end points. The time dependent motion of the string is represented by the partial differential equation:
1/c2 * (del2 * psi) / (del * t2) - (del2 * psi) / (del * x2) = 0
This problem is described in Chapter 5 of the book Solving Problems on Concurrent Processors by Fox et al. (And is much better type set than in HTML!)
The solution of this equation psi(x,t) is the vibration amplitude of the string expressed as a function of the x position of the string and time. If we give an initial position and velocity of the string as a function of x, then we can solve the equation to find the position of the string at any time t.
Let us assume that the string stretches over the interval from 0 to 1 in the x direction, and that the ends are anchored at amplitude 0. To solve this problem numerically, we choose uniform intervals delta x and delta t, of space and time. Then for each point i along the x direction, we can derive a scheme for computing the value of the amplitude at each time step. This assumes that we are computing the value at a new time step (t + delta t)(let's call this t+1) where we already know the values at the current time step t and the previous time step (t - delta t) (call it t-1):
psii(t+1)= (2 * psii(t)) - psii(t-1) + tau2 (psii-1(t) - (2 * psii(t)) + psii+1(t))
where tau = c * (delta t / delta x)
To set up this problem for MPI, you should choose N, the number of points in the discretization of the x direction. If the total x interval is from 0 to 1, this determines delta x as 1/(N-1), and position i is i/(N-1). You can choose time units so that delta t is 1. The units for the string equation can also be chosen so that the constant c is 1.
This is set up to be a one-dimensional problem, so you can divide up the points among the processors, so each processor is computing psi for N/NumProcs points. You will need arrays to record the values of the points at the various time steps. Then note the equation for point i also requires you to know the value of point i-1 and point i+1. Except for the global left and right endpoint which remains fixed at psi=0, this leads to the following algorithm for each processor:
For more details, we have copied for you Chapter 5 of the reference cited above.