2. Problem
• A room has four walls and a fireplace. Temperature of wall is 20°C, and
temperature of fireplace is 100°C. Write a parallel program using Jacobi
iteration to compute the temperature inside the room and plot (preferably in
color) temperature contours at 10°C intervals using Xlib calls or similar
graphics calls as available on your system.
6. Initial Matrix
[20 20 100 20 20]
[20 0 0 0 20]
[20 0 0 0 20]
[20 0 0 0 20]
[20 20 20 20 20]
The temperature of air which is initially set 0
increases during iterations.
7. Sequential Code
• Using a fixed number of iterations
for (iteration = 0; iteration < limit; iteration++)
{ for (i = 1; i < n; i++)
for (j = 1; j < n; j++) g[i][j] = 0.25*(h[i-1][j]+h[i+1][j]+h[i][j-1]+h[i][j+1]);
for (i = 1; i < n; i++) /* update points */
for (j = 1; j < n; j++) h[i][j] = g[i][j];
}
8. Parallel Methods
Split the fixed amount of iterations into process using Partitioning.
Start =0
RNG = iterations/num of process
Process 1: Start to Start+RNG, then Start = Start+RNG
Process 2: Start to Start+RNG, then Start = Start+RNG
Process 3: Start to Start+RNG, then Start = Start+RNG
.
.
.
9. MPI
if (rank > 0){ //Receives the data from the previous
ranks
MPI_Recv(&i_last, 1, MPI_INT, rank - 1, 1,
MPI_COMM_WORLD, &status );
if (rank < 4){
MPI_Send(&i_last, 1, MPI_INT, rank + 1, 1,
MPI_COMM_WORLD ); //Sends the boundary for
the other }
We would split the work and have each process send and
receive the data.
When equal to 0, It would begin to run the Jacobi iteration on
two rows, and then continue to pass that information to the
next process until it would finish