COMP 340 Project 2: Multithreaded Java Matrix Multiplication
Spring 2011
Due: lab period Tuesday April 26
Worth 25 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 at the end of Chapter
4 (pages 170-173).
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. Note that the project description contains both C and Java code listings.
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
R | C |
M11 | M12 | ... | M1C |
M21 | M22 | ... | M2C |
... | ... | ... | ... |
MR1 | MR2 | ... | 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:
You can easily construct such files using Notepad.
Using your Program:
- The class containing main() must
be called MatrixMultiply.
- 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 (make sure file names do not have embedded spaces). The three run arguments
are:
- Name of file containing the first matrix.
- Name of file containing the second matrix.
- Name of file into which to store the result matrix.
- 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.
- 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 25 points is broken down as follows:
- 10 points maximum for "Using Your Program" requirements. This includes correct results
( I will provide some test cases )
- 3 points maximum for "Robustness" requirements
- 2 point maximum for "Documentation" requirements
- 10 points maximum for "Threads" requirements
To Turn In
Send me all source files as email attachments to
psanderson@otterbein.edu
[ COMP 340
| Peter Sanderson
| Math Sciences server
| Math Sciences home page
| Otterbein
]
Last updated:
Peter Sanderson (PSanderson@otterbein.edu)