COMP 3400 Project 2: Multithreaded Java Matrix Multiplication
Spring 2017
Due: Tuesday February 14
Worth 35 points

Background

This assignment will gently introduce you to user threads provided by Java. You will produce a Java solution to the Matrix Multiplication project described in a separate handout. Also refer to the Java Threads Example handout.

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 handout, 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

You will develop your solution from scratch, but you can adapt code found in the handouts.

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.

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. In jGRASP, select "Run arguments" from the Build menu and enter the arguments, separated by spaces, in the provided text field. The files need to be in the same folder as your program, and the file names cannot have embedded spaces. The three run arguments are:
  3. The correct result matrix should be neatly displayed to the console as well as to the file. Matrix dimensions will be written to the file but not displayed on the console. 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 handout 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. See the Java Threads Example handout. This topic is also covered in my threads lecture notes. For your reference, Java Standard Edition 6 API documentation is found at http://docs.oracle.com/javase/6/docs/api/

Scoring

The maximum 35 points is broken down as follows:

To Turn In

Zip your project folder and send as an email attachment to psanderson@otterbein.edu

[ COMP 3400 | Peter Sanderson | Math Sciences home page | Otterbein ]

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