-
Notifications
You must be signed in to change notification settings - Fork 1
/
bfs_kernel.cu
47 lines (44 loc) · 1.39 KB
/
bfs_kernel.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef _KERNEL_H
#define _KERNEL_H
typedef struct Node {
int starting;
int no_of_edges;
}Node;
__global__ void
test(Node* d_graph_nodes, int no_of_nodes) {
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < no_of_nodes) {
d_graph_nodes[tid].starting+=1;
}
}
__global__ void
test1(bool* d_graph_visited, int no_of_nodes) {
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < no_of_nodes) {
d_graph_visited[tid] = true;
}
}
__global__ void
bfs_kernel(Node* d_graph_nodes, int* d_edge_list, bool* d_graph_level,
bool* d_graph_visited, int* d_cost, bool* loop, int no_of_nodes) {
int tid = blockIdx.x * blockDim.x + threadIdx.x;
//d_graph_level[tid] is true means the vertex in the current level
//is being visited
if (tid < no_of_nodes && d_graph_level[tid]) {
d_graph_level[tid] = false;
d_graph_visited[tid] = true;
for (int i = d_graph_nodes[tid].starting; i <
(d_graph_nodes[tid].no_of_edges +
d_graph_nodes[tid].starting); i++) {
int id = d_edge_list[i];
if (!d_graph_visited[id]) {
//calculate in which level the vertex is visited
d_cost[id] = d_cost[tid] + 1;
d_graph_level[id] = true;
//to make the loop continues
*loop = true;
}
}
}
}
#endif