3 #ifndef DUNE_ISTL_OWNEROVERLAPCOPY_HH 4 #define DUNE_ISTL_OWNEROVERLAPCOPY_HH 21 #include <dune/common/enumset.hh> 24 #include <dune/common/parallel/indexset.hh> 25 #include <dune/common/parallel/communicator.hh> 26 #include <dune/common/parallel/remoteindices.hh> 27 #include <dune/common/parallel/mpicollectivecommunication.hh> 32 #include <dune/common/parallel/collectivecommunication.hh> 35 template<
int dim,
template<
class,
class>
class Comm>
74 template <
class G,
class L>
109 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
110 localindices.insert(x);
123 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
124 remoteindices.insert(x);
142 return remoteindices;
150 localindices.clear();
151 remoteindices.clear();
156 std::set<IndexTripel> localindices;
158 std::set<RemoteIndexTripel> remoteindices;
170 template <
class GlobalIdType,
class LocalIdType=
int>
173 template<
typename M,
typename G,
typename L>
181 typedef typename std::set<IndexTripel>::const_iterator localindex_iterator;
182 typedef typename std::set<RemoteIndexTripel>::const_iterator remoteindex_iterator;
184 typedef Dune::ParallelLocalIndex<AttributeSet> LI;
186 typedef Dune::ParallelIndexSet<GlobalIdType,LI,512>
PIS;
187 typedef Dune::RemoteIndices<PIS>
RI;
188 typedef Dune::RemoteIndexListModifier<PIS,typename RI::Allocator,false>
RILM;
189 typedef typename RI::RemoteIndex
RX;
190 typedef Dune::BufferedCommunicator
BC;
191 typedef Dune::Interface
IF;
192 typedef EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>
OwnerSet;
193 typedef EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>
CopySet;
194 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,AttributeSet>
OwnerOverlapSet;
195 typedef Dune::AllSet<AttributeSet>
AllSet;
203 typedef typename CommPolicy<T>::IndexedType
V;
205 static V
gather(
const T& a, std::size_t i)
218 typedef typename CommPolicy<T>::IndexedType
V;
220 static V
gather(
const T& a, std::size_t i)
233 if (OwnerOverlapToAllInterfaceBuilt)
234 OwnerOverlapToAllInterface.free();
235 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,AttributeSet> OwnerOverlapSet;
236 typedef Combine<OwnerOverlapSet,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,AttributeSet> AllSet;
237 OwnerOverlapSet sourceFlags;
239 OwnerOverlapToAllInterface.build(ri,sourceFlags,destFlags);
240 OwnerOverlapToAllInterfaceBuilt =
true;
245 if (OwnerToAllInterfaceBuilt)
246 OwnerToAllInterface.free();
247 OwnerSet sourceFlags;
249 OwnerToAllInterface.build(ri,sourceFlags,destFlags);
250 OwnerToAllInterfaceBuilt =
true;
255 if (OwnerCopyToAllInterfaceBuilt)
256 OwnerCopyToAllInterface.free();
257 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,AttributeSet> OwnerCopySet;
258 typedef Combine<OwnerCopySet,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,AttributeSet> AllSet;
259 OwnerCopySet sourceFlags;
261 OwnerCopyToAllInterface.build(ri,sourceFlags,destFlags);
262 OwnerCopyToAllInterfaceBuilt =
true;
267 if (OwnerCopyToOwnerCopyInterfaceBuilt)
268 OwnerCopyToOwnerCopyInterface.free();
269 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,AttributeSet> OwnerCopySet;
270 OwnerCopySet sourceFlags;
271 OwnerCopySet destFlags;
272 OwnerCopyToOwnerCopyInterface.build(ri,sourceFlags,destFlags);
273 OwnerCopyToOwnerCopyInterfaceBuilt =
true;
278 if (CopyToAllInterfaceBuilt)
279 CopyToAllInterface.free();
282 CopyToAllInterface.build(ri,sourceFlags,destFlags);
283 CopyToAllInterfaceBuilt =
true;
317 if (!OwnerToAllInterfaceBuilt)
318 buildOwnerToAllInterface ();
320 communicator.template build<T>(OwnerToAllInterface);
321 communicator.template forward<CopyGatherScatter<T> >(source,dest);
334 if (!CopyToAllInterfaceBuilt)
335 buildCopyToAllInterface ();
337 communicator.template build<T>(CopyToAllInterface);
338 communicator.template forward<CopyGatherScatter<T> >(source,dest);
351 if (!OwnerOverlapToAllInterfaceBuilt)
352 buildOwnerOverlapToAllInterface ();
354 communicator.template build<T>(OwnerOverlapToAllInterface);
355 communicator.template forward<AddGatherScatter<T> >(source,dest);
368 if (!OwnerCopyToAllInterfaceBuilt)
369 buildOwnerCopyToAllInterface ();
371 communicator.template build<T>(OwnerCopyToAllInterface);
372 communicator.template forward<AddGatherScatter<T> >(source,dest);
385 if (!OwnerCopyToOwnerCopyInterfaceBuilt)
386 buildOwnerCopyToOwnerCopyInterface ();
388 communicator.template build<T>(OwnerCopyToOwnerCopyInterface);
389 communicator.template forward<AddGatherScatter<T> >(source,dest);
401 template<
class T1,
class T2>
402 void dot (
const T1& x,
const T1& y, T2& result)
const 405 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
407 mask.resize(x.size());
408 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
410 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
412 mask[i->local().local()] = 0;
416 for (
typename T1::size_type i=0; i<x.size(); i++)
417 result += x[i]*(y[i])*mask[i];
418 result = cc.sum(result);
429 typename FieldTraits<typename T1::field_type>::real_type
norm (
const T1& x)
const 432 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
434 mask.resize(x.size());
435 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
437 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
439 mask[i->local().local()] = 0;
441 typename T1::field_type result =
typename T1::field_type(0.0);
442 for (
typename T1::size_type i=0; i<x.size(); i++)
443 result += x[i].two_norm2()*mask[i];
444 return static_cast<double>(sqrt(cc.sum(result)));
447 typedef Dune::EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>
CopyFlags;
499 if(pis.seqNo()==oldseqNo)
502 delete globalLookup_;
505 globalLookup_ =
new GlobalLookupIndexSet(pis);
506 oldseqNo = pis.seqNo();
512 if(pis.seqNo()==oldseqNo)
515 delete globalLookup_;
517 globalLookup_ =
new GlobalLookupIndexSet(pis, size);
518 oldseqNo = pis.seqNo();
523 delete globalLookup_;
529 assert(globalLookup_ != 0);
530 return *globalLookup_;
541 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
543 x[i->local().local()] = 0;
557 bool freecomm_ =
false)
558 : comm(comm_), cc(comm_), pis(), ri(pis,pis,comm_),
559 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
560 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
561 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_),
574 : comm(MPI_COMM_WORLD), cc(MPI_COMM_WORLD), pis(), ri(pis,pis,MPI_COMM_WORLD),
575 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
576 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
577 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_), freecomm(false)
590 bool freecomm_ =
false)
591 : comm(comm_), cc(comm_), OwnerToAllInterfaceBuilt(false),
592 OwnerOverlapToAllInterfaceBuilt(false), OwnerCopyToAllInterfaceBuilt(false),
593 OwnerCopyToOwnerCopyInterfaceBuilt(false), CopyToAllInterfaceBuilt(false),
594 globalLookup_(0), category(cat_), freecomm(freecomm_)
612 ri.setIndexSets(pis,pis,cc);
616 int p = std::get<0>(*i);
617 RILM modifier = ri.template getModifier<false,true>(p);
618 typename PIS::const_iterator pi=pis.begin();
622 if (p!=std::get<0>(*i))
625 modifier = ri.template getModifier<false,true>(p);
630 while (pi->global()!=std::get<1>(*i) && pi!=pis.end())
633 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
646 ri.template getModifier<false,true>(0);
654 if (OwnerToAllInterfaceBuilt) OwnerToAllInterface.free();
655 if (OwnerOverlapToAllInterfaceBuilt) OwnerOverlapToAllInterface.free();
656 if (OwnerCopyToAllInterfaceBuilt) OwnerCopyToAllInterface.free();
657 if (OwnerCopyToOwnerCopyInterfaceBuilt) OwnerCopyToOwnerCopyInterface.free();
658 if (CopyToAllInterfaceBuilt) CopyToAllInterface.free();
659 if (globalLookup_)
delete globalLookup_;
661 if(comm!=MPI_COMM_NULL)
667 int wasFinalized = 0;
668 MPI_Finalized( &wasFinalized );
671 MPI_Comm_free(&comm);
679 CollectiveCommunication<MPI_Comm> cc;
682 mutable IF OwnerToAllInterface;
683 mutable bool OwnerToAllInterfaceBuilt;
684 mutable IF OwnerOverlapToAllInterface;
685 mutable bool OwnerOverlapToAllInterfaceBuilt;
686 mutable IF OwnerCopyToAllInterface;
687 mutable bool OwnerCopyToAllInterfaceBuilt;
688 mutable IF OwnerCopyToOwnerCopyInterface;
689 mutable bool OwnerCopyToOwnerCopyInterfaceBuilt;
690 mutable IF CopyToAllInterface;
691 mutable bool CopyToAllInterfaceBuilt;
692 mutable std::vector<double> mask;
694 GlobalLookupIndexSet* globalLookup_;
void clear()
Remove all indices from the sets.
Definition: owneroverlapcopy.hh:148
static void scatter(T &a, V v, std::size_t i)
Definition: owneroverlapcopy.hh:210
CommPolicy< T >::IndexedType V
Definition: owneroverlapcopy.hh:218
Dune::RemoteIndices< PIS > RI
Definition: owneroverlapcopy.hh:187
static V gather(const T &a, std::size_t i)
Definition: owneroverlapcopy.hh:220
EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::owner > OwnerSet
Definition: owneroverlapcopy.hh:192
Definition: allocator.hh:7
Dune::EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::copy > CopyFlags
Definition: owneroverlapcopy.hh:447
void buildOwnerCopyToOwnerCopyInterface() const
Definition: owneroverlapcopy.hh:265
void setSolverCategory(SolverCategory set)
Set right Solver Category (default is overlapping).
Definition: owneroverlapcopy.hh:291
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:315
void loadMatrixMarket(M &matrix, const std::string &filename, OwnerOverlapCopyCommunication< G, L > &comm, bool readIndices=true)
Load a parallel matrix/vector stored in matrix market format.
Definition: matrixmarket.hh:1031
Category for overlapping solvers.
Definition: solvercategory.hh:27
void project(T1 &x) const
Set vector to zero at copy dofs.
Definition: owneroverlapcopy.hh:539
const ParallelIndexSet & indexSet() const
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:463
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > ParallelIndexSet
The type of the parallel index set.
Definition: owneroverlapcopy.hh:450
const GlobalLookupIndexSet & globalLookup() const
Definition: owneroverlapcopy.hh:527
Categories for the solvers.
Definition: solvercategory.hh:19
void testRedistributed(int s)
void addOwnerCopyToAll(const T &source, T &dest) const
Communicate values from owner and copy data points to all other data points and add them to those val...
Definition: owneroverlapcopy.hh:366
Provides classes for reading and writing MatrixMarket Files with an extension for parallel matrices...
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:472
static void scatter(T &a, V v, std::size_t i)
Definition: owneroverlapcopy.hh:225
const std::set< IndexTripel > & localIndices() const
Get the set of indices local to the process.
Definition: owneroverlapcopy.hh:131
Dune::Interface IF
Definition: owneroverlapcopy.hh:191
Dune::AllSet< AttributeSet > AllSet
Definition: owneroverlapcopy.hh:195
void buildOwnerToAllInterface() const
Definition: owneroverlapcopy.hh:243
void buildOwnerCopyToAllInterface() const
Definition: owneroverlapcopy.hh:253
void freeGlobalLookup()
Definition: owneroverlapcopy.hh:521
Dune::GlobalLookupIndexSet< ParallelIndexSet > GlobalLookupIndexSet
The type of the reverse lookup of indices.
Definition: owneroverlapcopy.hh:457
Definition: owneroverlapcopy.hh:59
gather/scatter callback for communcation
Definition: owneroverlapcopy.hh:201
RemoteIndices & remoteIndices()
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:491
Attribute set for overlapping schwarz.
Definition: owneroverlapcopy.hh:56
EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::copy > CopySet
Definition: owneroverlapcopy.hh:193
~OwnerOverlapCopyCommunication()
Definition: owneroverlapcopy.hh:651
void addLocalIndex(const IndexTripel &x)
Add a new index triple to the set of local indices.
Definition: owneroverlapcopy.hh:104
L LocalIdType
The type of the local index.
Definition: owneroverlapcopy.hh:82
derive error class from the base class in common
Definition: istlexception.hh:16
void addRemoteIndex(const RemoteIndexTripel &x)
Add a new remote index triple to the set of remote indices.
Definition: owneroverlapcopy.hh:118
void addOwnerCopyToOwnerCopy(const T &source, T &dest) const
Communicate values from owner and copy data points to owner and copy data points and add them to thos...
Definition: owneroverlapcopy.hh:383
Dune::RemoteIndexListModifier< PIS, typename RI::Allocator, false > RILM
Definition: owneroverlapcopy.hh:188
Combine< EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::owner >, EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::overlap >, AttributeSet > OwnerOverlapSet
Definition: owneroverlapcopy.hh:194
void buildGlobalLookup()
Definition: owneroverlapcopy.hh:496
Definition: owneroverlapcopy.hh:59
Category
Definition: solvercategory.hh:21
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition: owneroverlapcopy.hh:332
FieldTraits< typename T1::field_type >::real_type norm(const T1 &x) const
Compute the global euclidian norm of a vector.
Definition: owneroverlapcopy.hh:429
OwnerOverlapCopyCommunication(SolverCategory::Category cat_=SolverCategory::overlapping)
Construct the communication without any indices using MPI_COMM_WORLD.
Definition: owneroverlapcopy.hh:573
Dune::BufferedCommunicator BC
Definition: owneroverlapcopy.hh:190
OwnerOverlapCopyCommunication(const IndexInfoFromGrid< GlobalIdType, LocalIdType > &indexinfo, MPI_Comm comm_, SolverCategory::Category cat_=SolverCategory::overlapping, bool freecomm_=false)
Constructor.
Definition: owneroverlapcopy.hh:587
void dot(const T1 &x, const T1 &y, T2 &result) const
Compute a global dot product of two vectors.
Definition: owneroverlapcopy.hh:402
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:171
static V gather(const T &a, std::size_t i)
Definition: owneroverlapcopy.hh:205
CommPolicy< T >::IndexedType V
Definition: owneroverlapcopy.hh:203
void buildOwnerOverlapToAllInterface() const
Definition: owneroverlapcopy.hh:231
std::tuple< GlobalIdType, LocalIdType, int > IndexTripel
A triple describing a local index.
Definition: owneroverlapcopy.hh:90
RI::RemoteIndex RX
Definition: owneroverlapcopy.hh:189
AttributeSet
Definition: owneroverlapcopy.hh:58
G GlobalIdType
The type of the global index.
Definition: owneroverlapcopy.hh:79
Definition: owneroverlapcopy.hh:59
std::tuple< int, GlobalIdType, int > RemoteIndexTripel
A triple describing a remote index.
Definition: owneroverlapcopy.hh:97
ParallelIndexSet & indexSet()
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:481
SolverCategory::Category getSolverCategory() const
Get Solver Category.
Definition: owneroverlapcopy.hh:299
OwnerOverlapCopyCommunication(MPI_Comm comm_, SolverCategory::Category cat_=SolverCategory::overlapping, bool freecomm_=false)
Construct the communication without any indices.
Definition: owneroverlapcopy.hh:555
void addOwnerOverlapToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points and add them to those values...
Definition: owneroverlapcopy.hh:349
void buildGlobalLookup(std::size_t size)
Definition: owneroverlapcopy.hh:509
void buildCopyToAllInterface() const
Definition: owneroverlapcopy.hh:276
Definition: owneroverlapcopy.hh:216
const CollectiveCommunication< MPI_Comm > & communicator() const
Definition: owneroverlapcopy.hh:303
Information about the index distribution.
Definition: owneroverlapcopy.hh:75
const std::set< RemoteIndexTripel > & remoteIndices() const
Get the set of remote indices.
Definition: owneroverlapcopy.hh:140
Dune::RemoteIndices< PIS > RemoteIndices
The type of the remote indices.
Definition: owneroverlapcopy.hh:453
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > PIS
Definition: owneroverlapcopy.hh:186