CSSE 220 – Object-Oriented Software Development

Fork/Join In Class Acivity

Objectives

Experiment with function objects and the Java Fork/Join Framework for parallel computing.

Tasks

Science! For this activity you’ll write a little code, run several experiments, fill out an excel spreadsheet with your data and answer a few questions as a "lab report".

We encourage you to work in pairs for this homework. We have not set up pair repositories, so just choose one person’s machine for the project and do your work there. (Consistently using one machine will also reduce the sources of variation in your experimental results.)

Complete the following tasks in the project ForkJoinIntro that you checked out in class.

  1. Get started with the fork/join framework.

    1. Open the class useless.Main. Run the class as a Java application; it will probably give you an error. Read the big comment block at the top of the file that describes how to run programs that use the fork/join framework. Follow those instructions and get help if the program still won’t run. (Eclipse may hide, or fold, this comment for us. Click the + symbol next to NOTE WELL to see the whole comment.)

      (This extra step is because the framework isn’t included in Java 6. If you are using Java 7, this step is not necessary.)

    2. Modify the Incrementor class so the program correctly prints The answer is 42.
  2. Visualizing the processors It can be fun to visualize how the fork-join code uses additional processors. The Resource Monitor program in Windows 7 can help with that.

    1. Open the Windows menu
    2. Type Resource in the Search box
    3. Choose Resource Monitor in the list
    4. Within Resource Monitor, switch to the CPU tab.
    5. Watch what happens to the CPU graphs as you run parallel code.
  3. A useful experiment, part 1. Next you’ll conduct two experiments with the code in the useful package. For this first experiment, you’ll vary the size of the array

    1. Run the class useful.Main, using your new knowledge from task a.
    2. Study the code in useful.Main and useful.ArraySummer. It’s based on the reading for today. Make sure you understand what the code is doing. In particular:
      • Notice that ArraySummer is a function object that recursively creates more function objects.
      • Observe the pattern of forks and joins in ArraySummer’s compute() method. Review Grossman’s Beginner’s Introduction to the Java ForkJoin Framework and ask questions if ArraySummer doesn’t make sense to you.
      • Study the use of StopWatch in useful.Main to collect timing information.
    3. Run your experiment!
      • Decide a range of array sizes that you want to test. (Actually, there's already a reasonable range in your excel spreadsheet...but feel free to add to it if you like)
      • Try the largest one first to make sure your memory allocation is big enough. Record the memory allocation that you’re using. (The big comment on how to run the programs also says how to change the memory allocation.)
      • Now run your program for each of the sizes and carefully note the size and the time reported. Enter them into the spreadsheet.
      • Take a look at the graph of your data. Does anything seem unusual about the results? Can you explain why they look like they do? Jot down any notes that seem like they would be helpful for your lab report.
  4. A useful experiment, part 2. Continuing with the useful package, next you’ll vary the cut-off point where the ArraySummer switches from parallel recursive tasks, to old-school sequential code.

  5. Programming Interlude. The provided mergesort package contains a sequential implementation of merge sort in the class SequentialMergeSorter. The package also provides the skeletons for a Main class and a parallel merge sorter.

    Before you can conduct the last two experiments, you need to complete ParallelMergeSorter. To do this:

    1. Study the classes mergesort.Main and SequentialMergeSorter.
    2. Also study the compute() method in ArraySummer.
    3. Now implement the compute() method in ParallelMergeSorter by combining the sorting algorithm from SequentialMergeSorter’s sort() method, with the fork/join technique and sequential threshold used in ArraySummer.
    4. Test your implementation by running mergesort.Main.
  6. Build your test fixture. To conduct the last two experiments, you also need to write some code to execute and time the tests. Use the timing code in useful.Main as a model, but carefully note the following differences:

  7. Sort and size. Conduct an experiment where you vary the size of the array to be sorted. This is just like task c above, except you should record both the sequential sorting time and the parallel sorting time for each size.
  8. Sort and threshold. Conduct an experiment where you hold the array size fixed and vary the sequential cut-off of your merge sort algorithm. This is just like task d above, except you should record both the sequential sorting time and the parallel sorting time for each threshold value.
  9. Lab Report. Answer the questions in the lab report text file.

  10. Be sure to email a copy of all code to the lab partner whose machine you didn’t use. We want both of you to have all the code.

Remember, in all your code:

Turn-in Instructions

Turn in your programming work by committing it to your SVN repository. Turn in your excel file and lab report text the same way. If you worked in pairs, only one of you needs to commit the work, but be sure to put both your names in the comments of the files you edit and in the lab report text file. Once your work is committed, email your professor with the your name, your partner's name, and whose repository contains the code.