3 #ifndef DUNE_PDELAB_BACKEND_ISTL_PARALLELHELPER_HH 4 #define DUNE_PDELAB_BACKEND_ISTL_PARALLELHELPER_HH 8 #include <dune/common/deprecated.hh> 9 #include <dune/common/parallel/mpihelper.hh> 10 #include <dune/common/stdstreams.hh> 12 #include <dune/istl/owneroverlapcopy.hh> 13 #include <dune/istl/solvercategory.hh> 14 #include <dune/istl/operators.hh> 15 #include <dune/istl/solvers.hh> 16 #include <dune/istl/preconditioners.hh> 17 #include <dune/istl/scalarproducts.hh> 18 #include <dune/istl/paamg/amg.hh> 19 #include <dune/istl/paamg/pinfo.hh> 20 #include <dune/istl/io.hh> 21 #include <dune/istl/superlu.hh> 44 template<
typename GFS>
49 typedef int RankIndex;
57 typedef typename GFS::Ordering::Traits::ContainerIndex ContainerIndex;
63 , _rank(gfs.gridView().comm().
rank())
72 if (gfs.entitySet().partitions().value == Partitions::interiorBorder.value)
76 _interiorBorder_all_interface = InteriorBorder_InteriorBorder_Interface;
77 _all_all_interface = InteriorBorder_InteriorBorder_Interface;
82 _interiorBorder_all_interface = InteriorBorder_All_Interface;
83 _all_all_interface = All_All_Interface;
86 if (_gfs.gridView().comm().size()>1)
92 gdh(_gfs,_ghosts,
false);
93 _gfs.gridView().communicate(gdh,_interiorBorder_all_interface,Dune::ForwardCommunication);
99 _gfs.gridView().communicate(pdh,_interiorBorder_all_interface,Dune::ForwardCommunication);
117 template<
typename X,
typename Mask>
120 typename Mask::const_iterator mask_it = mask.begin();
121 for (
typename X::iterator it = x.begin(),
129 template<
typename X,
typename Mask>
132 typename Mask::const_iterator mask_it = mask.begin();
133 for (
typename X::iterator it = x.begin(),
137 *it = (*mask_it == _rank ? *it :
typename X::field_type(0));
143 bool owned(
const ContainerIndex& i)
const 145 return _ranks[i] == _rank;
155 template<
typename X,
typename Y>
156 typename PromotionTraits<
157 typename X::field_type,
158 typename Y::field_type
174 template<
typename X,
typename Y,
typename Mask>
175 typename PromotionTraits<
176 typename X::field_type,
177 typename Y::field_type
181 typedef typename PromotionTraits<
182 typename X::field_type,
183 typename Y::field_type
184 >::PromotedType result_type;
188 typename Y::const_iterator y_it = y.begin();
189 typename Mask::const_iterator mask_it = mask.begin();
190 for (
typename X::const_iterator x_it = x.begin(),
193 ++x_it, ++y_it, ++mask_it)
201 template<
typename X,
typename Y,
typename Mask>
202 typename PromotionTraits<
203 typename X::field_type,
204 typename Y::field_type
208 typedef typename PromotionTraits<
209 typename X::field_type,
210 typename Y::field_type
211 >::PromotedType result_type;
215 typename Y::const_iterator y_it = y.begin();
216 typename Mask::const_iterator mask_it = mask.begin();
217 for (
typename X::const_iterator x_it = x.begin(),
220 ++x_it, ++y_it, ++mask_it)
221 r += (*mask_it == _rank ? Dune::dot(*x_it,*y_it) : result_type(0));
253 template<
typename MatrixType,
typename Comm>
261 bool owned_for_amg(std::size_t i)
const 271 const RankIndex _rank;
277 InterfaceType _interiorBorder_all_interface;
280 InterfaceType _all_all_interface;
285 template<
typename GFS>
286 template<
typename M,
typename C>
292 const bool is_bcrs_matrix =
300 const bool block_type_is_field_matrix =
309 static_assert(is_bcrs_matrix && block_type_is_field_matrix,
"matrix structure not compatible with AMG");
318 typedef typename GFS::Traits::GridViewType GV;
319 typedef typename RankVector::size_type size_type;
320 const GV& gv = _gfs.gridView();
323 const bool need_communication = _gfs.gridView().comm().size() > 1;
327 BoolVector sharedDOF(_gfs,
false);
329 if (need_communication)
332 _gfs.gridView().communicate(data_handle,_all_all_interface,Dune::ForwardCommunication);
336 typedef typename C::ParallelIndexSet::GlobalIndex GlobalIndex;
337 GlobalIndex count = 0;
339 for (size_type i = 0; i < sharedDOF.N(); ++i)
340 if (owned_for_amg(i) &&
native(sharedDOF)[i][0])
343 dverb << gv.comm().rank() <<
": shared block count is " << count.touint() << std::endl;
346 std::vector<GlobalIndex> counts(_gfs.gridView().comm().size());
347 _gfs.gridView().comm().allgather(&count, 1, &(counts[0]));
350 GlobalIndex start = std::accumulate(counts.begin(),counts.begin() + _rank,GlobalIndex(0));
353 GIVector scalarIndices(_gfs, std::numeric_limits<GlobalIndex>::max());
355 for (size_type i = 0; i < sharedDOF.N(); ++i)
356 if (owned_for_amg(i) &&
native(sharedDOF)[i][0])
358 native(scalarIndices)[i][0] = start;
363 if (need_communication)
366 _gfs.gridView().communicate(data_handle,_interiorBorder_all_interface,Dune::ForwardCommunication);
370 c.indexSet().beginResize();
371 for (size_type i=0; i<scalarIndices.N(); ++i)
373 Dune::OwnerOverlapCopyAttributeSet::AttributeSet attr;
374 if(
native(scalarIndices)[i][0] != std::numeric_limits<GlobalIndex>::max())
377 if (owned_for_amg(i))
380 attr = Dune::OwnerOverlapCopyAttributeSet::owner;
384 attr = Dune::OwnerOverlapCopyAttributeSet::copy;
386 c.indexSet().add(
native(scalarIndices)[i][0],
typename C::ParallelIndexSet::LocalIndex(i,attr));
389 c.indexSet().endResize();
392 std::set<int> neighbors;
394 if (need_communication)
397 _gfs.gridView().communicate(data_handle,_all_all_interface,Dune::ForwardCommunication);
400 c.remoteIndices().setNeighbours(neighbors);
401 c.remoteIndices().template rebuild<false>();
406 template<
int s,
bool isFakeMPIHelper>
409 typedef Dune::Amg::SequentialInformation
type;
419 typedef OwnerOverlapCopyCommunication<bigunsignedint<s>,
int>
type;
430 #endif // DUNE_PDELAB_BACKEND_ISTL_PARALLELHELPER_HH std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition: backend/interface.hh:199
GatherScatter data handle for creating a disjoint DOF partitioning.
Definition: genericdatahandle.hh:930
Definition: genericdatahandle.hh:716
Tag describing a BCRSMatrix.
Definition: backend/istl/tags.hh:60
Data handle for marking ghost DOFs.
Definition: genericdatahandle.hh:812
Data handle for marking shared DOFs.
Definition: genericdatahandle.hh:1014
Definition: parallelhelper.hh:45
static const unsigned int value
Definition: gridfunctionspace/tags.hh:177
void createIndexSetAndProjectForAMG(MatrixType &m, Comm &c)
Makes the matrix consistent and creates the parallel information for AMG.
Definition: parallelhelper.hh:407
typename native_type< T >::type Native
Alias of the native container type associated with T or T itself if it is not a backend wrapper...
Definition: backend/interface.hh:183
Tag describing an arbitrary FieldVector.
Definition: backend/istl/tags.hh:43
tags::container< T >::type container_tag(const T &)
Gets instance of container tag associated with T.
Definition: backend/istl/tags.hh:246
bool owned(const ContainerIndex &i) const
Tests whether the given index is owned by this process.
Definition: parallelhelper.hh:143
OwnerOverlapCopyCommunication< bigunsignedint< s >, int > type
Definition: parallelhelper.hh:419
Definition: adaptivity.hh:27
Tag describing an arbitrary FieldMatrix.
Definition: backend/istl/tags.hh:80
Dune::Amg::SequentialInformation type
Definition: parallelhelper.hh:409
Extracts the container tag from T.
Definition: backend/istl/tags.hh:142
RankIndex rank() const
Returns the MPI rank of this process.
Definition: parallelhelper.hh:229
bool isGhost(const ContainerIndex &i) const
Tests whether the given index belongs to a ghost DOF.
Definition: parallelhelper.hh:149
ParallelHelper(const GFS &gfs, int verbose=1)
Definition: parallelhelper.hh:61
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:113
const std::string s
Definition: function.hh:1102
PromotionTraits< typename X::field_type, typename Y::field_type >::PromotedType disjointDot(const X &x, const Y &y) const
Calculates the (rank-local) dot product of x and y on the disjoint partition defined by the helper...
Definition: parallelhelper.hh:160
Data handle for collecting set of neighboring MPI ranks.
Definition: genericdatahandle.hh:1060
void maskForeignDOFs(X &x) const
Mask out all DOFs not owned by the current process with 0.
Definition: parallelhelper.hh:107
Tag describing a BlockVector.
Definition: backend/istl/tags.hh:23