<s>
Samplesort	B-Operating_System
is	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
that	O
is	O
a	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
algorithm	I-Algorithm
often	O
used	O
in	O
parallel	O
processing	O
systems	O
.	O
</s>
<s>
Conventional	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
sorting	B-Algorithm
algorithms	I-Algorithm
partitions	O
the	O
array	O
into	O
sub-intervals	O
or	O
buckets	O
.	O
</s>
<s>
However	O
,	O
if	O
the	O
array	O
is	O
non-uniformly	O
distributed	O
,	O
the	O
performance	O
of	O
these	O
sorting	B-Algorithm
algorithms	I-Algorithm
can	O
be	O
significantly	O
throttled	O
.	O
</s>
<s>
Samplesort	B-Operating_System
addresses	O
this	O
issue	O
by	O
selecting	O
a	O
sample	O
of	O
size	O
from	O
the	O
-element	O
sequence	O
,	O
and	O
determining	O
the	O
range	O
of	O
the	O
buckets	O
by	O
sorting	B-Algorithm
the	O
sample	O
and	O
choosing	O
elements	O
from	O
the	O
result	O
.	O
</s>
<s>
Samplesort	B-Operating_System
is	O
described	O
in	O
the	O
1970	O
paper	O
,	O
"	O
Samplesort	B-Operating_System
:	O
A	O
Sampling	O
Approach	O
to	O
Minimal	O
Storage	O
Tree	O
Sorting	B-Algorithm
"	O
,	O
by	O
W	O
.	O
D	O
.	O
Frazer	O
and	O
A	O
.	O
C	O
.	O
McKellar	O
.	O
</s>
<s>
Samplesort	B-Operating_System
is	O
a	O
generalization	O
of	O
quicksort	B-Algorithm
.	O
</s>
<s>
Where	O
quicksort	B-Algorithm
partitions	O
its	O
input	O
into	O
two	O
parts	O
at	O
each	O
step	O
,	O
based	O
on	O
a	O
single	O
value	O
called	O
the	O
pivot	O
,	O
samplesort	B-Operating_System
instead	O
takes	O
a	O
larger	O
sample	O
from	O
its	O
input	O
and	O
divides	O
its	O
data	O
into	O
buckets	O
accordingly	O
.	O
</s>
<s>
Like	O
quicksort	B-Algorithm
,	O
it	O
then	O
recursively	O
sorts	O
the	O
buckets	O
.	O
</s>
<s>
To	O
devise	O
a	O
samplesort	B-Operating_System
implementation	O
,	O
one	O
needs	O
to	O
decide	O
on	O
the	O
number	O
of	O
buckets	O
.	O
</s>
<s>
(	O
This	O
may	O
mean	O
:	O
send	O
it	O
to	O
a	O
processor	O
,	O
in	O
a	O
multiprocessor	B-Operating_System
system	O
.	O
)	O
</s>
<s>
The	O
data	O
is	O
then	O
distributed	O
among	O
the	O
processors	O
,	O
which	O
perform	O
the	O
sorting	B-Algorithm
of	O
buckets	O
using	O
some	O
other	O
,	O
sequential	O
,	O
sorting	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
In	O
the	O
pseudo	O
code	O
,	O
samplesort	B-Operating_System
is	O
called	O
recursively	O
.	O
</s>
<s>
Frazer	O
and	O
McKellar	O
called	O
samplesort	B-Operating_System
just	O
once	O
and	O
used	O
quicksort	B-Algorithm
in	O
all	O
following	O
iterations	O
.	O
</s>
<s>
where	O
is	O
the	O
complexity	O
of	O
the	O
underlying	O
sequential	O
sorting	B-Algorithm
method	O
.	O
</s>
<s>
In	O
experiments	O
,	O
conducted	O
by	O
Frazer	O
and	O
McKellar	O
,	O
the	O
algorithm	O
needed	O
15%	O
fewer	O
comparisons	O
than	O
quicksort	B-Algorithm
.	O
</s>
<s>
Samplesort	B-Operating_System
is	O
often	O
used	O
in	O
parallel	O
systems	O
,	O
including	O
distributed	B-Architecture
systems	I-Architecture
such	O
as	O
bulk	B-Application
synchronous	I-Application
parallel	I-Application
machines	O
.	O
</s>
<s>
Due	O
to	O
the	O
variable	O
amount	O
of	O
splitters	O
(	O
in	O
contrast	O
to	O
only	O
one	O
pivot	O
in	O
Quicksort	B-Algorithm
)	O
,	O
Samplesort	B-Operating_System
is	O
very	O
well	O
suited	O
and	O
intuitive	O
for	O
parallelization	O
and	O
scaling	O
.	O
</s>
<s>
Furthermore	O
Samplesort	B-Operating_System
is	O
also	O
more	O
cache-efficient	O
than	O
implementations	O
of	O
e.g.	O
</s>
<s>
quicksort	B-Algorithm
.	O
</s>
<s>
Parallelization	O
is	O
implemented	O
by	O
splitting	O
the	O
sorting	B-Algorithm
for	O
each	O
processor	O
or	O
node	O
,	O
where	O
the	O
number	O
of	O
buckets	O
is	O
equal	O
to	O
the	O
number	O
of	O
processors	O
.	O
</s>
<s>
Samplesort	B-Operating_System
is	O
efficient	O
in	O
parallel	O
systems	O
because	O
each	O
processor	O
receives	O
approximately	O
the	O
same	O
bucket	O
size	O
.	O
</s>
<s>
Since	O
the	O
buckets	O
are	O
sorted	O
concurrently	O
,	O
the	O
processors	O
will	O
complete	O
the	O
sorting	B-Algorithm
at	O
approximately	O
the	O
same	O
time	O
,	O
thus	O
not	O
having	O
a	O
processor	O
wait	O
for	O
others	O
.	O
</s>
<s>
On	O
distributed	B-Architecture
systems	I-Architecture
,	O
the	O
splitters	O
are	O
chosen	O
by	O
taking	O
elements	O
on	O
each	O
processor	O
,	O
sorting	B-Algorithm
the	O
resulting	O
elements	O
with	O
a	O
distributed	O
sorting	B-Algorithm
algorithm	I-Algorithm
,	O
taking	O
every	O
-th	O
element	O
and	O
broadcasting	O
the	O
result	O
to	O
all	O
processors	O
.	O
</s>
<s>
This	O
costs	O
for	O
sorting	B-Algorithm
the	O
elements	O
on	O
processors	O
,	O
as	O
well	O
as	O
for	O
distributing	O
the	O
chosen	O
splitters	O
to	O
processors	O
.	O
</s>
<s>
The	O
local	O
sorting	B-Algorithm
takes	O
.	O
</s>
<s>
Experiments	O
performed	O
in	O
the	O
early	O
1990s	O
on	O
Connection	B-Device
Machine	I-Device
supercomputers	O
showed	O
samplesort	B-Operating_System
to	O
be	O
particularly	O
good	O
at	O
sorting	B-Algorithm
large	O
datasets	O
on	O
these	O
machines	O
,	O
because	O
its	O
incurs	O
little	O
interprocessor	O
communication	O
overhead	O
.	O
</s>
<s>
On	O
latter-day	O
GPUs	B-Architecture
,	O
the	O
algorithm	O
may	O
be	O
less	O
effective	O
than	O
its	O
alternatives	O
.	O
</s>
<s>
As	O
described	O
above	O
,	O
the	O
samplesort	B-Operating_System
algorithm	O
splits	O
the	O
elements	O
according	O
to	O
the	O
selected	O
splitters	O
.	O
</s>
<s>
An	O
efficient	O
implementation	O
strategy	O
is	O
proposed	O
in	O
the	O
paper	O
"	O
Super	O
Scalar	O
Sample	B-Operating_System
Sort	I-Operating_System
"	O
.	O
</s>
<s>
In	O
a	O
comparison	O
based	O
sorting	B-Algorithm
algorithm	I-Algorithm
the	O
comparison	O
operation	O
is	O
the	O
most	O
performance	O
critical	O
part	O
.	O
</s>
<s>
In	O
Samplesort	B-Operating_System
this	O
corresponds	O
to	O
determining	O
the	O
bucket	O
for	O
each	O
element	O
.	O
</s>
<s>
Super	O
Scalar	O
Sample	B-Operating_System
Sort	I-Operating_System
uses	O
a	O
balanced	O
search	O
tree	O
which	O
is	O
implicitly	O
stored	O
in	O
an	O
array	O
.	O
</s>
<s>
Since	O
the	O
number	O
of	O
buckets	O
is	O
known	O
at	O
compile	O
time	O
,	O
this	O
loop	O
can	O
be	O
unrolled	B-Operating_System
by	O
the	O
compiler	O
.	O
</s>
<s>
The	O
comparison	O
operation	O
is	O
implemented	O
with	O
predicated	B-General_Concept
instructions	I-General_Concept
.	O
</s>
<s>
Thus	O
,	O
there	O
occur	O
no	O
branch	B-General_Concept
mispredictions	I-General_Concept
,	O
which	O
would	O
slow	O
down	O
the	O
comparison	O
operation	O
significantly	O
.	O
</s>
<s>
To	O
avoid	O
this	O
doubling	O
of	O
comparisons	O
,	O
Super	O
Scalar	O
Sample	B-Operating_System
Sort	I-Operating_System
uses	O
an	O
additional	O
array	O
(	O
called	O
oracle	O
)	O
which	O
assigns	O
each	O
index	O
of	O
the	O
elements	O
to	O
a	O
bucket	O
.	O
</s>
<s>
A	O
key	O
disadvantage	O
of	O
the	O
efficient	O
Samplesort	B-Operating_System
implementation	O
shown	O
above	O
is	O
that	O
it	O
is	O
not	O
in-place	O
and	O
requires	O
a	O
second	O
temporary	O
array	O
of	O
the	O
same	O
size	O
as	O
the	O
input	O
sequence	O
during	O
sorting	B-Algorithm
.	O
</s>
<s>
quicksort	B-Algorithm
are	O
in-place	O
and	O
thus	O
more	O
space	O
efficient	O
.	O
</s>
<s>
However	O
,	O
Samplesort	B-Operating_System
can	O
be	O
implemented	O
in-place	O
as	O
well	O
.	O
</s>
