The variance of a set of numbers is defined to be the sum
For this assignment, you are to write a multi-threaded program to compute the variance of a set of numbers. The textbook discusses using multiple threads to speed up the calculation of the sum of a set of numbers; it is not difficult to extrapolate from this discussion to an approach for using multiple threads to speed up calculating the variance of a set of numbers, if you break down the calculation into two steps:
Your program should take two command-line arguments:
In either case, once it has read or generated its input numbers, the program should compute their variance and print the following output:
You can write your program either (i) in C++ with the POSIX threads library functions or (ii) in Java using Java's built-in support for multi-threading. Whichever language you use, be sure your program compiles and executes correctly on the department's Linux machines.
So that you do not have to write the tedious and non-parallel parts of this program, I am providing a sequential program that performs the required calculations.
Once you have confirmed that your program is operating correctly (for small numbers of inputs), try running it for a large number of generated inputs and varying values of (number of threads). Record at least half a dozen observations (different combinations of and ) to see how running time varies with these two variables. Also record which machine you performed these experiments on. You may find it interesting to see whether multi-threading can help even if you have more threads than processors. FYI, machines known to have multiple processors include SnowWhite.CS.Trinity.Edu (4 processors) and the Dwarf.CS.Trinity.Edu machines (2 processors each).
You may find it useful to look at some of sample programs, in particular the various programs to compute the sum of numbers.
Note that when you compile (and link) a program that uses the POSIX threads library, you need the flag -pthread. The sample programs page has an example of a Makefile that takes care of this.
(the number of threads) might not evenly divide . Your code should be prepared to cope with this. At the very least, it should print an error message and stop.
Submit your completed program (variance.cpp or Variance.java), plus the text file containing your timing measurements, as described in the Guidelines for Programming Assignments, using a subject header of ``cs3366 hw 4''.