3.parallel Processing - Algorithms
3.parallel Processing - Algorithms
PROCESSING/PROGRAMMING
CATALIN BOJA
[email protected]
BUCHAREST UNIVERSITY OF ECONOMIC STUDIES
SORTING ALGORITHMS FOR PARALLEL
PROCESSING
• Bubble Sort
• Optimized Bubble Sort Algorithm
• Odd-Even Sort
• Merge sort
• Bitonic Sort
BUBBLE SORT
do {
int new_n = 0;
• Reduces the number of iterations as
for(int i = 1; i < n; i++) n is moved closer to the beginning of
if(v[i-1] > v[i])
the array (as the rest of the array is
{
swap(&v[i-1],&v[i]); already sorted)
new_n = i;
} • Each iteration is still dependent on
n = new_n; 2 array values (i and i-1)
} while(n > 0);
• The dependencies are still there
ODD-EVEN SORT
}
}
• There are N iterations in the outer loop, and
each inner loop consists of a full pass through
the array, requiring O(N) operations.
ODD-EVEN SORT ALGORITHM – SOLUTION 2
Divide phase
Merge phase
https://en.wikipedia.org/wiki/Merge_sort
MERGESORT
From http://web.mst.edu/~ercal/387/slides/SLIDES-10-sorting.ppt
BITONIC MERGESORT
This is ok!
1 Local MAX; 1 Local MIN
The list is bitonic!
From http://web.mst.edu/~ercal/387/slides/SLIDES-10-sorting.ppt
BITONIC MERGESORT
• The algorithm involves multiple steps in which you take the N input array and
create a Bitonic sequence; you star with small sequences (2, 4, 8, …) until you
get to the final sequence of N values
• After you obtain the Bitonic search you rearrange the values by comparing
them with their correspondent in the other half. You start with initial N/2 halfs
and you move down until you get to 2 elements sequences
BITONIC MERGESORT
Phase I Phase II
https://www.geeksforgeeks.org/bitonic-sort/
BITONIC MERGESORT
18
SEARCHING ALGORITHMS
if (j == m)
count++;
}
return count;
}
BOYER–MOORE STRING-SEARCH ALGORITHM
• Uses the same principle as Boyer–Moore: increases the shift step when it’s
clear that the pattern is not present
• Complexity of O(n+m) because requires the build of the table algorithm for
the given pattern
• https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_
algorithm
• https://people.ok.ubc.ca/ylucet/DS/KnuthMorrisPratt.html
GAME OF LIFE
• Life is an example of a cellular automaton - any system in which rules are applied to
cells and their neighbors in a regular grid
• Invented by the mathematician John Conway in 1970
(https://www.youtube.com/watch?v=E8kUJL04ELA)
• The rules are not arbitrary chosen. They provide a balance -> it’s hard to tell
whether a pattern will die out completely, form a stable population, or grow forever
• is a zero-player game, meaning that its evolution is determined by its initial state,
requiring no further input
GAME OF LIFE
• The rules are applied simultaneously to every cell in the seed; “births and deaths occur
simultaneously, and the discrete moment at which this happens is sometimes called a tick“,
https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
GAME OF LIFE
• Used 2000 in the Google Toolbar for Internet Explorer in order to show the
PageRank (logarithmic value) of the current Web page
• Generated a link spam frenzy
• Removed from Firefox in 2011 and in 2013 received the last update; in 2016
Google officially removed support for Toolbar Pagerank
GOOGLE PAGERANK
• If your page has a PageRank of 20, and there are 4.285.199.774 pages
indexed by Google, it follows that the odds that a "random surfer" is reading
your page right now are 20/4.285.199.77
https://searchengineland.com/rip-google-pagerank-retrospective-244286
GOOGLE PAGERANK
• We assume page A has pages T1…Tn which point to it (i.e., are citations). The
parameter d is a damping factor which can be set between 0 and 1. We usually set d to
0.85. There are more details about d in the next section. Also C(A) is defined as the
number of links going out of page A. The PageRank of a page A is given as follows:
PR(A) = (1‐d) + d (PR(T1)/C(T1) + … + PR(Tn)/C(Tn))
• Note that the PageRanks form a probability distribution over web pages, so the sum of
all web pages’ PageRanks will be one.
http://infolab.stanford.edu/~backrub/google.html
GOOGLE PAGERANK
• The PageRank (PR) is actually a probability that the user will eventually visit that
page
• All web pages PRs sum will be equal to 1
• A page PR is given by
• Number and quality of inbound links
• Number of outbound links
• The PR of each linking page
• The probability to randomly hit the page by a user (who just clicks links) – damping factor,
usually 0.85
GOOGLE PAGERANK