` `

Here we present a PVM program that calculates heat diffusion through
a substrate, in this case a wire. Consider the one-dimensional heat
equation on a thin wire:

and a discretization of the form

giving the explicit formula

initial and boundary conditions:

The pseudo code for this computation is as follows:

for i = 1:tsteps-1; t = t+dt; a(i+1,1)=0; a(i+1,n+2)=0; for j = 2:n+1; a(i+1,j)=a(i,j) + mu*(a(i,j+1)-2*a(i,j)+a(i,j-1)); end; t; a(i+1,1:n+2); plot(a(i,:)) end

For this example we will use a master-slave programming model. The master, heat.c, spawns five copies of the program heatslv. The slaves compute the heat diffusion for subsections of the wire in parallel. At each time step the slaves exchange boundary information, in this case the temperature of the wire at the boundaries between processors.

Let's take a closer look at the code. In heat.c the
array `solution` will hold
the solution for the heat diffusion equation at each time step. This
array will be output at the end of the program in xgraph format. (xgraph
is a program for plotting data.)
First the heatslv tasks are spawned.
Next, the initial data set is computed. Notice that the ends of the wires are
given initial temperature values of zero.

The main part of the program is then executed four times, each with a different value for . A timer is used to compute the elapsed time of each compute phase. The initial data sets are sent to the heatslv tasks. The left and right neighbor task ids are sent along with the initial data set. The heatslv tasks use these to communicate boundary information. (Alternatively, we could have used the PVM group calls to map tasks to segments of the wire. By using the group calls we would have avoided explicitly communicating the task ids to the slave processes.)

After sending the initial data, the master process simply waits for results. When the results arrive, they are integrated into the solution matrix, the elapsed time is calculated, and the solution is written out to the xgraph file.

Once the data for all four phases has been computed and stored, the master program prints out the elapsed times and kills the slave processes.