Description
Objective :
• Lab 5 is intended to give you some experience with programming using pthreads.
• The Assignment: Threading Matrix Multiply
In this assignment you are to write a version of matrix multiply that uses threads to divide up the work necessary to compute the product of two matrices. There are several ways to improve the performance using threads. You need to divide the product in row dimension among multiple threads in the computation. That is, if you are computing A * B and A is a 10 x 10 matrix and B is a 10 x 10 matrix, your code should use threads to divide up the computation of the 10 rows of the product which is a 10 x 10 matrix. If you were to use 5 threads, then rows 0 and 1 of the product would be computed by thread 0, rows 2 and 3 would be computed by thread 1,…and rows 8 and 9 would be computed by thread 4.
• What you need to do
Your program must conform to the following prototype:
my matrix multiply -a a matrix file.txt -b b matrix file.txt -t thread count
where the -a and -b parameters specify input files containing matrices and thread count is the number of threads to use in your strip decompostion.
The input matrix files are text files having the following format. The first line contains two integers: rows columns. Then each line is an element in row major order. Lines that begin with ”#” should be considered comments and should be ignored. Here is an example matrix file
3 2
# Row 0
0.711306
0.890967
# Row 1
0.345199
0.380204
# Row 2
0.276921
0.026524
This matrix has 3 rows an 2 columns and contains comment lines showing row boundaries in the row-major ordering.
• Your assignment will be graded using a program that generates random matrices in this format (print-rand-matrix.c).
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.
• Your program will need to print out the result of A * B where A is contained in the file passed via the -a parameter and B is contained in the file passed via the -b parameter. It must print the product in the same format (with comments indicating rows) as the input matrix files: rows and columns on the first line, each element in row-major order on a separate line.
my matrix multiply -a a1000.txt -b b1000.txt -t 1
completes in 8.8 seconds when a1000.txt and b1000.txt are both 1000 x
1000 matracies while applying
my matrix multiply -a a1000.txt -b b1000.txt -t 2
the time drops to 4.9 seconds (where both of these times come from the ”real” number in the Linux time command).
• Hint: Refer to http://www.cs.ucsb.edu/ rich/class/cs170/labs/mmult/what i did.html
Reviews
There are no reviews yet.