From 91fcd61d556bf0d70ef2bbbe00a1a4d415ee292b Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 27 May 2015 14:49:30 +0200 Subject: [PATCH 1/2] Test the global reductions for more types. Previously, we only tested with int which left at least one bug unreveiled. Now we test with unsigned integers and floating point values in addition. --- tests/test_parallelistlinformation.cpp | 36 ++++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/test_parallelistlinformation.cpp b/tests/test_parallelistlinformation.cpp index 7a4f6f28..762dad4e 100644 --- a/tests/test_parallelistlinformation.cpp +++ b/tests/test_parallelistlinformation.cpp @@ -38,23 +38,24 @@ #include #ifdef HAVE_DUNE_ISTL -void runSumMaxMinTest(const int offset) +template +void runSumMaxMinTest(const T offset) { const int N=100; int start, end, istart, iend; std::tie(start,istart,iend,end) = computeRegions(N); Opm::ParallelISTLInformation comm(MPI_COMM_WORLD); auto mat = create1DLaplacian(*comm.indexSet(), N, start, end, istart, iend); - std::vector x(end-start); + std::vector x(end-start); assert(comm.indexSet()->size()==x.size()); for(auto i=comm.indexSet()->begin(), iend=comm.indexSet()->end(); i!=iend; ++i) x[i->local()]=i->global()+offset; auto containers = std::make_tuple(x, x, x, x); - auto operators = std::make_tuple(Opm::Reduction::makeGlobalSumFunctor(), - Opm::Reduction::makeGlobalMaxFunctor(), - Opm::Reduction::makeGlobalMinFunctor(), - Opm::Reduction::makeInnerProductFunctor()); - auto values = std::make_tuple(0,0,100000, 0); + auto operators = std::make_tuple(Opm::Reduction::makeGlobalSumFunctor(), + Opm::Reduction::makeGlobalMaxFunctor(), + Opm::Reduction::makeGlobalMinFunctor(), + Opm::Reduction::makeInnerProductFunctor()); + auto values = std::tuple(0,0,100000, 0); auto oldvalues = values; start = offset; end = start+N; @@ -65,12 +66,25 @@ void runSumMaxMinTest(const int offset) BOOST_CHECK(std::get<3>(values)==((end-1)*end*(2*end-1)-(start-1)*start*(2*start-1))/6+std::get<3>(oldvalues)); } -BOOST_AUTO_TEST_CASE(tupleReductionTest) +BOOST_AUTO_TEST_CASE(tupleReductionTestInt) { - runSumMaxMinTest(0); - runSumMaxMinTest(20); - runSumMaxMinTest(-20); + runSumMaxMinTest(0); + runSumMaxMinTest(20); + runSumMaxMinTest(-20); } + +BOOST_AUTO_TEST_CASE(tupleReductionTestUnsignedInt) +{ + runSumMaxMinTest(0); + runSumMaxMinTest(20); +} +BOOST_AUTO_TEST_CASE(tupleReductionTestFloat) +{ + runSumMaxMinTest(0); + runSumMaxMinTest(20); + runSumMaxMinTest(-20); +} + BOOST_AUTO_TEST_CASE(singleContainerReductionTest) { int N=100; From bc0e842ac84ee6789ea0cab839f4b749a3e7d5d9 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 27 May 2015 14:50:58 +0200 Subject: [PATCH 2/2] Fix creation of initial value for computing the max (Fixes PR #805). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bård spotet a bug after PR #805 was merged. Indead returning -numeric_limits::min() does not make sense for integral values. This commit resorts to returning numeric_limits::min(). Kudos to Bård for his attention. --- opm/core/linalg/ParallelIstlInformation.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opm/core/linalg/ParallelIstlInformation.hpp b/opm/core/linalg/ParallelIstlInformation.hpp index d7f9d383..03c87333 100644 --- a/opm/core/linalg/ParallelIstlInformation.hpp +++ b/opm/core/linalg/ParallelIstlInformation.hpp @@ -481,7 +481,7 @@ private: // for integral types. if( std::is_integral::value ) { - return -std::numeric_limits::min(); + return std::numeric_limits::min(); } else {