{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs140-matmul - CS 140 Matrix multiplication CS Matrix...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 140 : Matrix multiplication CS 140 : Matrix multiplication Matrix multiplication I : parallel issues Matrix multiplication II: cache issues Thanks to Jim Demmel and Kathy Yelick (UCB) for some of these slides
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Communication volume model Communication volume model Network of p processors Each with local memory Message-passing Communication volume ( v ) Total size (words) of all messages passed during computation Broadcasting one word costs volume p (actually, p-1 ) No explicit accounting for communication time Thus, can’t really model parallel efficiency or speedup; for that, we’d use the latency-bandwidth model (see extra slides)
Image of page 2
Matrix-Matrix Multiplication Matrix-Matrix Multiplication {implements C = C + A*B} for i = 1 to n for j = 1 to n for k = 1 to n C(i,j) = C(i,j) + A(i,k) * B(k,j) = + * C(i,j) C(i,j) A(i,:) B(:,j) Algorithm has 2*n 3 = O(n 3 ) Flops and operates on 3*n 2 words of memory
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Parallel Matrix Multiply Parallel Matrix Multiply Compute C = C + A*B Basic sequential algorithm: C(i,j) += A(i,1)*B(1,j) + A(i,2)*B(1,j) +…+ A(i,n)*B(n,j) work = t 1 = 2n 3 floating point operations (“flops”) Variables are: Data layout Structure of communication Schedule of communication
Image of page 4
Parallel Matrix Multiply with 1D Column Layout Parallel Matrix Multiply with 1D Column Layout Assume matrices are n x n and n is divisible by p A(i) is the n-by-n/p block column that processor i owns (similarly B(i) and C(i)) B(i,j) is a n/p-by-n/p sublock of B(i) in rows j*n/p through (j+1)*n/p Then: C(i) += A(0)*B(0,i) + A(1)*B(1,i) +…+ A(p-1)*B(p-1,i) p0 p1 p2 p3 p5 p4 p6 p7 (A reasonable assumption for analysis, not for code)
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Matmul for 1D layout on a Processor Matmul for 1D layout on a Processor Ring Ring Proc k communicates only with procs k-1 and k+1 Different pairs of processors can communicate simultaneously Round-Robin “Merry-Go-Round” algorithm Copy A(myproc) into MGR (MGR = “Merry-Go-Round”) C(myproc) = C(myproc) + MGR*B(myproc , myproc) for j = 1 to p-1 send MGR to processor myproc+1 mod p (but see deadlock below) receive MGR from processor myproc-1 mod p (but see below) C(myproc) = C(myproc) + MGR * B( myproc-j mod p , myproc)
Image of page 6
Matmul for 1D layout on a Processor Ring Matmul for 1D layout on a Processor Ring One iteration: v = n 2 All p-1 iterations: v = (p-1) * n 2 ~ pn 2 Optimal for 1D data layout: Perfect speedup for arithmetic A(myproc) must meet each C(myproc) “Nice” communication pattern – can probably overlap independent communications in the ring. In latency/bandwidth model (see extra slides), parallel efficiency e = 1 - O(p/n)
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
MatMul with 2D Layout MatMul with 2D Layout Consider processors in 2D grid (physical or logical) Processors can communicate with 4 nearest neighbors Alternative pattern: broadcast along rows and columns Assume p is square s x s grid p(0,0) p(0,1) p(0,2) p(1,0) p(1,1) p(1,2) p(2,0) p(2,1) p(2,2) p(0,0) p(0,1) p(0,2) p(1,0) p(1,1) p(1,2) p(2,0) p(2,1) p(2,2) p(0,0) p(0,1) p(0,2) p(1,0) p(1,1) p(1,2) p(2,0) p(2,1) p(2,2) = *
Image of page 8
Cannon’s Algorithm: 2-D merry-go-round Cannon’s Algorithm: 2-D merry-go-round … C(i,j) = C(i,j) + Σ
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern