CS 112 - Introduction to Computer Science II
Homework #11

Due: At the beginning of class 33.

NOTE: This work is to be done in pairs.  I strongly recommend the practice of Pair Programming described simply here.  Although team members are permitted to divide work, each team member should be able to informally present all work of his/her teammate.

Multithreading and Parallel Programming

1. Thread-safe function processing:  In this exercise, you will implement DoubleFunctionProcessor.java according to this specification.  The DoubleFunctionProcessor will be constructed with a single double value.  Multiple threads will seek to send DoubleFunction<Double> objects to the a DoubleFunctionProcessor's process method in order to replace that DoubleFunctionProcessor's current value with a new value that is output of the DoubleFunction.apply method call on that current value.  For example, a DoubleFunction<Double>'s apply method might return the result of addition to, subtraction from, or negation of the value, among other possibilities.  There might be many Threads seeking to process these functions all at the same time with varying compute times.  Your job is to make sure no concurrent calls to the process method are allowed to create an inconsistency in the data.  Also provided is example test code.  Note that your code will be tested with other tests as well.

(Screen capture from Wikipedia article)

2. N queens problem solution counter:  In this exercise, you will implement NQueensSolver, containing both a serial (i.e. single-processor) and a parallel version of an n queens problem solver according to this specification that finds and counts the number of possible solutions for a given size n.  Starter code with serial algorithm pseudocode is provided.  Your solution will be checked for correctness and appropriate parallel performance improvements. 

The only printing from your code is expressed thus in the pseudocode: "if verbose is true, print the cols array for testing/debugging purposes".  Any excess printing that fills the submission system with large amounts of output will result in a 1 point (5%) deduction.  Be sure to comment out your debugging print statements before submission.

Hint: For your multithreaded code, be sure to have a separate column assignment array "cols" for each thread.

 

Rubric: (20 points total)