counters-tut12 - Multicore Programming C to e Maste...

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

View Full Document Right Arrow Icon
Click to edit Master subtitlestyle Art of Multiprocessor Programming Multicore Programming Shared Counters Tutorial 12 CS 0368-3469 Spring 2009
Image of page 1

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 22 Summary Combining Trees Counting Network
Image of page 2
Art of Multiprocessor Programming 33 Art of Multiprocessor Programming 3 Software Combining Tree 4 Contention: All spinning local Parallelism: Potential n/log n speedup
Image of page 3

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 44 Art of Multiprocessor Programming 4 Combining Trees 0
Image of page 4
Art of Multiprocessor Programming 55 Art of Multiprocessor Programming 5 Combining Trees 0 +3
Image of page 5

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 66 Art of Multiprocessor Programming 6 Combining Trees 0 +3 +2
Image of page 6
Art of Multiprocessor Programming 77 Art of Multiprocessor Programming 7 Combining Trees 0 +3 +2 Two threads meet, combine sums
Image of page 7

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 88 Art of Multiprocessor Programming 8 Combining Trees 0 +3 +2 Two threads meet, combine sums +5
Image of page 8
Art of Multiprocessor Programming 99 Art of Multiprocessor Programming 9 Combining Trees 5 +3 +2 +5 Combined sumadded to root
Image of page 9

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 1010 Art of Multiprocessor Programming 10 Combining Trees 5 +3 +2 0 Result returned to children
Image of page 10
Art of Multiprocessor Programming 1111 Art of Multiprocessor Programming 11 Combining Trees 5 0 0 3 0 Results returned to threads
Image of page 11

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 1212 Trinary CombiningTree Implement a trinary CombiningTree. Allows up to three threads coming fromthreesubtrees to combineat a given node. Estimate the advantages and disadvantages?
Image of page 12
Art of Multiprocessor Programming 1313 Trinary Solution enum  CStatus{ IDLE,FIRST,SECOND,  THIRD,DONE,ROOT}
Image of page 13

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 1414 Trinary Solution public class  Node3 {   boolean  locked =  false ;    // is node locked?   int  drained =  0 // distributing after   CStatus3 cStatus;   // combining status   int  firstValue, secondValue, thirdValue;  //  values  int  result, secondResult, thirdResult;  //  results  Node3 parent;       // reference to parent   public  Node3() {     cStatus = CStatus3.ROOT;     public  Node3(Node3 parent) {     this .parent = parent;     cStatus = CStatus3.IDLE;     }
Image of page 14
Art of Multiprocessor Programming 1515 public int  getAndIncrement(){     CStatus3 myStatus;     Stack<Node3> stack =  new  Stack<Node3>();     Node3 myLeaf = leaf[ ThreadID.get() / 2];     Node3 node = myLeaf;     // phase one      while  ((myStatus = node.precombine())  == CStatus3.IDLE) {       node = node.parent;     }   Node3 stop = node;   } Trinary Solution
Image of page 15

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

View Full Document Right Arrow Icon
Art of Multiprocessor Programming 1616 public int  getAndIncrement(){     // phase two     node = myLeaf;     int  combined = 1;     while  (node != stop) {       combined = node.combine(combined);       stack.push(node);       node = node.parent;     }         } Trinary Solution
Image of page 16
Art of Multiprocessor Programming 1717 public int
Image of page 17

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

View Full Document Right Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '10
  • KLAZAR
  • Bodens ingenjörregemente, Ing 3, Ternary computer, Multiproce ing, Multiproce Programssor ssor, Multiproce ssor

{[ 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