C SC 340 Project 2: Multithreaded Java Matrix Multiplication
Spring 2009
Due: before start of lab period Thursday April 23
Worth 15 points

Background

This assignment will gently introduce you to user threads provided by Java. You will solve the Matrix Multiplication project described at the end of Chapter 4 beginning on page 162. Do only the Java solution! Although I am giving you this assignment prior to our lecture discussion of threads, you can proceed because it includes non-threads programming that you should do first.

Again, follow the "individual with partner" approach. Feel free to help and advise each other but produce an individual solution.

The Application

Your program will read the contents of two matrices from data files, multiply the two matrices, and write the resulting matrix both to a third file and to the console. As described in the textbook, the multiplication is to be performed by worker threads. Start by developing a solution without threads, then modify it to incorporate threads. This will assure that all the file I/O and data structures are working before you start to focus on threads.

Existing Code

There is none, other than that provided in the textbook. You will develop your solution from scratch.

Details

File Format: A matrix data file is a text file consisting of all integer values formatted something like this

RC
M11M12...M1C
M21M22...M2C
............
MR1MR2...MRC

R is the number of rows, C is the number of columns, and the M's are the data themselves. All numbers are separated by one or more spaces. This format is used for both reading and writing a matrix. If you need a quick refresher on Java file I/O, see my posted CSC 160 lecture notes.

Here are example contents of a text file containing such a matrix:
23
27-815
3694-526
You can easily construct such files using Notepad.

Using your Program:

  1. The class containing main() must be called MatrixMultiply.
  2. Main should expect three run arguments in its parameter array (if using jGRASP, select "Run arguments" from the Build menu and enter the arguments, separated by spaces, in the provided text field). The three run arguments are:
  3. The correct result matrix should be neatly displayed to the console as well as to the file. Note that the PrintStream class (the class that System.out belongs to) has a format method that uses C-printf-style formatting strings. For example, System.out.format("value %4d", 27); produces output value   27, using 4 to specify the fixed length of the decimal field into which the value 27 is right-aligned.
  4. If the input matrices cannot be multiplied because their dimensions are not compatible, display a descriptive message explaining the problem and terminate the program.

Robustness: Besides the matrix dimension mismatch described above, your program should also deal with the problem of non-existing input files - this should result in an error message followed by program termination. You may assume that the contents of input files are correctly formatted. If the output file already exists, have the user confirm before overwriting it (for confirmation input, use either the Scanner class in java.util or the static JOptionPane.showConfirmDialog() method in javax.swing - it does not require a frame if you use null for the first argument).

Documentation: Each of your classes and methods needs to be appropriately documented with comments. Make sure your name is at the top of each file.

Threads: Refer to the textbook problem description for information about how threads are to be used in your solution. I will add one additional requirement: the thread class must implement Runnable, not extend Thread. This topic is covered in my threads lecture notes. For your reference, Java 2 Standard Edition API documentation is found at http://math.otterbein.edu/home/java/j2sdk1.5/docs/api/

Scoring

The maximum 15 points is broken down as follows:

To Turn In

Send me all source files as email attachments to psanderson@otterbein.edu

[ C SC 340 | Peter Sanderson | Math Sciences server  | Math Sciences home page | Otterbein ]

Last updated:
Peter Sanderson (PSanderson@otterbein.edu)