Skip to content

Commit

Permalink
Improve calculateQ efficiency in Louvain (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuan0322 committed Aug 10, 2021
1 parent 79ec800 commit 35b2fdf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion analytical_engine/apps/pregel/louvain/louvain.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ANALYTICAL_ENGINE_APPS_PREGEL_LOUVAIN_LOUVAIN_H_

#include <map>
#include <set>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -336,11 +337,13 @@ class PregelLouvain
const grape::IteratorPair<md_t*>& messages) {
auto& state = vertex.state();
edata_t k_i_in = state.internal_weight;
std::set<vid_t> source_ids;
for (auto& m : messages) {
if (m.community_id == state.community) {
k_i_in += vertex.get_edge_value(m.source_id);
source_ids.insert(m.source_id);
}
}
k_i_in += vertex.get_edge_values(source_ids);
edata_t sigma_tot = state.community_sigma_total;
edata_t m2 = getTotalEdgeWeight(context, vertex);
edata_t k_i = state.node_weight + state.internal_weight;
Expand Down
30 changes: 30 additions & 0 deletions analytical_engine/apps/pregel/louvain/louvain_vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#define ANALYTICAL_ENGINE_APPS_PREGEL_LOUVAIN_LOUVAIN_VERTEX_H_

#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -99,6 +100,35 @@ class LouvainVertex : public PregelVertex<FRAG_T, VD_T, MD_T> {
return edata_t();
}

edata_t get_edge_values(const std::set<vid_t>& dst_ids) {
edata_t ret = 0;
if (!this->use_fake_edges()) {
for (auto& edge : this->incoming_edges()) {
auto gid = this->fragment_->Vertex2Gid(edge.get_neighbor());
if (dst_ids.find(gid) != dst_ids.end()) {
ret += static_cast<edata_t>(edge.get_data());
}
}
for (auto& edge : this->outgoing_edges()) {
auto gid = this->fragment_->Vertex2Gid(edge.get_neighbor());
if (dst_ids.find(gid) != dst_ids.end()) {
ret += static_cast<edata_t>(edge.get_data());
}
}
} else {
auto edges = this->fake_edges();
for (auto gid : dst_ids) {
if (edges.find(gid) != edges.end()) {
ret += edges.at(gid);
} else {
LOG(ERROR) << "Warning: Cannot find a edge from " << this->id()
<< " to " << gid;
}
}
}
return ret;
}

void set_fake_edges(std::map<vid_t, edata_t>&& edges) {
state_t& ref_state = this->state();
ref_state.fake_edges = std::move(edges);
Expand Down

0 comments on commit 35b2fdf

Please sign in to comment.