]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/graph_parallel/test/mesh_generator_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / graph_parallel / test / mesh_generator_test.cpp
CommitLineData
7c673cae
FG
1// Copyright (C) 2004-2008 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: Douglas Gregor
8// Andrew Lumsdaine
9
10#include <boost/graph/use_mpi.hpp>
11#include <boost/config.hpp>
12#include <boost/throw_exception.hpp>
13#include <boost/graph/mesh_graph_generator.hpp>
1e59de90 14#include <boost/core/lightweight_test.hpp>
7c673cae
FG
15#include <boost/graph/distributed/adjacency_list.hpp>
16#include <boost/graph/distributed/mpi_process_group.hpp>
17#include <boost/graph/distributed/graphviz.hpp>
18#include <boost/graph/iteration_macros.hpp>
19#include <iostream>
20#include <sstream>
21#include <iomanip>
22#include <string>
1e59de90 23#include <boost/core/lightweight_test.hpp>
7c673cae
FG
24
25#ifdef BOOST_NO_EXCEPTIONS
26void
27boost::throw_exception(std::exception const& ex)
28{
29 std::cout << ex.what() << std::endl;
30 abort();
31}
32#endif
33
34using namespace boost;
35using boost::graph::distributed::mpi_process_group;
36
37/****************************************************************************
38 * Timing
39 ****************************************************************************/
40typedef double time_type;
41
42inline time_type get_time()
43{
44 return MPI_Wtime();
45}
46
47std::string print_time(time_type t)
48{
49 std::ostringstream out;
50 out << std::setiosflags(std::ios::fixed) << std::setprecision(2) << t;
51 return out.str();
52}
53
54/****************************************************************************
55 * Edge weight generator iterator *
56 ****************************************************************************/
57template<typename F>
58class generator_iterator
59{
60public:
61 typedef std::input_iterator_tag iterator_category;
62 typedef typename F::result_type value_type;
63 typedef const value_type& reference;
64 typedef const value_type* pointer;
65 typedef void difference_type;
66
67 explicit generator_iterator(const F& f = F()) : f(f) { value = this->f(); }
68
69 reference operator*() const { return value; }
70 pointer operator->() const { return &value; }
71
72 generator_iterator& operator++()
73 {
74 value = f();
75 return *this;
76 }
77
78 generator_iterator operator++(int)
79 {
80 generator_iterator temp(*this);
81 ++(*this);
82 return temp;
83 }
84
85 bool operator==(const generator_iterator& other) const
86 { return f == other.f; }
87
88 bool operator!=(const generator_iterator& other) const
89 { return !(*this == other); }
90
91private:
92 F f;
93 value_type value;
94};
95
96template<typename F>
97inline generator_iterator<F> make_generator_iterator(const F& f)
98{ return generator_iterator<F>(f); }
99
1e59de90 100int main(int argc, char* argv[])
7c673cae
FG
101{
102 mpi::environment env(argc, argv);
103
104 if (argc < 5) {
105 std::cerr << "Usage: mesh_generator_test <x> <y> <toroidal> <emit dot file>\n";
106 exit(-1);
107 }
108
109 int x(atoi(argv[1])), y(atoi(argv[2]));
110 bool toroidal(argv[3] == std::string("true"));
111 bool emit_dot_file(argv[4] == std::string("true"));
112
113 typedef adjacency_list<listS,
114 distributedS<mpi_process_group, vecS>,
115 undirectedS> Graph;
116
117 Graph g(mesh_iterator<Graph>(x, y, toroidal),
118 mesh_iterator<Graph>(),
119 x*y);
120
121 synchronize(g);
122
123 BGL_FORALL_VERTICES(v, g, Graph)
124 if (toroidal)
125 assert(out_degree(v, g) == 4);
126 else
127 assert(out_degree(v, g) >= 2 && out_degree(v, g) <= 4);
128
129 if ( emit_dot_file )
130 write_graphviz("mesh.dot", g);
131
1e59de90 132 return boost::report_errors();
7c673cae 133}