CIS-4230/5230 Homework #2 (Voltage Fields)

Due: Monday, January 29, 2018

Reading: Chapter 4 in the text covers POSIX threads. My pthread Tutorial is also a useful reference. You should also read section 2.6 in the text on parallel performance issues, and section 2.2.5 on instruction level parallelism.

In this assignment you will implement a parallel program that computes a voltage field in two dimensions. Consider a square with metal sides but with each side insulated from the others. A voltage is applied to each side (for example using batteries) relative to the "bottom" plate (taken to be at zero volts). Although this is only a two dimensional problem, it could be a model of a long metal tube with a square cross section.

We will divide the space inside the square into a mesh of evenly spaced points. The voltage at each point is given (approximately) by the average of the voltage at the four adjacent points. The non-zero voltages on the sides thus drive the shape of the voltage field in the interior of the square.

To compute the interior voltages you must repeatedly pass over all interior points until the averages "stablize" to a fixed value. This may take quite a few iterations; after each iteration your program should compare the difference (as a percentage) between the previous values and the freshly computed values. If any point has a difference that is "too great" another iteration must be done.

See these slides for more information about the problem and how it should be solved.

The attached archive contains a serial version of this problem in main-0.c. The file main-1.c is currently a copy of the serial version but you should edit it to contain your parallel version (the edits will be extensive; use the serial version as a conceptual guide only). Be sure driver.c calls the version you want to test. Then run both the serial version and your parallel version and compare their performance. How much speed-up are you getting?

Submit your main-1.c to Moodle.