Skip to content

Commit

Permalink
Enabled multi-pass BFS and SSSP. SSSP has runtime error though.
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhwang committed Jun 22, 2016
1 parent 8b04971 commit d7060d3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 42 deletions.
11 changes: 6 additions & 5 deletions gunrock/app/bfs/bfs_app.cu
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,13 @@ float runBFS(GRGraph* output, BFS_Parameter *parameter)
float elapsed = 0.0f;
for (int i = 0; i < num_iters; ++i)
{
printf("%d round of bfs.\n", i);
printf("Round %d of bfs.\n", i+1);
util::GRError(
problem->Reset(parameter->src[i], enactor->GetFrontierType(),
max_queue_sizing, max_queue_sizing1),
"BFS Problem Data Reset Failed", __FILE__, __LINE__);
printf("before enactor reset.\n");
util::GRError(
enactor->Reset(), "BFS Enactor Reset failed", __FILE__, __LINE__);
printf("after enactor reset.\n");

cpu_timer.Start();

Expand All @@ -241,8 +239,6 @@ float runBFS(GRGraph* output, BFS_Parameter *parameter)

cpu_timer.Stop();

printf("after enactor run.\n");

elapsed += cpu_timer.ElapsedMillis();
}

Expand Down Expand Up @@ -465,6 +461,7 @@ float gunrock_bfs(
*/
float bfs(
int* bfs_label,
int* bfs_preds,
const int num_nodes,
const int num_edges,
const int* row_offsets,
Expand Down Expand Up @@ -493,11 +490,15 @@ float bfs(
graphi->row_offsets = (void*)&row_offsets[0]; // setting row_offsets
graphi->col_indices = (void*)&col_indices[0]; // setting col_indices


float elapsed_time = gunrock_bfs(grapho, graphi, config, data_t);
memcpy(bfs_label, (int*)grapho->node_value1, num_nodes * sizeof(int));
if (mark_predecessors)
memcpy(bfs_preds, (int*)grapho->node_value2, num_nodes * sizeof(int));

if (graphi) free(graphi);
if (grapho) free(grapho);
if (config) free(config);

return elapsed_time;
}
Expand Down
75 changes: 47 additions & 28 deletions gunrock/app/sssp/sssp_app.cu
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ template <
//bool DEBUG,
//bool SIZE_CHECK,
bool MARK_PREDECESSORS >
void runSSSP(GRGraph* output, SSSP_Parameter *parameter);
float runSSSP(GRGraph* output, SSSP_Parameter *parameter);

/**
* @brief Run test
Expand All @@ -80,12 +80,12 @@ template <
//bool INSTRUMENT,
//bool DEBUG,
//bool SIZE_CHECK >
void markPredecessorsSSSP(GRGraph* output, SSSP_Parameter *parameter)
float markPredecessorsSSSP(GRGraph* output, SSSP_Parameter *parameter)
{
if (parameter->mark_predecessors)
runSSSP<VertexId, SizeT, Value, true>(output, parameter);
return runSSSP<VertexId, SizeT, Value, true>(output, parameter);
else
runSSSP<VertexId, SizeT, Value, false>(output, parameter);
return runSSSP<VertexId, SizeT, Value, false>(output, parameter);
}

/**
Expand All @@ -110,7 +110,7 @@ template <
//bool DEBUG,
//bool SIZE_CHECK,
bool MARK_PREDECESSORS >
void runSSSP(GRGraph* output, SSSP_Parameter *parameter)
float runSSSP(GRGraph* output, SSSP_Parameter *parameter)
{
typedef SSSPProblem < VertexId,
SizeT,
Expand All @@ -126,10 +126,11 @@ void runSSSP(GRGraph* output, SSSP_Parameter *parameter)
Csr<VertexId, SizeT, Value>
*graph = (Csr<VertexId, SizeT, Value>*)parameter->graph;
bool quiet = parameter -> g_quiet;
VertexId src = (VertexId)parameter -> src[0];
int max_grid_size = parameter -> max_grid_size;
int num_gpus = parameter -> num_gpus;
int num_iters = parameter -> iterations;
double max_queue_sizing = parameter -> max_queue_sizing;
double max_queue_sizing1 = parameter -> max_queue_sizing1;
double max_in_sizing = parameter -> max_in_sizing;
ContextPtr *context = (ContextPtr*)parameter -> context;
std::string partition_method = parameter -> partition_method;
Expand Down Expand Up @@ -181,20 +182,25 @@ void runSSSP(GRGraph* output, SSSP_Parameter *parameter)

// Perform SSSP
CpuTimer cpu_timer;
float elapsed = 0.0f;
for (int i = 0; i < num_iters; ++i)
{
printf("Round %d of sssp.\n", i+1);

util::GRError(
problem->Reset(src, enactor->GetFrontierType(), max_queue_sizing),
"SSSP Problem Data Reset Failed", __FILE__, __LINE__);
util::GRError(
enactor->Reset(), "SSSP Enactor Reset failed", __FILE__, __LINE__);
util::GRError(
problem->Reset(parameter->src[i], enactor->GetFrontierType(), max_queue_sizing, max_queue_sizing1),
"SSSP Problem Data Reset Failed", __FILE__, __LINE__);
util::GRError(
enactor->Reset(), "SSSP Enactor Reset failed", __FILE__, __LINE__);

cpu_timer.Start();
util::GRError(
enactor->Enact(src, traversal_mode),
"SSSP Problem Enact Failed", __FILE__, __LINE__);
cpu_timer.Stop();
cpu_timer.Start();
util::GRError(
enactor->Enact(parameter->src[i], traversal_mode),
"SSSP Problem Enact Failed", __FILE__, __LINE__);
cpu_timer.Stop();

float elapsed = cpu_timer.ElapsedMillis();
elapsed += cpu_timer.ElapsedMillis();
}

// Copy out results
util::GRError(
Expand All @@ -213,6 +219,8 @@ void runSSSP(GRGraph* output, SSSP_Parameter *parameter)
if (org_size) { delete[] org_size; org_size = NULL; }
if (enactor ) { delete enactor ; enactor = NULL; }
if (problem ) { delete problem ; problem = NULL; }

return elapsed;
}

/**
Expand All @@ -225,7 +233,7 @@ void runSSSP(GRGraph* output, SSSP_Parameter *parameter)
* @param[in] context ModernGPU context
* @param[in] streams CUDA stream
*/
void dispatchSSSP(
float dispatchSSSP(
GRGraph* grapho,
const GRGraph* graphi,
const GRSetup* config,
Expand All @@ -234,7 +242,8 @@ void dispatchSSSP(
cudaStream_t* streams)
{
SSSP_Parameter *parameter = new SSSP_Parameter;
parameter->src = (long long*)malloc(sizeof(long long));
parameter->iterations = config->num_iters;
parameter->src = (long long*)malloc(sizeof(long long)*config->num_iters);
parameter->context = context;
parameter->streams = streams;
parameter->g_quiet = config -> quiet;
Expand All @@ -244,6 +253,8 @@ void dispatchSSSP(
parameter->traversal_mode = std::string(config -> traversal_mode);
parameter->mark_predecessors = config -> mark_predecessors;

float elapsed_time;

switch (data_t.VTXID_TYPE)
{
case VTXID_INT:
Expand Down Expand Up @@ -294,7 +305,7 @@ void dispatchSSSP(
printf(" source: %lld\n", (long long) parameter->src[0]);
}

markPredecessorsSSSP<int, int, int>(grapho, parameter);
elapsed_time = markPredecessorsSSSP<int, int, int>(grapho, parameter);

// reset for free memory
csr.row_offsets = NULL;
Expand Down Expand Up @@ -323,6 +334,7 @@ void dispatchSSSP(
}
}
free(parameter->src);
return elapsed_time;
}

/*
Expand All @@ -333,7 +345,7 @@ void dispatchSSSP(
* @param[in] config Gunrock primitive specific configurations
* @param[in] data_t Gunrock data type structure
*/
void gunrock_sssp(
float gunrock_sssp(
GRGraph* grapho,
const GRGraph* graphi,
const GRSetup* config,
Expand Down Expand Up @@ -375,7 +387,7 @@ void gunrock_sssp(
}
if (!config -> quiet) { printf("\n"); }

dispatchSSSP(grapho, graphi, config, data_t, context, streams);
return dispatchSSSP(grapho, graphi, config, data_t, context, streams);
}

/*
Expand All @@ -388,23 +400,25 @@ void gunrock_sssp(
* @param[in] col_indices CSR-formatted graph input column indices
* @param[in] source Source to begin traverse
*/
void sssp(
float sssp(
unsigned int* distances,
int* preds,
const int num_nodes,
const int num_edges,
const int* row_offsets,
const int* col_indices,
const unsigned int* edge_values,
const int source)
const int num_iters,
int* source,
const bool mark_preds)
{
struct GRTypes data_t; // primitive-specific data types
data_t.VTXID_TYPE = VTXID_INT; // integer vertex identifier
data_t.SIZET_TYPE = SIZET_INT; // integer graph size type
data_t.VALUE_TYPE = VALUE_INT; // integer attributes type

struct GRSetup *config = InitSetup(1, NULL); // primitive-specific configures
config -> source_vertex[0] = source; // source vertex to start
config -> mark_predecessors = false; // do not mark predecessors
struct GRSetup *config = InitSetup(num_iters, source); // primitive-specific configures
config -> mark_predecessors = mark_preds; // do not mark predecessors

struct GRGraph *grapho = (struct GRGraph*)malloc(sizeof(struct GRGraph));
struct GRGraph *graphi = (struct GRGraph*)malloc(sizeof(struct GRGraph));
Expand All @@ -415,11 +429,16 @@ void sssp(
graphi->col_indices = (void*)&col_indices[0]; // setting col_indices
graphi->edge_values = (void*)&edge_values[0]; // setting edge_values

gunrock_sssp(grapho, graphi, config, data_t);
float elapsed_time = gunrock_sssp(grapho, graphi, config, data_t);
memcpy(distances, (int*)grapho->node_value1, num_nodes * sizeof(int));
if (mark_preds)
memcpy(preds, (int*)grapho->node_value2, num_nodes * sizeof(int));

if (graphi) free(graphi);
if (grapho) free(grapho);
if (config) free(config);

return elapsed_time;
}

// Leave this at the end of the file
Expand Down
13 changes: 9 additions & 4 deletions gunrock/gunrock.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ float gunrock_bfs(
/*
* @brief Simple interface take in CSR arrays as input
*
* @param[out] bfs_label Return BFS label (depth) per nodes or the predecessor per nodes
* @param[out] bfs_label Return BFS label (depth) per nodes
* @param[out] bfs_label Return the predecessor per nodes
* @param[in] num_nodes Number of nodes of the input graph
* @param[in] num_edges Number of edges of the input graph
* @param[in] row_offsets CSR-formatted graph input row offsets
Expand All @@ -186,6 +187,7 @@ float gunrock_bfs(
*/
float bfs(
int* bfs_label,
int* bfs_pred,
const int num_nodes,
const int num_edges,
const int* row_offsets,
Expand Down Expand Up @@ -268,7 +270,7 @@ int cc(
* @param[in] config Primitive-specific configurations.
* @param[in] data_t Primitive-specific data type setting.
*/
void gunrock_sssp(
float gunrock_sssp(
struct GRGraph* grapho, // Output graph / results
const struct GRGraph* graphi, // Input graph structure
const struct GRSetup* config, // Flag configurations
Expand All @@ -285,14 +287,17 @@ void gunrock_sssp(
* @param[in] edge_values Input graph edge weight.
* @param[in] source Source node to start.
*/
void sssp(
float sssp(
unsigned int* distances, // Return shortest distances
int* preds,
const int num_nodes, // Input graph number of nodes
const int num_edges, // Input graph number of edges
const int* row_offsets, // Input graph row_offsets
const int* col_indices, // Input graph col_indices
const unsigned int* edge_values, // Input graph edge weight
const int source); // Source node to start
const int num_iters,
int* source,
const bool mark_preds);

/**
* @brief PageRank public interface.
Expand Down
4 changes: 2 additions & 2 deletions shared_lib_tests/shared_lib_bfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ int main(int argc, char* argv[])
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[1] = {1};
int srcs[3] = {0,1,2};

struct GRSetup *config = InitSetup(1, srcs); // gunrock configurations
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};
Expand Down
3 changes: 2 additions & 1 deletion shared_lib_tests/shared_lib_sssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ int main(int argc, char* argv[])
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(1, NULL); // gunrock configurations
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};
Expand Down
6 changes: 4 additions & 2 deletions shared_lib_tests/simple_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ int main(int argc, char* argv[])
///////////////////////////////////////////////////////////////////////////
// run different primitive tests
// graph traversal from given source return integer labels
bfs(bfs_label, nodes, edges, rows, cols, 1,/*source=*/ 0, 0, false, false);
bfs(bfs_label, 0, nodes, edges, rows, cols, 1,/*source=*/ 0, 0, false, false);
// node betweenness centrality from given source
// store computed results to bc_scores of floats
bc(bc_scores, nodes, edges, rows, cols, /*source=*/ 0);
// return number of component and per node component ID
int num_components = cc(conn_comp, nodes, edges, rows, cols);
// return shortest distance for each vertex from given source
sssp(sssp_dist, nodes, edges, rows, cols, vals, /*source=*/ 0);
sssp(sssp_dist, 0, nodes, edges, rows, cols, vals, 1,/*source=*/ 0,false);


// return top-ranked nodes and their PageRank values of floats
pagerank(top_nodes, top_ranks, nodes, edges, rows, cols, false);

Expand Down

0 comments on commit d7060d3

Please sign in to comment.