4 #ifndef DUNE_OWNEROVERLAPCOPY_HH
5 #define DUNE_OWNEROVERLAPCOPY_HH
22 #include <dune/common/tuples.hh>
23 #include <dune/common/enumset.hh>
26 #include <dune/common/parallel/indexset.hh>
27 #include <dune/common/parallel/communicator.hh>
28 #include <dune/common/parallel/remoteindices.hh>
29 #include <dune/common/parallel/mpicollectivecommunication.hh>
34 #include <dune/common/parallel/collectivecommunication.hh>
36 template<
int dim,
template<
class,
class>
class Comm>
75 template <
class G,
class L>
110 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
111 localindices.insert(x);
124 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
125 remoteindices.insert(x);
143 return remoteindices;
151 localindices.clear();
152 remoteindices.clear();
157 std::set<IndexTripel> localindices;
159 std::set<RemoteIndexTripel> remoteindices;
171 template <
class GlobalIdType,
class LocalIdType=
int>
174 template<
typename M,
typename G,
typename L>
182 typedef typename std::set<IndexTripel>::const_iterator localindex_iterator;
183 typedef typename std::set<RemoteIndexTripel>::const_iterator remoteindex_iterator;
185 typedef Dune::ParallelLocalIndex<AttributeSet> LI;
187 typedef Dune::ParallelIndexSet<GlobalIdType,LI,512>
PIS;
188 typedef Dune::RemoteIndices<PIS>
RI;
189 typedef Dune::RemoteIndexListModifier<PIS,typename RI::Allocator,false>
RILM;
190 typedef typename RI::RemoteIndex
RX;
191 typedef Dune::BufferedCommunicator
BC;
192 typedef Dune::Interface
IF;
193 typedef EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>
OwnerSet;
194 typedef EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>
CopySet;
195 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,
AttributeSet>
OwnerOverlapSet;
196 typedef Dune::AllSet<AttributeSet>
AllSet;
204 typedef typename CommPolicy<T>::IndexedType
V;
219 typedef typename CommPolicy<T>::IndexedType
V;
234 if (OwnerOverlapToAllInterfaceBuilt)
235 OwnerOverlapToAllInterface.free();
236 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,
AttributeSet>
OwnerOverlapSet;
237 typedef Combine<OwnerOverlapSet,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,
AttributeSet>
AllSet;
238 OwnerOverlapSet sourceFlags;
240 OwnerOverlapToAllInterface.build(ri,sourceFlags,destFlags);
241 OwnerOverlapToAllInterfaceBuilt =
true;
246 if (OwnerToAllInterfaceBuilt)
247 OwnerToAllInterface.free();
250 OwnerToAllInterface.build(ri,sourceFlags,destFlags);
251 OwnerToAllInterfaceBuilt =
true;
256 if (OwnerCopyToAllInterfaceBuilt)
257 OwnerCopyToAllInterface.free();
258 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,
AttributeSet> OwnerCopySet;
259 typedef Combine<OwnerCopySet,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,
AttributeSet>
AllSet;
260 OwnerCopySet sourceFlags;
262 OwnerCopyToAllInterface.build(ri,sourceFlags,destFlags);
263 OwnerCopyToAllInterfaceBuilt =
true;
268 if (OwnerCopyToOwnerCopyInterfaceBuilt)
269 OwnerCopyToOwnerCopyInterface.free();
270 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,
AttributeSet> OwnerCopySet;
271 OwnerCopySet sourceFlags;
272 OwnerCopySet destFlags;
273 OwnerCopyToOwnerCopyInterface.build(ri,sourceFlags,destFlags);
274 OwnerCopyToOwnerCopyInterfaceBuilt =
true;
279 if (CopyToAllInterfaceBuilt)
280 CopyToAllInterface.free();
283 CopyToAllInterface.build(ri,sourceFlags,destFlags);
284 CopyToAllInterfaceBuilt =
true;
320 if (!OwnerToAllInterfaceBuilt)
323 communicator.template build<T>(OwnerToAllInterface);
324 communicator.template forward<CopyGatherScatter<T> >(source,dest);
337 if (!CopyToAllInterfaceBuilt)
340 communicator.template build<T>(CopyToAllInterface);
341 communicator.template forward<CopyGatherScatter<T> >(source,dest);
354 if (!OwnerOverlapToAllInterfaceBuilt)
357 communicator.template build<T>(OwnerOverlapToAllInterface);
358 communicator.template forward<AddGatherScatter<T> >(source,dest);
371 if (!OwnerCopyToAllInterfaceBuilt)
374 communicator.template build<T>(OwnerCopyToAllInterface);
375 communicator.template forward<AddGatherScatter<T> >(source,dest);
388 if (!OwnerCopyToOwnerCopyInterfaceBuilt)
391 communicator.template build<T>(OwnerCopyToOwnerCopyInterface);
392 communicator.template forward<AddGatherScatter<T> >(source,dest);
404 template<
class T1,
class T2>
405 void dot (
const T1& x,
const T1& y, T2& result)
const
408 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
410 mask.resize(x.size());
411 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
413 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
415 mask[i->local().local()] = 0;
419 for (
typename T1::size_type i=0; i<x.size(); i++)
420 result += x[i]*(y[i])*mask[i];
421 result = cc.sum(result);
432 double norm (
const T1& x)
const
435 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
437 mask.resize(x.size());
438 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
440 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
442 mask[i->local().local()] = 0;
445 for (
typename T1::size_type i=0; i<x.size(); i++)
446 result += x[i].two_norm2()*mask[i];
447 return sqrt(cc.sum(result));
450 typedef Dune::EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>
CopyFlags;
502 if(pis.seqNo()==oldseqNo)
505 delete globalLookup_;
509 oldseqNo = pis.seqNo();
515 if(pis.seqNo()==oldseqNo)
518 delete globalLookup_;
521 oldseqNo = pis.seqNo();
526 delete globalLookup_;
532 assert(globalLookup_ != 0);
533 return *globalLookup_;
544 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
546 x[i->local().local()] = 0;
560 bool freecomm_ =
false)
561 : comm(comm_), cc(comm_), pis(), ri(pis,pis,comm_),
562 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
563 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
564 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_),
577 : comm(MPI_COMM_WORLD), cc(MPI_COMM_WORLD), pis(), ri(pis,pis,MPI_COMM_WORLD),
578 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
579 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
580 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_), freecomm(false)
593 bool freecomm_ =
false)
594 : comm(comm_), cc(comm_), OwnerToAllInterfaceBuilt(false),
595 OwnerOverlapToAllInterfaceBuilt(false), OwnerCopyToAllInterfaceBuilt(false),
596 OwnerCopyToOwnerCopyInterfaceBuilt(false), CopyToAllInterfaceBuilt(false),
597 globalLookup_(0), category(cat_), freecomm(freecomm_)
615 ri.setIndexSets(pis,pis,cc);
620 RILM modifier = ri.template getModifier<false,true>(p);
621 typename PIS::const_iterator pi=pis.begin();
628 modifier = ri.template getModifier<false,true>(p);
633 while (pi->global()!=get<1>(*i) && pi!=pis.end())
636 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
649 ri.template getModifier<false,true>(0);
657 if (OwnerToAllInterfaceBuilt) OwnerToAllInterface.free();
658 if (OwnerOverlapToAllInterfaceBuilt) OwnerOverlapToAllInterface.free();
659 if (OwnerCopyToAllInterfaceBuilt) OwnerCopyToAllInterface.free();
660 if (OwnerCopyToOwnerCopyInterfaceBuilt) OwnerCopyToOwnerCopyInterface.free();
661 if (CopyToAllInterfaceBuilt) CopyToAllInterface.free();
662 if (globalLookup_)
delete globalLookup_;
664 if(comm!=MPI_COMM_NULL)
670 int wasFinalized = 0;
671 MPI_Finalized( &wasFinalized );
674 MPI_Comm_free(&comm);
682 CollectiveCommunication<MPI_Comm> cc;
685 mutable IF OwnerToAllInterface;
686 mutable bool OwnerToAllInterfaceBuilt;
687 mutable IF OwnerOverlapToAllInterface;
688 mutable bool OwnerOverlapToAllInterfaceBuilt;
689 mutable IF OwnerCopyToAllInterface;
690 mutable bool OwnerCopyToAllInterfaceBuilt;
691 mutable IF OwnerCopyToOwnerCopyInterface;
692 mutable bool OwnerCopyToOwnerCopyInterfaceBuilt;
693 mutable IF CopyToAllInterface;
694 mutable bool CopyToAllInterfaceBuilt;
695 mutable std::vector<double> mask;
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:318
Dune::GlobalLookupIndexSet< ParallelIndexSet > GlobalLookupIndexSet
The type of the reverse lookup of indices.
Definition: owneroverlapcopy.hh:460
EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::copy > CopySet
Definition: owneroverlapcopy.hh:194
Category for ovelapping solvers.
Definition: solvercategory.hh:26
void clear()
Remove all indices from the sets.
Definition: owneroverlapcopy.hh:149
const GlobalLookupIndexSet & globalLookup() const
Definition: owneroverlapcopy.hh:530
static V gather(const T &a, std::size_t i)
Definition: owneroverlapcopy.hh:206
EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::owner > OwnerSet
Definition: owneroverlapcopy.hh:193
friend void loadMatrixMarket(M &, const std::string &, OwnerOverlapCopyCommunication< G, L > &, bool)
Load a parallel matrix/vector stored in matrix market format.
Definition: matrixmarket.hh:1044
AttributeSet
Definition: owneroverlapcopy.hh:59
void testRedistributed(int s)
Definition: owneroverlapcopy.hh:60
Attribute set for overlapping schwarz.
Definition: owneroverlapcopy.hh:57
CommPolicy< T >::IndexedType V
Definition: owneroverlapcopy.hh:219
void addLocalIndex(const IndexTripel &x)
Add a new index triple to the set of local indices.
Definition: owneroverlapcopy.hh:105
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > PIS
Definition: owneroverlapcopy.hh:187
Dune::EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::copy > CopyFlags
Definition: owneroverlapcopy.hh:450
OwnerOverlapCopyCommunication(MPI_Comm comm_, SolverCategory::Category cat_=SolverCategory::overlapping, bool freecomm_=false)
Construct the communication without any indices.
Definition: owneroverlapcopy.hh:558
const std::set< IndexTripel > & localIndices() const
Get the set of indices local to the process.
Definition: owneroverlapcopy.hh:132
void buildOwnerOverlapToAllInterface() const
Definition: owneroverlapcopy.hh:232
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:352
~OwnerOverlapCopyCommunication()
Definition: owneroverlapcopy.hh:654
void buildOwnerToAllInterface() const
Definition: owneroverlapcopy.hh:244
Dune::RemoteIndices< PIS > RemoteIndices
The type of the remote indices.
Definition: owneroverlapcopy.hh:456
Categories for the solvers.
Definition: solvercategory.hh:18
void buildGlobalLookup(std::size_t size)
Definition: owneroverlapcopy.hh:512
Information about the index distribution.
Definition: owneroverlapcopy.hh:76
void buildGlobalLookup()
Definition: owneroverlapcopy.hh:499
static V gather(const T &a, std::size_t i)
Definition: owneroverlapcopy.hh:221
gather/scatter callback for communcation
Definition: owneroverlapcopy.hh:202
RI::RemoteIndex RX
Definition: owneroverlapcopy.hh:190
Category
Definition: solvercategory.hh:20
void dot(const T1 &x, const T1 &y, T2 &result) const
Compute a global dot product of two vectors.
Definition: owneroverlapcopy.hh:405
G GlobalIdType
The type of the global index.
Definition: owneroverlapcopy.hh:80
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:386
void project(T1 &x) const
Set vector to zero at copy dofs.
Definition: owneroverlapcopy.hh:542
RemoteIndices & remoteIndices()
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:494
CommPolicy< T >::IndexedType V
Definition: owneroverlapcopy.hh:204
Dune::Interface IF
Definition: owneroverlapcopy.hh:192
void addRemoteIndex(const RemoteIndexTripel &x)
Add a new remote index triple to the set of remote indices.
Definition: owneroverlapcopy.hh:119
const CollectiveCommunication< MPI_Comm > & communicator() const
Definition: owneroverlapcopy.hh:306
Combine< EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::owner >, EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::overlap >, AttributeSet > OwnerOverlapSet
Definition: owneroverlapcopy.hh:195
tuple< int, GlobalIdType, int > RemoteIndexTripel
A triple describing a remote index.
Definition: owneroverlapcopy.hh:98
OwnerOverlapCopyCommunication(const IndexInfoFromGrid< GlobalIdType, LocalIdType > &indexinfo, MPI_Comm comm_, SolverCategory::Category cat_=SolverCategory::overlapping, bool freecomm_=false)
Constructor.
Definition: owneroverlapcopy.hh:590
Dune::RemoteIndexListModifier< PIS, typename RI::Allocator, false > RILM
Definition: owneroverlapcopy.hh:189
const std::set< RemoteIndexTripel > & remoteIndices() const
Get the set of remote indices.
Definition: owneroverlapcopy.hh:141
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition: owneroverlapcopy.hh:335
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > ParallelIndexSet
The type of the parallel index set.
Definition: owneroverlapcopy.hh:453
Definition: owneroverlapcopy.hh:60
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:475
const ParallelIndexSet & indexSet() const
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:466
derive error class from the base class in common
Definition: istlexception.hh:16
Dune::BufferedCommunicator BC
Definition: owneroverlapcopy.hh:191
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:369
L LocalIdType
The type of the local index.
Definition: owneroverlapcopy.hh:83
void buildOwnerCopyToOwnerCopyInterface() const
Definition: owneroverlapcopy.hh:266
tuple< GlobalIdType, LocalIdType, int > IndexTripel
A triple describing a local index.
Definition: owneroverlapcopy.hh:91
const SolverCategory::Category getSolverCategory() const
Set Solver Category.
Definition: owneroverlapcopy.hh:302
static void scatter(T &a, V v, std::size_t i)
Definition: owneroverlapcopy.hh:211
double norm(const T1 &x) const
Compute the global euclidian norm of a vector.
Definition: owneroverlapcopy.hh:432
Dune::RemoteIndices< PIS > RI
Definition: owneroverlapcopy.hh:188
void buildOwnerCopyToAllInterface() const
Definition: owneroverlapcopy.hh:254
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:172
void buildCopyToAllInterface() const
Definition: owneroverlapcopy.hh:277
static void scatter(T &a, V v, std::size_t i)
Definition: owneroverlapcopy.hh:226
void setSolverCategory(SolverCategory set)
Set right Solver Category (default is overlapping).
Definition: owneroverlapcopy.hh:293
void freeGlobalLookup()
Definition: owneroverlapcopy.hh:524
Definition: owneroverlapcopy.hh:60
OwnerOverlapCopyCommunication(SolverCategory::Category cat_=SolverCategory::overlapping)
Construct the communication without any indices using MPI_COMM_WORLD.
Definition: owneroverlapcopy.hh:576
Definition: owneroverlapcopy.hh:217
ParallelIndexSet & indexSet()
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:484
Dune::AllSet< AttributeSet > AllSet
Definition: owneroverlapcopy.hh:196