Docsity

Multiprocessors - Slides - High Performance Computer Architecture | CS 6290, Study notes of Computer Science

Partial preview of the text

Download Multiprocessors - Slides - High Performance Computer Architecture | CS 6290 and more Study notes Computer Science in PDF only on Docsity!

CS

Multiprocessors

Multiprocessing • Flynn’s Taxonomy of Parallel Machines

– How many Instruction streams? – How many Data streams?

• SISD: Single I Stream, Single D Stream

– A uniprocessor

• SIMD: Single I, Multiple D Streams

– Each “processor” works on its own data – But all execute the same instrs in lockstep – E.g. a vector processor or MMX

ILP limitsreached?

Multiprocessors • Why do we need multiprocessors?

  • Uniprocessor speed keeps improving – But there are things that need even more speed
    • Wait for a few years for Moore’s law to catch up? • Or use multiple processors and do it now?

• Multiprocessor software problem

  • Most code is sequential (for uniprocessors)
    • MUCH easier to write and debug
      • Correct parallel code very, very difficult to write

        Efficient and correct is even harder - Debugging even more difficult (Heisenbugs)

MIMD Multiprocessors^ Centralized Shared Memory

Distributed Memory

Distributed-Memory Machines • Two kinds

  • Distributed Shared-Memory (DSM)
    • All processors can address all memory locations • Data sharing like in SMP • Also called NUMA (non-uniform memory access) • Latencies of different memory locations can differ (local access faster than remote access) - Message-Passing - A processor can directly address only local memory • To communicate with other processors, must explicitly send/receive messages - Also called multicomputers or clusters

• Most accesses local, so less memory contention

(can scale to well over 1000 processors)

Message-Passing Machines • A cluster of computers

  • Each with its own processor and memory – An interconnect to pass messages between them – Producer-Consumer Scenario:
    • P1 produces data D, uses a SEND to send it to P2 • The network routes the message to P2 • P2 then calls a RECEIVE to get the message
      • Two types of send primitives
        • Synchronous: P1 stops until P2 confirms receipt of message • Asynchronous: P1 sends its message and continues
          • Standard libraries for message passing: Most common is MPI – Message Passing Interface

Parallel Performance • Serial sections

– Very difficult to parallelize the entire app– Amdahl’s law

• Large remote access latency (100s of ns)

– Overall IPC goes down

Parallel Parallel Parallel Overall Speedup F ) F

( 1 Speedup

= 1024 Speedup Parallel =

F Parallel =

Speedup Overall = 1024 Speedup Parallel =

F Parallel =

Speedup Overall = (^8). 2 CPI = estCost RemoteRequ estRate RemoteRequ CPI CPI Base ×

= (^4). 0 CPI Base =

estRate RemoteRequ = Cycles 1200 ns/Cycle (^33). 0 400ns estCost RemoteRequ = = We need at least 7 processors just to break even! This cost reduced with CMP/multi-core

Message Passing Pros and Cons • Pros

  • Simpler and cheaper hardware – Explicit communication makes programmers aware of costly (communication) operations

• Cons

  • Explicit communication is painful to program – Requires manual optimization
    • If you want a variable to be local and accessible via LD/ST, you must declare it as such - If other processes need to read or write this variable, you must explicitly code the needed sends and receives to do this

Shared Memory Pros and Cons • Pros

  • Communication happens automatically – More natural way of programming
    • Easier to write correct programs and gradually optimize them
      • No need to manually distribute data (but can help if you do)

• Cons

  • Needs more hardware support – Easy to write correct, but inefficient programs (remote accesses look the same as local ones)

Shared Memory: A Program • Calculating the sum of array elements

#define ASIZE 1024 #define NUMPROC 4 shared double array[ASIZE]; shared double allSum=0; shared mutex sumLock; double mySum=0; for(int i=myPIDASIZE/NUMPROC;i<(myPID+1)ASIZE/NUMPROC;i++) mySum+=array[i]; lock(sumLock); allSum+=mySum; unlock(sumLock); if(myPID=0) printf(“Sum: %lf\n”,allSum);** Array is shared Each processor adds its partial sums to the final result “Master” processor prints the result Each processor sums up “its” part of the array

Cache Coherence Definition •

A memory system is coherent if

A read R from address X on processor P1 returns thevalue written by the most recent write W to X on P1 if noother processor has written to X between W and R.

If P1 writes to X and P2 reads X after a sufficient time,and there are no other writes to X in between, P2’s readreturns the value written by P1’s write.

Writes to the same location are serialized: two writes tolocation X are seen in the same order by all processors.

Cache Coherence Definition • Property 1. preserves program order

  • It says that in the absence of sharing, each processor behaves as a uniprocessor would

• Property 2. says that any write to an address must

eventually be seen by all processors

  • If P1 writes to X and P2 keeps reading X, P2 must eventually see the new value

• Property 3. preserves causality

  • Suppose X starts at 0. Processor P1 increments X and processor P waits until X is 1 and then increments it to 2. Processor P3 musteventually see that X becomes 2. - If different processors could see writes in different order, P2 can see P1’s write and do its own write, while P3 first sees the write by P2 andthen the write by P1. Now we have two processors that will foreverdisagree about the value of A.

Snooping • Typically used for bus-based (SMP) multiprocessors

  • Serialization on the bus used to maintain coherence property 3
    • Two flavors
      • Write-update (write broadcast)
        • A write to shared data is broadcast to update all copies • All subsequent reads will return the new written value (property 2) • All see the writes in the order of broadcasts One bus == one order seen by all (property 3) - Write-invalidate - Write to shared data forces invalidation of all other cached copies • Subsequent reads miss and fetch new value (property 2) • Writes ordered by invalidations on the bus (property 3)

Update vs. Invalidate • A burst of writes by a processor to one addr

  • Update: each sends an update – Invalidate: possibly only the first invalidation is sent
    • Writes to different words of a block
      • Update: update sent for each word – Invalidate: possibly only the first invalidation is sent
        • Producer-consumer communication latency
          • Update: producer sends an update, consumer reads new value from its cache - Invalidate: producer invalidates consumer’s copy, consumer’s read misses and has to request the block - Which is better depends on application - But write-invalidate is simpler and implemented in most MP-capable processors today