• 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   mpi_process_group::process_id_type 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   parallel::variant_distribution<mpi_process_group> distrib
65     = parallel::block(pg, n);
66 
67   typedef adjacency_list<vecS,
68         distributedS<mpi_process_group, vecS>,
69         undirectedS> Graph;
70 
71   typedef keep_local_edges<parallel::variant_distribution<mpi_process_group>,
72                            mpi_process_group::process_id_type>
73     EdgeFilter;
74 
75   typedef unique_rmat_iterator<rand48, Graph, EdgeFilter>
76     RMATIter;
77 
78   if (id == 0) printf("INFO: Generating graph.\n");
79 
80   rand48 gen;
81   Graph g(RMATIter(gen, n, m, a, b, c, d, true, EdgeFilter(distrib, id)),
82           RMATIter(), n, pg, distrib);
83 
84   synchronize(g);
85 
86   if (id == 0) printf("INFO: Starting connected components.\n");
87 
88   std::vector<int> local_components_vec(num_vertices(g));
89   typedef iterator_property_map<std::vector<int>::iterator, property_map<Graph, vertex_index_t>::type> ComponentMap;
90   ComponentMap component(local_components_vec.begin(), get(vertex_index, g));
91 
92   time_type start = get_time();
93   int num_components = connected_components(g, component);
94   time_type end = get_time();
95 
96   if (process_id(g.process_group()) == 0) {
97       std::cout << "INFO: Test Complete. components found = " << num_components
98                 << ", time = " << print_time(end - start) << "s." << std::endl;
99       printf("RESULT: %d %d %d %f %f %f %f %f\n",
100              num_processes(pg), n, m, a, b, c, d, end - start);
101   }
102 
103 }
104 
105 int
main(int argc,char * argv[])106 main(int argc, char* argv[])
107 {
108   mpi::environment env(argc, argv);
109 
110   if (argc < 7)
111     test_filtered_rmat_cc(40, 200, 0.58, 0.19, 0.19, 0.04);
112   else
113     test_filtered_rmat_cc(atoi(argv[1]), atoi(argv[2]),
114                           atof(argv[3]), atof(argv[4]),
115                           atof(argv[5]), atof(argv[6]));
116 
117   return 0;
118 }
119