Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. Assignment 1
  2. Design: Due Thursday 1/23/20 Final: Due Thursday 2/06/20
  3.  
  4. Goal
  5. The goal of this assignment is to
  6.  
  7. better understand three variations of matrix multiplication
  8. write a program in C
  9. analyze the impact of the cache on program performance.
  10. Program statement
  11. Mr. Krabs needs a lightning quick matrix multiplier.
  12.  
  13. Back story
  14. Mr. Krabs has three suppliers for crab, lettuce, buns, sauce, etc. Each charges different amounts for each ingredient. He also knows how much of each he uses each day. Sponge Bob told him that to compute the cost for each ingredient on each day he need only do some matrix multiplication. Mr. Krabs has hired you (and not the sponge) to implement this matrix multiplication.
  15.  
  16. Analysis
  17. Given a problem statement, an analyst asks questions to better understand what exactly the client's problem is (clients are notorious for not knowing their own problems!). In this assignment there are three key questions "What is a matrix?", "What are the steps one takes to multiply two matrices?", and "What is the process to select each day's supplier?"
  18.  
  19. To answer the first question, a programer thinks of a matrix as a two-dimensional array of numbers.
  20.  
  21. For the second question, to multiply two matrices involves computing the dot product of various rows and columns. Rather than repeat it here, Wolfram's Matrix Multiply Page describes the process in detail. You may also find it helpful to do a simple exercise provides a simple example.
  22.  
  23. In our case, Mr. Krabs purchased an algorithm for you to implement (from Plankton's algorithm emporium). Call this Version 1. In this algorithm the values in the product matrix are computed one by one using a loop that iterates k times to compute the dot product of row r from the first matrix and column c from the second. In pseudo code this is
  24.  
  25. for each row r
  26. for each column c
  27. for each index k
  28. product[r][c] += A[r,k] * B[k,c]
  29. assuming that product is initialized to all zeros.
  30.  
  31. Filling the matrices Mr. Krabs will use into the algorithm above, yields
  32.  
  33. for each row r = Monday then Tuesday
  34. for each column c = Sandy then Squidward
  35. for each index k = Crab then Lettuce
  36. product[r,c] += usage[r,k] * costs[k,c]
  37. The final question is best answered with an example. Consider the following product.
  38.  
  39. cost matrix usage matrix
  40. Crab Lettuce Sandy Squidward
  41. Mon 8 1 * Crab 1.99 1.50
  42. Tue 2 9 Lettuce 2.99 4.50
  43. Here is a trace each time product is updated:
  44.  
  45. product[Monday][Sandy] += 8 * 1.99 // k = Crab
  46. product[Monday][Sandy] += 1 * 2.99 // k = Lettuce
  47. product[Monday][Squidward] += 8 * 1.50 // k = Crab
  48. product[Monday][Squidward] += 1 * 4.50 // k = Lettuce
  49.  
  50. product[Tuesday][Sandy] += 2 * 1.99 // k = Crab
  51. product[Tuesday][Sandy] += 9 * 2.99 // k = Lettuce
  52. product[Tuesday][Squidward] += 2 * 1.50 // k = Crab
  53. product[Tuesday][Squidward] += 9 * 4.50 // k = Lettuce
  54. The resulting matrix is:
  55.  
  56. Sandy Squidward
  57. Mon 18.91 16.50
  58. Tue 30.89 43.50
  59. Here, the product matrix says that Mr. Crabs should order from Squidward on Monday (because the total cost of 16.50 is less than Sandy's 18.91), while on Tuesday he should order from Sandy.
  60.  
  61. So far so good, but, alas, as these things go, there was what has become known in Bikini Bottom as the debate:
  62.  
  63. Patrick said that he knows a better way -- change the order of the outer two loops (this is Version 2)
  64. Sponge bob said Patrick is wrong, you want to change the order of the inner two loops (this is Version 3).
  65. Mr. Krabs threw up his claws and has since decided to task you (he pays well) with understanding how all three work.
  66.  
  67. Design Requirements
  68. Due: Thursday 1/23/20
  69.  
  70. Add Buns to the list of supplies Mr. Crabs needs daily, and also add the day Wednesday.
  71.  
  72. He needs 10 Buns on Monday, 6 on Tuesday, and 3 on Wednesday.
  73. On Wednesday his needs also include 3 Crab and 4 Lettuce.
  74. Sandy charges 0.50 for Buns while Squidward charges 0.60.
  75. Trace the computation of the product as done above using all three versions of the multiplication algorithm (original, Patrick's, and Sponge Bob's).
  76.  
  77. Record each trace in a simple text file named Asgn1Design.txt that begins with the header.
  78.  
  79. // This is my work
  80. // <Your Name>
  81. // CS366\fP
  82. Note: Each of the three traces should be labeled with the name of the version and the psudeo code used to produce it.
  83.  
  84. For each of the three traces, use the result to answer the question "On each day, who should Mr. Crabs purchase supplies from?"
  85.  
  86. At the end of all three traces, weigh in on the debate by explaining which algorithm is better and why you think so.
  87.  
  88. What to hand in
  89. Be sure to add, commit, and push your Asgn1Design.txt file before the due date for this asignment.
  90. Also include a no-more-than-one page summary of this article about cpu caching in a file called summary.txt in this repository.
  91. Implementation requirements
  92. Due: Thursday 2/06/20
  93.  
  94. Edit mm.c to include with the following header comment
  95. // This is my code
  96. // <Your Name>
  97. // CS366\fP
  98. Right after the header comment, include a comment with the machine name, processor model, cache size, as well as the sizes of the L1, L2, and L3 caches. Use the commands lscpu and hostname to help.
  99. In mm.c, write the body (and appropriate comments) of a function to calculate C = A * B. The function to edit is
  100. void multiply(array A, array B, array C, int n)
  101. Create functions patrick and sponge for the two corresponding variants.
  102. You code should generate no warnings or errors when compiles with gcc -Wall
  103. What do hand in
  104. Be sure to commit and push mm.c before the due date for this assignment.
  105. Include a summary in matmult.txt explaining who was right and why you think the order does or does not matter. Include and refer to a copy of your program's output in your explanation.
  106. Make sure that you have no commited any "derivable" files (e.g., .o or executable files).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement