/usr/include/dune/istl/paamg/indicescoarsener.hh is in libdune-istl-dev 2.4.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_AMG_INDICESCOARSENER_HH
#define DUNE_AMG_INDICESCOARSENER_HH
#include <dune/common/parallel/indicessyncer.hh>
#include <dune/common/unused.hh>
#include <vector>
#include "renumberer.hh"
#if HAVE_MPI
#include <dune/istl/owneroverlapcopy.hh>
#endif
#include "pinfo.hh"
namespace Dune
{
namespace Amg
{
/**
* @addtogroup ISTL_PAAMG
*
* @{
*/
/** @file
* @author Markus Blatt
* @brief Provides a class for building the index set
* and remote indices on the coarse level.
*/
template<typename T, typename E>
class IndicesCoarsener
{};
#if HAVE_MPI
template<typename T, typename E>
class ParallelIndicesCoarsener
{
public:
/**
* @brief The set of excluded attributes
*/
typedef E ExcludedAttributes;
/**
* @brief The type of the parallel information.
*/
typedef T ParallelInformation;
typedef typename ParallelInformation::ParallelIndexSet ParallelIndexSet;
/**
* @brief The type of the global index.
*/
typedef typename ParallelIndexSet::GlobalIndex GlobalIndex;
/**
* @brief The type of the local index.
*/
typedef typename ParallelIndexSet::LocalIndex LocalIndex;
/**
* @brief The type of the attribute.
*/
typedef typename LocalIndex::Attribute Attribute;
/**
* @brief The type of the remote indices.
*/
typedef Dune::RemoteIndices<ParallelIndexSet> RemoteIndices;
/**
* @brief Build the coarse index set after the aggregatio.
*
* @param fineInfo The parallel information at the fine level.
* @param fineGraph The graph of the fine lecel,
* @param visitedMap Map for marking vertices as visited.
* @param aggregates The mapping of unknowns onto aggregates.
* @param coarseInfo The information about the parallel data decomposition
* on the coarse level.
* @return The number of unknowns on the coarse level.
*/
template<typename Graph, typename VM>
static typename Graph::VertexDescriptor
coarsen(ParallelInformation& fineInfo,
Graph& fineGraph,
VM& visitedMap,
AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
ParallelInformation& coarseInfo,
typename Graph::VertexDescriptor noAggregates);
private:
template<typename G, typename I>
class ParallelAggregateRenumberer : public AggregateRenumberer<G>
{
typedef typename G::VertexDescriptor Vertex;
typedef I GlobalLookupIndexSet;
typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
typedef typename IndexPair::GlobalIndex GlobalIndex;
public:
ParallelAggregateRenumberer(AggregatesMap<Vertex>& aggregates, const I& lookup)
: AggregateRenumberer<G>(aggregates), isPublic_(false), lookup_(lookup),
globalIndex_(std::numeric_limits<GlobalIndex>::max())
{}
void operator()(const typename G::ConstEdgeIterator& edge)
{
AggregateRenumberer<G>::operator()(edge);
const IndexPair* pair= lookup_.pair(edge.target());
if(pair!=0) {
globalIndex(pair->global());
attribute(pair->local().attribute());
isPublic(pair->local().isPublic());
}
}
Vertex operator()(const GlobalIndex& global)
{
DUNE_UNUSED_PARAMETER(global);
Vertex current = this->number_;
this->operator++();
return current;
}
bool isPublic()
{
return isPublic_;
}
void isPublic(bool b)
{
isPublic_ = isPublic_ || b;
}
void reset()
{
globalIndex_ = std::numeric_limits<GlobalIndex>::max();
isPublic_=false;
}
void attribute(const Attribute& attribute)
{
attribute_=attribute;
}
Attribute attribute()
{
return attribute_;
}
const GlobalIndex& globalIndex() const
{
return globalIndex_;
}
void globalIndex(const GlobalIndex& global)
{
globalIndex_ = global;
}
private:
bool isPublic_;
Attribute attribute_;
const GlobalLookupIndexSet& lookup_;
GlobalIndex globalIndex_;
};
template<typename Graph, typename VM, typename I>
static void buildCoarseIndexSet(const ParallelInformation& pinfo,
Graph& fineGraph,
VM& visitedMap,
AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
ParallelIndexSet& coarseIndices,
ParallelAggregateRenumberer<Graph,I>& renumberer);
template<typename Graph,typename I>
static void buildCoarseRemoteIndices(const RemoteIndices& fineRemote,
const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
ParallelIndexSet& coarseIndices,
RemoteIndices& coarseRemote,
ParallelAggregateRenumberer<Graph,I>& renumberer);
};
/**
* @brief Coarsen Indices in the parallel case.
*/
template<typename G, typename L, typename E>
class IndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
: public ParallelIndicesCoarsener<OwnerOverlapCopyCommunication<G,L>,E>
{};
#endif
/**
* @brief Coarsen Indices in the sequential case.
*
* Nothing to be coarsened here. Just renumber the aggregates
* consecutively
*/
template<typename E>
class IndicesCoarsener<SequentialInformation,E>
{
public:
template<typename Graph, typename VM>
static typename Graph::VertexDescriptor
coarsen(const SequentialInformation & fineInfo,
Graph& fineGraph,
VM& visitedMap,
AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
SequentialInformation& coarseInfo,
typename Graph::VertexDescriptor noAggregates);
};
#if HAVE_MPI
template<typename T, typename E>
template<typename Graph, typename VM>
inline typename Graph::VertexDescriptor
ParallelIndicesCoarsener<T,E>::coarsen(ParallelInformation& fineInfo,
Graph& fineGraph,
VM& visitedMap,
AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
ParallelInformation& coarseInfo,
typename Graph::VertexDescriptor noAggregates)
{
DUNE_UNUSED_PARAMETER(noAggregates);
ParallelAggregateRenumberer<Graph,typename ParallelInformation::GlobalLookupIndexSet> renumberer(aggregates, fineInfo.globalLookup());
buildCoarseIndexSet(fineInfo, fineGraph, visitedMap, aggregates,
coarseInfo.indexSet(), renumberer);
buildCoarseRemoteIndices(fineInfo.remoteIndices(), aggregates, coarseInfo.indexSet(),
coarseInfo.remoteIndices(), renumberer);
return renumberer;
}
template<typename T, typename E>
template<typename Graph, typename VM, typename I>
void ParallelIndicesCoarsener<T,E>::buildCoarseIndexSet(const ParallelInformation& pinfo,
Graph& fineGraph,
VM& visitedMap,
AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
ParallelIndexSet& coarseIndices,
ParallelAggregateRenumberer<Graph,I>& renumberer)
{
// fineGraph is the local subgraph corresponding to the vertices the process owns.
// i.e. no overlap/copy vertices can be visited traversing the graph
typedef typename Graph::ConstVertexIterator Iterator;
typedef typename ParallelInformation::GlobalLookupIndexSet GlobalLookupIndexSet;
Iterator end = fineGraph.end();
const GlobalLookupIndexSet& lookup = pinfo.globalLookup();
coarseIndices.beginResize();
// Setup the coarse index set and renumber the aggregate consecutively
// ascending from zero according to the minimum global index belonging
// to the aggregate
for(Iterator index = fineGraph.begin(); index != end; ++index) {
if(aggregates[*index]!=AggregatesMap<typename Graph::VertexDescriptor>::ISOLATED)
// Isolated vertices will not be represented on the next level.
// These should only be there if skipIsolated is activiated in
// the coarsening criterion as otherwise they will be aggregated
// and should have real aggregate number in the map right now.
if(!get(visitedMap, *index)) {
// This vertex was not visited by breadthFirstSearch yet.
typedef typename GlobalLookupIndexSet::IndexPair IndexPair;
const IndexPair* pair= lookup.pair(*index);
renumberer.reset(); // reset attribute and global index.
if(pair!=0) {
// vertex is in the index set. Note that not all vertices have
// to be in the index set, just the ones where communication
// will happen.
assert(!ExcludedAttributes::contains(pair->local().attribute()));
renumberer.attribute(pair->local().attribute());
renumberer.isPublic(pair->local().isPublic());
renumberer.globalIndex(pair->global());
}
// Reconstruct aggregate and mark vertices as visited
aggregates.template breadthFirstSearch<false>(*index, aggregates[*index],
fineGraph, renumberer, visitedMap);
typedef typename GlobalLookupIndexSet::IndexPair::GlobalIndex GlobalIndex;
if(renumberer.globalIndex()!=std::numeric_limits<GlobalIndex>::max()) {
// vertex is in the index set.
//std::cout <<" Adding global="<< renumberer.globalIndex()<<" local="<<static_cast<std::size_t>(renumberer)<<std::endl;
coarseIndices.add(renumberer.globalIndex(),
LocalIndex(renumberer, renumberer.attribute(),
renumberer.isPublic()));
}
aggregates[*index] = renumberer;
++renumberer;
}
}
coarseIndices.endResize();
assert(static_cast<std::size_t>(renumberer) >= coarseIndices.size());
// Reset the visited flags
for(Iterator vertex=fineGraph.begin(); vertex != end; ++vertex)
put(visitedMap, *vertex, false);
}
template<typename T, typename E>
template<typename Graph, typename I>
void ParallelIndicesCoarsener<T,E>::buildCoarseRemoteIndices(const RemoteIndices& fineRemote,
const AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
ParallelIndexSet& coarseIndices,
RemoteIndices& coarseRemote,
ParallelAggregateRenumberer<Graph,I>& renumberer)
{
std::vector<char> attributes(static_cast<std::size_t>(renumberer));
GlobalLookupIndexSet<ParallelIndexSet> coarseLookup(coarseIndices, static_cast<std::size_t>(renumberer));
typedef typename RemoteIndices::const_iterator Iterator;
Iterator end = fineRemote.end();
for(Iterator neighbour = fineRemote.begin();
neighbour != end; ++neighbour) {
int process = neighbour->first;
assert(neighbour->second.first==neighbour->second.second);
// Mark all as not known
typedef typename std::vector<char>::iterator CIterator;
for(CIterator iter=attributes.begin(); iter!= attributes.end(); ++iter)
*iter = std::numeric_limits<char>::max();
typedef typename RemoteIndices::RemoteIndexList::const_iterator Iterator;
Iterator riEnd = neighbour->second.second->end();
for(Iterator index = neighbour->second.second->begin();
index != riEnd; ++index) {
if(!E::contains(index->localIndexPair().local().attribute()) &&
aggregates[index->localIndexPair().local()] !=
AggregatesMap<typename Graph::VertexDescriptor>::ISOLATED)
{
assert(aggregates[index->localIndexPair().local()]<attributes.size());
if (attributes[aggregates[index->localIndexPair().local()]] != 3)
attributes[aggregates[index->localIndexPair().local()]] = index->attribute();
}
}
// Build remote index list
typedef RemoteIndexListModifier<ParallelIndexSet,typename RemoteIndices::Allocator,false> Modifier;
typedef typename RemoteIndices::RemoteIndex RemoteIndex;
typedef typename ParallelIndexSet::const_iterator IndexIterator;
Modifier coarseList = coarseRemote.template getModifier<false,true>(process);
IndexIterator iend = coarseIndices.end();
for(IndexIterator index = coarseIndices.begin(); index != iend; ++index)
if(attributes[index->local()] != std::numeric_limits<char>::max()) {
// remote index is present
coarseList.insert(RemoteIndex(Attribute(attributes[index->local()]), &(*index)));
}
//std::cout<<coarseRemote<<std::endl;
}
// The number of neighbours should not change!
assert(coarseRemote.neighbours()==fineRemote.neighbours());
// snyc the index set and the remote indices to recompute missing
// indices
IndicesSyncer<ParallelIndexSet> syncer(coarseIndices, coarseRemote);
syncer.sync(renumberer);
}
#endif
template<typename E>
template<typename Graph, typename VM>
typename Graph::VertexDescriptor
IndicesCoarsener<SequentialInformation,E>::coarsen(const SequentialInformation& fineInfo,
Graph& fineGraph,
VM& visitedMap,
AggregatesMap<typename Graph::VertexDescriptor>& aggregates,
SequentialInformation& coarseInfo,
typename Graph::VertexDescriptor noAggregates)
{
DUNE_UNUSED_PARAMETER(fineInfo);
DUNE_UNUSED_PARAMETER(fineGraph);
DUNE_UNUSED_PARAMETER(visitedMap);
DUNE_UNUSED_PARAMETER(aggregates);
DUNE_UNUSED_PARAMETER(coarseInfo);
DUNE_UNUSED_PARAMETER(noAggregates);
return noAggregates;
}
} //namespace Amg
} // namespace Dune
#endif
|