ug4
parallel_matrix_boost.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022: G-CSC, Goethe University Frankfurt
3  * Author: Felix Salfelder, 2022
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef UG_PARALLEL_MATRIX_BOOST_H
34 #define UG_PARALLEL_MATRIX_BOOST_H
35 #ifdef UG_PARALLEL
39 
40 
41 namespace boost{
42 
43 template <class T> struct graph_traits<ug::BGLParallelMatrix<ug::ParallelMatrix<T>>>{
46  typedef typename type::edge edge_descriptor;
47  typedef directed_tag directed_category;
51  typedef disallow_parallel_edge_tag edge_parallel_category;
53  typedef int degree_size_type;
54  typedef int vertices_size_type;
55  //typedef typename ug::SparseMatrix<T>::const_row_iterator adjacency_iterator;
56 };
57 
58 template<class T>
59 std::pair<typename ug::BGLParallelMatrix<T>::vertex_iterator,
61  ug::BGLParallelMatrix<T> const& M)
62 {
63  auto b = M.begin_vertices();
64  auto e = M.end_vertices();
65 
66  return std::make_pair(b,e);
67 }
68 
69 #if 0
71 {
72  return x.owner();
73 }
74 
76 {
77  return x.local();
78 }
79 #else
80 // not needed.
81 using ug::detail::owner;
82 using ug::detail::local;
83 #endif
84 
85 template<class T>
87 {
88 // return M.out_degree(v);
89  incomplete();
90  return 17;
91 }
92 
93 template<class T>
96 {
97  return e.source();
98 }
99 
100 template<class T>
103 {
104  return e.target();
105 }
106 
107 template<class T>
109 {
110  incomplete();
111  return 0;
112 }
113 
114 template<class T>
115 inline SM_edge_weight_map<T>
116 //inline typename property_map<ug::SparseMatrix<T>, edge_weight_t>::type
117 get(edge_weight_t, ug::BGLParallelMatrix<T> const & g) {
118  incomplete();
119 // return SM_edge_weight_map<T>(g);
120 }
121 
122 template<class T>
123 inline std::pair<typename ug::BGLParallelMatrix<T>::out_edge_iterator,
127  ug::BGLParallelMatrix<T> const& M)
128 {
129  auto l = local(v);
130 // auto o = owner(v);
131 
132  auto b = M.begin_out_edges(l);
133  auto e = M.end_out_edges(l);
134 
135  return std::make_pair(b, e);
136 }
137 
138 template<class T>
139 inline std::pair<typename ug::BGLParallelMatrix<T>::adjacency_iterator,
143  ug::BGLParallelMatrix<T> const& M)
144 {
145  auto l = local(v);
146  auto b = M.begin_adjacent_vertices(l);
147  auto e = M.end_adjacent_vertices(l);
148 
149  return std::make_pair(b,e);
150 }
151 
152 template<class T>
154  : public put_get_helper<size_t, bglp_matrix_index_map<T> > { //
155 public:
156  typedef size_t vertex_index_type;
157  typedef size_t vertex_descriptor;
158  typedef readable_property_map_tag category;
162 
164  }
165  bglp_matrix_index_map(ug::SparseMatrix<T>const&, boost::vertex_index_t) { untested();
166  }
167  template<class X>
169  }
170  template <class T_>
171  value_type operator[](T_ x) const {
172  return x.local();
173  }
174  value_type operator[](int x) const {
175  return x;
176  }
178  return *this;
179  }
180 };
181 
182 template<class T>
183 struct property_map<ug::BGLParallelMatrix<T>, vertex_index_t>{
185  typedef type const_type;
186 };
187 
188 template<class T>
189 typename property_map<ug::BGLParallelMatrix<T>, vertex_index_t>::const_type
190 get(vertex_index_t, ug::BGLParallelMatrix<T> const& m)
191 {
192  typedef typename property_map<ug::BGLParallelMatrix<T>, vertex_index_t>::type type;
193  return type(m);
194 }
195 
197 
198 // duplicate, same as graph_traits<ug::SparseMatrix<T>>?
199 template <class T> struct graph_traits<ug::ParallelMatrix<ug::SparseMatrix<T>>>{
200  typedef int vertex_descriptor;
202  typedef directed_tag directed_category;
203  typedef counting_iterator<size_t> vertex_iterator;
206  typedef disallow_parallel_edge_tag edge_parallel_category;
208  typedef int degree_size_type;
209  typedef int vertices_size_type;
210  //typedef typename ug::SparseMatrix<T>::const_row_iterator adjacency_iterator;
211 };
212 
213 template<class T>
214 std::pair<counting_iterator<size_t>, counting_iterator<size_t> > vertices(
216 {
217  counting_iterator<size_t> b(0);
218  counting_iterator<size_t> e(M.num_rows());
219 
220  return std::make_pair(b,e);
221 }
222 
223 template<class T>
224 struct property_map<ug::ParallelMatrix<T>, vertex_index_t>{
225  typedef typename T::value_type value_type;
227  typedef type const_type;
228 };
229 
230 } // boost
231 
232 namespace ug {
233 
234 using boost::counting_iterator;
235 
236 #if 0
237 template<class T>
238 std::pair<counting_iterator<size_t>, counting_iterator<size_t> > vertices(
240 {
241  counting_iterator<size_t> b(0);
242  counting_iterator<size_t> e(M.num_rows());
243 
244  return std::make_pair(b,e);
245 }
246 
247 template<class T>
248 inline std::pair<boost::SM_out_edge_iterator<T>, boost::SM_out_edge_iterator<T>>
250 {
251  typedef boost::SM_out_edge_iterator<T> Iter;
252  auto a = boost::adjacent_vertices(v, g);
253  return std::make_pair(Iter(a.first), Iter(a.second));
254 }
255 #endif
256 
257 // stuff neeeded in boost::print_graph (?)
258 using boost::out_edges;
259 using boost::vertices;
260 using boost::source;
261 using boost::target;
262 
263 } // ug
264 
265 #endif // UG_PARALLEL
266 #endif // guard
Definition: sparsematrix_boost.h:37
Definition: sparsematrix_boost.h:152
Definition: sparsematrix_boost.h:211
Definition: parallel_matrix_boost.h:154
readable_property_map_tag category
Definition: parallel_matrix_boost.h:158
value_type operator[](T_ x) const
Definition: parallel_matrix_boost.h:171
value_type operator[](int x) const
Definition: parallel_matrix_boost.h:174
bglp_matrix_index_map(X const &)
Definition: parallel_matrix_boost.h:168
vertex_index_type value_type
Definition: parallel_matrix_boost.h:159
size_t vertex_index_type
Definition: parallel_matrix_boost.h:156
bglp_matrix_index_map & operator=(const bglp_matrix_index_map &s)
Definition: parallel_matrix_boost.h:177
vertex_descriptor key_type
Definition: parallel_matrix_boost.h:161
vertex_index_type reference
Definition: parallel_matrix_boost.h:160
size_t vertex_descriptor
Definition: parallel_matrix_boost.h:157
bglp_matrix_index_map(bglp_matrix_index_map const &p)
Definition: parallel_matrix_boost.h:163
bglp_matrix_index_map(ug::SparseMatrix< T >const &, boost::vertex_index_t)
Definition: parallel_matrix_boost.h:165
Definition: sparsematrix_boost.h:350
Definition: parallel_matrix.h:124
Definition: parallel_matrix.h:193
vertex_descriptor target() const
Definition: parallel_matrix.h:202
vertex_descriptor source() const
Definition: parallel_matrix.h:199
Definition: parallel_matrix.h:168
Definition: parallel_matrix.h:68
adjacency_iterator begin_adjacent_vertices(int row) const
Definition: parallel_matrix.h:264
out_edge_iterator begin_out_edges(int row) const
Definition: parallel_matrix.h:274
vertex_iterator end_vertices() const
Definition: parallel_matrix.h:313
adjacency_iterator end_adjacent_vertices(int row) const
Definition: parallel_matrix.h:269
boost::filter_iterator< filter_local, vertex_iterator_ > vertex_iterator
Definition: parallel_matrix.h:122
vertex_iterator begin_vertices() const
Definition: parallel_matrix.h:304
out_edge_iterator end_out_edges(int row) const
Definition: parallel_matrix.h:279
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
Definition: parallel_matrix.h:43
int local() const
Definition: parallel_matrix.h:50
int owner() const
Definition: parallel_matrix.h:49
#define untested()
Definition: lua_table_handle.cpp:15
Definition: boost_serialization_routines.h:49
std::pair< typename ug::BGLParallelMatrix< T >::out_edge_iterator, typename ug::BGLParallelMatrix< T >::out_edge_iterator > out_edges(typename ug::BGLParallelMatrix< T >::vertex_descriptor v, ug::BGLParallelMatrix< T > const &M)
Definition: parallel_matrix_boost.h:125
std::pair< typename graph_traits< T >::adjacency_iterator, typename graph_traits< T >::adjacency_iterator > adjacent_vertices(size_t v, ug::BidirectionalMatrix< T > const &M)
Definition: bidirectional_boost.h:108
std::pair< SM_out_edge_iterator< typename T::value_type >, SM_out_edge_iterator< typename T::value_type > > out_edges(size_t v, ug::BidirectionalMatrix< T > const &g)
Definition: bidirectional_boost.h:136
int out_degree(int v, ug::BidirectionalMatrix< T > const &M)
Definition: bidirectional_boost.h:76
std::pair< counting_iterator< size_t >, counting_iterator< size_t > > vertices(ug::BidirectionalMatrix< T > const &M)
Definition: bidirectional_boost.h:60
SM_edge_weight_map< typename T::value_type, ug::BidirectionalMatrix< T > > get(edge_weight_t, ug::BidirectionalMatrix< T > const &g)
Definition: bidirectional_boost.h:157
int num_vertices(ug::BidirectionalMatrix< T > const &M)
Definition: bidirectional_boost.h:70
size_t target(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &m)
Definition: bidirectional_boost.h:100
size_t source(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &)
Definition: bidirectional_boost.h:94
std::pair< counting_iterator< size_t >, counting_iterator< size_t > > vertices(ug::ParallelMatrix< ug::SparseMatrix< T >> const &M)
Definition: parallel_matrix_boost.h:214
int local(bglp_vertex_descriptor p)
Definition: parallel_matrix.h:57
int owner(bglp_vertex_descriptor p)
Definition: parallel_matrix.h:53
the ug namespace
T value_type
Definition: sparsematrix_interface.h:2
Definition: sparsematrix_boost.h:309
SM_traversal_tag traversal_category
Definition: parallel_matrix_boost.h:52
directed_tag directed_category
Definition: parallel_matrix_boost.h:47
disallow_parallel_edge_tag edge_parallel_category
Definition: parallel_matrix_boost.h:51
ug::detail::bglp_vertex_descriptor vertex_descriptor
Definition: parallel_matrix_boost.h:45
type::edge edge_descriptor
Definition: parallel_matrix_boost.h:46
ug::BGLParallelMatrix< ug::ParallelMatrix< T > > type
Definition: parallel_matrix_boost.h:44
type::vertex_iterator vertex_iterator
Definition: parallel_matrix_boost.h:50
type::out_edge_iterator out_edge_iterator
Definition: parallel_matrix_boost.h:48
type::adjacency_iterator adjacency_iterator
Definition: parallel_matrix_boost.h:49
directed_tag directed_category
Definition: parallel_matrix_boost.h:202
disallow_parallel_edge_tag edge_parallel_category
Definition: parallel_matrix_boost.h:206
SM_adjacency_iterator< T > adjacency_iterator
Definition: parallel_matrix_boost.h:205
int degree_size_type
Definition: parallel_matrix_boost.h:208
int vertices_size_type
Definition: parallel_matrix_boost.h:209
counting_iterator< size_t > vertex_iterator
Definition: parallel_matrix_boost.h:203
SM_traversal_tag traversal_category
Definition: parallel_matrix_boost.h:207
SM_edge< T > edge_descriptor
Definition: parallel_matrix_boost.h:201
SM_out_edge_iterator< T > out_edge_iterator
Definition: parallel_matrix_boost.h:204
int vertex_descriptor
Definition: parallel_matrix_boost.h:200
type const_type
Definition: parallel_matrix_boost.h:185
bglp_matrix_index_map< T > type
Definition: parallel_matrix_boost.h:184
T::value_type value_type
Definition: parallel_matrix_boost.h:225
sparse_matrix_index_map< value_type > type
Definition: parallel_matrix_boost.h:226
type const_type
Definition: parallel_matrix_boost.h:227
#define incomplete()
Definition: trace.h:10