3 #ifndef DUNE_ISTL_OWNEROVERLAPCOPY_HH 4 #define DUNE_ISTL_OWNEROVERLAPCOPY_HH 21 #include <dune/common/tuples.hh> 22 #include <dune/common/enumset.hh> 25 #include <dune/common/parallel/indexset.hh> 26 #include <dune/common/parallel/communicator.hh> 27 #include <dune/common/parallel/remoteindices.hh> 28 #include <dune/common/parallel/mpicollectivecommunication.hh> 33 #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;
206 static V
gather(
const T& a, std::size_t i)
219 typedef typename CommPolicy<T>::IndexedType
V;
221 static V
gather(
const T& a, std::size_t i)
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();
248 OwnerSet sourceFlags;
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;
318 if (!OwnerToAllInterfaceBuilt)
319 buildOwnerToAllInterface ();
321 communicator.template build<T>(OwnerToAllInterface);
322 communicator.template forward<CopyGatherScatter<T> >(source,dest);
335 if (!CopyToAllInterfaceBuilt)
336 buildCopyToAllInterface ();
338 communicator.template build<T>(CopyToAllInterface);
339 communicator.template forward<CopyGatherScatter<T> >(source,dest);
352 if (!OwnerOverlapToAllInterfaceBuilt)
353 buildOwnerOverlapToAllInterface ();
355 communicator.template build<T>(OwnerOverlapToAllInterface);
356 communicator.template forward<AddGatherScatter<T> >(source,dest);
369 if (!OwnerCopyToAllInterfaceBuilt)
370 buildOwnerCopyToAllInterface ();
372 communicator.template build<T>(OwnerCopyToAllInterface);
373 communicator.template forward<AddGatherScatter<T> >(source,dest);
386 if (!OwnerCopyToOwnerCopyInterfaceBuilt)
387 buildOwnerCopyToOwnerCopyInterface ();
389 communicator.template build<T>(OwnerCopyToOwnerCopyInterface);
390 communicator.template forward<AddGatherScatter<T> >(source,dest);
402 template<
class T1,
class T2>
403 void dot (
const T1& x,
const T1& y, T2& result)
const 406 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
408 mask.resize(x.size());
409 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
411 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
413 mask[i->local().local()] = 0;
417 for (
typename T1::size_type i=0; i<x.size(); i++)
418 result += x[i]*(y[i])*mask[i];
419 result = cc.sum(result);
430 double norm (
const T1& x)
const 433 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
435 mask.resize(x.size());
436 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
438 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
440 mask[i->local().local()] = 0;
442 typename T1::field_type result =
typename T1::field_type(0.0);
443 for (
typename T1::size_type i=0; i<x.size(); i++)
444 result += x[i].two_norm2()*mask[i];
445 return static_cast<double>(sqrt(cc.sum(result)));
448 typedef Dune::EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>
CopyFlags;
500 if(pis.seqNo()==oldseqNo)
503 delete globalLookup_;
506 globalLookup_ =
new GlobalLookupIndexSet(pis);
507 oldseqNo = pis.seqNo();
513 if(pis.seqNo()==oldseqNo)
516 delete globalLookup_;
518 globalLookup_ =
new GlobalLookupIndexSet(pis, size);
519 oldseqNo = pis.seqNo();
524 delete globalLookup_;
530 assert(globalLookup_ != 0);
531 return *globalLookup_;
542 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
544 x[i->local().local()] = 0;
558 bool freecomm_ =
false)
559 : comm(comm_), cc(comm_), pis(), ri(pis,pis,comm_),
560 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
561 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
562 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_),
575 : comm(MPI_COMM_WORLD), cc(MPI_COMM_WORLD), pis(), ri(pis,pis,MPI_COMM_WORLD),
576 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
577 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
578 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_), freecomm(false)
591 bool freecomm_ =
false)
592 : comm(comm_), cc(comm_), OwnerToAllInterfaceBuilt(false),
593 OwnerOverlapToAllInterfaceBuilt(false), OwnerCopyToAllInterfaceBuilt(false),
594 OwnerCopyToOwnerCopyInterfaceBuilt(false), CopyToAllInterfaceBuilt(false),
595 globalLookup_(0), category(cat_), freecomm(freecomm_)
613 ri.setIndexSets(pis,pis,cc);
618 RILM modifier = ri.template getModifier<false,true>(p);
619 typename PIS::const_iterator pi=pis.begin();
626 modifier = ri.template getModifier<false,true>(p);
631 while (pi->global()!=get<1>(*i) && pi!=pis.end())
634 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
647 ri.template getModifier<false,true>(0);
655 if (OwnerToAllInterfaceBuilt) OwnerToAllInterface.free();
656 if (OwnerOverlapToAllInterfaceBuilt) OwnerOverlapToAllInterface.free();
657 if (OwnerCopyToAllInterfaceBuilt) OwnerCopyToAllInterface.free();
658 if (OwnerCopyToOwnerCopyInterfaceBuilt) OwnerCopyToOwnerCopyInterface.free();
659 if (CopyToAllInterfaceBuilt) CopyToAllInterface.free();
660 if (globalLookup_)
delete globalLookup_;
662 if(comm!=MPI_COMM_NULL)
668 int wasFinalized = 0;
669 MPI_Finalized( &wasFinalized );
672 MPI_Comm_free(&comm);
680 CollectiveCommunication<MPI_Comm> cc;
683 mutable IF OwnerToAllInterface;
684 mutable bool OwnerToAllInterfaceBuilt;
685 mutable IF OwnerOverlapToAllInterface;
686 mutable bool OwnerOverlapToAllInterfaceBuilt;
687 mutable IF OwnerCopyToAllInterface;
688 mutable bool OwnerCopyToAllInterfaceBuilt;
689 mutable IF OwnerCopyToOwnerCopyInterface;
690 mutable bool OwnerCopyToOwnerCopyInterfaceBuilt;
691 mutable IF CopyToAllInterface;
692 mutable bool CopyToAllInterfaceBuilt;
693 mutable std::vector<double> mask;
695 GlobalLookupIndexSet* globalLookup_;
const std::set< IndexTripel > & localIndices() const
Get the set of indices local to the process.
Definition: owneroverlapcopy.hh:132
Dune::RemoteIndices< PIS > RI
Definition: owneroverlapcopy.hh:188
void buildCopyToAllInterface() const
Definition: owneroverlapcopy.hh:277
const GlobalLookupIndexSet & globalLookup() const
Definition: owneroverlapcopy.hh:528
Definition: owneroverlapcopy.hh:217
EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::owner > OwnerSet
Definition: owneroverlapcopy.hh:193
Categories for the solvers.
Definition: solvercategory.hh:17
Dune::EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::copy > CopyFlags
Definition: owneroverlapcopy.hh:448
EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::copy > CopySet
Definition: owneroverlapcopy.hh:194
~OwnerOverlapCopyCommunication()
Definition: owneroverlapcopy.hh:652
void buildOwnerToAllInterface() const
Definition: owneroverlapcopy.hh:244
Dune::RemoteIndices< PIS > RemoteIndices
The type of the remote indices.
Definition: owneroverlapcopy.hh:454
Attribute set for overlapping schwarz.
Definition: owneroverlapcopy.hh:57
Category for ovelapping solvers.
Definition: solvercategory.hh:25
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > PIS
Definition: owneroverlapcopy.hh:187
G GlobalIdType
The type of the global index.
Definition: owneroverlapcopy.hh:80
void buildGlobalLookup()
Definition: owneroverlapcopy.hh:497
static void scatter(T &a, V v, std::size_t i)
Definition: owneroverlapcopy.hh:211
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:350
OwnerOverlapCopyCommunication(MPI_Comm comm_, SolverCategory::Category cat_=SolverCategory::overlapping, bool freecomm_=false)
Construct the communication without any indices.
Definition: owneroverlapcopy.hh:556
derive error class from the base class in common
Definition: istlexception.hh:16
AttributeSet
Definition: owneroverlapcopy.hh:59
SolverCategory::Category getSolverCategory() const
Get Solver Category.
Definition: owneroverlapcopy.hh:300
void clear()
Remove all indices from the sets.
Definition: owneroverlapcopy.hh:149
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
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:172
tuple< int, GlobalIdType, int > RemoteIndexTripel
A triple describing a remote index.
Definition: owneroverlapcopy.hh:98
Dune::Interface IF
Definition: owneroverlapcopy.hh:192
void buildOwnerOverlapToAllInterface() const
Definition: owneroverlapcopy.hh:232
static V gather(const T &a, std::size_t i)
Definition: owneroverlapcopy.hh:221
RI::RemoteIndex RX
Definition: owneroverlapcopy.hh:190
const std::set< RemoteIndexTripel > & remoteIndices() const
Get the set of remote indices.
Definition: owneroverlapcopy.hh:141
Combine< EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::owner >, EnumItem< AttributeSet, OwnerOverlapCopyAttributeSet::overlap >, AttributeSet > OwnerOverlapSet
Definition: owneroverlapcopy.hh:195
void dot(const T1 &x, const T1 &y, T2 &result) const
Compute a global dot product of two vectors.
Definition: owneroverlapcopy.hh:403
void buildGlobalLookup(std::size_t size)
Definition: owneroverlapcopy.hh:510
void project(T1 &x) const
Set vector to zero at copy dofs.
Definition: owneroverlapcopy.hh:540
RemoteIndices & remoteIndices()
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:492
CommPolicy< T >::IndexedType V
Definition: owneroverlapcopy.hh:219
L LocalIdType
The type of the local index.
Definition: owneroverlapcopy.hh:83
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:384
tuple< GlobalIdType, LocalIdType, int > IndexTripel
A triple describing a local index.
Definition: owneroverlapcopy.hh:91
Dune::BufferedCommunicator BC
Definition: owneroverlapcopy.hh:191
void testRedistributed(int s)
OwnerOverlapCopyCommunication(const IndexInfoFromGrid< GlobalIdType, LocalIdType > &indexinfo, MPI_Comm comm_, SolverCategory::Category cat_=SolverCategory::overlapping, bool freecomm_=false)
Constructor.
Definition: owneroverlapcopy.hh:588
const CollectiveCommunication< MPI_Comm > & communicator() const
Definition: owneroverlapcopy.hh:304
CommPolicy< T >::IndexedType V
Definition: owneroverlapcopy.hh:204
static void scatter(T &a, V v, std::size_t i)
Definition: owneroverlapcopy.hh:226
const ParallelIndexSet & indexSet() const
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:464
Provides classes for reading and writing MatrixMarket Files with an extension for parallel matrices...
static V gather(const T &a, std::size_t i)
Definition: owneroverlapcopy.hh:206
Definition: owneroverlapcopy.hh:60
Dune::RemoteIndexListModifier< PIS, typename RI::Allocator, false > RILM
Definition: owneroverlapcopy.hh:189
double norm(const T1 &x) const
Compute the global euclidian norm of a vector.
Definition: owneroverlapcopy.hh:430
void copyCopyToAll(const T &source, T &dest) const
Communicate values from copy data points to all other data points.
Definition: owneroverlapcopy.hh:333
void buildOwnerCopyToOwnerCopyInterface() const
Definition: owneroverlapcopy.hh:266
Dune::ParallelIndexSet< GlobalIdType, LI, 512 > ParallelIndexSet
The type of the parallel index set.
Definition: owneroverlapcopy.hh:451
void buildOwnerCopyToAllInterface() const
Definition: owneroverlapcopy.hh:254
const RemoteIndices & remoteIndices() const
Get the underlying remote indices.
Definition: owneroverlapcopy.hh:473
Dune::AllSet< AttributeSet > AllSet
Definition: owneroverlapcopy.hh:196
Definition: owneroverlapcopy.hh:60
Definition: owneroverlapcopy.hh:60
Dune::GlobalLookupIndexSet< ParallelIndexSet > GlobalLookupIndexSet
The type of the reverse lookup of indices.
Definition: owneroverlapcopy.hh:458
void freeGlobalLookup()
Definition: owneroverlapcopy.hh:522
void addLocalIndex(const IndexTripel &x)
Add a new index triple to the set of local indices.
Definition: owneroverlapcopy.hh:105
void addRemoteIndex(const RemoteIndexTripel &x)
Add a new remote index triple to the set of remote indices.
Definition: owneroverlapcopy.hh:119
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:367
gather/scatter callback for communcation
Definition: owneroverlapcopy.hh:202
ParallelIndexSet & indexSet()
Get the underlying parallel index set.
Definition: owneroverlapcopy.hh:482
void setSolverCategory(SolverCategory set)
Set right Solver Category (default is overlapping).
Definition: owneroverlapcopy.hh:292
void copyOwnerToAll(const T &source, T &dest) const
Communicate values from owner data points to all other data points.
Definition: owneroverlapcopy.hh:316
Definition: basearray.hh:19
Information about the index distribution.
Definition: owneroverlapcopy.hh:76
Category
Definition: solvercategory.hh:19
OwnerOverlapCopyCommunication(SolverCategory::Category cat_=SolverCategory::overlapping)
Construct the communication without any indices using MPI_COMM_WORLD.
Definition: owneroverlapcopy.hh:574