25 #include <dolfin/common/MPI.h> 56 node(
const typename std::vector<T>::const_iterator& begin_it,
57 const typename std::vector<T>::const_iterator& end_it)
58 : begin_edge(begin_it), end_edge(end_it) {}
61 typename std::vector<T>::const_iterator
begin()
const 62 {
return begin_edge; }
65 typename std::vector<T>::const_iterator
end()
const 70 {
return (end_edge - begin_edge); }
74 {
return *(begin_edge + i); }
78 typename std::vector<T>::const_iterator begin_edge;
79 typename std::vector<T>::const_iterator end_edge;
89 CSRGraph(MPI_Comm mpi_comm,
const std::vector<X>& graph)
90 : _node_offsets(1, 0), _mpi_comm(mpi_comm)
94 for (
auto const &
edges : graph)
95 num_edges +=
edges.size();
98 _node_offsets.reserve(graph.size());
99 _edges.reserve(num_edges);
102 for (
auto const &node_edges : graph)
104 _edges.insert(_edges.end(), node_edges.begin(), node_edges.end());
105 _node_offsets.push_back(_node_offsets.back() + node_edges.size());
109 calculate_node_distribution();
113 CSRGraph(MPI_Comm mpi_comm,
const T* xadj,
const T* adjncy,
114 std::size_t n) : _mpi_comm(mpi_comm)
116 _node_offsets.assign(xadj, xadj + n + 1);
117 _edges.assign(adjncy, adjncy + xadj[n]);
120 calculate_node_distribution();
141 return node(_edges.begin() + _node_offsets[i],
142 _edges.begin() + _node_offsets[i + 1]);
149 {
return _node_offsets; }
154 {
return _node_offsets; }
158 {
return _edges.size(); }
163 dolfin_assert(i <
size());
164 return (_node_offsets[i + 1] - _node_offsets[i]);
169 {
return _node_offsets.size() - 1; }
173 {
return _node_distribution.back(); }
177 {
return _node_distribution; }
181 {
return _node_distribution; }
186 void calculate_node_distribution()
189 const T num_nodes =
size();
192 _node_distribution.insert(_node_distribution.begin(), 0);
193 for (std::size_t i = 1; i != _node_distribution.size(); ++i)
194 _node_distribution[i] += _node_distribution[i - 1];
199 std::vector<T> _edges;
203 std::vector<T> _node_offsets;
208 std::vector<T> _node_distribution;
const std::vector< T > & nodes() const
Definition: CSRGraph.h:148
std::size_t size() const
Number of local nodes in graph.
Definition: CSRGraph.h:168
std::size_t num_edges() const
Number of local edges in graph.
Definition: CSRGraph.h:157
const std::vector< T > & edges() const
Definition: CSRGraph.h:128
std::vector< T > & node_distribution()
Return number of nodes (offset) on each process (non-const)
Definition: CSRGraph.h:180
std::vector< T > & edges()
Definition: CSRGraph.h:133
std::vector< T >::const_iterator begin() const
Iterator pointing to beginning of edges.
Definition: CSRGraph.h:61
CSRGraph()=delete
Empty CSR Graph.
~CSRGraph()
Destructor.
Definition: CSRGraph.h:124
std::size_t size() const
Number of outgoing edges for this node.
Definition: CSRGraph.h:69
std::vector< T > & nodes()
Definition: CSRGraph.h:153
const std::vector< T > & node_distribution() const
Return number of nodes (offset) on each process.
Definition: CSRGraph.h:176
Definition: CSRGraph.h:51
T size_global() const
Total (global) number of nodes in parallel graph.
Definition: CSRGraph.h:172
std::size_t num_edges(std::size_t i) const
Number of edges from node i.
Definition: CSRGraph.h:161
static void all_gather(MPI_Comm comm, const std::vector< T > &in_values, std::vector< T > &out_values)
Definition: MPI.h:708
node(const typename std::vector< T >::const_iterator &begin_it, const typename std::vector< T >::const_iterator &end_it)
Node object, listing a set of outgoing edges.
Definition: CSRGraph.h:56
const T & operator[](std::size_t i) const
Access outgoing edge i of this node.
Definition: CSRGraph.h:73
CSRGraph(MPI_Comm mpi_comm, const std::vector< X > &graph)
Definition: CSRGraph.h:89
const node operator[](std::size_t i) const
Definition: CSRGraph.h:139
CSRGraph(MPI_Comm mpi_comm, const T *xadj, const T *adjncy, std::size_t n)
Create a CSR Graph from ParMETIS style adjacency lists.
Definition: CSRGraph.h:113
Compressed Sparse Row graph.
Definition: CSRGraph.h:44
std::vector< T >::const_iterator end() const
Iterator pointing to beyond end of edges.
Definition: CSRGraph.h:65