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> 11 #include <dune/common/typetraits.hh> 13 #if HAVE_UG && PDELAB_SEQUENTIAL_UG 15 #include <dune/grid/uggrid.hh> 18 #include <dune/istl/owneroverlapcopy.hh> 19 #include <dune/istl/solvercategory.hh> 20 #include <dune/istl/operators.hh> 21 #include <dune/istl/solvers.hh> 22 #include <dune/istl/preconditioners.hh> 23 #include <dune/istl/scalarproducts.hh> 24 #include <dune/istl/paamg/amg.hh> 25 #include <dune/istl/paamg/pinfo.hh> 26 #include <dune/istl/io.hh> 27 #include <dune/istl/superlu.hh> 50 template<
typename GFS>
55 typedef int RankIndex;
63 typedef typename GFS::Ordering::Traits::ContainerIndex ContainerIndex;
69 , _rank(gfs.gridView().comm().
rank())
78 if (gfs.entitySet().partitions().value == Partitions::interiorBorder.value)
82 _interiorBorder_all_interface = InteriorBorder_InteriorBorder_Interface;
83 _all_all_interface = InteriorBorder_InteriorBorder_Interface;
88 _interiorBorder_all_interface = InteriorBorder_All_Interface;
89 _all_all_interface = All_All_Interface;
92 if (_gfs.gridView().comm().size()>1)
98 gdh(_gfs,_ghosts,
false);
99 _gfs.gridView().communicate(gdh,_interiorBorder_all_interface,Dune::ForwardCommunication);
105 _gfs.gridView().communicate(pdh,_interiorBorder_all_interface,Dune::ForwardCommunication);
123 template<
typename X,
typename Mask>
126 typename Mask::const_iterator mask_it = mask.begin();
127 for (
typename X::iterator it = x.begin(),
135 template<
typename X,
typename Mask>
138 typename Mask::const_iterator mask_it = mask.begin();
139 for (
typename X::iterator it = x.begin(),
143 *it = (*mask_it == _rank ? *it :
typename X::field_type(0));
149 bool owned(
const ContainerIndex& i)
const 151 return _ranks[i] == _rank;
161 template<
typename X,
typename Y>
162 typename PromotionTraits<
163 typename X::field_type,
164 typename Y::field_type
180 template<
typename X,
typename Y,
typename Mask>
181 typename PromotionTraits<
182 typename X::field_type,
183 typename Y::field_type
187 typedef typename PromotionTraits<
188 typename X::field_type,
189 typename Y::field_type
190 >::PromotedType result_type;
194 typename Y::const_iterator y_it = y.begin();
195 typename Mask::const_iterator mask_it = mask.begin();
196 for (
typename X::const_iterator x_it = x.begin(),
199 ++x_it, ++y_it, ++mask_it)
207 template<
typename X,
typename Y,
typename Mask>
208 typename PromotionTraits<
209 typename X::field_type,
210 typename Y::field_type
214 typedef typename PromotionTraits<
215 typename X::field_type,
216 typename Y::field_type
217 >::PromotedType result_type;
221 typename Y::const_iterator y_it = y.begin();
222 typename Mask::const_iterator mask_it = mask.begin();
223 for (
typename X::const_iterator x_it = x.begin(),
226 ++x_it, ++y_it, ++mask_it)
227 r += (*mask_it == _rank ? Dune::dot(*x_it,*y_it) : result_type(0));
259 template<
typename MatrixType,
typename Comm>
267 bool owned_for_amg(std::size_t i)
const 277 const RankIndex _rank;
283 InterfaceType _interiorBorder_all_interface;
286 InterfaceType _all_all_interface;
291 template<
typename GFS>
292 template<
typename M,
typename C>
298 const bool is_bcrs_matrix =
306 const bool block_type_is_field_matrix =
315 static_assert(is_bcrs_matrix && block_type_is_field_matrix,
"matrix structure not compatible with AMG");
324 typedef typename GFS::Traits::GridViewType GV;
325 typedef typename RankVector::size_type size_type;
326 const GV& gv = _gfs.gridView();
329 const bool need_communication = _gfs.gridView().comm().size() > 1;
333 BoolVector sharedDOF(_gfs,
false);
335 if (need_communication)
338 _gfs.gridView().communicate(data_handle,_all_all_interface,Dune::ForwardCommunication);
342 typedef typename C::ParallelIndexSet::GlobalIndex GlobalIndex;
343 GlobalIndex count = 0;
345 for (size_type i = 0; i < sharedDOF.N(); ++i)
346 if (owned_for_amg(i) &&
native(sharedDOF)[i][0])
349 dverb << gv.comm().rank() <<
": shared block count is " << count.touint() << std::endl;
352 std::vector<GlobalIndex> counts(_gfs.gridView().comm().size());
353 _gfs.gridView().comm().allgather(&count, 1, &(counts[0]));
356 GlobalIndex start = std::accumulate(counts.begin(),counts.begin() + _rank,GlobalIndex(0));
359 GIVector scalarIndices(_gfs, std::numeric_limits<GlobalIndex>::max());
361 for (size_type i = 0; i < sharedDOF.N(); ++i)
362 if (owned_for_amg(i) &&
native(sharedDOF)[i][0])
364 native(scalarIndices)[i][0] = start;
369 if (need_communication)
372 _gfs.gridView().communicate(data_handle,_interiorBorder_all_interface,Dune::ForwardCommunication);
376 c.indexSet().beginResize();
377 for (size_type i=0; i<scalarIndices.N(); ++i)
379 Dune::OwnerOverlapCopyAttributeSet::AttributeSet attr;
380 if(
native(scalarIndices)[i][0] != std::numeric_limits<GlobalIndex>::max())
383 if (owned_for_amg(i))
386 attr = Dune::OwnerOverlapCopyAttributeSet::owner;
390 attr = Dune::OwnerOverlapCopyAttributeSet::copy;
392 c.indexSet().add(
native(scalarIndices)[i][0],
typename C::ParallelIndexSet::LocalIndex(i,attr));
395 c.indexSet().endResize();
398 std::set<int> neighbors;
400 if (need_communication)
403 _gfs.gridView().communicate(data_handle,_all_all_interface,Dune::ForwardCommunication);
406 c.remoteIndices().setNeighbours(neighbors);
407 c.remoteIndices().template rebuild<false>();
412 template<
int s,
bool isFakeMPIHelper>
415 typedef Dune::Amg::SequentialInformation
type;
425 typedef OwnerOverlapCopyCommunication<bigunsignedint<s>,
int>
type;
434 #if HAVE_UG && PDELAB_SEQUENTIAL_UG 436 void assertParallelUG(Dune::CollectiveCommunication<Dune::UGGrid<dim> > comm)
438 static_assert(Dune::AlwaysFalse<Dune::UGGrid<dim> >::
value,
"Using sequential UG in parallel environment");
447 #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:51
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:413
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:149
OwnerOverlapCopyCommunication< bigunsignedint< s >, int > type
Definition: parallelhelper.hh:425
Definition: adaptivity.hh:27
Tag describing an arbitrary FieldMatrix.
Definition: backend/istl/tags.hh:80
Dune::Amg::SequentialInformation type
Definition: parallelhelper.hh:415
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:235
bool isGhost(const ContainerIndex &i) const
Tests whether the given index belongs to a ghost DOF.
Definition: parallelhelper.hh:155
ParallelHelper(const GFS &gfs, int verbose=1)
Definition: parallelhelper.hh:67
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
void assertParallelUG(T comm)
Definition: parallelhelper.hh:431
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:166
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:113
Tag describing a BlockVector.
Definition: backend/istl/tags.hh:23