void randomgraph_construction(graph_t &g, size_t vertex_num, size_t edge_num, gBenchPerf_event & perf, int perf_group) { vector<pair<size_t,size_t> > edges; for (size_t i=0;i<edge_num;i++) { edges.push_back(make_pair(rand()%vertex_num, rand()%vertex_num)); } perf.open(perf_group); perf.start(perf_group); for (size_t i=0;i<vertex_num;i++) { vertex_iterator vit = g.add_vertex(); vit->set_property(vertex_property(i)); } #ifdef SIM SIM_BEGIN(true); #endif for (size_t i=0;i<edge_num;i++) { edge_iterator eit; g.add_edge(edges[i].first, edges[i].second, eit); #ifndef SIM eit->set_property(edge_property(i)); #endif } #ifdef SIM SIM_END(true); #endif perf.stop(perf_group); }
void parallel_randomgraph_construction(graph_t &g, size_t vertex_num, size_t edge_num) { vector<pair<size_t,size_t> > edges; for (size_t i=0;i<edge_num;i++) { edges.push_back(make_pair(rand()%vertex_num, rand()%vertex_num)); } for (size_t i=0;i<vertex_num;i++) { vertex_iterator vit = g.add_vertex(); vit->set_property(vertex_property(i)); } uint64_t chunk = (unsigned)ceil(edge_num/(double)threadnum); #pragma omp parallel num_threads(threadnum) { unsigned tid = omp_get_thread_num(); unsigned start = tid*chunk; unsigned end = start + chunk; if (end > edge_num) end = edge_num; #ifdef SIM SIM_BEGIN(true); #endif for (size_t i=start;i<end;i++) { edge_iterator eit; g.add_edge(edges[i].first, edges[i].second, eit); #ifndef SIM eit->set_property(edge_property(i)); #endif } #ifdef SIM SIM_END(true); #endif } }