1 // Copyright (C) 2007 Trustees of Indiana University
3 // Authors: Douglas Gregor
6 // Use, modification and distribution is subject to the Boost Software
7 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/mpi/graph_communicator.hpp>
11 namespace boost
{ namespace mpi
{
13 // Incidence Graph requirements
14 std::pair
<detail::comm_out_edge_iterator
, detail::comm_out_edge_iterator
>
15 out_edges(int vertex
, const graph_communicator
& comm
)
17 int nneighbors
= out_degree(vertex
, comm
);
18 shared_array
<int> neighbors(new int[nneighbors
]);
19 BOOST_MPI_CHECK_RESULT(MPI_Graph_neighbors
,
20 ((MPI_Comm
)comm
, vertex
, nneighbors
, neighbors
.get()));
21 return std::make_pair(detail::comm_out_edge_iterator(vertex
, neighbors
, 0),
22 detail::comm_out_edge_iterator(vertex
, neighbors
,
26 int out_degree(int vertex
, const graph_communicator
& comm
)
29 BOOST_MPI_CHECK_RESULT(MPI_Graph_neighbors_count
,
30 ((MPI_Comm
)comm
, vertex
, &nneighbors
));
34 // Adjacency Graph requirements
35 std::pair
<detail::comm_adj_iterator
, detail::comm_adj_iterator
>
36 adjacent_vertices(int vertex
, const graph_communicator
& comm
)
38 int nneighbors
= out_degree(vertex
, comm
);
39 shared_array
<int> neighbors(new int[nneighbors
]);
40 BOOST_MPI_CHECK_RESULT(MPI_Graph_neighbors
,
41 ((MPI_Comm
)comm
, vertex
, nneighbors
, neighbors
.get()));
42 return std::make_pair(detail::comm_adj_iterator(neighbors
, 0),
43 detail::comm_adj_iterator(neighbors
, nneighbors
));
46 // Edge List Graph requirements
47 std::pair
<detail::comm_edge_iterator
, detail::comm_edge_iterator
>
48 edges(const graph_communicator
& comm
);
50 std::pair
<detail::comm_edge_iterator
, detail::comm_edge_iterator
>
51 edges(const graph_communicator
& comm
)
54 BOOST_MPI_CHECK_RESULT(MPI_Graphdims_get
, ((MPI_Comm
)comm
, &nnodes
, &nedges
));
56 shared_array
<int> indices(new int[nnodes
]);
57 shared_array
<int> edges(new int[nedges
]);
58 BOOST_MPI_CHECK_RESULT(MPI_Graph_get
,
59 ((MPI_Comm
)comm
, nnodes
, nedges
,
60 indices
.get(), edges
.get()));
61 return std::make_pair(detail::comm_edge_iterator(indices
, edges
),
62 detail::comm_edge_iterator(nedges
));
66 int num_edges(const graph_communicator
& comm
)
69 BOOST_MPI_CHECK_RESULT(MPI_Graphdims_get
, ((MPI_Comm
)comm
, &nnodes
, &nedges
));
73 } } // end namespace boost::mpi