21#ifndef OPM_PARALLELISTLINFORMATION_HEADER_INCLUDED
22#define OPM_PARALLELISTLINFORMATION_HEADER_INCLUDED
26#if HAVE_MPI && HAVE_DUNE_ISTL
34#include <dune/istl/owneroverlapcopy.hh>
43class ParallelISTLInformation
47 using ParallelIndexSet = Dune::OwnerOverlapCopyCommunication<int, int>::ParallelIndexSet;
49 using RemoteIndices = Dune::OwnerOverlapCopyCommunication<int, int>::RemoteIndices;
52 ParallelISTLInformation();
56 ParallelISTLInformation(MPI_Comm communicator);
62 ParallelISTLInformation(
const std::shared_ptr<ParallelIndexSet>& indexSet,
63 const std::shared_ptr<RemoteIndices>& remoteIndices,
64 MPI_Comm communicator);
69 ParallelISTLInformation(
const ParallelISTLInformation& other);
72 std::shared_ptr<ParallelIndexSet> indexSet()
const
78 std::shared_ptr<RemoteIndices> remoteIndices()
const
80 return remoteIndices_;
91 void copyValuesTo(ParallelIndexSet& indexSet, RemoteIndices& remoteIndices,
92 std::size_t local_component_size = 0,
93 std::size_t num_components = 1)
const;
99 void copyOwnerToAll (
const T& source, T& dest)
const;
102 const std::vector<double>& updateOwnerMask(
const T& container)
const;
109 const std::vector<double>& getOwnerMask()
const
133 template<
typename Container,
typename BinaryOperator,
typename T>
134 void computeReduction(
const Container& container, BinaryOperator binaryOperator,
138 template<
typename... Containers,
typename... BinaryOperators,
typename... ReturnValues>
139 void computeTupleReduction(
const std::tuple<Containers...>& containers,
140 std::tuple<BinaryOperators...>& operators,
141 std::tuple<ReturnValues...>& values)
const;
143 std::shared_ptr<ParallelIndexSet> indexSet_;
144 std::shared_ptr<RemoteIndices> remoteIndices_;
146 mutable std::vector<double> ownerMask_;
156 template<
typename BinaryOperator>
157 struct MaskIDOperator
161 typedef typename std::remove_cv<
162 typename std::remove_reference<typename BinaryOperator::result_type>::type
170 template<
class T,
class T1>
171 T operator()(
const T& t1,
const T& t2,
const T1& mask)
173 return b_(t1, maskValue(t2, mask));
175 template<
class T,
class T1>
176 T maskValue(
const T& t,
const T1& mask)
180 BinaryOperator& localOperator()
184 Result getInitialValue()
194 struct InnerProductFunctor
203 T operator()(
const T& t1,
const T& t2,
const T1& mask)
205 T masked = maskValue(t2, mask);
206 return t1 + masked * masked;
209 T maskValue(
const T& t,
const T1& mask)
213 std::plus<T> localOperator()
215 return std::plus<T>();
228 template<
typename BinaryOperator>
229 struct MaskToMinOperator
233 typedef typename std::remove_reference<
234 typename std::remove_const<typename BinaryOperator::result_type>::type
237 MaskToMinOperator(BinaryOperator b)
246 template<
class T,
class T1>
247 T operator()(
const T& t1,
const T& t2,
const T1& mask)
249 return b_(t1, maskValue(t2, mask));
251 template<
class T,
class T1>
252 T maskValue(
const T& t,
const T1& mask)
260 return getInitialValue();
263 Result getInitialValue()
268 if( std::is_integral<Result>::value )
270 return std::numeric_limits<Result>::min();
274 return -std::numeric_limits<Result>::max();
281 BinaryOperator& localOperator()
292 template<
typename BinaryOperator>
293 struct MaskToMaxOperator
297 typedef typename std::remove_cv<
298 typename std::remove_reference<typename BinaryOperator::result_type>::type
301 MaskToMaxOperator(BinaryOperator b)
310 template<
class T,
class T1>
311 T operator()(
const T& t1,
const T& t2,
const T1& mask)
313 return b_(t1, maskValue(t2, mask));
315 template<
class T,
class T1>
316 T maskValue(
const T& t,
const T1& mask)
324 return std::numeric_limits<T>::max();
327 BinaryOperator& localOperator()
331 Result getInitialValue()
333 return std::numeric_limits<Result>::max();
342 MaskIDOperator<std::plus<T> >
343 makeGlobalSumFunctor()
345 return MaskIDOperator<std::plus<T> >();
351 auto makeGlobalMaxFunctor()
355 using result_type = T;
356 const result_type& operator()(
const T& t1,
const T& t2)
358 return std::max(t1, t2);
361 return MaskToMinOperator(MaxOp());
367 template<
typename T,
typename Enable =
void>
370 using result_type = T;
371 result_type operator()(
const T& t1,
374 return std::max(std::abs(t1), std::abs(t2));
382 struct MaxAbsFunctor<T, typename std::enable_if<std::is_unsigned<T>::value>::type>
384 using result_type = T;
385 result_type operator()(
const T& t1,
388 return std::max(t1, t2);
397 MaskIDOperator<detail::MaxAbsFunctor<T> >
398 makeLInfinityNormFunctor()
400 return MaskIDOperator<detail::MaxAbsFunctor<T> >();
407 makeGlobalMinFunctor()
411 using result_type = T;
412 const result_type& operator()(
const T& t1,
const T& t2)
414 return std::min(t1, t2);
417 return MaskToMaxOperator(MinOp());
420 InnerProductFunctor<T>
421 makeInnerProductFunctor()
423 return InnerProductFunctor<T>();
441 ->
decltype(container[0]*(*maskContainer)[0]);
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:37
auto accumulateMaskedValues(const T1 &container, const std::vector< double > *maskContainer) -> decltype(container[0] *(*maskContainer)[0])
Accumulates entries masked with 1.