dune-istl 3.0-git
indicescoarsener.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_AMG_INDICESCOARSENER_HH
4#define DUNE_AMG_INDICESCOARSENER_HH
5
6#include <dune/common/parallel/indicessyncer.hh>
7#include <dune/common/unused.hh>
8#include <vector>
9#include "renumberer.hh"
10
11#if HAVE_MPI
13#endif
14
15#include "pinfo.hh"
16
17namespace Dune
18{
19 namespace Amg
20 {
21
33 template<typename T, typename E>
35 {};
36
37
38#if HAVE_MPI
39
40 template<typename T, typename E>
42 {
43 public:
48
53
54 typedef typename ParallelInformation::ParallelIndexSet ParallelIndexSet;
55
59 typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
60
64 typedef typename ParallelIndexSet::LocalIndex LocalIndex;
65
69 typedef typename LocalIndex::Attribute Attribute;
70
75
87 template<typename Graph, typename VM>
88 static typename Graph::VertexDescriptor
90 Graph& fineGraph,
91 VM& visitedMap,
94 typename Graph::VertexDescriptor noAggregates);
95
96 private:
97 template<typename G, typename I>
98 class ParallelAggregateRenumberer : public AggregateRenumberer<G>
99 {
100 typedef typename G::VertexDescriptor Vertex;
101
102 typedef I GlobalLookupIndexSet;
103
104 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
105
106 typedef typename IndexPair::GlobalIndex GlobalIndex;
107
108 public:
110 : AggregateRenumberer<G>(aggregates), isPublic_(false), lookup_(lookup),
111 globalIndex_(std::numeric_limits<GlobalIndex>::max())
112 {}
113
114
115 void operator()(const typename G::ConstEdgeIterator& edge)
116 {
118 const IndexPair* pair= lookup_.pair(edge.target());
119 if(pair!=0) {
120 globalIndex(pair->global());
121 attribute(pair->local().attribute());
122 isPublic(pair->local().isPublic());
123 }
124 }
125
126 Vertex operator()(const GlobalIndex& global)
127 {
129 Vertex current = this->number_;
130 this->operator++();
131 return current;
132 }
133
134 bool isPublic()
135 {
136 return isPublic_;
137 }
138
139 void isPublic(bool b)
140 {
141 isPublic_ = isPublic_ || b;
142 }
143
144 void reset()
145 {
146 globalIndex_ = std::numeric_limits<GlobalIndex>::max();
147 isPublic_=false;
148 }
149
151 {
152 attribute_=attribute;
153 }
154
156 {
157 return attribute_;
158 }
159
160 const GlobalIndex& globalIndex() const
161 {
162 return globalIndex_;
163 }
164
165 void globalIndex(const GlobalIndex& global)
166 {
167 globalIndex_ = global;
168 }
169
170 private:
171 bool isPublic_;
172 Attribute attribute_;
173 const GlobalLookupIndexSet& lookup_;
174 GlobalIndex globalIndex_;
175 };
176
177 template<typename Graph, typename VM, typename I>
178 static void buildCoarseIndexSet(const ParallelInformation& pinfo,
179 Graph& fineGraph,
180 VM& visitedMap,
184
185 template<typename Graph,typename I>
186 static void buildCoarseRemoteIndices(const RemoteIndices& fineRemote,
191
192 };
193
197 template<typename G, typename L, typename E>
199 : public ParallelIndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
200 {};
201
202
203#endif
204
211 template<typename E>
213 {
214 public:
215 template<typename Graph, typename VM>
216 static typename Graph::VertexDescriptor
217 coarsen(const SequentialInformation & fineInfo,
218 Graph& fineGraph,
219 VM& visitedMap,
222 typename Graph::VertexDescriptor noAggregates);
223 };
224
225#if HAVE_MPI
226 template<typename T, typename E>
227 template<typename Graph, typename VM>
228 inline typename Graph::VertexDescriptor
230 Graph& fineGraph,
231 VM& visitedMap,
234 typename Graph::VertexDescriptor noAggregates)
235 {
238 buildCoarseIndexSet(fineInfo, fineGraph, visitedMap, aggregates,
239 coarseInfo.indexSet(), renumberer);
240 buildCoarseRemoteIndices(fineInfo.remoteIndices(), aggregates, coarseInfo.indexSet(),
241 coarseInfo.remoteIndices(), renumberer);
242
243 return renumberer;
244 }
245
246 template<typename T, typename E>
247 template<typename Graph, typename VM, typename I>
248 void ParallelIndicesCoarsener<T,E>::buildCoarseIndexSet(const ParallelInformation& pinfo,
249 Graph& fineGraph,
250 VM& visitedMap,
252 ParallelIndexSet& coarseIndices,
254 {
255 // fineGraph is the local subgraph corresponding to the vertices the process owns.
256 // i.e. no overlap/copy vertices can be visited traversing the graph
257 typedef typename Graph::ConstVertexIterator Iterator;
258 typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
259
260 Iterator end = fineGraph.end();
261 const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
262
263 coarseIndices.beginResize();
264
265 // Setup the coarse index set and renumber the aggregate consecutively
266 // ascending from zero according to the minimum global index belonging
267 // to the aggregate
268 for(Iterator index = fineGraph.begin(); index != end; ++index) {
270 // Isolated vertices will not be represented on the next level.
271 // These should only be there if skipIsolated is activiated in
272 // the coarsening criterion as otherwise they will be aggregated
273 // and should have real aggregate number in the map right now.
274 if(!get(visitedMap, *index)) {
275 // This vertex was not visited by breadthFirstSearch yet.
276 typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
277 const IndexPair* pair= lookup.pair(*index);
278
279 renumberer.reset(); // reset attribute and global index.
280 if(pair!=0) {
281 // vertex is in the index set. Note that not all vertices have
282 // to be in the index set, just the ones where communication
283 // will happen.
284 assert(!ExcludedAttributes::contains(pair->local().attribute()));
285 renumberer.attribute(pair->local().attribute());
286 renumberer.isPublic(pair->local().isPublic());
287 renumberer.globalIndex(pair->global());
288 }
289
290 // Reconstruct aggregate and mark vertices as visited
291 aggregates.template breadthFirstSearch<false>(*index, aggregates[*index],
292 fineGraph, renumberer, visitedMap);
293
294 typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex GlobalIndex;
295
296 if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()) {
297 // vertex is in the index set.
298 //std::cout <<" Adding global="<< renumberer.globalIndex()<<" local="<<static_cast<std::size_t>(renumberer)<<std::endl;
299 coarseIndices.add(renumberer.globalIndex(),
300 LocalIndex(renumberer, renumberer.attribute(),
301 renumberer.isPublic()));
302 }
303
304 aggregates[*index] = renumberer;
305 ++renumberer;
306 }
307 }
308
309 coarseIndices.endResize();
310
311 assert(static_cast<std::size_t>(renumberer) >= coarseIndices.size());
312
313 // Reset the visited flags
314 for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
315 put(visitedMap, *vertex, false);
316 }
317
318 template<typename T, typename E>
319 template<typename Graph, typename I>
320 void ParallelIndicesCoarsener<T,E>::buildCoarseRemoteIndices(const RemoteIndices& fineRemote,
321 const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
322 ParallelIndexSet& coarseIndices,
323 RemoteIndices& coarseRemote,
324 ParallelAggregateRenumberer<Graph,I>& renumberer)
325 {
326 std::vector<char> attributes(static_cast<std::size_t>(renumberer));
327
328 GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices, static_cast<std::size_t>(renumberer));
329
330 typedef typename RemoteIndices::const_iterator Iterator;
331 Iterator end = fineRemote.end();
332
333 for(Iterator neighbour = fineRemote.begin();
334 neighbour != end; ++neighbour) {
335 int process = neighbour->first;
336
337 assert(neighbour->second.first==neighbour->second.second);
338
339 // Mark all as not known
340 typedef typename std::vector<char>::iterator CIterator;
341
342 for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
343 *iter = std::numeric_limits<char>::max();
344
345 typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
346 Iterator riEnd = neighbour->second.second->end();
347
348 for(Iterator index = neighbour->second.second->begin();
349 index != riEnd; ++index) {
350 if(!E::contains(index->localIndexPair().local().attribute()) &&
351 aggregates[index->localIndexPair().local()] !=
353 {
354 assert(aggregates[index->localIndexPair().local()]<attributes.size());
355 if (attributes[aggregates[index->localIndexPair().local()]] != 3)
356 attributes[aggregates[index->localIndexPair().local()]] = index->attribute();
357 }
358 }
359
360 // Build remote index list
361 typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
362 typedef typename RemoteIndices::RemoteIndex RemoteIndex;
363 typedef typename ParallelIndexSet::const_iterator IndexIterator;
364
365 Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
366
367 IndexIterator iend = coarseIndices.end();
368 for(IndexIterator index = coarseIndices.begin(); index != iend; ++index)
369 if(attributes[index->local()] != std::numeric_limits<char>::max()) {
370 // remote index is present
371 coarseList.insert(RemoteIndex(Attribute(attributes[index->local()]), &(*index)));
372 }
373 //std::cout<<coarseRemote<<std::endl;
374 }
375
376 // The number of neighbours should not change!
377 assert(coarseRemote.neighbours()==fineRemote.neighbours());
378
379 // snyc the index set and the remote indices to recompute missing
380 // indices
381 IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
382 syncer.sync(renumberer);
383
384 }
385
386#endif
387
388 template<typename E>
389 template<typename Graph, typename VM>
390 typename Graph::VertexDescriptor
406
407 } //namespace Amg
408} // namespace Dune
409#endif
Classes providing communication interfaces for overlapping Schwarz methods.
LocalIndex::Attribute Attribute
The type of the attribute.
Definition indicescoarsener.hh:69
void operator()(const typename G::ConstEdgeIterator &edge)
Definition indicescoarsener.hh:115
void isPublic(bool b)
Definition indicescoarsener.hh:139
ParallelInformation::ParallelIndexSet ParallelIndexSet
Definition indicescoarsener.hh:54
ParallelIndexSet::LocalIndex LocalIndex
The type of the local index.
Definition indicescoarsener.hh:64
T ParallelInformation
The type of the parallel information.
Definition indicescoarsener.hh:52
Attribute attribute()
Definition indicescoarsener.hh:155
Vertex operator()(const GlobalIndex &global)
Definition indicescoarsener.hh:126
static Graph::VertexDescriptor coarsen(ParallelInformation &fineInfo, Graph &fineGraph, VM &visitedMap, AggregatesMap< typename Graph::VertexDescriptor > &aggregates, ParallelInformation &coarseInfo, typename Graph::VertexDescriptor noAggregates)
Build the coarse index set after the aggregatio.
Definition indicescoarsener.hh:229
static const V ISOLATED
Identifier of isolated vertices.
Definition aggregates.hh:554
ParallelIndexSet::GlobalIndex GlobalIndex
The type of the global index.
Definition indicescoarsener.hh:59
void attribute(const Attribute &attribute)
Definition indicescoarsener.hh:150
E ExcludedAttributes
The set of excluded attributes.
Definition indicescoarsener.hh:47
void globalIndex(const GlobalIndex &global)
Definition indicescoarsener.hh:165
Dune::RemoteIndices< ParallelIndexSet > RemoteIndices
The type of the remote indices.
Definition indicescoarsener.hh:74
ParallelAggregateRenumberer(AggregatesMap< Vertex > &aggregates, const I &lookup)
Definition indicescoarsener.hh:109
const GlobalIndex & globalIndex() const
Definition indicescoarsener.hh:160
Definition basearray.hh:19
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get(const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition dependency.hh:292
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition owneroverlapcopy.hh:173
Class providing information about the mapping of the vertices onto aggregates.
Definition aggregates.hh:543
Definition indicescoarsener.hh:35
Definition indicescoarsener.hh:42
Definition pinfo.hh:26
Definition renumberer.hh:14
void operator++()
Definition renumberer.hh:55
void operator()(const typename G::ConstEdgeIterator &edge)
Definition renumberer.hh:49
Vertex number_
Definition renumberer.hh:33