#include #include #include #include #include FILE *fp; //Structure to hold a node information struct Node { int starting; int no_of_edges; }; void BFSGraph(int argc, char** argv); void Usage(int argc, char**argv){ fprintf(stderr,"Usage: %s \n", argv[0]); } //////////////////////////////////////////////////////////////////////////////// // Main Program //////////////////////////////////////////////////////////////////////////////// int main( int argc, char** argv) { BFSGraph( argc, argv); } //////////////////////////////////////////////////////////////////////////////// //Apply BFS on a Graph using CUDA //////////////////////////////////////////////////////////////////////////////// void BFSGraph( int argc, char** argv) { int no_of_nodes = 0; int edge_list_size = 0; char *input_f; int num_omp_threads; if(argc!=3){ Usage(argc, argv); exit(0); } num_omp_threads = atoi(argv[1]); input_f = argv[2]; printf("Reading File\n"); //Read in Graph from a file fp = fopen(input_f,"r"); if(!fp) { printf("Error Reading graph file\n"); return; } int source = 0; fscanf(fp,"%d",&no_of_nodes); // allocate host memory Node* h_graph_nodes = (Node*) malloc(sizeof(Node)*no_of_nodes); bool *h_graph_mask = (bool*) malloc(sizeof(bool)*no_of_nodes); bool *h_updating_graph_mask = (bool*) malloc(sizeof(bool)*no_of_nodes); bool *h_graph_visited = (bool*) malloc(sizeof(bool)*no_of_nodes); int start, edgeno; // initalize the memory for( unsigned int i = 0; i < no_of_nodes; i++) { fscanf(fp,"%d %d",&start,&edgeno); h_graph_nodes[i].starting = start; h_graph_nodes[i].no_of_edges = edgeno; h_graph_mask[i]=false; h_updating_graph_mask[i]=false; h_graph_visited[i]=false; } //read the source node from the file fscanf(fp,"%d",&source); // source=0; //tesing code line //set the source node as true in the mask h_graph_mask[source]=true; h_graph_visited[source]=true; fscanf(fp,"%d",&edge_list_size); int id,cost; int* h_graph_edges = (int*) malloc(sizeof(int)*edge_list_size); for(int i=0; i < edge_list_size ; i++) { fscanf(fp,"%d",&id); fscanf(fp,"%d",&cost); h_graph_edges[i] = id; } if(fp) fclose(fp); // allocate mem for the result on host side int* h_cost = (int*) malloc( sizeof(int)*no_of_nodes); for(int i=0;i