distributed_rmat_cc_ps.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/property_map/parallel/distributed_property_map.hpp>
  13. #include <boost/graph/distributed/mpi_process_group.hpp>
  14. #include <boost/graph/distributed/concepts.hpp>
  15. #include <boost/graph/distributed/connected_components_parallel_search.hpp>
  16. #include <boost/graph/distributed/connected_components.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_cc(int n, int m, double a, double b, double c, double d)
  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.\n",
  51. n, m, a, b, c, d);
  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. undirectedS> 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. time_type gen_start = get_time();
  62. Graph g(RMATIter(pg, distrib, gen, n, m, a, b, c, d, true),
  63. RMATIter(), n, pg, distrib);
  64. time_type gen_end = get_time();
  65. std::cout << "INFO: Graph Gen time: " << print_time(gen_end - gen_start) << std::endl;
  66. synchronize(g);
  67. if (id == 0) printf("INFO: Starting connected components.\n");
  68. std::vector<int> local_components_vec(num_vertices(g));
  69. typedef iterator_property_map<std::vector<int>::iterator, property_map<Graph, vertex_index_t>::type> ComponentMap;
  70. ComponentMap component(local_components_vec.begin(), get(vertex_index, g));
  71. time_type start = get_time();
  72. int num_components = connected_components_ps(g, component);
  73. time_type end = get_time();
  74. if (process_id(g.process_group()) == 0) {
  75. std::cout << "INFO: Test Complete. components found = " << num_components
  76. << ", time = " << print_time(end - start) << "s." << std::endl;
  77. printf("RESULT: %d %d %d %f %f %f %f %f\n",
  78. num_processes(pg), n, m, a, b, c, d, end - start);
  79. }
  80. }
  81. int
  82. main(int argc, char* argv[])
  83. {
  84. mpi::environment env(argc, argv);
  85. if (argc < 7)
  86. test_filtered_rmat_cc(40, 200, 0.58, 0.19, 0.19, 0.04);
  87. else
  88. test_filtered_rmat_cc(atoi(argv[1]), atoi(argv[2]),
  89. atof(argv[3]), atof(argv[4]),
  90. atof(argv[5]), atof(argv[6]));
  91. return 0;
  92. }