<s>
The	O
breadth-first-search	B-Algorithm
algorithm	I-Algorithm
is	O
a	O
way	O
to	O
explore	O
the	O
vertices	O
of	O
a	O
graph	O
layer	O
by	O
layer	O
.	O
</s>
<s>
For	O
instance	O
,	O
BFS	O
is	O
used	O
by	O
Dinic	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
to	O
find	O
maximum	O
flow	O
in	O
a	O
graph	O
.	O
</s>
<s>
Moreover	O
,	O
BFS	O
is	O
also	O
one	O
of	O
the	O
kernel	O
algorithms	O
in	O
Graph500	B-Device
benchmark	O
,	O
which	O
is	O
a	O
benchmark	O
for	O
data-intensive	O
supercomputing	O
problems	O
.	O
</s>
<s>
This	O
article	O
discusses	O
the	O
possibility	O
of	O
speeding	O
up	O
BFS	O
through	O
the	O
use	O
of	O
parallel	B-Operating_System
computing	I-Operating_System
.	O
</s>
<s>
In	O
the	O
conventional	O
sequential	O
BFS	B-Algorithm
algorithm	I-Algorithm
,	O
two	O
data	O
structures	O
are	O
created	O
to	O
store	O
the	O
frontier	O
and	O
the	O
next	O
frontier	O
.	O
</s>
<s>
At	O
the	O
beginning	O
of	O
the	O
BFS	B-Algorithm
algorithm	I-Algorithm
,	O
a	O
given	O
source	O
vertex	O
s	O
is	O
the	O
only	O
vertex	O
in	O
the	O
frontier	O
.	O
</s>
<s>
As	O
a	O
simple	O
and	O
intuitive	O
solution	O
,	O
the	O
classic	O
Parallel	B-Operating_System
Random	I-Operating_System
Access	I-Operating_System
Machine	I-Operating_System
(	O
PRAM	O
)	O
approach	O
is	O
just	O
an	O
extension	O
of	O
the	O
sequential	O
algorithm	O
that	O
is	O
shown	O
above	O
.	O
</s>
<s>
However	O
,	O
there	O
are	O
two	O
problems	O
in	O
this	O
simple	O
parallelization	B-Operating_System
.	O
</s>
<s>
Secondly	O
,	O
in	O
spite	O
of	O
the	O
speedup	O
of	O
each	O
layer-traversal	O
due	O
to	O
parallel	B-Operating_System
processing	I-Operating_System
,	O
a	O
barrier	B-Operating_System
synchronization	O
is	O
needed	O
after	O
every	O
layer	O
in	O
order	O
to	O
completely	O
discover	O
all	O
neighbor	O
vertices	O
in	O
the	O
frontier	O
.	O
</s>
<s>
This	O
simple	O
parallelization	B-Operating_System
's	O
asymptotic	O
complexity	O
is	O
same	O
as	O
sequential	O
algorithm	O
in	O
the	O
worst	O
case	O
,	O
but	O
some	O
optimizations	O
can	O
be	O
made	O
to	O
achieve	O
better	O
BFS	O
parallelization	B-Operating_System
,	O
for	O
example	O
:	O
</s>
<s>
Mitigating	O
barrier	B-Operating_System
synchronization	O
.	O
</s>
<s>
Barrier	B-Operating_System
synchronization	O
is	O
necessary	O
after	O
each	O
layer-traversal	O
to	O
ensure	O
the	O
correctness	O
of	O
parallel	O
BFS	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
reducing	O
the	O
cost	O
of	O
barrier	B-Operating_System
synchronization	O
is	O
an	O
effective	O
way	O
to	O
speed	O
up	O
parallel	O
BFS	O
.	O
</s>
<s>
Because	O
there	O
is	O
a	O
barrier	B-Operating_System
synchronization	O
after	O
each	O
layer-traversal	O
,	O
every	O
processing	O
entity	O
must	O
wait	O
until	O
the	O
last	O
of	O
them	O
finish	O
its	O
work	O
.	O
</s>
<s>
In	O
parallel	O
BFS	O
,	O
this	O
feature	O
reduces	O
the	O
benefits	O
from	O
parallelization	B-Operating_System
due	O
to	O
unbalanced	O
load	O
.	O
</s>
<s>
Many	O
parallel	O
BFS	B-Algorithm
algorithms	I-Algorithm
on	O
shared	O
memory	O
can	O
be	O
divided	O
into	O
two	O
types	O
:	O
container	O
centric	O
approaches	O
and	O
vertex	O
centric	O
approaches	O
.	O
</s>
<s>
Alternatively	O
,	O
they	O
can	O
be	O
global	O
to	O
provide	O
implicit	O
load	O
balancing	O
,	O
where	O
special	O
data	O
structures	O
are	O
used	O
for	O
concurrent	B-Operating_System
access	O
from	O
processing	O
entities	O
.	O
</s>
<s>
The	O
typical	O
data	O
structure	O
in	O
serial	O
BFS	O
and	O
some	O
parallel	O
BFS	O
is	O
FIFO	B-Operating_System
Queue	I-Operating_System
,	O
as	O
it	O
is	O
simple	O
and	O
fast	O
where	O
insertion	O
and	O
delete	O
operation	O
costs	O
only	O
constant	O
time	O
.	O
</s>
<s>
The	O
insertion	O
operation	O
in	O
a	O
bag	O
takes	O
O(logn )	O
time	O
in	O
the	O
worst-case	O
,	O
whereas	O
it	O
takes	O
only	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
which	O
is	O
as	O
fast	O
as	O
FIFO	B-Operating_System
.	O
</s>
<s>
Moreover	O
,	O
the	O
reducer	B-Operating_System
can	O
be	O
combined	O
with	O
the	O
bag-structure	O
to	O
write	O
vertices	O
in	O
parallel	O
and	O
traverse	O
them	O
efficiently	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
vertex	O
centric	O
approach	O
is	O
well-suited	O
for	O
GPUs	B-Architecture
if	O
every	O
thread	O
is	O
mapped	O
to	O
exactly	O
one	O
vertex	O
.	O
</s>
<s>
Load	O
balancing	O
is	O
still	O
an	O
important	O
issue	O
for	O
data	O
partition	O
,	O
which	O
determines	O
how	O
we	O
can	O
benefit	O
from	O
parallelization	B-Operating_System
.	O
</s>
<s>
For	O
the	O
implementation	O
of	O
data	O
storage	O
,	O
each	O
processor	O
can	O
store	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
its	O
local	O
vertices	O
,	O
in	O
which	O
each	O
row	O
for	O
each	O
vertex	O
is	O
a	O
row	O
of	O
outgoing	O
edges	O
represented	O
by	O
destination	O
vertex	O
indices	O
.	O
</s>
<s>
Obviously	O
,	O
one	O
all-to-all	B-Operating_System
communication	I-Operating_System
(	O
which	O
means	O
each	O
entity	O
has	O
different	O
messages	O
for	O
all	O
others	O
)	O
is	O
necessary	O
in	O
each	O
step	O
when	O
exchanging	O
the	O
current	O
frontier	O
and	O
the	O
next	O
vertex	O
frontier	O
.	O
</s>
<s>
The	O
following	O
pseudo-code	O
of	O
a	O
1-D	O
distributed	O
memory	O
BFS	O
was	O
originally	O
designed	O
for	O
IBM	B-Operating_System
BlueGene/L	I-Operating_System
systems	O
,	O
which	O
have	O
a	O
3D	B-Operating_System
torus	I-Operating_System
network	O
architecture	O
.	O
</s>
<s>
Because	O
the	O
synchronization	O
is	O
the	O
main	O
extra	O
cost	O
for	O
parallelized	B-Operating_System
BFS	O
,	O
the	O
authors	O
of	O
this	O
paper	O
also	O
developed	O
a	O
scalable	O
all-to-all	B-Operating_System
communication	I-Operating_System
based	O
on	O
point-to-point	B-Architecture
communications	I-Architecture
.	O
</s>
<s>
After	O
that	O
,	O
they	O
also	O
reduced	O
the	O
number	O
of	O
point-to-point	B-Architecture
communication	I-Architecture
,	O
taking	O
advantage	O
of	O
its	O
high-bandwidth	O
torus	O
network	O
.	O
</s>
<s>
Combined	O
with	O
multi-threading	O
,	O
the	O
following	O
pseudo	O
code	O
of	O
1D	O
distributed	O
memory	O
BFS	O
also	O
specifies	O
thread	O
stack	O
and	O
thread	O
barrier	B-Operating_System
,	O
which	O
comes	O
from	O
the	O
paper	O
.	O
</s>
<s>
Moreover	O
,	O
Thread	O
barrier	B-Operating_System
is	O
also	O
necessary	O
for	O
synchronization	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
although	O
distributed	O
memory	O
with	O
multi-threading	O
might	O
benefit	O
from	O
refinement	O
of	O
parallelization	B-Operating_System
,	O
it	O
also	O
introduces	O
extra	O
synchronization	O
cost	O
for	O
threads	O
.	O
</s>
<s>
processor	O
view	O
(	O
line	O
23	O
)	O
:	O
run	O
a	O
thread	O
barrier	B-Operating_System
,	O
wait	O
until	O
all	O
threads(of the same processor )	O
finish	O
their	O
job	O
.	O
</s>
<s>
global	O
view	O
(	O
line	O
28	O
–	O
30	O
)	O
:	O
run	O
an	O
all-to-all	B-Operating_System
communication	I-Operating_System
with	O
master	O
thread	O
to	O
let	O
each	O
processor	O
know	O
,	O
which	O
local	O
vertices	O
should	O
be	O
put	O
into	O
the	O
next	O
frontier	O
.	O
</s>
<s>
processor	O
view	O
(	O
line	O
31	O
)	O
:	O
run	O
a	O
thread	O
barrier	B-Operating_System
,	O
wait	O
until	O
the	O
communication	O
finished(of master thread )	O
.	O
</s>
<s>
processor	O
view	O
(	O
line	O
37	O
)	O
:	O
run	O
a	O
thread	O
barrier	B-Operating_System
,	O
wait	O
until	O
all	O
threads(of the same processor )	O
finish	O
their	O
job	O
.	O
</s>
<s>
processor	O
view	O
(	O
line	O
40	O
)	O
:	O
run	O
a	O
thread	O
barrier	B-Operating_System
,	O
wait	O
until	O
all	O
threads	O
send	O
all	O
their	O
vertices	O
in	O
their	O
stack	O
.	O
</s>
<s>
Because	O
BFS	B-Algorithm
algorithm	I-Algorithm
always	O
uses	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
as	O
the	O
representation	O
of	O
the	O
graph	O
.	O
</s>
<s>
If	O
there	O
are	O
in	O
total	O
P	O
=	O
R·C	O
processors	O
,	O
then	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
will	O
be	O
divided	O
like	O
below	O
:	O
</s>
<s>
In	O
the	O
"	O
expand	O
"	O
phase	O
,	O
if	O
the	O
edge	O
list	O
for	O
a	O
given	O
vertex	O
is	O
the	O
column	O
of	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
,	O
then	O
for	O
each	O
vertex	O
v	O
in	O
the	O
frontier	O
,	O
the	O
owner	O
of	O
v	O
is	O
responsible	O
to	O
tell	O
other	O
processors	O
in	O
its	O
processor	O
column	O
that	O
v	O
is	O
visited	O
.	O
</s>
<s>
The	O
pseudo-code	O
below	O
describes	O
more	O
details	O
of	O
2D	O
BFS	B-Algorithm
algorithm	I-Algorithm
,	O
which	O
comes	O
from	O
the	O
paper	O
:	O
</s>
<s>
This	O
is	O
the	O
advantage	O
of	O
2D	O
partitioning	O
over	O
1D	O
partitioning	O
,	O
because	O
all	O
processors	O
are	O
involved	O
in	O
the	O
all-to-all	B-Operating_System
communication	I-Operating_System
operation	O
in	O
1D	O
partitioning	O
.	O
</s>
<s>
Aside	O
from	O
basic	O
ideas	O
of	O
parallel	O
BFS	O
,	O
some	O
optimization	O
strategies	O
can	O
be	O
used	O
to	O
speed	O
up	O
parallel	O
BFS	B-Algorithm
algorithm	I-Algorithm
and	O
improve	O
the	O
efficiency	O
.	O
</s>
<s>
This	O
can	O
be	O
determined	O
efficient	O
if	O
the	O
frontier	O
is	O
represented	O
by	O
a	O
bitmap	B-Data_Structure
.	O
</s>
<s>
Load	O
balancing	O
is	O
very	O
important	O
not	O
only	O
in	O
parallel	O
BFS	O
but	O
also	O
in	O
all	O
parallel	B-Operating_System
algorithms	I-Operating_System
,	O
because	O
balanced	O
work	O
can	O
improve	O
the	O
benefit	O
of	O
parallelization	B-Operating_System
.	O
</s>
<s>
In	O
fact	O
,	O
almost	O
all	O
of	O
parallel	O
BFS	B-Algorithm
algorithm	I-Algorithm
designers	O
should	O
observe	O
and	O
analyze	O
the	O
work	O
partitioning	O
of	O
their	O
algorithm	O
and	O
provide	O
a	O
load	O
balancing	O
mechanism	O
for	O
it	O
.	O
</s>
<s>
There	O
are	O
some	O
special	O
data	O
structures	O
that	O
parallel	O
BFS	O
can	O
benefit	O
from	O
,	O
such	O
as	O
CSR	O
(	O
Compressed	O
Sparse	O
Row	O
)	O
,	O
bag-structure	O
,	O
bitmap	B-Data_Structure
and	O
so	O
on	O
.	O
</s>
<s>
The	O
insertion	O
operation	O
in	O
a	O
bag	O
takes	O
O(1 )	O
amortized	B-General_Concept
time	I-General_Concept
and	O
the	O
union	O
of	O
two	O
bags	O
takes	O
Θ(lgn )	O
time	O
.	O
</s>
<s>
Moreover	O
,	O
bitmap	B-Data_Structure
is	O
also	O
a	O
very	O
useful	O
data	O
structure	O
to	O
memorize	O
which	O
vertices	O
are	O
already	O
visited	O
,	O
regardless	O
in	O
the	O
bottom-up	O
BFS	O
.	O
</s>
<s>
Graph500	B-Device
is	O
the	O
first	O
benchmark	O
for	O
data-intensive	O
supercomputing	O
problems	O
.	O
</s>
<s>
Graph500	B-Device
also	O
provides	O
two	O
reference	O
implementations	O
for	O
kernel	O
2	O
and	O
3	O
.	O
</s>
<s>
For	O
the	O
synchronization	O
,	O
AML	O
(	O
Active	O
Messages	O
Library	O
,	O
which	O
is	O
an	O
SPMD	B-Operating_System
communication	O
library	O
build	O
on	O
top	O
of	O
MPI3	B-Application
,	O
intend	O
to	O
be	O
used	O
in	O
fine	O
grain	O
applications	O
like	O
Graph500	B-Device
)	O
barrier	B-Operating_System
ensures	O
the	O
consistent	O
traversal	O
after	O
each	O
layer	O
.	O
</s>
<s>
Thus	O
,	O
users	O
should	O
implement	O
their	O
own	O
BFS	B-Algorithm
algorithm	I-Algorithm
based	O
on	O
their	O
hardware	O
.	O
</s>
<s>
Different	O
from	O
TOP500	B-Operating_System
,	O
the	O
performance	O
metric	O
in	O
Graph500	B-Device
is	O
Traversed	O
Edges	O
Per	O
Second(TEPS )	O
.	O
</s>
