Thm13 - PRAM Models

download Thm13 - PRAM Models

of 22

Transcript of Thm13 - PRAM Models

  • 8/18/2019 Thm13 - PRAM Models

    1/22

    PRAM Models

     Advanced Algorithms & Data Structures

    Lecture Theme 13

    Prof. Dr. Th. OttmannSummer Semester 2006

  • 8/18/2019 Thm13 - PRAM Models

    2/22

    2

    • InthePRAM model,processorscommunicatebyreadingfromandwritingtothesharedmemorylocations.

    • The power of a PRAM depends on the kind of access to the shared

    memory locations.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    3/22

    3

    Ineveryclockcycle,• IntheExclusiveReadExclusiveWrite

    (EREW)PRAM,eachmemorylocation

    canbeaccessedonlybyoneprocessor.

    • IntheConcurrentReadExclusiveWrite

    (CREW)PRAM,multipleprocessorcanreadfromthesamememorylocation,but

    onlyoneprocessorcanwrite.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    4/22

    4

    • IntheConcurrentReadConcurrentWrite(CRCW)PRAM,multipleprocessorcan

    readfromorwritetothesamememory

    location.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    5/22

    5

    • Itiseasytoallowconcurrentreading.However,concurrentwritinggivesriseto

    conflicts.

    • Ifmultipleprocessorswritetothesame

    memorylocationsimultaneously,itisnot

    clearwhatiswrittentothememorylocation.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    6/22

    6

    • IntheCommonCRCWPRAM,alltheprocessorsmustwritethesamevalue.

    • Inthe ArbitraryCRCWPRAM,oneofthe

    processorsarbitrarilysucceedsinwriting.

    • InthePriorityCRCWPRAM,processors

    haveprioritiesassociatedwiththemandthehighestpriorityprocessorsucceedsin

    writing.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    7/22

    7

    • TheEREWPRAMistheweakestandthePriorityCRCWPRAMisthestrongest

    PRAMmodel.

    • TherelativepowersofthedifferentPRAM

    modelsareasfollows.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    8/22

    8

    • Analgorithmdesignedforaweakermodelcanbeexecutedwithinthesame

    timeandworkcomplexitiesona

    strongermodel.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    9/22

    9

    • Wesaymodel A islesspowerfulcomparedtomodelB ifeither:

    • thetimecomplexityforsolvinga

    problemisasymptoticallylessinmodel

    B ascomparedtomodel A.or,

    • ifthetimecomplexitiesarethesame,theprocessororworkcomplexityis

    asymptoticallylessinmodelB as

    comparedtomodel A.

    Classification of the PRAM model

  • 8/18/2019 Thm13 - PRAM Models

    10/22

  • 8/18/2019 Thm13 - PRAM Models

    11/22

    11

     Addingn numbersonaPRAM

     Adding n numbers on a PRAM

  • 8/18/2019 Thm13 - PRAM Models

    12/22

    12

    • ThisalgorithmworksontheEREWPRAMmodelastherearenoreadorwrite

    conflicts.

    • Wewillusethisalgorithmtodesigna

    matrixmultiplicationalgorithmonthe

    EREWPRAM.

     Adding n numbers on a PRAM

  • 8/18/2019 Thm13 - PRAM Models

    13/22

    13

    Forsimplicity,weassumethatn =2p  forsomeinteger p.

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    14/22

    14

    • Eachcanbecomputedin

    parallel.

    • Weallocaten processorsforcomputingci,j.

    SupposetheseprocessorsareP1 , P2 ,…,Pn.• Inthefirsttimestep,processor

    computestheproductai,m x bm,j.

    • Wehavenown numbersandweusethe

    additionalgorithmtosumthesen numbers

    inlogn time.

    , , 1 ,i jc i j n≤ ≤

    , 1mP   m n≤ ≤

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    15/22

    15

    • Computingeachtakesn

    processorsandlogn time.

    • Sincetherearen2 suchci,j s,weneed

    overallO (n3

    ) processorsandO (logn) time.• Theprocessorrequirementcanbe

    reducedtoO (n3/logn).Exercise!

    • Hence,theworkcomplexityisO (n3)

    , , 1 ,i jc i j n≤ ≤

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    16/22

    16

    • However,thisalgorithmrequires

    concurrentreadcapability.

    • Notethat,eachelementai,j (andbi,j)

    participatesincomputingn elementsfromtheC matrix.

    • Hencen differentprocessorswilltryto

    readeachai,j (andbi,j)inouralgorithm.

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    17/22

    17

    Forsimplicity,weassumethatn =2p  forsomeinteger p.

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    18/22

    18

    • HenceouralgorithmrunsontheCREW

    PRAM andweneedtoavoidthereadconflictstomakeitrunontheEREW

    PRAM.

    • Wewillcreaten copiesofeachofthe

    elementsai,j (andbi,j).Thenonecopycan

    beusedforcomputingeachci,j .

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    19/22

    19

    Creatingn copiesofanumberinO (logn)

    timeusingO (n) processorsontheEREWPRAM.

    • Inthefirststep,oneprocessorreadsthenumberandcreatesacopy.Hence,there

    aretwocopiesnow.

    • Inthesecondstep,twoprocessorsreadthesetwocopiesandcreatefourcopies.

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    20/22

    20

    • Sincethenumberofcopiesdoublesin

    everystep,n copiesarecreatedinO (logn)steps.

    • Thoughweneedn processors,theprocessorrequirementcanbereducedto

    O(n /logn).

    Exercise!

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    21/22

    21

    • Sincetherearen2 elementsinthematrix A

    (andin B),weneedO(n3 /logn)processorsandO(logn) timetocreaten

    copiesofeachelement.

    • Afterthis,therearenoreadconflictsinour

    algorithm.Theoverallmatrixmultiplication

    algorithmnowtakeO(logn) timeandO(n3 /logn) processorsontheEREW

    PRAM.

    Matrix multiplication

  • 8/18/2019 Thm13 - PRAM Models

    22/22

    22

    • Thememoryrequirementisofcourse

    muchhigherfortheEREWPRAM.

    Matrix multiplication