• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/property_map/parallel/distributed_property_map.hpp>
16 #include <boost/graph/distributed/mpi_process_group.hpp>
17 #include <boost/graph/distributed/concepts.hpp>
18 #include <boost/graph/distributed/connected_components_parallel_search.hpp>
19 #include <boost/graph/distributed/connected_components.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
30 void
throw_exception(std::exception const & ex)31 boost::throw_exception(std::exception const& ex)
32 {
33   std::cout << ex.what() << std::endl;
34   abort();
35 }
36 #endif
37 
38 using namespace boost;
39 using boost::graph::distributed::mpi_process_group;
40 
41 typedef double time_type;
42 
get_time()43 inline time_type get_time()
44 {
45   return MPI_Wtime();
46 }
47 
print_time(time_type t)48 std::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 
55 void
test_filtered_rmat_cc(int n,int m,double a,double b,double c,double d)56 test_filtered_rmat_cc(int n, int m, double a, double b, double c, double d)
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.\n",
62                       n, m, a, b, c, d);
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         undirectedS> 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   time_type gen_start = get_time();
78   Graph g(RMATIter(pg, distrib, gen, n, m, a, b, c, d, true),
79           RMATIter(), n, pg, distrib);
80   time_type gen_end = get_time();
81   std::cout << "INFO: Graph Gen time: " << print_time(gen_end - gen_start) << std::endl;
82 
83   synchronize(g);
84 
85   if (id == 0) printf("INFO: Starting connected components.\n");
86 
87   std::vector<int> local_components_vec(num_vertices(g));
88   typedef iterator_property_map<std::vector<int>::iterator, property_map<Graph, vertex_index_t>::type> ComponentMap;
89   ComponentMap component(local_components_vec.begin(), get(vertex_index, g));
90 
91   time_type start = get_time();
92   int num_components = connected_components_ps(g, component);
93   time_type end = get_time();
94 
95   if (process_id(g.process_group()) == 0) {
96       std::cout << "INFO: Test Complete. components found = " << num_components
97                 << ", time = " << print_time(end - start) << "s." << std::endl;
98       printf("RESULT: %d %d %d %f %f %f %f %f\n",
99              num_processes(pg), n, m, a, b, c, d, end - start);
100   }
101 
102 }
103 
104 int
main(int argc,char * argv[])105 main(int argc, char* argv[])
106 {
107   mpi::environment env(argc, argv);
108 
109   if (argc < 7)
110     test_filtered_rmat_cc(40, 200, 0.58, 0.19, 0.19, 0.04);
111   else
112     test_filtered_rmat_cc(atoi(argv[1]), atoi(argv[2]),
113                           atof(argv[3]), atof(argv[4]),
114                           atof(argv[5]), atof(argv[6]));
115 
116   return 0;
117 }
118