Programming Assignment 2
CS 51590
Parallel Programming
Spring, 2022

This assignment makes use of the files contained in this zip file. This assignment is due Friday, May 6.

This assignment is based on the fork-join.zip and thread-pools.zip examples that we used in class.

This assignment has three parts.

In the zip file there is a file Hw2.java that outlines the Fork/Join solution of a simple problem. The first part of this assignment is for you to complete the solution in Hw2.java.

The problem outlined in Hw2.java is to count the longest run of zeros in an array of integers. The main() method first initializes a (large) array with random integers. Then the main() method should sequentially calculate the longest run of zeros in the data array. This sequential solution gives you a verification of correctness for your parallel solution. After solving the problem sequentially, the main() method should solve the problem using the Fork/Join framework. The Hw2.java file contains the code for submitting the initial problem to the Fork/Join pool. You need to write the code that implements the compute() method of the Fork/Join task. The compute() method should return an Integer value that is the length of the longest run of zeros in the sub-array of arr determined by the lo and hi fields.

Your Fork/Join compute() method should use a "divide-and-conquer" strategy. Given the problem of finding the longest run of zeros in an array, compute() should divide the array in half and create two sub-problems that find the longest run of zeros in each half of the array. The main issue is how to "combine" the results from the two halves into the correct result for the whole array. If you know the length of the longest run of zeros from the left half of the array, and the length of the longest run of zeros from the right half of the array, how do you find the length of the longest run of zeros in the array?

The Fork/Join solution should, of course, compute the same result as the sequential solution. And the Fork/Join solution should, of course, be faster than the sequential solution. But how much faster depends a lot on the choice of the SEQUENTIAL_CUTOFF parameter. For the second part of this assignment, create a program Hw2_benchmarks.java that runs your Fork/Join solution on a given (large) array using many different values for SEQUENTIAL_CUTOFF. The goal of the benchmark program is to determine a reasonable value for SEQUENTIAL_CUTOFF. Values of SEQUENTIAL_CUTOFF that are too big or too small both give poor parallel performance. Write a program that solves the same array many times, but with different values of SEQUENTIAL_CUTOFF, and prints out timing information so that you can see which cutoff values are reasonable. No specific cutoff value will be "best"; you should see a range of cutoff values that all give reasonable performance. At the beginning of your Hw2_benchmarks.java file, write a comment that explains what cutoff values your benchmarks show are reasonable.

For the third part of this assignment, run your program on several medium sized arrays (with size around 1,000,000) that are filled with all zeros. The result from your program should be the size of the array. Then, run your program on a large array (at least size 500,000,000) that is filled with all zeros. What happens to your program on the large array? Write an explanation file, All_zeros_explanation.txt, that explains why your program behaves as it does.

Turn in a zip file called CS51590Hw2Surname.zip (where Surname is your last name) containing your versions of Hw2.java, Hw2_benchmarks.java, and All_zeros_explanation.txt.

This assignment is due Friday, May 6.