Question: Put it all together to read in the data from file, spawn four threads, and allocate the task of summing each quadrant pair to a
Put it all together to read in the data from file, spawn four threads, and allocate the task of summing each quadrant pair to a separate thread.
After the threads complete their computation, the results need to be stored in the matrix C another dimensional array variable in main.
Your program should work for any size matrices.
In ThreadOperation write a method named getQuadrantIndexes that determines the indexes needed to iterate over one of the four quadrants. For instance, your method might take as input the row count, column count, and a quadrant String, and then return numbers in an array: row start, row end, column start, column end. Although Im demonstrating this method using a String to indicate the quadrant, an integer would also work fine, and an enum with four values would be best.
public static int getQuadrantIndexesint rows, int columns, String quadrant
Called as int indexes getQuadrantIndexesrows columns, upper left;
There are many different and some better ways to get the indexes, but this is the way that I think will make sense to the most people.
So how do you actually calculate the indexes needed? You will need four conditions if elseif, elseif, else for the four quadrants. Figure out the pattern based on the following examples:
Example
columns
rows
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Example
columns
rows
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Example
columns
rows
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Example Fillintheblanks
C columns
R rows
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Row indexes from to
Column indexes from to
Main.java should be organized as follows Strongly consider using the following notes as comments:
Your main method opens a text file using the file name from the command line, and reads in the number of rows, the number of columns, and two matrices, A and B into two dimensional array variables.
Instantiate four ThreadOperation objects and pass them the information they need to sum up paired quadrants, including a reference to a result matrix C Note that C should have the same dimensions as A and B
Start up all the threads and use join to make sure they finish before printing.
Print out the summed matrix.
ThreadOperation.java Organization
I recommend formatting the ThreadOperation constructor as follows:
ThreadOperationA : int B : int C : int String quadrant
run : void
A B and C all refer to complete matrices no submatrices of the same size. As long as the Thread is not accessing the same row and column as another Thread, theres no problem!
UML Diagram for Matrix Addition Part
You tell me
For part you must turn in a UML diagram of your code, including the ways you modified Main and ThreadOperation to complete the assignment.
Compilation and Execution
I will test your program as follows:
javac java
java Main matrixtxt
or
java Main matrixtxt
or
java Main matrixtxt
Using this as a BASE
import java.ioIOException;
import java.ioFile;
import java.util.Scanner;
public class Main
public static void mainString args
if argslength
System.out.printlnUsage: java Main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
