PandA-2024.02
examples
MachSuite
MachSuite
bfs
queue
bfs.c
Go to the documentation of this file.
1
/*
2
Implementation based on:
3
Hong, Oguntebi, Olukotun. "Efficient Parallel Graph Exploration on Multi-Core CPU and GPU." PACT, 2011.
4
*/
5
6
#include "
bfs.h
"
7
8
#define Q_PUSH(node) { queue[q_in==0?N_NODES-1:q_in-1]=node; q_in=(q_in+1)%N_NODES; }
9
#define Q_PEEK() (queue[q_out])
10
#define Q_POP() { q_out = (q_out+1)%N_NODES; }
11
#define Q_EMPTY() (q_in>q_out ? q_in==q_out+1 : (q_in==0)&&(q_out==N_NODES-1))
12
13
void
bfs
(
node_t
nodes
[
N_NODES
],
edge_t
edges
[
N_EDGES
],
14
node_index_t
starting_node,
level_t
level
[N_NODES],
15
edge_index_t
level_counts[
N_LEVELS
])
16
{
17
node_index_t
queue[
N_NODES
];
18
node_index_t
q_in, q_out;
19
node_index_t
dummy;
20
node_index_t
n;
21
edge_index_t
e;
22
23
/*init_levels: for( n=0; n<N_NODES; n++ )*/
24
/*level[n] = MAX_LEVEL;*/
25
/*init_horizons: for( i=0; i<N_LEVELS; i++ )*/
26
/*level_counts[i] = 0;*/
27
28
q_in = 1;
29
q_out = 0;
30
level
[starting_node] = 0;
31
level_counts[0] = 1;
32
Q_PUSH
(starting_node);
33
34
loop_queue:
for
( dummy=0; dummy<
N_NODES
; dummy++ ) {
// Typically while(not_empty(queue)){
35
if
(
Q_EMPTY
() )
36
break
;
37
n =
Q_PEEK
();
38
Q_POP
();
39
edge_index_t
tmp_begin =
nodes
[n].edge_begin;
40
edge_index_t
tmp_end =
nodes
[n].edge_end;
41
loop_neighbors:
for
( e=tmp_begin; e<tmp_end; e++ ) {
42
node_index_t
tmp_dst =
edges
[e].dst;
43
level_t
tmp_level =
level
[tmp_dst];
44
45
if
( tmp_level ==
MAX_LEVEL
) {
// Unmarked
46
level_t
tmp_level =
level
[n]+1;
47
level
[tmp_dst] = tmp_level;
48
++level_counts[tmp_level];
49
Q_PUSH
(tmp_dst);
50
}
51
}
52
}
53
54
/*
55
printf("Horizons:");
56
for( i=0; i<N_LEVELS; i++ )
57
printf(" %d", level_counts[i]);
58
printf("\n");
59
*/
60
}
nodes
struct Node nodes[7]
Definition:
simple_raytrace.c:62
N_NODES
#define N_NODES
Definition:
bfs.h:18
Q_PUSH
#define Q_PUSH(node)
Definition:
bfs.c:8
node_index_t
uint64_t node_index_t
Definition:
bfs.h:26
level_t
int8_t level_t
Definition:
bfs.h:40
Q_POP
#define Q_POP()
Definition:
bfs.c:10
edges
unsigned edges[4545]
Definition:
graph.h:25
bfs.h
N_LEVELS
#define N_LEVELS
Definition:
bfs.h:22
bfs
void bfs(node_t nodes[N_NODES], edge_t edges[N_EDGES], node_index_t starting_node, level_t level[N_NODES], edge_index_t level_counts[N_LEVELS])
Definition:
bfs.c:9
MAX_LEVEL
#define MAX_LEVEL
Definition:
bfs.h:41
edge_index_t
uint64_t edge_index_t
Definition:
bfs.h:25
node_t_struct
Definition:
bfs.h:35
Q_EMPTY
#define Q_EMPTY()
Definition:
bfs.c:11
level
int level
Definition:
main.c:98
edge_t_struct
Definition:
bfs.h:28
Q_PEEK
#define Q_PEEK()
Definition:
bfs.c:9
N_EDGES
#define N_EDGES
Definition:
bfs.h:19
Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by
1.8.13