Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/memgraph
Submodule memgraph updated 501 files
11 changes: 11 additions & 0 deletions cpp/pagerank_module/algorithm/pagerank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <algorithm>
#include <future>
#include <numeric>
#include <unordered_map>

namespace pagerank_alg {

Expand Down Expand Up @@ -178,6 +179,16 @@ const std::vector<EdgePair> &PageRankGraph::GetOrderedEdges() const { return ord

std::uint64_t PageRankGraph::GetOutDegree(const std::uint64_t node_id) const { return out_degree_[node_id]; }

void PageRankGraph::ClearUnusedVectors() {
ordered_edges_.clear();
out_degree_.clear();
memgraph_to_id.clear();
memgraph_to_id = std::unordered_map<std::uint64_t, std::uint64_t>{};

ordered_edges_.shrink_to_fit();
out_degree_.shrink_to_fit();
}

std::vector<double> ParallelIterativePageRank(const PageRankGraph &graph, std::size_t max_iterations,
double damping_factor, double stop_epsilon, uint32_t number_of_threads) {
number_of_threads = std::min(number_of_threads, std::thread::hardware_concurrency());
Expand Down
2 changes: 2 additions & 0 deletions cpp/pagerank_module/algorithm/pagerank.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class PageRankGraph {
/// @return -- out degree of node node_id
std::uint64_t GetOutDegree(std::uint64_t node_id) const;

void ClearUnusedVectors();

private:
/// node_count equals number of nodes in graph
std::uint64_t node_count_;
Expand Down
2 changes: 2 additions & 0 deletions cpp/pagerank_module/pagerank_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void PagerankWrapper(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *resu
auto pageranks =
pagerank_alg::ParallelIterativePageRank(pagerank_graph, max_iterations, damping_factor, stop_epsilon, num_threads);

pagerank_graph.ClearUnusedVectors();
mgp_result_reserve(result, pagerank_graph.GetNodeCount());
for (std::uint64_t node_id = 0; node_id < pagerank_graph.GetNodeCount(); ++node_id) {
InsertPagerankRecord(memgraph_graph, result, memory, pagerank_graph.GetMemgraphNodeId(node_id),
pageranks[node_id]);
Expand Down
Loading