Question: Problem Description Given two integer matrices, A and B , you are asked to write a program to perform matrix addition ( A + B
Problem Description
Given two integer matrices, A and B you are asked to write a program to perform matrix addition A B
Both matrices will have the same number of rows and columns.
You need to divide A and B into four equal or close to equal size submatrices I will refer to them as A A A A and B B B B
If the original matrices have R rows and C columns, then each submatrix should have dimensions close to R x C In other words, each submatrix should be about onequarter the size of the original matrices.
You need to create four Java threads. Each thread performs addition on one pair of the submatrices. For example, thread performs addition on A and B thread performs addition on A and B etc.
The final result should be stored in a matrix C of size R x C
You must divide the twodimensional array into the form such as: AA&A@A&A Same for B and C
Using the above example, if
A
Then the upper left corner is
A
One of your threads is responsible for adding
A BC
Same as
List of classes that you will write:
Main contains the main method.
ThreadOperation extends Thread and performs submatrix addition
Instructions for Part
For part you need to create both of the above classes.
In the main method of Main, instantiate four ThreadOperation objects, start them, and join them. Each ThreadOperation will take as input through the constructor two matrices and a quadrant indicator. The indicator could be a String, an int, an enum or a set of indexes. Its up to you.
In Main.java, write a static method named printdArray that takes a twodimensional array as input and prints it out with the rows and columns lined up You must use System.out.printf.
Instantiate a test d array with any values you like in main and use it to verify that printdArray works.
The filename should be given through the command prompt and passed into main via String args
Open and connect to the file using a Scanner.
Read in the number of rows and columns and save these in local variables in main.
Read in the first and second matrices twodimensional arrays from the file. I recommend writing a method to accomplish this task and calling the method twice once for each matrix Consider using this method header:
public static int matrixFromFileint rows, int columns, Scanner filereader
NOTE: if you are using a static scanner or an objectoriented approach then you may not need to pass these arguments to the method.
Information on the file format
the first line has two numbers, R and C R rows, C columns the size of both matrices A and B
the next R lines each has C elements for one of the rows of A
the next R lines each has C elements for one of the rows of B
Example:
For the above example, is the number of rows, is the number of columns. The first matrix values are highlighted in green and the second matrix is highlighted in red. The result of the sum should be as follow:
Example: The upper left quadrants of the corresponding matrices highlighted in yellow will be added together
For your convenience, three test cases are provided: matrixtxt matrixtxt and matrixtxt
One of the goals is to minimize the resource usage, such as memory and processor cycles. Explain how multithreaded code accomplishes this goal in your document. YOU MUST ANSWER THIS QUESTION IN A COMMENT AT THE TOP OF YOUR Main CLASS. Tell me about blocking on IO multicore machines, how sluggish humans are, etcetera, and then tell me how multithreading helps. Compare threads to processes and tell me the advantages of multithreading. It doesnt have to be long. Three sentences will suffice if they are good sentences.
UML Diagram for Matrix Addition Part
Main
printdArraymatrix: int : void
ThreadOperation
A : int
B : int
quadrant : String
ThreadOperationA : int B : int quadrant : String
run : void
Compilation and Execution
test your program as follows:
javac java
java Main matrixtxt
WE USE THIS AS A BASE
This code is provided to give you a
starting place. It should be modified.
No further imports are needed.
import java.ioIOException;
import java.ioFile;
import java.util.Scanner;
public class Main
public static void mainString args
System.out.println;
TEST USING
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
