complete a C program to employ multi-threading to multiply two matrices using the Pthreads library. You...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
complete a C program to employ multi-threading to multiply two matrices using the Pthreads library. You will create as many threads as there are cells in the resulting matrix. A review of matrix multiplication follows. Your solution will start from an initial source file: Mod2/matrix/matrix- mult.c. A makefile and several sample test files are in the same directory. 2. Matrix Multiplication Matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The resulting matrix, known as the matrix product, has the number of rows of the first and the number of columns of the second matrix. If A is an m x n matrix and B is an n xp matrix, -619-69 B A- 012 such that: 421 022 by by b Cmp buy The matrix product C=AB is defined to be the xp matrix. C21 C22 +6868 Cml Cm2 bap c₂ = anby, +anby,+ + aimbus = Σaubus, You should familiarize yourself with the types pthread_t and pthread_attr_t as well as the system calls pthread_create() and pthread_join(). When you compile your program, you will need to include the pthread and math libraries: gcc matrix-mult.c -pthread -fno-stack-protector -Im -o matrix-mult 4. Other Requirements The following list includes other requirements that your program must meet: The program must print a heading which includes the class name (ACO350) and your name (not "Prof. Eckert"). Each cell of the resulting matrix must be calculated by a different thread. Turn in only your source file: matrix-mult.c. . 5. Approach The main thread will create multiple threads. Each additional thread will solve one cell of the matrix multiplication problem in the following way: Given two matrices A and B: Where: . C = A x B is: • • 1 A = The result multiplying A x B is: 4 2 5 58 139 3 6 64 154 58 (1 x 7) + (2 x 9) + (3 x 11) 64 (1 x 8) + (2 x 10) + (3 x 12) 139 = (4 x 7) + (5 x 9) + (6 x 11) 154 = (4 x 8) + (5 x 10) + (6 x 12) B = 7 9 11 8 10 12 First row of A, first column of B First row of A, second column of B Second row of A, first column of B Second row of A, second column of B The work required to perform this multiplication can be divided in n parts (one part per cell in the final matrix). Each part will be assigned to a different thread with an assigned row from matrix A and column from matrix B. For example, the first thread (assigned to A row 0 and B column 0) will compute the result of C[0,0] = (1 x 7) + (2 x 9) + (3 x 11) = 58. Each thread will update its cell of the final matrix C. Start with the source code: matrix_multo.c. This file has a skeletal main function as well as complete functions to read a matrix from the source file and print a matrix. Be sure to read and understand the starting code before beginning your project. The source code has several comments which contain the phrase "TO DO" for which you should be looking. There are two sample data files that you can use to test your program: data1.txt and data2.txt. The expected results can be seen in the Sample Output section below. 6. Required Source File matrix-mult.c 7. Sample Output data1.txt pi@pi4:-/AC0350/sample_code/module_2 $ ./mat datal.txt Multi-threaded Matrix Multiplication AC0350 Prof. Eckert A [2x3]: 1 2 3 456 B [3x2]: 7 8 9 10 11 12 A x B= C [2x2]: 58 64 139 154 data2.txt pi@pi4:-/AC0350/sample_code/module 2 $ ./mat data2.txt Multi-threaded Matrix Multiplication - AC0350 Prof. Eckert A [10x10]: 1 3 7 43 56 32 33 44 12 1 2 3 6 7 9 54 34 2 34 5 74 89 2 2 3 6 45 89 51 3 42 75 10 5 87 42 85 5 22 12 5 90 10 8 53 90 53 78 54 78 21 50 20 2 7 67 34 63 92 43 76 10 11 77 42 76 9 88 21 45 68 77 30 5 23 8 65 1 78 9 54 9 43 2 3 45 2 6 54 3 67 2 10 2 34 80 5 76 1 15 43 18 93 29 3 92 8 77 7 56 83 46 32 B [10x10]: 26 9 23 26 39 3 29 55 9 49 22 30 57 5 50 81 12 43 36 27 19 64 44 33 87 24 92 24 95 64 79 92 85 66 51 4 5 8 47 81 53 5 44 77 12 50 37 92 35 55 72 62 55 40 60 98 83 70 63 58 44 38 21 10 0 12 27 37 44 53 62 73 86 90 1 67 42 26 9 88 61 45 28 7 80 A x B= C [10x10]: 5863 6900 9595 7595 9424 10393 10548 10722 9049 6345 7127 13421 13213 13327 19182 15460 22217 21748 14993 14966 8884 8658 8549 8567 15190 8400 10043 10203 7777 6980 9411 7348 9196 5594 13611 12206 10874 9797 7263 10967 4322 11138 8329 15963 19878 17169 17774 20295 19243 10445 11912 15289 11195 18721 19109 18102 19564 20215 18820 10701 12070 8809 14743 10503 19969 12073 20561 23678 17756 14868 15784 18937 22688 19643 29550 23386 27434 30690 21937 22499 15455 17432 17618 19054 24581 19789 17799 20486 16484 14503 16121 22715 21707 21363 30985 24424 32915 30216 19885 22928 complete a C program to employ multi-threading to multiply two matrices using the Pthreads library. You will create as many threads as there are cells in the resulting matrix. A review of matrix multiplication follows. Your solution will start from an initial source file: Mod2/matrix/matrix- mult.c. A makefile and several sample test files are in the same directory. 2. Matrix Multiplication Matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The resulting matrix, known as the matrix product, has the number of rows of the first and the number of columns of the second matrix. If A is an m x n matrix and B is an n xp matrix, -619-69 B A- 012 such that: 421 022 by by b Cmp buy The matrix product C=AB is defined to be the xp matrix. C21 C22 +6868 Cml Cm2 bap c₂ = anby, +anby,+ + aimbus = Σaubus, You should familiarize yourself with the types pthread_t and pthread_attr_t as well as the system calls pthread_create() and pthread_join(). When you compile your program, you will need to include the pthread and math libraries: gcc matrix-mult.c -pthread -fno-stack-protector -Im -o matrix-mult 4. Other Requirements The following list includes other requirements that your program must meet: The program must print a heading which includes the class name (ACO350) and your name (not "Prof. Eckert"). Each cell of the resulting matrix must be calculated by a different thread. Turn in only your source file: matrix-mult.c. . 5. Approach The main thread will create multiple threads. Each additional thread will solve one cell of the matrix multiplication problem in the following way: Given two matrices A and B: Where: . C = A x B is: • • 1 A = The result multiplying A x B is: 4 2 5 58 139 3 6 64 154 58 (1 x 7) + (2 x 9) + (3 x 11) 64 (1 x 8) + (2 x 10) + (3 x 12) 139 = (4 x 7) + (5 x 9) + (6 x 11) 154 = (4 x 8) + (5 x 10) + (6 x 12) B = 7 9 11 8 10 12 First row of A, first column of B First row of A, second column of B Second row of A, first column of B Second row of A, second column of B The work required to perform this multiplication can be divided in n parts (one part per cell in the final matrix). Each part will be assigned to a different thread with an assigned row from matrix A and column from matrix B. For example, the first thread (assigned to A row 0 and B column 0) will compute the result of C[0,0] = (1 x 7) + (2 x 9) + (3 x 11) = 58. Each thread will update its cell of the final matrix C. Start with the source code: matrix_multo.c. This file has a skeletal main function as well as complete functions to read a matrix from the source file and print a matrix. Be sure to read and understand the starting code before beginning your project. The source code has several comments which contain the phrase "TO DO" for which you should be looking. There are two sample data files that you can use to test your program: data1.txt and data2.txt. The expected results can be seen in the Sample Output section below. 6. Required Source File matrix-mult.c 7. Sample Output data1.txt pi@pi4:-/AC0350/sample_code/module_2 $ ./mat datal.txt Multi-threaded Matrix Multiplication AC0350 Prof. Eckert A [2x3]: 1 2 3 456 B [3x2]: 7 8 9 10 11 12 A x B= C [2x2]: 58 64 139 154 data2.txt pi@pi4:-/AC0350/sample_code/module 2 $ ./mat data2.txt Multi-threaded Matrix Multiplication - AC0350 Prof. Eckert A [10x10]: 1 3 7 43 56 32 33 44 12 1 2 3 6 7 9 54 34 2 34 5 74 89 2 2 3 6 45 89 51 3 42 75 10 5 87 42 85 5 22 12 5 90 10 8 53 90 53 78 54 78 21 50 20 2 7 67 34 63 92 43 76 10 11 77 42 76 9 88 21 45 68 77 30 5 23 8 65 1 78 9 54 9 43 2 3 45 2 6 54 3 67 2 10 2 34 80 5 76 1 15 43 18 93 29 3 92 8 77 7 56 83 46 32 B [10x10]: 26 9 23 26 39 3 29 55 9 49 22 30 57 5 50 81 12 43 36 27 19 64 44 33 87 24 92 24 95 64 79 92 85 66 51 4 5 8 47 81 53 5 44 77 12 50 37 92 35 55 72 62 55 40 60 98 83 70 63 58 44 38 21 10 0 12 27 37 44 53 62 73 86 90 1 67 42 26 9 88 61 45 28 7 80 A x B= C [10x10]: 5863 6900 9595 7595 9424 10393 10548 10722 9049 6345 7127 13421 13213 13327 19182 15460 22217 21748 14993 14966 8884 8658 8549 8567 15190 8400 10043 10203 7777 6980 9411 7348 9196 5594 13611 12206 10874 9797 7263 10967 4322 11138 8329 15963 19878 17169 17774 20295 19243 10445 11912 15289 11195 18721 19109 18102 19564 20215 18820 10701 12070 8809 14743 10503 19969 12073 20561 23678 17756 14868 15784 18937 22688 19643 29550 23386 27434 30690 21937 22499 15455 17432 17618 19054 24581 19789 17799 20486 16484 14503 16121 22715 21707 21363 30985 24424 32915 30216 19885 22928
Expert Answer:
Answer rating: 100% (QA)
To create a C program that employs multithreading to multiply two matrices using the Pthreads library you can use the following code as a starting poi... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
How can process technology optimize inventory management in the supply chain?
-
If P(x,y) = cxy at the points (1,1),(2,1),(2,2), and (3,1), and equals 0 elsewhere, find c.
-
4. In St. Albert, Alberta, there are two bakers, Anderson and Carlson. Anderson's bread tastes just like Carlson's. Anderson has average costs of $1 per loaf of bread. Carlson has average costs of $2...
-
A camera weighing 0.53 lb is mounted on a small tripod weighing 0.44 lb, assuming that the weight of the camera is uniformly distributed and that the line of action of the weight of the tripod passes...
-
In R Studio plot the following two items of the Amazon, AMZN Stock: 1. The past five years of stock price data 2. The past 20 years of 10-year US Treasury Bond Yields. Then explain your findings, the...
-
The interest rates in the UK and the United States are, respectively, \(4 \%\) and \(6 \%\) per annum compounded continuously. The spot price of the UK pound is \(\$ 1.6\). The forward price for a UK...
-
If you put $ 15,000 in the bank today to save for college, and leave it for 20 years, what quarterly rate of interest will you have to earn in order to be able to pay a $ 50,000 tuition bill when you...
-
Shouldthe project be accepted using the IRR and NPV methods? WACC 9% Cost of machine2 million Working capital needed at time 0 is $250,000 none is recovered at projects end Cash flow year 1 $500,000...
-
Shown on the following page are responsibility income statements for Butterfield, Inc., for the month of March. Instructions a. The company plans to initiate an advertising campaign for one of the...
-
How can organizations systematically fortify their regulatory compliance infrastructure to withstand the crucible of regulatory scrutiny, engendering a robust compliance culture that permeates every...
-
What is the focus of todays tort reformers?
-
Is todays American society an unduly litigious society?
-
True Or False The collateral-source rule has been abolished in some states because allowing the admission of evidence of supplemental benefits helps ensure that liability is divided among tortfeasors...
-
True Or False In State Farm v. Campbell, the Court found the punitive-damage award grossly excessive because the ratio between the compensatory damages and punitive damage was unreasonable.
-
True Or False Courts are generally willing to uphold legislation imposing limits both on economic damages and non-economic damages.
-
Accrued revenue is revenue that ww. OA. the business has earned, but not yet collected in cash OB. will be collected and earned in the future OC. has been collected and earned OD. the business has...
-
One hundred pounds of water at atmospheric pressure are heated from 60F to 200F. What is the enthalpy change? The internal energy change? Why is the difference between the internal energy change and...
-
Patty Bayan is a single taxpayer living at 543 Space Drive, Houston, TX 77099. Her Social Security number is 466-33-1234. For 2012, Patty has no dependents, and her W-2 from her job at a local...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-7. Ivan sold the following securities during the year and received a Form 1099-B that...
-
If Charles, a 16-year-old child model, earns $50,000 a year and is completely self supporting even though he lives with his parents, can his parents claim him as a dependent? Why or why not?...
-
You are to open the books of F. Polk, a trader, via the journal to record the assets and liabilities, and are then to record the dialy transactions for the month of May. A trial balance is to be...
-
Show the journal entries necessary to record the following items: 2017 Apr 1 Bought office furniture on credit from Durham Brothers Ltd 1,400. 4 We take goods costing 270 out of the business...
-
You are to show the journal entries necessary to record the following items which occured in 2016: (a) May 1 Bought a motor bike on credit from Lakeside Garage for 5,500. (b) May 3 A debt of 347...
Study smarter with the SolutionInn App