SlideShare a Scribd company logo
CHAPTER 12 Parallel and Distributed Algorithms
Algorithm 12.1.1 Maximum This algorithm returns the maximum value in array  a [0], ... ,  a [ n  - 1]. The value of  a . length  is the number of elements in the array. Input Parameters:  a Output Parameters: None maximum ( a ) { n  =  a . length current_max  =  a [0] for  i  = 1 to  n  - 1 if ( a [ i ] >  current_max ) current_max  =  a [ i ] return  current_max }
Algorithm 12.2.2 Parallel Search Given an array  a  of size  n  and a number  x , this algorithm searches for  x  in  a  and returns true if there is an  i  such that  a [ i ] =  x  and false otherwise. Input Parameters:  a , x Output Parameters: None parallel_search ( a , x ) { n  =  a . length found  = false for  i  = 0 to  n  - 1 in parallel if ( a [ i ] ==  x ) found  = true return  found }
Algorithm 12.2.4 Locate Given an array  a  and a value  x , the algorithm returns an index  i   such that  a [ i ] =  x  if there is one, and -1 otherwise. Input Parameters:  a , x Output Parameters: None locate ( a , x ) { n  =  a . length location  = -1 found  = false for  i  = 0 to  n  - 1 in parallel if ( a [ i ] ==  x ) location  =  i return  location }
Cache Coherence Problem What value does  a [ i ] contain, after performing this code? n  =  a . length x  = 0 for  i  = 0 to  n  in parallel if ( i  ==  n ) x  = 1 else a [ i ] =  x
Algorithm 12.2.5 ER Broadcast This algorithm takes as input a value  x  and an array  a  and assigns  x  to all elements of the array. Input Parameters:  a , x Output Parameters: None er_broadcast ( a , x ) { n  =   a . length a [0] =  x for  i  = 0 to   lg  n   - 1 for  j  = 0 to 2 i   -  1 in parallel if (2 i  +  j  <  n ) a [2 i  +  j  ] =  a [ j ] }
Algorithm 12.2.11 Sequential   -Sum This algorithm computes  given an array  a  as input. Input Parameters:  a , x Output Parameters: None sequential _  _ sum ( a ) { n  =  a . length current_sum  =  a [0] for  i  = 1 to  n  - 1 current_sum  =  current_sum      a [ i ] return  current_sum }
Algorithm 12.2.12 Parallel   -Sum This EREW algorithm computes  given an array  a  as input. Input Parameters:  a , x Output Parameters: None parallel _  _ sum ( a ) { n  =  a . length for  i  = 0 to   lg  n   - 1 for  j  = 0 to   n /2 i+1    - 1 in parallel if ( j  * 2 i+1  + 2 i  <  n ) a [ j  * 2 i+1  + 2 i ] =  a [ j  * 2 i+1  + 2 i ]     a [ j  * 2 i+1  + 2 i ] return  a [0] }
Algorithm 12.2.16 Optimal   -Sum This algorithm computes  given an array  a  as input.
Input Parameters:  a Output Parameters: None optimal _  _ sum ( a ) { n  =  a . length blocksize  = 2  lg lg  n    // first, compute    sum of all blocks of  // size  blocksize  ≈ lg  n for  i  = 0 to   n / blocksize   in parallel { base  =  i  *  blocksize for  j  = 1 to  blocksize  - 1 if ( base  +  j  <  n ) a [ base ] =  a [ base ]     a [ base  +  j ] } // second, compute the    sum of the remaining  //   n / blocksize   elements for  i  = lg  blocksize  to   lg  n   - 1 for  j  = 0 to   n /2 i+1    - 1 in parallel if ( j  * 2 i+1  + 2 i  <  n ) a [ j  * 2 i+1  + 2 i ] =  a [ j  * 2 i+1  + 2 i ]     a [ j  * 2 i+1  + 2 i ] return  a [0] }
Algorithm 12.2.20 Optimal ER Broadcast This algorithm takes as input a value  x  and an array  a  and assigns  x  to all elements of the array.
Input Parameters:  a , x Output Parameters: None optimal_er_broadcast ( a , x ) { n  =  a . length n  =   n /lg  n  a [0] =  x // Use  er_broadcast to fill the first  n ’ cells of  a  with  x for  i  = 0 to   lg  n ’   - 1 for  j  = 0 to 2 i  - 1 in parallel if (2 i  +  j  <  n ’) a [2 i  + j ] =  a [ j ] // Spread the contents using  n  processors // each performing the sequential algorithm for  i  = 1 to   lg  n  for  j  = 0 to  n ’ - 1 in parallel if ( i  ×  n ’ +  j  <  n ) a [ i  ×  n ’ +  j ] =  a [ j ] }
Algorithm 12.2.25 Sequential Prefix This algorithm computes the prefixes  for all 0  ≤  k  <  n  given an  n -element array  a  as input. Input Parameters:  a Output Parameters: None sequential _ prefix ( a ) { n  =  a . length sum [0]  = a [0] for  i  = 0 to  n  - 1 sum [ i ] =  sum [ i  – 1]     a [ i ] }
Algorithm 12.2.26 Parallel Prefix This algorithm computes the prefixes  for all 0  ≤  k  <  n  given an  n -element array  a  as input. Input Parameters:  a Output Parameters: None parallel _ prefix ( a ) { n  =  a . length for  i  = 0 to  n  - 1 sum [ j ] =  a [ j ] for  i  = 0 to   lg  n  for  j  = 0 to n   - 1 in parallel if ( j  + 2 i  <  n ) sum [ j  + 2 i ] =  sum [ j ]     sum [ j  + 2 i ] }
Algorithm 12.2.31 Sequential List Ranking This algorithm takes as an input the first node  u  of a linked list. Each node has fields  next , the next node of the list or null for the last node in the list, and  rank , which is assigned the distance of the node from the end of the list. Input Parameters:  u Output Parameters: None sequential_list_ranking ( u ) { n  = 0 // counter for total number of nodes node  =  u while ( node  ! = null) { n  =  n  + 1 node  =  node . next } node  =  u  // start again at the beginning while ( node  ! = null) { node . rank  =  n n  =  n  - 1 node  =  node . next } }
Algorithm 12.2.32 List Ranking This algorithm takes as an input the first node  u  of a linked list  L ( u ). Each node has fields  next , the next node of the list or null for the last node in the list, and  rank , which is assigned the distance of the node from the end of the list.
Input Parameters:  u Output Parameters: None list_ranking(u) { for each  node  in  L ( u ) in parallel node . rank  = 1 done  = false do { for each  node  in  L ( u ) in parallel if ( node . next  == null) done  = true else { node . rank  =  node . rank  +  node . next . rank node . next  =  node . next . next } } while (! done ) }
Algorithm 12.4.11 Minimum Label This algorithm takes as input a two-dimensional array  a  with indexes ranging from 0 to  n  + 1. Every element of the array contains fields  color  and  label . The color field of elements in rows and columns with indexes 0 or  n  + 1 is assumed to be zero.  The algorithm computes a component labeling for  a  and stores it in the label  field .
Input Parameters:  a , n Output Parameters: None minimum_label ( a , n ) { // initialize the label field of // every black pixel to a unique value for  i , j     {1, ... ,  n } in parallel if ( a [ i , j ]. color  == 1) a [ i , j ]. label  =  i  ×  n  +  j else   a [ i , j ]. label  = 0 // perform the second step on // every label  n 2  times for  k  = 1 to  n 2 for  i , j     {1, ... ,  n } in parallel for  x  =  i  - 1 to  i  + 1 for  y  =  j  - 1 to  j  + 1 if ( a [ x , y ]. color  == 1)   a [ i , j ]. label  =  min( a [ i , j ]. label ,  a [ x , y ]. label ) }
Algorithm 12.5.2 Ring Broadcast This algorithm is run on a ring network. The initiator runs  init_ring_broadcast , and the noninitiators run  ring_broadcast .  All processors terminate successfully after having received a message from the initiator. init_ring_broadcast () { send  token  to successor receive  token  from predecessor terminate } ring_broadcast () { receive  token  from predecessor send  token  to successor terminate }
Algorithm 12.5.4 Broadcast This algorithm works on any (fixed) connected network. The initiator runs  init_broadcast  and the noninitiators  broadcast . All processors terminate successfully after having received a message from the initiator. In the algorithms we assume that the current machine we are running the code on is called  p . init_broadcast () { N  = { q  |  q  is a neighbor of  p } for each  q      N send  token  to neighbor  q terminate } broadcast () { receive  token  from neighbor  q N  = { q  |  q  is a neighbor of  p } for each  q      N send  token  to neighbor  q terminate }
Algorithm 12.5.5 Echo This algorithm works on any (fixed) connected network. The initiator runs  init_echo  and the noninitiators  echo . All processors terminate successfully after having received a message from the initiator. The initiator terminates after all processors have received its message. The machine on which we are running the code is called  p . init_echo () { N  = { q  |  q  is a neighbor of  p } for each  q      N send  token  to neighbor  q counter  = 0 while ( counter  < | N |) { receive  token counter ++ } terminate }
echo () { receive  token  from neighbor  q parent  =  q N  = { q  |  q  is a neighbor of  p } - { parent } for each  q      N send  token  to neighbor  q counter  = 0 while ( counter  < | N |) { receive  token counter ++ } send token to neighbor parent terminate }
Algorithm 12.5.9 Leader Election This algorithm runs on the unidirectional ring. The initiators run  init_election  and the noninitiators run  election . All processors terminate successfully, and exactly one initiator has its  leader  attribute set to true. In the algorithms, we assume that the current machine we are running the code on is called  p . Every processor has a next neighbor,  p . next , to which it can send messages.
init_election() { send     token , p . ID    to  p . next min  =  p . ID receive     token , I      while ( p . ID  !=  I ) { if ( I  <  min ) min  =  I send     token , I     to  p . next receive     token , I      } if ( p . ID  ==  min ) p . leader  = true else p . leader  = false terminate } election () { p . leader  = false // noninitiator is never chosen as leader do { receive     token , I      send     token , I     to  p . next } while (true) }

More Related Content

What's hot

algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
Monika Choudhery
 
Algorithm Design and Complexity - Course 5
Algorithm Design and Complexity - Course 5Algorithm Design and Complexity - Course 5
Algorithm Design and Complexity - Course 5
Traian Rebedea
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Melaku Bayih Demessie
 
Alg1
Alg1Alg1
Chapter 3 Arrays in Java
Chapter 3 Arrays in JavaChapter 3 Arrays in Java
Chapter 3 Arrays in Java
Khirulnizam Abd Rahman
 
Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE students
UR11EC098
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
luzenith_g
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2
bilawalali74
 
Linear Convolution using Matlab Code
Linear Convolution  using Matlab CodeLinear Convolution  using Matlab Code
Linear Convolution using Matlab Code
Bharti Airtel Ltd.
 
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
Frank Nielsen
 
DFT and IDFT Matlab Code
DFT and IDFT Matlab CodeDFT and IDFT Matlab Code
DFT and IDFT Matlab Code
Bharti Airtel Ltd.
 
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingAlgorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Traian Rebedea
 
Chapter 4 - Classes in Java
Chapter 4 - Classes in JavaChapter 4 - Classes in Java
Chapter 4 - Classes in Java
Khirulnizam Abd Rahman
 
Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
Matlab Assignment Experts
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
Matlab Assignment Experts
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
Knoldus Inc.
 
DCDR
DCDRDCDR
بررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارش
بررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارشبررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارش
بررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارش
پروژه مارکت
 
Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2
Traian Rebedea
 

What's hot (19)

algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Algorithm Design and Complexity - Course 5
Algorithm Design and Complexity - Course 5Algorithm Design and Complexity - Course 5
Algorithm Design and Complexity - Course 5
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Alg1
Alg1Alg1
Alg1
 
Chapter 3 Arrays in Java
Chapter 3 Arrays in JavaChapter 3 Arrays in Java
Chapter 3 Arrays in Java
 
Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE students
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2
 
Linear Convolution using Matlab Code
Linear Convolution  using Matlab CodeLinear Convolution  using Matlab Code
Linear Convolution using Matlab Code
 
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
 
DFT and IDFT Matlab Code
DFT and IDFT Matlab CodeDFT and IDFT Matlab Code
DFT and IDFT Matlab Code
 
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingAlgorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
 
Chapter 4 - Classes in Java
Chapter 4 - Classes in JavaChapter 4 - Classes in Java
Chapter 4 - Classes in Java
 
Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
Extractors & Implicit conversions
Extractors & Implicit conversionsExtractors & Implicit conversions
Extractors & Implicit conversions
 
DCDR
DCDRDCDR
DCDR
 
بررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارش
بررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارشبررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارش
بررسی دو روش شناسایی سیستم های متغیر با زمان به همراه شبیه سازی و گزارش
 
Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2
 

Viewers also liked

Hybrid worlds - Fungi Progression - crews
Hybrid worlds -  Fungi Progression - crewsHybrid worlds -  Fungi Progression - crews
Hybrid worlds - Fungi Progression - crews
rv media
 
Chap02alg
Chap02algChap02alg
Chap02alg
Munhchimeg
 
Disco Dirt Evaluation
Disco Dirt EvaluationDisco Dirt Evaluation
Disco Dirt Evaluation
hanmat
 
Presentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen InkoopbeleidPresentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen Inkoopbeleid
Johan Stuiver
 
Haiti Slide Show1
Haiti Slide Show1Haiti Slide Show1
Haiti Slide Show1
rahmda
 
Don't Screw Up Your Licensing
Don't Screw Up Your LicensingDon't Screw Up Your Licensing
Don't Screw Up Your Licensing
Ansel Halliburton
 
Hybrid worlds fungi final - crews
Hybrid worlds   fungi final - crewsHybrid worlds   fungi final - crews
Hybrid worlds fungi final - crews
rv media
 
データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』
shinya Jingushi
 
GTS Website
GTS WebsiteGTS Website
GTS Website
Chuckcoe
 
Alliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame ProjectenAlliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame ProjectenJohan Stuiver
 
TLF Reunion 2011
TLF Reunion 2011TLF Reunion 2011
TLF Reunion 2011
Debbie Horres
 
Nings To Knols Upload
Nings To Knols UploadNings To Knols Upload
Nings To Knols Upload
guesta3ed78
 

Viewers also liked (20)

Lecture916
Lecture916Lecture916
Lecture916
 
Hybrid worlds - Fungi Progression - crews
Hybrid worlds -  Fungi Progression - crewsHybrid worlds -  Fungi Progression - crews
Hybrid worlds - Fungi Progression - crews
 
Chap02alg
Chap02algChap02alg
Chap02alg
 
Disco Dirt Evaluation
Disco Dirt EvaluationDisco Dirt Evaluation
Disco Dirt Evaluation
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Presentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen InkoopbeleidPresentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen Inkoopbeleid
 
Haiti Slide Show1
Haiti Slide Show1Haiti Slide Show1
Haiti Slide Show1
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture915
Lecture915Lecture915
Lecture915
 
Lecture7
Lecture7Lecture7
Lecture7
 
Don't Screw Up Your Licensing
Don't Screw Up Your LicensingDon't Screw Up Your Licensing
Don't Screw Up Your Licensing
 
Hybrid worlds fungi final - crews
Hybrid worlds   fungi final - crewsHybrid worlds   fungi final - crews
Hybrid worlds fungi final - crews
 
データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』
 
Lecture3
Lecture3Lecture3
Lecture3
 
GTS Website
GTS WebsiteGTS Website
GTS Website
 
Alliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame ProjectenAlliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame Projecten
 
TLF Reunion 2011
TLF Reunion 2011TLF Reunion 2011
TLF Reunion 2011
 
Nings To Knols Upload
Nings To Knols UploadNings To Knols Upload
Nings To Knols Upload
 
Lecture913
Lecture913Lecture913
Lecture913
 
Lecture910
Lecture910Lecture910
Lecture910
 

Similar to Chap12alg

Chap08alg
Chap08algChap08alg
Chap08alg
Munhchimeg
 
Chap07alg
Chap07algChap07alg
Chap07alg
Munhchimeg
 
Chap07alg
Chap07algChap07alg
Chap07alg
Munkhchimeg
 
Chap05alg
Chap05algChap05alg
Chap05alg
Munhchimeg
 
Chap05alg
Chap05algChap05alg
Chap05alg
Munkhchimeg
 
Ada notes
Ada notesAda notes
Chap06alg
Chap06algChap06alg
Chap06alg
Munkhchimeg
 
Chap06alg
Chap06algChap06alg
Chap06alg
Munhchimeg
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
appasami
 
Lect-2.pptx
Lect-2.pptxLect-2.pptx
Lect-2.pptx
mrizwan38
 
Chap03alg
Chap03algChap03alg
Chap03alg
Munkhchimeg
 
Chap03alg
Chap03algChap03alg
Chap03alg
Munhchimeg
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
SajalFayyaz
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
KokilaK25
 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdf
Sheba41
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
Omprakash Chauhan
 
21-algorithms.ppt
21-algorithms.ppt21-algorithms.ppt
cgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdfcgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdf
meenasp
 
21-algorithms (1).ppt
21-algorithms (1).ppt21-algorithms (1).ppt
21-algorithms (1).ppt
DaniloMislosAlbay
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
Drishti Bhalla
 

Similar to Chap12alg (20)

Chap08alg
Chap08algChap08alg
Chap08alg
 
Chap07alg
Chap07algChap07alg
Chap07alg
 
Chap07alg
Chap07algChap07alg
Chap07alg
 
Chap05alg
Chap05algChap05alg
Chap05alg
 
Chap05alg
Chap05algChap05alg
Chap05alg
 
Ada notes
Ada notesAda notes
Ada notes
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Lect-2.pptx
Lect-2.pptxLect-2.pptx
Lect-2.pptx
 
Chap03alg
Chap03algChap03alg
Chap03alg
 
Chap03alg
Chap03algChap03alg
Chap03alg
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Advanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdfAdvanced Datastructures and algorithms CP4151unit1b.pdf
Advanced Datastructures and algorithms CP4151unit1b.pdf
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
21-algorithms.ppt
21-algorithms.ppt21-algorithms.ppt
21-algorithms.ppt
 
cgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdfcgrchapter2version-1-200729063505 (1).pdf
cgrchapter2version-1-200729063505 (1).pdf
 
21-algorithms (1).ppt
21-algorithms (1).ppt21-algorithms (1).ppt
21-algorithms (1).ppt
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 

More from Munhchimeg (20)

Ded algorithm1
Ded algorithm1Ded algorithm1
Ded algorithm1
 
Ded algorithm
Ded algorithmDed algorithm
Ded algorithm
 
Tobch lecture1
Tobch lecture1Tobch lecture1
Tobch lecture1
 
Tobch lecture
Tobch lectureTobch lecture
Tobch lecture
 
Recursive
RecursiveRecursive
Recursive
 
Lecture916
Lecture916Lecture916
Lecture916
 
Lecture915
Lecture915Lecture915
Lecture915
 
Lecture914
Lecture914Lecture914
Lecture914
 
Lecture912
Lecture912Lecture912
Lecture912
 
Lecture911
Lecture911Lecture911
Lecture911
 
Lecture910
Lecture910Lecture910
Lecture910
 
Lecture9
Lecture9Lecture9
Lecture9
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture5
Lecture5Lecture5
Lecture5
 
Lecture4
Lecture4Lecture4
Lecture4
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Pm104 standard
Pm104 standardPm104 standard
Pm104 standard
 
Pm104 2004 2005
Pm104 2004 2005Pm104 2004 2005
Pm104 2004 2005
 
Lecture914
Lecture914Lecture914
Lecture914
 

Recently uploaded

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 

Recently uploaded (20)

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 

Chap12alg

  • 1. CHAPTER 12 Parallel and Distributed Algorithms
  • 2. Algorithm 12.1.1 Maximum This algorithm returns the maximum value in array a [0], ... , a [ n - 1]. The value of a . length is the number of elements in the array. Input Parameters: a Output Parameters: None maximum ( a ) { n = a . length current_max = a [0] for i = 1 to n - 1 if ( a [ i ] > current_max ) current_max = a [ i ] return current_max }
  • 3. Algorithm 12.2.2 Parallel Search Given an array a of size n and a number x , this algorithm searches for x in a and returns true if there is an i such that a [ i ] = x and false otherwise. Input Parameters: a , x Output Parameters: None parallel_search ( a , x ) { n = a . length found = false for i = 0 to n - 1 in parallel if ( a [ i ] == x ) found = true return found }
  • 4. Algorithm 12.2.4 Locate Given an array a and a value x , the algorithm returns an index i such that a [ i ] = x if there is one, and -1 otherwise. Input Parameters: a , x Output Parameters: None locate ( a , x ) { n = a . length location = -1 found = false for i = 0 to n - 1 in parallel if ( a [ i ] == x ) location = i return location }
  • 5. Cache Coherence Problem What value does a [ i ] contain, after performing this code? n = a . length x = 0 for i = 0 to n in parallel if ( i == n ) x = 1 else a [ i ] = x
  • 6. Algorithm 12.2.5 ER Broadcast This algorithm takes as input a value x and an array a and assigns x to all elements of the array. Input Parameters: a , x Output Parameters: None er_broadcast ( a , x ) { n = a . length a [0] = x for i = 0 to  lg n  - 1 for j = 0 to 2 i - 1 in parallel if (2 i + j < n ) a [2 i + j ] = a [ j ] }
  • 7. Algorithm 12.2.11 Sequential  -Sum This algorithm computes given an array a as input. Input Parameters: a , x Output Parameters: None sequential _  _ sum ( a ) { n = a . length current_sum = a [0] for i = 1 to n - 1 current_sum = current_sum  a [ i ] return current_sum }
  • 8. Algorithm 12.2.12 Parallel  -Sum This EREW algorithm computes given an array a as input. Input Parameters: a , x Output Parameters: None parallel _  _ sum ( a ) { n = a . length for i = 0 to  lg n  - 1 for j = 0 to  n /2 i+1  - 1 in parallel if ( j * 2 i+1 + 2 i < n ) a [ j * 2 i+1 + 2 i ] = a [ j * 2 i+1 + 2 i ]  a [ j * 2 i+1 + 2 i ] return a [0] }
  • 9. Algorithm 12.2.16 Optimal  -Sum This algorithm computes given an array a as input.
  • 10. Input Parameters: a Output Parameters: None optimal _  _ sum ( a ) { n = a . length blocksize = 2  lg lg n  // first, compute  sum of all blocks of // size blocksize ≈ lg n for i = 0 to  n / blocksize  in parallel { base = i * blocksize for j = 1 to blocksize - 1 if ( base + j < n ) a [ base ] = a [ base ]  a [ base + j ] } // second, compute the  sum of the remaining //  n / blocksize  elements for i = lg blocksize to  lg n  - 1 for j = 0 to  n /2 i+1  - 1 in parallel if ( j * 2 i+1 + 2 i < n ) a [ j * 2 i+1 + 2 i ] = a [ j * 2 i+1 + 2 i ]  a [ j * 2 i+1 + 2 i ] return a [0] }
  • 11. Algorithm 12.2.20 Optimal ER Broadcast This algorithm takes as input a value x and an array a and assigns x to all elements of the array.
  • 12. Input Parameters: a , x Output Parameters: None optimal_er_broadcast ( a , x ) { n = a . length n =  n /lg n  a [0] = x // Use er_broadcast to fill the first n ’ cells of a with x for i = 0 to  lg n ’  - 1 for j = 0 to 2 i - 1 in parallel if (2 i + j < n ’) a [2 i + j ] = a [ j ] // Spread the contents using n processors // each performing the sequential algorithm for i = 1 to  lg n  for j = 0 to n ’ - 1 in parallel if ( i × n ’ + j < n ) a [ i × n ’ + j ] = a [ j ] }
  • 13. Algorithm 12.2.25 Sequential Prefix This algorithm computes the prefixes for all 0 ≤ k < n given an n -element array a as input. Input Parameters: a Output Parameters: None sequential _ prefix ( a ) { n = a . length sum [0] = a [0] for i = 0 to n - 1 sum [ i ] = sum [ i – 1]  a [ i ] }
  • 14. Algorithm 12.2.26 Parallel Prefix This algorithm computes the prefixes for all 0 ≤ k < n given an n -element array a as input. Input Parameters: a Output Parameters: None parallel _ prefix ( a ) { n = a . length for i = 0 to n - 1 sum [ j ] = a [ j ] for i = 0 to  lg n  for j = 0 to n - 1 in parallel if ( j + 2 i < n ) sum [ j + 2 i ] = sum [ j ]  sum [ j + 2 i ] }
  • 15. Algorithm 12.2.31 Sequential List Ranking This algorithm takes as an input the first node u of a linked list. Each node has fields next , the next node of the list or null for the last node in the list, and rank , which is assigned the distance of the node from the end of the list. Input Parameters: u Output Parameters: None sequential_list_ranking ( u ) { n = 0 // counter for total number of nodes node = u while ( node ! = null) { n = n + 1 node = node . next } node = u // start again at the beginning while ( node ! = null) { node . rank = n n = n - 1 node = node . next } }
  • 16. Algorithm 12.2.32 List Ranking This algorithm takes as an input the first node u of a linked list L ( u ). Each node has fields next , the next node of the list or null for the last node in the list, and rank , which is assigned the distance of the node from the end of the list.
  • 17. Input Parameters: u Output Parameters: None list_ranking(u) { for each node in L ( u ) in parallel node . rank = 1 done = false do { for each node in L ( u ) in parallel if ( node . next == null) done = true else { node . rank = node . rank + node . next . rank node . next = node . next . next } } while (! done ) }
  • 18. Algorithm 12.4.11 Minimum Label This algorithm takes as input a two-dimensional array a with indexes ranging from 0 to n + 1. Every element of the array contains fields color and label . The color field of elements in rows and columns with indexes 0 or n + 1 is assumed to be zero. The algorithm computes a component labeling for a and stores it in the label field .
  • 19. Input Parameters: a , n Output Parameters: None minimum_label ( a , n ) { // initialize the label field of // every black pixel to a unique value for i , j  {1, ... , n } in parallel if ( a [ i , j ]. color == 1) a [ i , j ]. label = i × n + j else a [ i , j ]. label = 0 // perform the second step on // every label n 2 times for k = 1 to n 2 for i , j  {1, ... , n } in parallel for x = i - 1 to i + 1 for y = j - 1 to j + 1 if ( a [ x , y ]. color == 1) a [ i , j ]. label = min( a [ i , j ]. label , a [ x , y ]. label ) }
  • 20. Algorithm 12.5.2 Ring Broadcast This algorithm is run on a ring network. The initiator runs init_ring_broadcast , and the noninitiators run ring_broadcast . All processors terminate successfully after having received a message from the initiator. init_ring_broadcast () { send token to successor receive token from predecessor terminate } ring_broadcast () { receive token from predecessor send token to successor terminate }
  • 21. Algorithm 12.5.4 Broadcast This algorithm works on any (fixed) connected network. The initiator runs init_broadcast and the noninitiators broadcast . All processors terminate successfully after having received a message from the initiator. In the algorithms we assume that the current machine we are running the code on is called p . init_broadcast () { N = { q | q is a neighbor of p } for each q  N send token to neighbor q terminate } broadcast () { receive token from neighbor q N = { q | q is a neighbor of p } for each q  N send token to neighbor q terminate }
  • 22. Algorithm 12.5.5 Echo This algorithm works on any (fixed) connected network. The initiator runs init_echo and the noninitiators echo . All processors terminate successfully after having received a message from the initiator. The initiator terminates after all processors have received its message. The machine on which we are running the code is called p . init_echo () { N = { q | q is a neighbor of p } for each q  N send token to neighbor q counter = 0 while ( counter < | N |) { receive token counter ++ } terminate }
  • 23. echo () { receive token from neighbor q parent = q N = { q | q is a neighbor of p } - { parent } for each q  N send token to neighbor q counter = 0 while ( counter < | N |) { receive token counter ++ } send token to neighbor parent terminate }
  • 24. Algorithm 12.5.9 Leader Election This algorithm runs on the unidirectional ring. The initiators run init_election and the noninitiators run election . All processors terminate successfully, and exactly one initiator has its leader attribute set to true. In the algorithms, we assume that the current machine we are running the code on is called p . Every processor has a next neighbor, p . next , to which it can send messages.
  • 25. init_election() { send  token , p . ID  to p . next min = p . ID receive  token , I  while ( p . ID != I ) { if ( I < min ) min = I send  token , I  to p . next receive  token , I  } if ( p . ID == min ) p . leader = true else p . leader = false terminate } election () { p . leader = false // noninitiator is never chosen as leader do { receive  token , I  send  token , I  to p . next } while (true) }