forked from gunrock/gunrock
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shared_lib_bfs.c
44 lines (35 loc) · 1.58 KB
/
shared_lib_bfs.c
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
/**
* @brief BFS test for shared library advanced interface
* @file shared_lib_bfs.c
*/
#include <stdio.h>
#include <gunrock/gunrock.h>
int main(int argc, char* argv[])
{
////////////////////////////////////////////////////////////////////////////
struct GRTypes data_t; // data type structure
data_t.VTXID_TYPE = VTXID_INT; // vertex identifier
data_t.SIZET_TYPE = SIZET_INT; // graph size type
data_t.VALUE_TYPE = VALUE_INT; // attributes type
int srcs[3] = {0,1,2};
struct GRSetup *config = InitSetup(3, srcs); // gunrock configurations
int num_nodes = 7, num_edges = 15; // number of nodes and edges
int row_offsets[8] = {0, 3, 6, 9, 11, 14, 15, 15};
int col_indices[15] = {1, 2, 3, 0, 2, 4, 3, 4, 5, 5, 6, 2, 5, 6, 6};
struct GRGraph *grapho = (struct GRGraph*)malloc(sizeof(struct GRGraph));
struct GRGraph *graphi = (struct GRGraph*)malloc(sizeof(struct GRGraph));
graphi->num_nodes = num_nodes;
graphi->num_edges = num_edges;
graphi->row_offsets = (void*)&row_offsets[0];
graphi->col_indices = (void*)&col_indices[0];
gunrock_bfs(grapho, graphi, config, data_t);
////////////////////////////////////////////////////////////////////////////
int *labels = (int*)malloc(sizeof(int) * graphi->num_nodes);
labels = (int*)grapho->node_value1;
int node; for (node = 0; node < graphi->num_nodes; ++node)
printf("Node_ID [%d] : Label [%d]\n", node, labels[node]);
if (graphi) free(graphi);
if (grapho) free(grapho);
if (labels) free(labels);
return 0;
}