Write a multithreaded java program that performs matrix multiplication

Goals The goals for this lab are to help you tune up your perhaps rusty C programming skills, and to give you some experience with programming using pthreads.

An loop is used whose counter k, ranges from 0 to e A three level nested loop is used to perform the multiplication.

For C, this latter requirement is especially important because the language only includes the ability to store values in a one-dimensional array. The convention we will use and the convention used in most C programs is to list them by row -- called row major order.

That is, each thread gets its own rectangular region and the entire product matrix is covered by all of the rectangles. In that light, we will use the "convention" that matrix elements are named by an ordered pair, where the first entry in the pair is the row number and the second is the column number.

Probably the easiest way to see how this works is through an example. If the product matrix had rows, then each "strip" of the matrix would have 20 rows for its thread to compute.

Put another way, when your assignment is graded, it will be executed using the prototype shown above using the file format shown and the results compared electronically to that generated by a known working solution.

You will need to write a funtion that can read matrix files in this format and to do the argument parsing necessary so that the prototype shown above works properly.

C i,j is then the sum of these multiplications.

This function is available from http: Here is an example matrix file 3 2 Row 0 0. It will help in the future. Note that the number of threads may not divide the number of rows evenly.

The outer loop is counting off rows in the index i while the inner loop indexes columns in the j variable. Matrix Multiply Now that you have -- uh -- mastered the matrix ouchyou can think about matrix arithmetic.

If you have implemented the threading correctly you should expect to see quite a bit of speed-up when the machine you are using has multiple processors. At any iteration of the loop, i refers to the row number and j to the column number of the position in matrix C that we are trying to fill. Threading Matrix Multiply In this assignment you you are to write a version of matrix multiply that uses threads to divide up the work necessary to compute the product of two matraces.

Both the correctness and the speed-up of the program due to parallelism will be considered as well as the degree to which the program handles error conditions. If it does, then notice how the loops run.

Additionally, within each row, elements are listed from lowest column number to highest.

C Program to Perform Matrix Multiplication

Please test your code thoroughly. Lines that begin with " " should be considered comments and should be ignored. The program must conform to a specific prototype and generate output in the specified format. Then each line is an element in row major order. This form of parallelization is called a "strip" decomposition of the matrix since the effect of partitioning one dimension only is to assign a "strip" of the matrix to each thread for computation.

An inner loop has the loop counter j ranging from 0 to f. If in doubt please speak to the TAs or the instructor for clarification. The first line contains two integers: Handling error cases is part of the assignment so please make sure you code does so.

If it does, then you should consider it a sign that you need to brush up on your C. It must print the product in the same format with comments indicating rows as the input matrix files: They also can be multiplied, but the multiplication process is somewhat non-intuitive.

Extra Credit Because of cache line size limitations, it may be more efficient to divide the production of the product into tesselating rectangles rather than strips.2 comments to "MULTITHREADED MATRIX MULTIPLICATION IN JAVA" Can you post an output example for this program?

3 May at srdvsanaa says: CAN YOU EXPLAIN EACH LINE IN THIS CODE IN DETAILS?? Post a Comment. Newer Post. Let the two matrix to be multiplied be A and B.

Java Program to Perform Matrix Multiplication

Let A be a matrix of order d*e - d rows and e columns and B be the second matrix of order e*f. Note that the number of columns in the first matrix should be the same as the number of rows in the second matrix.

The product matrix will be of order d*f. a program to print random matricies: print-rand-matrix.c; a function to return a matrix multiplication is a little bit more restricted in terms of what can be multiplied than its scalar counterpart.

In this assignment you you are to write a version of matrix multiply that uses threads to divide up the work necessary to compute the. This is a java program to perform a simple matrix multiplication. For matrix multiplication to happen the column of the first matrix should be equal to the row of the second matrix.

Here is the source code of the Java Program to Perform Matrix Multiplication. The Java program is successfully compiled and run on a Windows system.

The program output is also shown below. 1st Java Program OOPS Concepts Class Object Abstraction Encapsulation Polymorphism Inheritance Java Matrix Operations: Previous Chapter: Next Chapter: Matrix (Two Dimensional Array) Creation in Java; Matrix Addition in Java; ultimedescente.com Trying to get a multi-threaded matrix multiplication to work in Java.

It is given a (m x n) matrix, a (n x k) matrix and 't' threads to perform the operation on. My program works when the matrices are square and t == n.

When running with t.

Write a multithreaded java program that performs matrix multiplication
Rated 4/5 based on 95 review