3#ifndef DUNE_ISTL_OWNEROVERLAPCOPY_HH
4#define DUNE_ISTL_OWNEROVERLAPCOPY_HH
35template<
int dim,
template<
class,
class>
class Comm>
74 template <
class G,
class L>
110 localindices.insert(x);
124 remoteindices.insert(x);
142 return remoteindices;
150 localindices.clear();
151 remoteindices.clear();
170 template <
class GlobalIdType,
class LocalIdType=
int>
171 class OwnerOverlapCopyCommunication
173 template<
typename M,
typename G,
typename L>
174 friend void loadMatrixMarket(
M&,
176 OwnerOverlapCopyCommunication<G,L>&,
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;
231 void buildOwnerOverlapToAllInterface ()
const
233 if (OwnerOverlapToAllInterfaceBuilt)
234 OwnerOverlapToAllInterface.
free();
235 OwnerOverlapSet sourceFlags;
238 OwnerOverlapToAllInterface.
build(ri,sourceFlags,destFlags);
239 OwnerOverlapToAllInterfaceBuilt =
true;
242 void buildOwnerToAllInterface ()
const
244 if (OwnerToAllInterfaceBuilt)
245 OwnerToAllInterface.
free();
246 OwnerSet sourceFlags;
248 OwnerToAllInterface.
build(ri,sourceFlags,destFlags);
249 OwnerToAllInterfaceBuilt =
true;
252 void buildOwnerCopyToAllInterface ()
const
254 if (OwnerCopyToAllInterfaceBuilt)
255 OwnerCopyToAllInterface.
free();
257 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,AttributeSet> OwnerCopySet;
258 OwnerCopySet sourceFlags;
259 Combine<OwnerCopySet,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,AttributeSet> destFlags;
260 OwnerCopyToAllInterface.
build(ri,sourceFlags,destFlags);
261 OwnerCopyToAllInterfaceBuilt =
true;
264 void buildOwnerCopyToOwnerCopyInterface ()
const
266 if (OwnerCopyToOwnerCopyInterfaceBuilt)
267 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;
277 void buildCopyToAllInterface ()
const
279 if (CopyToAllInterfaceBuilt)
280 CopyToAllInterface.
free();
283 CopyToAllInterface.
build(ri,sourceFlags,destFlags);
284 CopyToAllInterfaceBuilt =
true;
297 const CollectiveCommunication<MPI_Comm>& communicator()
const
309 void copyOwnerToAll (
const T& source, T& dest)
const
311 if (!OwnerToAllInterfaceBuilt)
312 buildOwnerToAllInterface ();
315 communicator.template forward<CopyGatherScatter<T> >(source,dest);
326 void copyCopyToAll (
const T& source, T& dest)
const
328 if (!CopyToAllInterfaceBuilt)
329 buildCopyToAllInterface ();
332 communicator.template forward<CopyGatherScatter<T> >(source,dest);
343 void addOwnerOverlapToAll (
const T& source, T& dest)
const
345 if (!OwnerOverlapToAllInterfaceBuilt)
346 buildOwnerOverlapToAllInterface ();
348 communicator.template build<T>(OwnerOverlapToAllInterface);
349 communicator.template forward<AddGatherScatter<T> >(source,dest);
360 void addOwnerCopyToAll (
const T& source, T& dest)
const
362 if (!OwnerCopyToAllInterfaceBuilt)
363 buildOwnerCopyToAllInterface ();
365 communicator.template build<T>(OwnerCopyToAllInterface);
366 communicator.template forward<AddGatherScatter<T> >(source,dest);
377 void addOwnerCopyToOwnerCopy (
const T& source, T& dest)
const
379 if (!OwnerCopyToOwnerCopyInterfaceBuilt)
380 buildOwnerCopyToOwnerCopyInterface ();
382 communicator.template build<T>(OwnerCopyToOwnerCopyInterface);
383 communicator.template forward<AddGatherScatter<T> >(source,dest);
395 template<
class T1,
class T2>
396 void dot (
const T1& x,
const T1& y, T2& result)
const
407 mask[i->local().local()] = 0;
411 for (
typename T1::size_type i=0; i<x.size(); i++)
412 result += (x[i]*(y[i]))*
static_cast<real_type
>(mask[i]);
413 result = cc.sum(result);
435 mask[i->local().local()] = 0;
437 auto result = real_type(0.0);
438 for (
typename T1::size_type i=0; i<x.size(); i++)
439 result += Impl::asVector(x[i]).two_norm2()*mask[i];
441 return sqrt(cc.sum(result));
469 const RemoteIndices& remoteIndices()
const
488 RemoteIndices& remoteIndices()
493 void buildGlobalLookup()
496 if(pis.
seqNo()==oldseqNo)
499 delete globalLookup_;
503 oldseqNo = pis.
seqNo();
509 if(pis.
seqNo()==oldseqNo)
512 delete globalLookup_;
515 oldseqNo = pis.
seqNo();
518 void freeGlobalLookup()
520 delete globalLookup_;
526 assert(globalLookup_ != 0);
527 return *globalLookup_;
536 void project (T1& x)
const
540 x[i->local().local()] = 0;
552 OwnerOverlapCopyCommunication (MPI_Comm comm_,
554 bool freecomm_ =
false)
555 : comm(comm_), cc(comm_), pis(), ri(pis,pis,comm_),
556 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
557 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
558 CopyToAllInterfaceBuilt(false), globalLookup_(0), category_(cat_),
571 : comm(MPI_COMM_WORLD), cc(MPI_COMM_WORLD), pis(), ri(pis,pis,MPI_COMM_WORLD),
572 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
573 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
574 CopyToAllInterfaceBuilt(false), globalLookup_(0), category_(cat_), freecomm(false)
584 OwnerOverlapCopyCommunication (
const IndexInfoFromGrid<GlobalIdType, LocalIdType>& indexinfo,
587 bool freecomm_ =
false)
588 : comm(comm_), cc(comm_), OwnerToAllInterfaceBuilt(false),
589 OwnerOverlapToAllInterfaceBuilt(false), OwnerCopyToAllInterfaceBuilt(false),
590 OwnerCopyToOwnerCopyInterfaceBuilt(false), CopyToAllInterfaceBuilt(false),
591 globalLookup_(0), category_(cat_), freecomm(freecomm_)
595 for (localindex_iterator i=indexinfo.localIndices().begin(); i!=indexinfo.localIndices().end(); ++i)
610 if (indexinfo.remoteIndices().size()>0)
612 remoteindex_iterator i=indexinfo.remoteIndices().begin();
613 int p = std::get<0>(*i);
614 RILM modifier = ri.template getModifier<false,true>(p);
616 for ( ; i!=indexinfo.remoteIndices().
end(); ++i)
619 if (p!=std::get<0>(*i))
622 modifier = ri.template getModifier<false,true>(p);
627 while (pi->global()!=std::get<1>(*i) && pi!=pis.
end())
630 DUNE_THROW(ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
643 ri.template getModifier<false,true>(0);
648 ~OwnerOverlapCopyCommunication ()
651 if (OwnerToAllInterfaceBuilt) OwnerToAllInterface.
free();
652 if (OwnerOverlapToAllInterfaceBuilt) OwnerOverlapToAllInterface.
free();
653 if (OwnerCopyToAllInterfaceBuilt) OwnerCopyToAllInterface.
free();
654 if (OwnerCopyToOwnerCopyInterfaceBuilt) OwnerCopyToOwnerCopyInterface.
free();
655 if (CopyToAllInterfaceBuilt) CopyToAllInterface.
free();
656 if (globalLookup_)
delete globalLookup_;
658 if(comm!=MPI_COMM_NULL)
664 int wasFinalized = 0;
665 MPI_Finalized( &wasFinalized );
668 MPI_Comm_free(&comm);
673 OwnerOverlapCopyCommunication (
const OwnerOverlapCopyCommunication&)
676 CollectiveCommunication<MPI_Comm> cc;
679 mutable IF OwnerToAllInterface;
680 mutable bool OwnerToAllInterfaceBuilt;
681 mutable IF OwnerOverlapToAllInterface;
682 mutable bool OwnerOverlapToAllInterfaceBuilt;
683 mutable IF OwnerCopyToAllInterface;
684 mutable bool OwnerCopyToAllInterfaceBuilt;
685 mutable IF OwnerCopyToOwnerCopyInterface;
686 mutable bool OwnerCopyToOwnerCopyInterfaceBuilt;
687 mutable IF CopyToAllInterface;
688 mutable bool CopyToAllInterfaceBuilt;
Provides classes for reading and writing MatrixMarket Files with an extension for parallel matrices.
void testRedistributed(int s)
static constexpr size_type M()
void build(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags)
ArrayList< IndexPair, N >::const_iterator const_iterator
void add(const GlobalIndex &global)
MPI_Comm communicator() const
GlobalLookupIndexSet(const ParallelIndexSet &indexset, std::size_t size)
V::value_type IndexedType
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
void setIndexSets(const ParallelIndexSet &source, const ParallelIndexSet &destination, const MPI_Comm &comm, const std::vector< int > &neighbours=std::vector< int >())
derive error class from the base class in common
Definition istlexception.hh:17
Attribute set for overlapping Schwarz.
Definition owneroverlapcopy.hh:57
AttributeSet
Definition owneroverlapcopy.hh:58
@ owner
Definition owneroverlapcopy.hh:59
@ copy
Definition owneroverlapcopy.hh:59
@ overlap
Definition owneroverlapcopy.hh:59
Information about the index distribution.
Definition owneroverlapcopy.hh:76
std::tuple< GlobalIdType, LocalIdType, int > IndexTripel
A triple describing a local index.
Definition owneroverlapcopy.hh:90
void addRemoteIndex(const RemoteIndexTripel &x)
Add a new remote index triple to the set of remote indices.
Definition owneroverlapcopy.hh:118
G GlobalIdType
The type of the global index.
Definition owneroverlapcopy.hh:79
const std::set< IndexTripel > & localIndices() const
Get the set of indices local to the process.
Definition owneroverlapcopy.hh:131
const std::set< RemoteIndexTripel > & remoteIndices() const
Get the set of remote indices.
Definition owneroverlapcopy.hh:140
L LocalIdType
The type of the local index.
Definition owneroverlapcopy.hh:82
void clear()
Remove all indices from the sets.
Definition owneroverlapcopy.hh:148
void addLocalIndex(const IndexTripel &x)
Add a new index triple to the set of local indices.
Definition owneroverlapcopy.hh:104
std::tuple< int, GlobalIdType, int > RemoteIndexTripel
A triple describing a remote index.
Definition owneroverlapcopy.hh:97
gather/scatter callback for communcation
Definition owneroverlapcopy.hh:202
static void scatter(T &a, V v, std::size_t i)
Definition owneroverlapcopy.hh:210
CommPolicy< T >::IndexedType V
Definition owneroverlapcopy.hh:203
static V gather(const T &a, std::size_t i)
Definition owneroverlapcopy.hh:205
Definition owneroverlapcopy.hh:217
static V gather(const T &a, std::size_t i)
Definition owneroverlapcopy.hh:220
static void scatter(T &a, V v, std::size_t i)
Definition owneroverlapcopy.hh:225
CommPolicy< T >::IndexedType V
Definition owneroverlapcopy.hh:218
Category
Definition solvercategory.hh:21
@ overlapping
Category for overlapping solvers.
Definition solvercategory.hh:27