Added utilities to compute a real L-infinity norm in parallel.

This commit is contained in:
Markus Blatt 2016-06-07 15:00:57 +02:00
parent 2d746e8c54
commit 008c5b7c8f
2 changed files with 32 additions and 3 deletions

View File

@ -185,6 +185,7 @@ public:
/// to compute a reduction. Or with tuples of them to compute multiple reductions with only
/// one global communication.
/// The possible functors needed can be constructed with Opm::Reduction::makeGlobalMaxFunctor(),
/// Opm::Reduction::makeLInfinityNormFunctor(),
/// Opm::Reduction::makeGlobalMinFunctor(), and
/// Opm::Reduction::makeGlobalSumFunctor().
/// \tparam type of the container or the tuple of containers.
@ -574,6 +575,30 @@ private:
(std::pointer_to_binary_function<const T&,const T&,const T&>
((const T&(*)(const T&, const T&))std::max<T>));
}
namespace detail
{
/// \brief Computes the maximum of theabsolute values of two values.
template<typename T>
struct MaxAbsFunctor
{
typedef T result_type;
result_type operator()(const T& t1, const T& t2)
{
return std::max(std::abs(t1),std::abs(t2));
}
};
}
/// \brief Create a functor for computing a global L infinity norm
///
/// To be used with ParallelISTLInformation::computeReduction.
template<class T>
MaskIDOperator<detail::MaxAbsFunctor<T> >
makeLInfinityNormFunctor()
{
return MaskIDOperator<detail::MaxAbsFunctor<T> >();
}
/// \brief Create a functor for computing a global minimum.
///
/// To be used with ParallelISTLInformation::computeReduction.

View File

@ -45,12 +45,13 @@ void runSumMaxMinTest(const T offset)
assert(comm.indexSet()->size()==x.size());
for(auto it=comm.indexSet()->begin(), itend=comm.indexSet()->end(); it!=itend; ++it)
x[it->local()]=it->global()+offset;
auto containers = std::make_tuple(x, x, x, x);
auto containers = std::make_tuple(x, x, x, x, x);
auto operators = std::make_tuple(Opm::Reduction::makeGlobalSumFunctor<T>(),
Opm::Reduction::makeGlobalMaxFunctor<T>(),
Opm::Reduction::makeGlobalMinFunctor<T>(),
Opm::Reduction::makeInnerProductFunctor<T>());
auto values = std::tuple<T,T,T,T>(0,0,100000, 0);
Opm::Reduction::makeInnerProductFunctor<T>(),
Opm::Reduction::makeLInfinityNormFunctor<T>());
auto values = std::tuple<T,T,T,T,T>(0,0,100000, 0, 0);
auto oldvalues = values;
start = offset;
end = start+N;
@ -59,10 +60,12 @@ void runSumMaxMinTest(const T offset)
BOOST_CHECK(std::get<1>(values)==std::max(N+offset-1, std::get<1>(oldvalues)));
BOOST_CHECK(std::get<2>(values)==std::min(offset, std::get<2>(oldvalues)));
BOOST_CHECK(std::get<3>(values)==((end-1)*end*(2*end-1)-(start-1)*start*(2*start-1))/6+std::get<3>(oldvalues));
BOOST_CHECK(std::get<4>(values)==std::max(std::abs(offset),std::abs(N+offset-1)));
}
BOOST_AUTO_TEST_CASE(tupleReductionTestInt)
{
runSumMaxMinTest<int>(-200);
runSumMaxMinTest<int>(0);
runSumMaxMinTest<int>(20);
runSumMaxMinTest<int>(-20);
@ -75,6 +78,7 @@ BOOST_AUTO_TEST_CASE(tupleReductionTestUnsignedInt)
}
BOOST_AUTO_TEST_CASE(tupleReductionTestFloat)
{
runSumMaxMinTest<float>(-200);
runSumMaxMinTest<float>(0);
runSumMaxMinTest<float>(20);
runSumMaxMinTest<float>(-20);