-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathadjlist_remove_test.cpp
More file actions
146 lines (119 loc) · 4.41 KB
/
Copy pathadjlist_remove_test.cpp
File metadata and controls
146 lines (119 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2004 The Trustees of Indiana University.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Authors: Douglas Gregor
// Andrew Lumsdaine
#include <boost/graph/use_mpi.hpp>
#include <boost/config.hpp>
#include <boost/throw_exception.hpp>
#include <boost/graph/distributed/adjacency_list.hpp>
#include <boost/graph/distributed/mpi_process_group.hpp>
#include <boost/graph/parallel/distribution.hpp>
#include <iostream>
#include <cassert>
#include <boost/core/lightweight_test.hpp>
#ifdef BOOST_NO_EXCEPTIONS
void
boost::throw_exception(std::exception const& ex)
{
std::cout << ex.what() << std::endl;
abort();
}
#endif
using namespace boost;
using boost::graph::distributed::mpi_process_group;
void test_bidirectional_graph()
{
typedef adjacency_list<listS, distributedS<mpi_process_group, vecS>,
bidirectionalS> Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef std::pair<std::size_t, std::size_t> E;
E edges[3] = { E(0,3), E(1,4), E(2,5) };
Graph g(&edges[0], &edges[0] + 3, 6);
assert(num_processes(g.process_group()) == 2);
if (process_id(g.process_group()) == 0)
std::cerr << "Testing bidirectional graph edge removal...";
synchronize(g.process_group());
graph_traits<Graph>::vertex_iterator vi = vertices(g).first;
Vertex u = *vi++;
Vertex v = *vi++;
Vertex w = *vi++;
BOOST_TEST(vi == vertices(g).second);
BOOST_TEST((process_id(g.process_group()) == 0 && out_degree(u, g) == 1)
|| (process_id(g.process_group()) == 1 && in_degree(u, g) == 1));
BOOST_TEST((process_id(g.process_group()) == 0 && out_degree(v, g) == 1)
|| (process_id(g.process_group()) == 1 && in_degree(v, g) == 1));
BOOST_TEST((process_id(g.process_group()) == 0 && out_degree(w, g) == 1)
|| (process_id(g.process_group()) == 1 && in_degree(w, g) == 1));
// Remove edges
if (process_id(g.process_group()) == 0) {
remove_edge(*out_edges(u, g).first, g);
remove_edge(*out_edges(w, g).first, g);
} else {
remove_edge(*in_edges(v, g).first, g);
remove_edge(*in_edges(w, g).first, g);
}
synchronize(g);
BOOST_TEST(num_edges(g) == 0);
BOOST_TEST(out_degree(u, g) == 0);
BOOST_TEST(out_degree(v, g) == 0);
BOOST_TEST(out_degree(w, g) == 0);
BOOST_TEST(in_degree(u, g) == 0);
BOOST_TEST(in_degree(v, g) == 0);
BOOST_TEST(in_degree(w, g) == 0);
if (process_id(g.process_group()) == 0) std::cerr << "OK.\n";
}
void test_undirected_graph()
{
typedef adjacency_list<listS, distributedS<mpi_process_group, vecS>,
undirectedS> Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
typedef std::pair<std::size_t, std::size_t> E;
E the_edges[3] = { E(0,3), E(1,4), E(2,5) };
Graph g(&the_edges[0], &the_edges[0] + 3, 6);
assert(num_processes(g.process_group()) == 2);
if (process_id(g.process_group()) == 0)
std::cerr << "Testing undirected graph edge removal...";
synchronize(g.process_group());
graph_traits<Graph>::vertex_iterator vi = vertices(g).first;
Vertex u = *vi++;
Vertex v = *vi++;
Vertex w = *vi++;
BOOST_TEST(vi == vertices(g).second);
BOOST_TEST(degree(u, g) == 1);
BOOST_TEST(degree(v, g) == 1);
BOOST_TEST(degree(w, g) == 1);
// Remove edges
if (process_id(g.process_group()) == 0) {
BOOST_TEST(num_edges(g) == 3);
remove_edge(*out_edges(u, g).first, g);
remove_edge(*out_edges(w, g).first, g);
} else {
BOOST_TEST(num_edges(g) == 0);
remove_edge(*in_edges(v, g).first, g);
remove_edge(*in_edges(w, g).first, g);
}
synchronize(g);
if (num_edges(g) > 0) {
Edge e = *edges(g).first;
std::cerr << "#" << process_id(g.process_group()) << ": extra edge! ("
<< local(source(e, g)) << "@" << owner(source(e, g))
<< ", "
<< local(target(e, g)) << "@" << owner(target(e, g))
<< ")\n";
}
BOOST_TEST(num_edges(g) == 0);
BOOST_TEST(degree(u, g) == 0);
BOOST_TEST(degree(v, g) == 0);
BOOST_TEST(degree(w, g) == 0);
if (process_id(g.process_group()) == 0) std::cerr << "OK.\n";
}
int main(int argc, char** argv)
{
boost::mpi::environment env(argc, argv);
test_bidirectional_graph();
test_undirected_graph();
return boost::report_errors();
}