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/mpicollectivecommunication.hh>
34 #include<dune/common/collectivecommunication.hh>
36 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;
218 typedef typename CommPolicy<T>::IndexedType
V;
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();
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;
319 if (!OwnerToAllInterfaceBuilt)
322 communicator.template build<T>(OwnerToAllInterface);
323 communicator.template forward<CopyGatherScatter<T> >(source,dest);
336 if (!CopyToAllInterfaceBuilt)
339 communicator.template build<T>(CopyToAllInterface);
340 communicator.template forward<CopyGatherScatter<T> >(source,dest);
353 if (!OwnerOverlapToAllInterfaceBuilt)
356 communicator.template build<T>(OwnerOverlapToAllInterface);
357 communicator.template forward<AddGatherScatter<T> >(source,dest);
370 if (!OwnerCopyToAllInterfaceBuilt)
373 communicator.template build<T>(OwnerCopyToAllInterface);
374 communicator.template forward<AddGatherScatter<T> >(source,dest);
387 if (!OwnerCopyToOwnerCopyInterfaceBuilt)
390 communicator.template build<T>(OwnerCopyToOwnerCopyInterface);
391 communicator.template forward<AddGatherScatter<T> >(source,dest);
403 template<
class T1,
class T2>
404 void dot (
const T1& x,
const T1& y, T2& result)
const
407 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
409 mask.resize(x.size());
410 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
412 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
414 mask[i->local().local()] = 0;
418 for (
typename T1::size_type i=0; i<x.size(); i++)
419 result += x[i]*(y[i])*mask[i];
420 result = cc.sum(result);
431 double norm (
const T1& x)
const
434 if (mask.size()!=
static_cast<typename std::vector<double>::size_type
>(x.size()))
436 mask.resize(x.size());
437 for (
typename std::vector<double>::size_type i=0; i<mask.size(); i++)
439 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
441 mask[i->local().local()] = 0;
444 for (
typename T1::size_type i=0; i<x.size(); i++)
445 result += x[i].two_norm2()*mask[i];
446 return sqrt(cc.sum(result));
449 typedef Dune::EnumItem<AttributeSet,OwnerOverlapCopyAttributeSet::copy>
CopyFlags;
501 if(pis.seqNo()==oldseqNo)
504 delete globalLookup_;
508 oldseqNo = pis.seqNo();
514 if(pis.seqNo()==oldseqNo)
517 delete globalLookup_;
520 oldseqNo = pis.seqNo();
525 delete globalLookup_;
531 assert(globalLookup_ != 0);
532 return *globalLookup_;
543 for (
typename PIS::const_iterator i=pis.begin(); i!=pis.end(); ++i)
545 x[i->local().local()] = 0;
559 bool freecomm_ =
false)
560 : comm(comm_), cc(comm_), pis(), ri(pis,pis,comm_),
561 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
562 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
563 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_),
576 : comm(MPI_COMM_WORLD), cc(MPI_COMM_WORLD), pis(), ri(pis,pis,MPI_COMM_WORLD),
577 OwnerToAllInterfaceBuilt(false), OwnerOverlapToAllInterfaceBuilt(false),
578 OwnerCopyToAllInterfaceBuilt(false), OwnerCopyToOwnerCopyInterfaceBuilt(false),
579 CopyToAllInterfaceBuilt(false), globalLookup_(0), category(cat_), freecomm(false)
592 bool freecomm_ =
false)
593 : comm(comm_), cc(comm_), OwnerToAllInterfaceBuilt(false),
594 OwnerOverlapToAllInterfaceBuilt(false), OwnerCopyToAllInterfaceBuilt(false),
595 OwnerCopyToOwnerCopyInterfaceBuilt(false), CopyToAllInterfaceBuilt(false),
596 globalLookup_(0), category(cat_), freecomm(freecomm_)
614 ri.setIndexSets(pis,pis,cc);
619 RILM modifier = ri.template getModifier<false,true>(p);
620 typename PIS::const_iterator pi=pis.begin();
627 modifier = ri.template getModifier<false,true>(p);
632 while (pi->global()!=get<1>(*i) && pi!=pis.end())
635 DUNE_THROW(
ISTLError,
"OwnerOverlapCopyCommunication: global index not in index set");
648 ri.template getModifier<false,true>(0);
656 if (OwnerToAllInterfaceBuilt) OwnerToAllInterface.free();
657 if (OwnerOverlapToAllInterfaceBuilt) OwnerOverlapToAllInterface.free();
658 if (OwnerCopyToAllInterfaceBuilt) OwnerCopyToAllInterface.free();
659 if (OwnerCopyToOwnerCopyInterfaceBuilt) OwnerCopyToOwnerCopyInterface.free();
660 if (CopyToAllInterfaceBuilt) CopyToAllInterface.free();
661 if (globalLookup_)
delete globalLookup_;
663 if(comm!=MPI_COMM_NULL)
664 MPI_Comm_free(&comm);
671 CollectiveCommunication<MPI_Comm> cc;
674 mutable IF OwnerToAllInterface;
675 mutable bool OwnerToAllInterfaceBuilt;
676 mutable IF OwnerOverlapToAllInterface;
677 mutable bool OwnerOverlapToAllInterfaceBuilt;
678 mutable IF OwnerCopyToAllInterface;
679 mutable bool OwnerCopyToAllInterfaceBuilt;
680 mutable IF OwnerCopyToOwnerCopyInterface;
681 mutable bool OwnerCopyToOwnerCopyInterfaceBuilt;
682 mutable IF CopyToAllInterface;
683 mutable bool CopyToAllInterfaceBuilt;
684 mutable std::vector<double> mask;