







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Three methods for parallel sorting: unlimited parallelism using bubble sort, fixed parallelism with counting sort, and scalable parallelism through batcher’s bitonic sort. Each approach is detailed, including code snippets and explanations.
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Three solutions to sorting in parallel:• Unlimited parallelism — similar to bubble sort• Fixed parallelism — 26 threads, one per letter• Scalable parallelism — Batcher’s Bitonic Sort
Cat
Art
Eel
Bus
Fun
Cat
Dog
Art
Eel
Bus
Fun
Cat
Art
Dog
Bus
Eel
Fun
Art
Cat
Bus
Dog
Eel
Fun
Art
Bus
Cat
Dog
Eel
Fun
void
swap_pairs(int start) {
forall(i
in(start...n
stride
by
{ rec
temp; bool
done
= true;
if
(strcmp(L
[i].x, L
[i+1].x)
temp
L[i];
L[i]
L[i+1];
L[i+1]
= temp; done
false;
} if
(!start) continue
= !(&&/done);
Cog
Cat
Art
Cel
Bus
Bun
counts['C']++counts['C']++
counts['A']++counts['C']++
counts['B']++counts['B']++
counts['A']
Art
counts['B'] Bus
Bun
counts['C'] Cog
Cat
Cel
Art
Bun
Bus
Cat
Cel
Cog
Art
Bun
Bus
Cat
Cel
Cog
rec[]
localSort(int index, int
myCount)
rec
temp[] = new rec[myCount]; int
j^
for
(int i = 0; i < n
; i++)
if^
(letRank(L
[i].x[0])
index)
temp[j++] = L
[i];
alphabetizeInPlace(temp, myCount);return
temp;
rec L
[n]; int t
int m
log2(t
int size
n^
t;
typedef
struct
{ char x[MAXLEN];
int
home;
key;
key BufK
[m
][size
bool free'[m
= false, ready'[m
Assume
L^ localized into equal contiguous segments
Assume
BufK
localized by first index
forall
(index
in(0..t
-1))
{
rec
myL[size
]^ = localize(L
),^
inputCopy[size
];
key
Kn[][]
=^
localize(BufK
),^
K[size
];
for
(int
i^
=^ 0;
i^
<^ size
;^ i++)
{
K[i].x
=^
myL[i].x;
K[i].home
=^
localToGobal(myL,
i,
0);
} alphabetizeInPlace(K,
size
,^ bit(index,
/*
up
or
down
*/);
....
/*
main
loop
*/
for
(int
i^
=^ 0;
i^
<^ size
;^ i++)
inputCopy[i]
=^
L[K[i].home];
barrier;for
(int
i^
=^ 0; i
<^
size
;^ i++)
myL[i]
=^
inputCopy[i];
}
void merge(int index, int d, int p, key
Kn[][],
key
K[])
{ for (int i = 0;
i < size
; i++) {
bool want;int cmp;cmp = strcmp(Kn[index][i].x, K[i].x);if (bit(index, d) == bit(index, p))want = (cmp
0);
elsewant = (cmp
< 0);
if (want)K[i] = Kn[i];} }^