5#ifndef DUNE_ISTL_OWNEROVERLAPCOPY_HH
6#define DUNE_ISTL_OWNEROVERLAPCOPY_HH
37template<
int dim,
template<
class,
class>
class Comm>
76 template <
class G,
class L>
112 localindices.insert(x);
126 remoteindices.insert(x);
144 return remoteindices;
152 localindices.clear();
153 remoteindices.clear();
172 template <
class GlobalIdType,
class LocalIdType=
int>
173 class OwnerOverlapCopyCommunication
175 template<
typename M,
typename G,
typename L>
176 friend void loadMatrixMarket(
M&,
178 OwnerOverlapCopyCommunication<G,L>&,
194 typedef EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner> OwnerSet;
195 typedef EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy> CopySet;
196 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,AttributeSet> OwnerOverlapSet;
233 void buildOwnerOverlapToAllInterface ()
const
235 if (OwnerOverlapToAllInterfaceBuilt)
236 OwnerOverlapToAllInterface.
free();
237 OwnerOverlapSet sourceFlags;
240 OwnerOverlapToAllInterface.
build(ri,sourceFlags,destFlags);
241 OwnerOverlapToAllInterfaceBuilt =
true;
244 void buildOwnerToAllInterface ()
const
246 if (OwnerToAllInterfaceBuilt)
247 OwnerToAllInterface.
free();
248 OwnerSet sourceFlags;
250 OwnerToAllInterface.
build(ri,sourceFlags,destFlags);
251 OwnerToAllInterfaceBuilt =
true;
254 void buildOwnerCopyToAllInterface ()
const
256 if (OwnerCopyToAllInterfaceBuilt)
257 OwnerCopyToAllInterface.
free();
259 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,AttributeSet> OwnerCopySet;
260 OwnerCopySet sourceFlags;
261 Combine<OwnerCopySet,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::overlap>,AttributeSet> destFlags;
262 OwnerCopyToAllInterface.
build(ri,sourceFlags,destFlags);
263 OwnerCopyToAllInterfaceBuilt =
true;
266 void buildOwnerCopyToOwnerCopyInterface ()
const
268 if (OwnerCopyToOwnerCopyInterfaceBuilt)
269 OwnerCopyToOwnerCopyInterface.
free();
272 typedef Combine<EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::owner>,EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>,AttributeSet> OwnerCopySet;
273 OwnerCopySet sourceFlags;
274 OwnerCopySet destFlags;
275 OwnerCopyToOwnerCopyInterface.
build(ri,sourceFlags,destFlags);
276 OwnerCopyToOwnerCopyInterfaceBuilt =
true;
279 void buildCopyToAllInterface ()
const
281 if (CopyToAllInterfaceBuilt)
282 CopyToAllInterface.
free();
285 CopyToAllInterface.
build(ri,sourceFlags,destFlags);
286 CopyToAllInterfaceBuilt =
true;
299 const Communication<MPI_Comm>& communicator()
const
311 void copyOwnerToAll (
const T& source, T& dest)
const
313 if (!OwnerToAllInterfaceBuilt)
314 buildOwnerToAllInterface ();
317 communicator.template forward<CopyGatherScatter<T> >(source,dest);
328 void copyCopyToAll (
const T& source, T& dest)
const
330 if (!CopyToAllInterfaceBuilt)
331 buildCopyToAllInterface ();
334 communicator.template forward<CopyGatherScatter<T> >(source,dest);
345 void addOwnerOverlapToAll (
const T& source, T& dest)
const
347 if (!OwnerOverlapToAllInterfaceBuilt)
348 buildOwnerOverlapToAllInterface ();
350 communicator.template build<T>(OwnerOverlapToAllInterface);
351 communicator.template forward<AddGatherScatter<T> >(source,dest);
362 void addOwnerCopyToAll (
const T& source, T& dest)
const
364 if (!OwnerCopyToAllInterfaceBuilt)
365 buildOwnerCopyToAllInterface ();
367 communicator.template build<T>(OwnerCopyToAllInterface);
368 communicator.template forward<AddGatherScatter<T> >(source,dest);
379 void addOwnerCopyToOwnerCopy (
const T& source, T& dest)
const
381 if (!OwnerCopyToOwnerCopyInterfaceBuilt)
382 buildOwnerCopyToOwnerCopyInterface ();
384 communicator.template build<T>(OwnerCopyToOwnerCopyInterface);
385 communicator.template forward<AddGatherScatter<T> >(source,dest);
397 template<
class T1,
class T2>
398 void dot (
const T1& x,
const T1& y, T2& result)
const
403 if (mask.
size()!=
static_cast<size_type
>(x.size()))
405 mask.
assign(x.size(),
true);
408 mask[i->local().local()] =
false;
412 for (
typename T1::size_type i=0; i<x.size(); i++)
413 result += (x[i]*(y[i]))*
static_cast<real_type
>(bool(mask[i]));
414 result = cc.
sum(result);
429 if (mask.
size()!=
static_cast<size_type
>(x.size()))
431 mask.
assign(x.size(),
true);
434 mask[i->local().local()] =
false;
436 auto result = real_type(0.0);
437 for (
typename T1::size_type i=0; i<x.size(); i++)
438 result += Impl::asVector(x[i]).two_norm2()*
static_cast<real_type
>(bool(mask[i]));
492 void buildGlobalLookup()
495 if(pis.
seqNo()==oldseqNo)
498 delete globalLookup_;
502 oldseqNo = pis.
seqNo();
508 if(pis.
seqNo()==oldseqNo)
511 delete globalLookup_;
514 oldseqNo = pis.
seqNo();
517 void freeGlobalLookup()
519 delete globalLookup_;
525 assert(globalLookup_ != 0);
526 return *globalLookup_;
535 void project (T1& x)
const
539 x[i->local().local()] = 0;
551 OwnerOverlapCopyCommunication (MPI_Comm comm_,
553 bool freecomm_ =
false)
554 : comm(comm_), cc(comm_), pis(), ri(pis,pis,comm_),
555 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
556 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
557 CopyToAllInterfaceBuilt(false), globalLookup_(0), category_(cat_),
570 : comm(MPI_COMM_WORLD), cc(MPI_COMM_WORLD), pis(), ri(pis,pis,MPI_COMM_WORLD),
571 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
572 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
573 CopyToAllInterfaceBuilt(false), globalLookup_(0), category_(cat_), freecomm(false)
583 OwnerOverlapCopyCommunication (
const IndexInfoFromGrid<GlobalIdType, LocalIdType>& indexinfo,
586 bool freecomm_ =
false)
587 : comm(comm_), cc(comm_), OwnerToAllInterfaceBuilt(false),
588 OwnerOverlapToAllInterfaceBuilt(false), OwnerCopyToAllInterfaceBuilt(false),
589 OwnerCopyToOwnerCopyInterfaceBuilt(false), CopyToAllInterfaceBuilt(false),
590 globalLookup_(0), category_(cat_), freecomm(freecomm_)
594 for (localindex_iterator i=indexinfo.localIndices().begin(); i!=indexinfo.localIndices().end(); ++i)
609 if (indexinfo.remoteIndices().size()>0)
611 remoteindex_iterator i=indexinfo.remoteIndices().begin();
612 int p = std::get<0>(*i);
613 RILM modifier = ri.template getModifier<false,true>(p);
615 for ( ; i!=indexinfo.remoteIndices().
end(); ++i)
618 if (p!=std::get<0>(*i))
621 modifier = ri.template getModifier<false,true>(p);
626 while (pi->global()!=std::get<1>(*i) && pi!=pis.
end())
629 DUNE_THROW(ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
642 ri.template getModifier<false,true>(0);
647 ~OwnerOverlapCopyCommunication ()
650 if (OwnerToAllInterfaceBuilt) OwnerToAllInterface.
free();
651 if (OwnerOverlapToAllInterfaceBuilt) OwnerOverlapToAllInterface.
free();
652 if (OwnerCopyToAllInterfaceBuilt) OwnerCopyToAllInterface.
free();
653 if (OwnerCopyToOwnerCopyInterfaceBuilt) OwnerCopyToOwnerCopyInterface.
free();
654 if (CopyToAllInterfaceBuilt) CopyToAllInterface.
free();
655 if (globalLookup_)
delete globalLookup_;
656 if (freecomm && (comm != MPI_COMM_NULL))
661 int wasFinalized = 0;
662 MPI_Finalized(&wasFinalized);
664 MPI_Comm_free(&comm);
670 OwnerOverlapCopyCommunication (
const OwnerOverlapCopyCommunication&)
673 Communication<MPI_Comm> cc;
676 mutable IF OwnerToAllInterface;
677 mutable bool OwnerToAllInterfaceBuilt;
678 mutable IF OwnerOverlapToAllInterface;
679 mutable bool OwnerOverlapToAllInterfaceBuilt;
680 mutable IF OwnerCopyToAllInterface;
681 mutable bool OwnerCopyToAllInterfaceBuilt;
682 mutable IF OwnerCopyToOwnerCopyInterface;
683 mutable bool OwnerCopyToOwnerCopyInterfaceBuilt;
684 mutable IF CopyToAllInterface;
685 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()
#define DUNE_THROW(E,...)
void build(const R &remoteIndices, const T1 &sourceFlags, const T2 &destFlags)
void setIndexSets(const ParallelIndexSet &source, const ParallelIndexSet &destination, const MPI_Comm &comm, const std::vector< int > &neighbours=std::vector< int >())
ArrayList< IndexPair, N >::const_iterator const_iterator
void add(const GlobalIndex &global)
MPI_Comm communicator() const
RemoteIndices(const ParallelIndexSet &source, const ParallelIndexSet &destination, const MPI_Comm &comm, const std::vector< int > &neighbours=std::vector< int >(), bool includeSelf=false)
GlobalLookupIndexSet(const ParallelIndexSet &indexset, std::size_t size)
V::value_type IndexedType
Dune::RemoteIndex< GlobalIndex, Attribute > RemoteIndex
derive error class from the base class in common
Definition istlexception.hh:19
Attribute set for overlapping Schwarz.
Definition owneroverlapcopy.hh:59
AttributeSet
Definition owneroverlapcopy.hh:60
@ owner
Definition owneroverlapcopy.hh:61
@ copy
Definition owneroverlapcopy.hh:61
@ overlap
Definition owneroverlapcopy.hh:61
Information about the index distribution.
Definition owneroverlapcopy.hh:78
std::tuple< GlobalIdType, LocalIdType, int > IndexTripel
A triple describing a local index.
Definition owneroverlapcopy.hh:92
void addRemoteIndex(const RemoteIndexTripel &x)
Add a new remote index triple to the set of remote indices.
Definition owneroverlapcopy.hh:120
G GlobalIdType
The type of the global index.
Definition owneroverlapcopy.hh:81
const std::set< IndexTripel > & localIndices() const
Get the set of indices local to the process.
Definition owneroverlapcopy.hh:133
const std::set< RemoteIndexTripel > & remoteIndices() const
Get the set of remote indices.
Definition owneroverlapcopy.hh:142
L LocalIdType
The type of the local index.
Definition owneroverlapcopy.hh:84
void clear()
Remove all indices from the sets.
Definition owneroverlapcopy.hh:150
void addLocalIndex(const IndexTripel &x)
Add a new index triple to the set of local indices.
Definition owneroverlapcopy.hh:106
std::tuple< int, GlobalIdType, int > RemoteIndexTripel
A triple describing a remote index.
Definition owneroverlapcopy.hh:99
gather/scatter callback for communication
Definition owneroverlapcopy.hh:204
static void scatter(T &a, V v, std::size_t i)
Definition owneroverlapcopy.hh:212
CommPolicy< T >::IndexedType V
Definition owneroverlapcopy.hh:205
static V gather(const T &a, std::size_t i)
Definition owneroverlapcopy.hh:207
Definition owneroverlapcopy.hh:219
static V gather(const T &a, std::size_t i)
Definition owneroverlapcopy.hh:222
static void scatter(T &a, V v, std::size_t i)
Definition owneroverlapcopy.hh:227
CommPolicy< T >::IndexedType V
Definition owneroverlapcopy.hh:220
Category
Definition solvercategory.hh:23
@ overlapping
Category for overlapping solvers.
Definition solvercategory.hh:29