Commit 5cd8d5c6 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Avoid unnecessary testing for valid vertices in unfiltered graphs in parallel loops

parent 8c8323af
......@@ -48,8 +48,8 @@ void normalize_betweenness(const Graph& g,
schedule(runtime) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
put(vertex_betweenness, v, vfactor * get(vertex_betweenness, v));
}
......
......@@ -72,17 +72,14 @@ struct get_closeness
for (i = 0; i < N; ++i)
{
vertex_t v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
unchecked_vector_property_map<val_type,VertexIndex>
dist_map(vertex_index, num_vertices(g));
for (int j = 0; j < N; ++j)
{
if (vertex(j, g) != graph_traits<Graph>::null_vertex())
dist_map[vertex(j, g)] = numeric_limits<val_type>::max();
}
for (auto u : vertices_range(g))
dist_map[u] = numeric_limits<val_type>::max();
dist_map[v] = 0;
......
......@@ -53,7 +53,7 @@ struct get_eigentrust
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c_type sum = 0;
......@@ -77,7 +77,7 @@ struct get_eigentrust
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c_sum[v] = 0;
......@@ -92,8 +92,8 @@ struct get_eigentrust
schedule(runtime) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
t[v] = 1.0/V;
}
......@@ -108,7 +108,7 @@ struct get_eigentrust
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
t_temp[v] = 0;
......@@ -140,7 +140,7 @@ struct get_eigentrust
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
t[v] = t_temp[v];
}
......
......@@ -64,7 +64,7 @@ struct get_eigenvector
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c_temp[v] = 0;
......@@ -87,7 +87,7 @@ struct get_eigenvector
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c_temp[v] /= norm;
delta += abs(c_temp[v] - c[v]);
......@@ -108,7 +108,7 @@ struct get_eigenvector
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c[v] = c_temp[v];
}
......
......@@ -58,7 +58,7 @@ struct get_hits
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
x[v] = 1.0 / V;
y[v] = 1.0 / V;
......@@ -76,7 +76,7 @@ struct get_hits
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
x_temp[v] = 0;
......@@ -109,7 +109,7 @@ struct get_hits
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
x_temp[v] /= x_norm;
y_temp[v] /= y_norm;
......@@ -131,7 +131,7 @@ struct get_hits
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
x[v] = x_temp[v];
y[v] = y_temp[v];
......
......@@ -60,7 +60,7 @@ struct get_katz
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c_temp[v] = get(beta, v);
......@@ -81,7 +81,7 @@ struct get_katz
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
delta += abs(c_temp[v] - c[v]);
}
......@@ -99,7 +99,7 @@ struct get_katz
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
c_temp[v] = c[v];
}
......
......@@ -47,7 +47,7 @@ struct get_pagerank
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
put(deg, v, 0);
for (const auto& e : out_edges_range(v, g))
......@@ -65,7 +65,7 @@ struct get_pagerank
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
rank_type r = 0;
for (const auto& e : in_or_out_edges_range(v, g))
......@@ -95,7 +95,7 @@ struct get_pagerank
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
put(rank, v, get(r_temp, v));
}
......
......@@ -108,7 +108,7 @@ struct get_trust_transitivity
for (i = 0; i < N; ++i)
{
vertex_t v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
t[v].resize((source == -1 && target == -1) ? N : 1);
}
......@@ -118,7 +118,7 @@ struct get_trust_transitivity
for (i = (target == -1) ? 0 : target; i < N; ++i)
{
vertex_t tgt = vertex(i, g);
if (tgt == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(tgt, g))
continue;
// mark the sources
......@@ -212,7 +212,7 @@ struct get_trust_transitivity
for (j = 0; j < N2; ++j)
{
vertex_t src = vertex(j, g);
if (src == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(src, g))
continue;
t_type weight = dist_map[src];
sum_w[src] += weight;
......@@ -226,7 +226,7 @@ struct get_trust_transitivity
for (j = 0; j < N2; ++j)
{
vertex_t src = vertex(j, g);
if (src == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(src, g))
continue;
size_t tidx = (target == -1) ? vertex_index[tgt] : 0;
if (sum_w[src] > 0)
......
......@@ -102,8 +102,8 @@ struct get_global_clustering
schedule(runtime) if (N > 100) reduction(+:triangles, n)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
#ifdef USING_OPENMP
......@@ -125,8 +125,8 @@ struct get_global_clustering
schedule(runtime) if (N > 100) reduction(+:cerr)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
#ifdef USING_OPENMP
......@@ -167,8 +167,8 @@ struct set_clustering_to_property
schedule(runtime) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
#ifdef USING_OPENMP
......
......@@ -125,7 +125,7 @@ struct get_extended_clustering
for (i = 0; i < N; ++i)
{
vertex_t v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
// We must disconsider paths through the original vertex
......
......@@ -277,7 +277,7 @@ void get_sig(Graph& g, std::vector<size_t>& sig)
sig.resize(is_directed::apply<Graph>::type::value ? 2 * N : N);
for (size_t i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
auto v = vertex(i, g);
sig[i] = out_degree(v, g);
if(is_directed::apply<Graph>::type::value)
sig[i + N] = in_degreeS()(v, g);
......@@ -363,7 +363,7 @@ struct get_all_motifs
subgraphs;
typename graph_traits<Graph>::vertex_descriptor v =
(p < 1) ? V[i] : vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
typename wrap_undirected::apply<Graph>::type ug(g);
......
......@@ -2680,7 +2680,7 @@ void move_sweep(vector<BlockState>& states, vector<MEntries>& m_entries_r,
for (i = 0; i < N; ++i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
for (auto e : out_edges_range(v, g))
E += eweight[e];
......
......@@ -107,7 +107,7 @@ struct get_communities
for (i = 0; i < NV; ++i)
{
vertex_t v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
size_t new_s;
......@@ -209,7 +209,7 @@ struct get_communities
for (i = 0; i < NV; ++i)
{
vertex_t v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
temp_s[v] = s[v];
}
......
......@@ -54,8 +54,8 @@ struct get_assortativity_coefficient
schedule(runtime) if (N > 100) reduction(+:e_kk, n_edges)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
val_t k1 = deg(v, g);
......@@ -91,8 +91,8 @@ struct get_assortativity_coefficient
reduction(+:err)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
val_t k1 = deg(v, g);
......@@ -135,8 +135,8 @@ struct get_scalar_assortativity_coefficient
schedule(runtime) if (N > 100) reduction(+:e_xy,n_edges,a,b,da,db)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
double k1 = double(deg(v, g));
......@@ -172,8 +172,8 @@ struct get_scalar_assortativity_coefficient
reduction(+:err)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
double k1 = double(deg(v, g));
......
......@@ -70,8 +70,8 @@ struct get_avg_correlation
firstprivate(s_sum, s_sum2, s_count) schedule(runtime) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
auto v = vertex(i, g);
if (!is_valid_vertex(v, g))
continue;
put_point(v, deg1, deg2, g, weight, s_sum, s_sum2, s_count);
}
......
......@@ -65,7 +65,7 @@ struct get_correlation_histogram
{
typename graph_traits<Graph>::vertex_descriptor v =
vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
put_point(v, deg1, deg2, g, weight, s_hist);
}
......
......@@ -137,7 +137,7 @@ struct get_geometric
schedule(runtime) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
auto v = vertex(i, g);
get_box(points[i], w, box, ranges, periodic_boundary);
for (int k = 0; k < power(3, int(box.size())); ++k)
......
......@@ -87,7 +87,7 @@ struct clear_vertices
for (int i = N - 1; i >= 0; --i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
if (!is_valid_vertex(v, g))
continue;
remove_vertex(v, g);
}
......
......@@ -574,8 +574,10 @@ out_edges(Vertex v, const adj_list<Vertex>& g)
{
typedef typename adj_list<Vertex>::out_edge_iterator ei_t;
typedef typename adj_list<Vertex>::make_out_edge mk_edge;
return std::make_pair(ei_t(g._out_edges[v].begin(), mk_edge(v)),
ei_t(g._out_edges[v].end(), mk_edge(v)));
auto& edges = g._out_edges[v];
auto mke = mk_edge(v);
return std::make_pair(ei_t(edges.begin(), mke),
ei_t(edges.end(), mke));
}
template <class Vertex>
......@@ -586,8 +588,10 @@ in_edges(Vertex v, const adj_list<Vertex>& g)
{
typedef typename adj_list<Vertex>::in_edge_iterator ei_t;
typedef typename adj_list<Vertex>::make_in_edge mk_edge;
return std::make_pair(ei_t(g._in_edges[v].begin(), mk_edge(v)),
ei_t(g._in_edges[v].end(), mk_edge(v)));
auto& edges = g._in_edges[v];
auto mke = mk_edge(v);
return std::make_pair(ei_t(edges.begin(), mke),
ei_t(edges.end(), mke));
}
template <class Vertex>
......@@ -597,8 +601,9 @@ std::pair<typename adj_list<Vertex>::adjacency_iterator,
adjacent_vertices(Vertex v, const adj_list<Vertex>& g)
{
typedef typename adj_list<Vertex>::adjacency_iterator ai_t;
return std::make_pair(ai_t(g._out_edges[v].begin()),
ai_t(g._out_edges[v].end()));
auto& edges = g._out_edges[v];
return std::make_pair(ai_t(edges.begin()),
ai_t(edges.end()));
}
template <class Vertex>
......
......@@ -75,7 +75,7 @@ struct copy_vertex_property_dispatch
for (i = 0; i < N; ++i)
{
auto v = vertex(i, src);
if (v == graph_traits<GraphSrc>::null_vertex())
if (!is_valid_vertex(v, src))
continue;
auto new_v = vertex(index_map[i], tgt);
p_tgt[new_v] = p_src[v];
......@@ -146,7 +146,7 @@ struct copy_edge_property_dispatch
for (i = 0; i < N; ++i)
{
auto v = vertex(i, src);
if (v == graph_traits<GraphSrc>::null_vertex())
if (!is_valid_vertex(v, src))
continue;
for (auto e : out_edges_range(v, src))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment