distributed_rmat_pagerank.cpp 3.2 KB

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