QuestionQuestion

Working Summary: In this assignment, you will do:
(a) matrix multiplication parallelly as well as sequentially.
(b) and, you will compare the execution times of both the versions (i.e., sequential vs. parallel).
Specifications:
There will be two different aspects of this programming assignment:
(a) You will develop and submit a program, named ‘matrixmul’, which will accept n number of processes and will read two matrices from an input file, named ‘input.txt’. Here, n is defined as: 1 ≤ n ≤ N, where N is the number of elements in the final (resultant) matrix.
If n = 1, then you have one process allocated and you need to execute matrix multiplication sequentially. And, if n > 1 then the computation must be in parallel, utilizing all processes allocated – your program will be judged based on how well you have distributed the load using your own algorithm.
You need to describe your load balancing algorithm in the report file named, ‘myreport’ (preferably a .doc file). Well distributed /well-balanced tasks will be regarded as a better algorithm

You need to print (on screen) the internal details while the program is computing the multiplications such as: how many processes allocated, which processes will do what job or how many multiplication (i.e., the job distribution), execution steps, intermediate results done by each process (print process_id versus intermediate_result). Finally, the resultant matrix must be printed. Also, provide an output file generated by the redirect (‘>’) output into ‘Output.txt’ for the sample input file (see attachment: input0.txt).
Setting the upper limit (Optional): The maximum size of a row or a column in a matrix can be 100.
(b) Here, you run a different version of the matrix multiplication parallelly as well as sequentially – however, here you will compare their performance: parallel versus sequential execution. The name of the program will be ‘matmulperform’. You will compute the randomly generated n by n (square) matrix of real numbers, numbers can be both negative and positive. You need to measure the execution time by recording the start and end time, where n = 2 to 50. You must take average execution time from (minimum) 100 iterations for each individual case for n = 2 to 50. You need to execute the task for 1 process for sequential execution as well as for n processes for parallel execution. Save your computed results in comma separated vector (CSV) file(s) named ‘Seq_exe.csv’ and ‘Paral_exe.csv’, which will contain the average execution time for sequential as well as parallel execution respectively for n = 2 to 50.
You can open such ~.csv file to be processed by Excel to generate graphs. Anyway, you will generate a graph: ‘Sequential versus Parallel execution’, where x-axis indicates n = 2 to 50 and the y-axis indicates the corresponding average processing time. Place the graph in ‘myreport’ (i.e., the report file, which is generated in section #(a)), explain the graph – if there is an anomaly, also explain that. Further, describe your algorithm in pseudo-code and place it in ‘myreport’.

In the report, you must describe the machine you are using in terms of the available number of cores/processors or, clock-rate, etc.
Programming Language Preferences: You can use the POSIX or MPI libraries (but NOT OpenMP) for creating thread/processes. You can code either in C, C#, Fortran (90/95), Java (for thread only) or python.
For any other language-preference, consult the instructor first or, make sure that the language supports the thread or process creation. And if you need, you can also use the programming language’s libraries related to this parallel computation (if exists any).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

* Part 1 Code - matrixmul
*/
public class matrixmul {

private double[][] A;
private double[][] B;
private double[][] C;
private int n;
private ArrayList<MatrixMultiplyThread> threads;

// Constructor
public matrixmul(double[][] A, double[][] B) {
    this.A = A;
    this.B = B;
    this.n = 1;
}

// Method to get Matrix1
public double[][] getMatrix1() {
    return A;
}

// Method to get Matrix2
public double[][] getMatrix2() {
    return B;
}

// Method to set number of processes
public void setProcesses(int n) {
    this.n = n;
    int rows = A.length;
    int cols = B[0].length;
    this.C = new double[rows][cols];
    this.threads = new ArrayList<MatrixMultiplyThread>();
    for (int i = 0; i < n; i++) {
      threads.add(new MatrixMultiplyThread(this));
    }
    int count = 0;
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
       threads.get(count % n).addCoordinate(new Coordinate(i, j));
       count++;
      }
    }
}

// Method to print threads
public void printThreads() {
    if (threads != null) {
      for (MatrixMultiplyThread thread: threads) {
       System.out.println(thread);
      }
    }
}

// Method to perform multiplication
public double[][] multiply() throws InterruptedException {
    for (MatrixMultiplyThread thread: threads)
      thread.start();
    for (MatrixMultiplyThread thread: threads)
      thread.join();
    return C;
}

// Method to add to result matrix
public synchronized void add(int i, int j, double value) {
    C[i][j] += value;
}

// Method to get duration
public long getDuration() {
    long duration = 0l;
    for (MatrixMultiplyThread thread: threads) {
      duration += thread.getDuration();
    }
    return duration / threads.size();
}

// Method to parse matrices from file
public static matrixmul parse(String filename) throws IOException {
    Scanner s = new Scanner(new File(filename));
    ArrayList<ArrayList<Double>> matrix1 = new ArrayList<ArrayList<Double>>();
    while (s.hasNextLine()) {
      String line = s.nextLine();
      line = line.replace(" ",""...

By purchasing this solution you'll be able to access the following files:
Solution.java, Solution.txt, Solution1.txt, Solution1.java, Solution.csv, Solution1.csv and Solution.docx.

$112.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats