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...
-
In each case below, fill in the missing amount. Case #1 ............. Work in Process, October 1 .................. 5,000 gallons ........................Units started during October...
-
Think of a good (other than smartphones) that has increased or even decreased in quality over time while the price has remained relatively constant. Explain how the change in quality could bias CPI.
-
Explain the detective approach to solving a forensic problem versus the scientific approach.
-
Sue Helms Appliances wants to establish an assembly line to manufacture its new product, the Micro Popcorn Popper. The goal is to produce five poppers per hour. The tasks, task times, and immediate...
-
Problem 5-Available-for-Sale Securities at Fair Value On January 1, 20Y9, Valuation Allowance for Available-for-Sale Investments had a zero balance. On December 31, 20Y9, the cost of the...
-
The trial balance of Pacilio Security Services Inc. as of January 1, 2017, had the following normal balances: Cash ................. 78 , 972 P e t t y C a s h . . . . . . . . . . . . . . . . 100 A c...
-
3. The yearly cash flow estimates of the Price Increase option (see Exhibit 5a) on the equipment decision ignore any possible working capital require- ments. That is, these estimates assume that no...
-
== i. Ms. Afiya has the opportunity to invest RM20,000 in a project that will generate cash inflows of RM5,000 at the end of each of the next 10 years. Alternatively, Ms. Afiya can invest the...
-
The State of Adua has distinguished itself as a "superpower". As such, it is increasingly undertaking initiatives to promote democracy, particularly in States termed to be "developing". Its strategic...
-
A 2.04 kg toy train rolls around a circular horizontal track. If the train has an angular acceleration of -2.21 rads/s 2 and is released with an angular speed of 17.5 rpm, what time is required for...
-
Calculate what your investment will be worth if you invest $500 per month during your entire working lifetime (age 25 to 65 = 40 years). Specific directions are as follows: Begin with $1,000 in your...
-
The partners in Salmon Company decide to liquidate the firm when the balance sheet shows the following. SALMON COMPANY Balance Sheet April 30, 2017 Assets Liabilities and Owners' Equity Cash $28,000...
-
Can you please help me solve the following questions. I will also need the answers step by step. thank you in advance 1 Cecilia and Nathan estimate their total cost for a vacation in Australia to be...
-
The age-old saying for investing is "buy low and sell high," but this is easier said than done. Investors who panic about falling prices sell their investments, which in turn lowers the price 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?...
-
What are some typical consumer complaints?
-
What are five methods of resolving consumer complaints?
-
Marta loves shopping for holiday gifts for her friends and family. This year she started looking for gifts early, in June. She hopes that the extra time will allow her to find the perfect gift for...
Study smarter with the SolutionInn App