]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/graph_parallel/test/distributed_rmat_pagerank.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / graph_parallel / test / distributed_rmat_pagerank.cpp
CommitLineData
7c673cae
FG
1// Copyright (C) 2006 The Trustees of Indiana University.
2
3// Use, modification and distribution is subject to the Boost Software
4// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7// Authors: Brian Barrett
8// Nick Edmonds
9// Andrew Lumsdaine
10
11#include <boost/graph/use_mpi.hpp>
12#include <boost/config.hpp>
13#include <boost/throw_exception.hpp>
14#include <boost/graph/distributed/adjacency_list.hpp>
15#include <boost/graph/distributed/compressed_sparse_row_graph.hpp>
16#include <boost/property_map/parallel/distributed_property_map.hpp>
17#include <boost/graph/distributed/mpi_process_group.hpp>
18#include <boost/graph/distributed/concepts.hpp>
19#include <boost/graph/distributed/page_rank.hpp>
20#include <boost/graph/rmat_graph_generator.hpp>
21#include <boost/random/linear_congruential.hpp>
22#include <boost/graph/graphviz.hpp>
23#include <boost/property_map/vector_property_map.hpp>
24
25#include <iostream>
26#include <cstdlib>
27#include <iomanip>
28
29#ifdef BOOST_NO_EXCEPTIONS
30void
31boost::throw_exception(std::exception const& ex)
32{
33 std::cout << ex.what() << std::endl;
34 abort();
35}
36#endif
37
38using namespace boost;
39using boost::graph::distributed::mpi_process_group;
40
41typedef double time_type;
42
43inline time_type get_time()
44{
45 return MPI_Wtime();
46}
47
48std::string print_time(time_type t)
49{
50 std::ostringstream out;
51 out << std::setiosflags(std::ios::fixed) << std::setprecision(2) << t;
52 return out.str();
53}
54
55void
56test_filtered_rmat_pagerank(int n, int m, double a, double b, double c, double d, int iters)
57{
58 mpi_process_group pg;
59 std::size_t id = process_id(pg);
60
61 if (id == 0) printf("INFO: Params: n=%d, m=%d, a=%f, b=%f, c=%f, d=%f, iters=%d.\n",
62 n, m, a, b, c, d, iters);
63
64 typedef parallel::variant_distribution<mpi_process_group> Distribution;
65 Distribution distrib = parallel::block(pg, n);
66
67 typedef adjacency_list<vecS,
68 distributedS<mpi_process_group, vecS>,
69 bidirectionalS> Graph;
70
71 typedef scalable_rmat_iterator<mpi_process_group, Distribution, rand48, Graph>
72 RMATIter;
73
74 if (id == 0) printf("INFO: Generating graph.\n");
75
76 rand48 gen;
77 Graph g(RMATIter(pg, distrib, gen, n, m, a, b, c, d, true),
78 RMATIter(), n, pg, distrib);
79
80 synchronize(g);
81
82 if (id == 0) printf("INFO: Starting PageRank.\n");
83
84 std::vector<double> ranks(num_vertices(g));
85
86 time_type start = get_time();
87 page_rank(g, make_iterator_property_map(ranks.begin(), get(boost::vertex_index, g)),
88 graph::n_iterations(iters), 0.85, n);
89 time_type end = get_time();
90
91 if (process_id(g.process_group()) == 0) {
92 std::cout << "INFO: Test Complete. time = " <<
93 print_time(end - start) << "s." << std::endl;
94 printf("RESULT: %d %d %d %f %f %f %f %f\n",
95 num_processes(pg), n, m, a, b, c, d, end - start);
96 }
97
98}
99
100int
101main(int argc, char* argv[])
102{
103 mpi::environment env(argc, argv);
104
105 if (argc < 8)
106 test_filtered_rmat_pagerank(40, 200, 0.58, 0.19, 0.19, 0.04, 10);
107 else
108 test_filtered_rmat_pagerank(atoi(argv[1]), atoi(argv[2]), atof(argv[3]),
109 atof(argv[4]), atof(argv[5]), atof(argv[6]),
110 atoi(argv[7]));
111
112 return 0;
113}