/** * Copyright 2022 AntGroup CO., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include "olap/olap_on_disk.h" #include "tools/json.hpp" #include "./algo.h" using namespace lgraph_api; using namespace lgraph_api::olap; using json = nlohmann::json; class MyConfig : public ConfigBase { public: size_t num_iterations = 20; std::string name = std::string("pagerank"); void AddParameter(fma_common::Configuration & config) { ConfigBase::AddParameter(config); config.Add(num_iterations, "num_iterations", true) .Comment("the num_iterations of pagerank"); } void Print() { ConfigBase::Print(); std::cout << " name: " << name << std::endl; std::cout << " num_iterations: " << num_iterations << std::endl; } MyConfig(int &argc, char** &argv): ConfigBase(argc, argv) { fma_common::Configuration config; AddParameter(config); config.ExitAfterHelp(true); config.ParseAndFinalize(argc, argv); Print(); } }; int main(int argc, char** argv) { auto start_time = get_time(); MemUsage memUsage; memUsage.startMemRecord(); // prepare start_time = get_time(); MyConfig config(argc, argv); int num_iterations = config.num_iterations; OlapOnDisk graph; graph.Load(config); memUsage.print(); memUsage.reset(); auto prepare_cost = get_time() - start_time; printf("prepare_cost = %.2lf(s)\n", prepare_cost); // core start_time = get_time(); ParallelVector pr = graph.AllocVertexArray(); PageRankCore(graph, num_iterations, pr); auto all_vertices = graph.AllocVertexSubset(); all_vertices.Fill(); size_t max_pr_vi = graph.ProcessVertexActive([&](size_t vi) { return vi; }, all_vertices, 0, [&](size_t a, size_t b) { return pr[a] > pr[b] ? a : b; }); memUsage.print(); memUsage.reset(); auto core_cost = get_time() - start_time; printf("core_cost = %.2lf(s)\n", core_cost); // output start_time = get_time(); // TODO(any): if (config.id_mapping) { printf("max rank value is pr[%s] = %lf\n", graph.mapped_to_origin_[max_pr_vi].c_str(), pr[max_pr_vi]); } else { printf("max rank value is pr[%ld] = %lf\n", max_pr_vi, pr[max_pr_vi]); } auto output_cost = get_time() - start_time; printf("output_cost = %.2lf(s)\n", output_cost); printf("total_cost = %.2lf(s)\n", prepare_cost + core_cost + output_cost); printf("DONE."); return 0; }