Ejemplo n.º 1
0
//==============================================================//
void dc(graph_t& g, gBenchPerf_event & perf, int perf_group) 
{
    perf.open(perf_group);
    perf.start(perf_group);
#ifdef SIM
    SIM_BEGIN(true);
#endif
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        // out degree
        vit->property().outdegree = vit->edges_size();

        // in degree
        edge_iterator eit;
        for (eit=vit->edges_begin(); eit!=vit->edges_end(); eit++) 
        {
            vertex_iterator targ = g.find_vertex(eit->target());
            (targ->property().indegree)++;
        }
    }
#ifdef SIM
    SIM_END(true);
#endif
    perf.stop(perf_group);
}// end dc
Ejemplo n.º 2
0
void degree_analyze(graph_t& g, 
                    uint64_t& indegree_max, uint64_t& indegree_min,
                    uint64_t& outdegree_max, uint64_t& outdegree_min)
{
    vertex_iterator vit;
    indegree_max=outdegree_max=0;
    indegree_min=outdegree_min=numeric_limits<uint64_t>::max();


    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        if (indegree_max < vit->property().indegree)
            indegree_max = vit->property().indegree;

        if (outdegree_max < vit->property().outdegree)
            outdegree_max = vit->property().outdegree;

        if (indegree_min > vit->property().indegree)
            indegree_min = vit->property().indegree;

        if (outdegree_min > vit->property().outdegree)
            outdegree_min = vit->property().outdegree;
    }

    return;
}
Ejemplo n.º 3
0
void reset_graph(graph_t & g)
{
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        vit->property().indegree = 0;
        vit->property().outdegree = 0;
    }
}
Ejemplo n.º 4
0
void output(graph_t& g)
{
    cout<<"Results: \n";
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        cout<<"== vertex "<<vit->id()<<": edge#-"<<vit->edges_size()<<"\n";
    }
}
Ejemplo n.º 5
0
//==============================================================//
void output(graph_t& g)
{
    cout<<"Betweenness Centrality Results: \n";
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        cout<<"== vertex "<<vit->id()<<": "<<vit->property().BC<<"\n";
    }
}
Ejemplo n.º 6
0
void reset_graph(graph_t & g)
{
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        vit->property().root = vit->id();
    }

}
Ejemplo n.º 7
0
void output(graph_t& g)
{
    cout<<"WCC Results: \n";
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        cout << vit->id() << " " << vit->property().root << "\n";
    }
}
Ejemplo n.º 8
0
void output(graph_t& g) 
{
    cout<<"Degree Centrality Results: \n";
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        cout<<"== vertex "<<vit->id()<<": in-"<<vit->property().indegree
            <<" out-"<<vit->property().outdegree<<"\n";
    }
}
Ejemplo n.º 9
0
void reset_graph(graph_t & g)
{
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        vit->property().degree = 0;
        vit->property().removed = false;
    }

}
Ejemplo n.º 10
0
void parallel_init(graph_t& g, unsigned threadnum,
                   vector<vector<uint64_t> >& global_input_tasks)
{
    global_input_tasks.resize(threadnum);
    for (vertex_iterator vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        vit->property().root = vit->id();
        global_input_tasks[vertex_distributor(vit->id(), threadnum)].push_back(vit->id());

    }
}
Ejemplo n.º 11
0
size_t kcore(graph_t& g, size_t k, gBenchPerf_event & perf, int perf_group) 
{
    size_t remove_cnt=0;

    queue<vertex_iterator> process_q;

    // initialize
    for (vertex_iterator vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        size_t degree = vit->edges_size();
        vit->property().degree = degree;

        if (degree < k) 
        {
            process_q.push(vit);
            vit->property().removed = true;
            remove_cnt++;
        }
    }
    
    perf.open(perf_group);
    perf.start(perf_group);

    // remove vertices iteratively 
    while (!process_q.empty()) 
    {

        vertex_iterator vit = process_q.front();
        process_q.pop();

        for (edge_iterator eit=vit->edges_begin(); eit!=vit->edges_end(); eit++) 
        {
            size_t targ = eit->target();
            vertex_iterator targ_vit = g.find_vertex(targ);
            if (targ_vit->property().removed==false)
            {
                targ_vit->property().degree--;
                if (targ_vit->property().degree < k) 
                {
                    targ_vit->property().removed = true;
                    process_q.push(targ_vit);
                    remove_cnt++;
                }
            }
        }

    }

    perf.stop(perf_group);
    return remove_cnt;
}  // end kcore
Ejemplo n.º 12
0
//==============================================================//
void output(graph_t& g)
{
    cout<<"kCore Results: \n";
    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++)
    {
        cout<<"== vertex "<<vit->id()<<": degree-"<<vit->property().degree
            <<" removed-";
        if (vit->property().removed) 
            cout<<"true\n";
        else
            cout<<"false\n";
    }
}
Ejemplo n.º 13
0
size_t parallel_kcore(graph_t& g, size_t k, unsigned threadnum, gBenchPerf_multi & perf, int perf_group)
{
    // initialize
    size_t remove_cnt=0;
    vector<vector<uint64_t> > global_input_tasks(threadnum);
    vector<vector<uint64_t> > global_output_tasks(threadnum*threadnum);
    
    for (vertex_iterator vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        size_t degree = vit->edges_size();
        vit->property().degree = degree;

        if (degree < k) 
        {
            global_input_tasks[vertex_distributor(vit->id(), threadnum)].push_back(vit->id());
            vit->property().removed = true;
            remove_cnt++;
        }
    }

    bool stop = false;
    #pragma omp parallel num_threads(threadnum) shared(stop,global_input_tasks,global_output_tasks) 
    {
        unsigned tid = omp_get_thread_num();
        vector<uint64_t> & input_tasks = global_input_tasks[tid];
        
        perf.open(tid, perf_group);
        perf.start(tid, perf_group);  
        while(!stop)
        {
            #pragma omp barrier
            // process local queue
            stop = true;
            
        
            for (unsigned i=0;i<input_tasks.size();i++)
            {
                uint64_t vid=input_tasks[i];
                vertex_iterator vit = g.find_vertex(vid);
                
                for (edge_iterator eit=vit->edges_begin();eit!=vit->edges_end();eit++)
                {
                    uint64_t dest_vid = eit->target();
                    vertex_iterator destvit = g.find_vertex(dest_vid);

                    if (destvit->property().removed==false)
                    {
                        unsigned oldval = __sync_fetch_and_sub(&(destvit->property().degree), 1);
                        if (oldval == k)
                        {
                            destvit->property().removed=true;
                            __sync_fetch_and_add(&remove_cnt, 1);
                            global_output_tasks[vertex_distributor(dest_vid,threadnum)+tid*threadnum].push_back(dest_vid);
                        }
                    }
                }
            }
            #pragma omp barrier
            input_tasks.clear();
            for (unsigned i=0;i<threadnum;i++)
            {
                if (global_output_tasks[i*threadnum+tid].size()!=0)
                {
                    stop = false;
                    input_tasks.insert(input_tasks.end(),
                            global_output_tasks[i*threadnum+tid].begin(),
                            global_output_tasks[i*threadnum+tid].end());
                    global_output_tasks[i*threadnum+tid].clear();
                }
            }
            #pragma omp barrier

        }
        perf.stop(tid, perf_group);
    }

    return remove_cnt;
}
Ejemplo n.º 14
0
void bc(graph_t& g, bool undirected,
        gBenchPerf_event & perf, int perf_group)
{
    typedef list<size_t> vertex_list_t;
    // initialization
    size_t vnum = g.num_vertices();

    vector<vertex_list_t> shortest_path_parents(vnum);
    vector<size_t> num_of_paths(vnum);
    vector<int8_t> depth_of_vertices(vnum); // 8 bits signed
    vector<double> centrality_update(vnum);

    double normalizer;
    normalizer = (undirected)? 2.0 : 1.0;

    perf.open(perf_group);
    perf.start(perf_group);


    vertex_iterator vit;
    for (vit=g.vertices_begin(); vit!=g.vertices_end(); vit++) 
    {
        size_t vertex_s = vit->id();
        stack<size_t> order_seen_stack;
        queue<size_t> BFS_queue;

        BFS_queue.push(vertex_s);

        for (size_t i=0;i<vnum;i++) 
        {
            shortest_path_parents[i].clear();

            num_of_paths[i] = (i==vertex_s) ? 1 : 0;
            depth_of_vertices[i] = (i==vertex_s) ? 0: -1;
            centrality_update[i] = 0;
        }

        // BFS traversal
        while (!BFS_queue.empty()) 
        {
            size_t v = BFS_queue.front();
            BFS_queue.pop();
            order_seen_stack.push(v);

            vertex_iterator vit = g.find_vertex(v);

            for (edge_iterator eit=vit->edges_begin(); eit!= vit->edges_end(); eit++) 
            {
                size_t w = eit->target();
                
                if (depth_of_vertices[w]<0) 
                {
                    BFS_queue.push(w);
                    depth_of_vertices[w] = depth_of_vertices[v] + 1;
                }

                if (depth_of_vertices[w] == (depth_of_vertices[v] + 1)) 
                {
                    num_of_paths[w] += num_of_paths[v];
                    shortest_path_parents[w].push_back(v);
                }
            }

        }

        // dependency accumulation
        while (!order_seen_stack.empty()) 
        {
            size_t w = order_seen_stack.top();
            order_seen_stack.pop();

            double coeff = (1+centrality_update[w])/(double)num_of_paths[w];
            vertex_list_t::iterator iter;
            for (iter=shortest_path_parents[w].begin(); 
                  iter!=shortest_path_parents[w].end(); iter++) 
            {
                size_t v=*iter;

                centrality_update[v] += (num_of_paths[v]*coeff);
            }

            if (w!=vertex_s) 
            {
                vertex_iterator vit = g.find_vertex(w);
                vit->property().BC += centrality_update[w]/normalizer;
            }
        }
    }

    perf.stop(perf_group);

    return;
}