2015-01-21 08:44:20 -06:00
|
|
|
/*
|
|
|
|
Copyright 2015 Dr. Markus Blatt - HPC-Simulation-Software & Services
|
|
|
|
Copyright 2015 NTNU
|
2015-05-22 13:59:41 -05:00
|
|
|
Copyright 2015 Statoil AS
|
2015-01-21 08:44:20 -06:00
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_BOOST_TEST
|
|
|
|
#define BOOST_TEST_DYN_LINK
|
|
|
|
#endif
|
|
|
|
#define NVERBOSE // to suppress our messages when throwing
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE OPM-ParallelIstlInformation
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include "DuneIstlTestHelpers.hpp"
|
|
|
|
#include <opm/core/linalg/ParallelIstlInformation.hpp>
|
|
|
|
#include <functional>
|
|
|
|
#ifdef HAVE_DUNE_ISTL
|
2015-01-23 13:48:53 -06:00
|
|
|
|
2015-05-27 07:49:30 -05:00
|
|
|
template<typename T>
|
|
|
|
void runSumMaxMinTest(const T offset)
|
2015-01-21 08:44:20 -06:00
|
|
|
{
|
2015-01-23 13:48:53 -06:00
|
|
|
const int N=100;
|
2015-01-21 08:44:20 -06:00
|
|
|
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);
|
2015-05-27 07:49:30 -05:00
|
|
|
std::vector<T> x(end-start);
|
2015-01-21 08:44:20 -06:00
|
|
|
assert(comm.indexSet()->size()==x.size());
|
2015-05-28 07:05:09 -05:00
|
|
|
for(auto it=comm.indexSet()->begin(), itend=comm.indexSet()->end(); it!=itend; ++it)
|
|
|
|
x[it->local()]=it->global()+offset;
|
2015-05-22 13:47:02 -05:00
|
|
|
auto containers = std::make_tuple(x, x, x, x);
|
2015-05-27 07:49:30 -05:00
|
|
|
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);
|
2015-01-21 08:44:20 -06:00
|
|
|
auto oldvalues = values;
|
2015-05-22 13:47:02 -05:00
|
|
|
start = offset;
|
|
|
|
end = start+N;
|
2015-01-21 08:44:20 -06:00
|
|
|
comm.computeReduction(containers,operators,values);
|
2015-01-23 13:48:53 -06:00
|
|
|
BOOST_CHECK(std::get<0>(values)==std::get<0>(oldvalues)+((N-1+2*offset)*N)/2);
|
|
|
|
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)));
|
2015-05-22 13:47:02 -05:00
|
|
|
BOOST_CHECK(std::get<3>(values)==((end-1)*end*(2*end-1)-(start-1)*start*(2*start-1))/6+std::get<3>(oldvalues));
|
2015-01-23 13:48:53 -06:00
|
|
|
}
|
|
|
|
|
2015-05-27 07:49:30 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(tupleReductionTestInt)
|
|
|
|
{
|
|
|
|
runSumMaxMinTest<int>(0);
|
|
|
|
runSumMaxMinTest<int>(20);
|
|
|
|
runSumMaxMinTest<int>(-20);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(tupleReductionTestUnsignedInt)
|
2015-01-23 13:48:53 -06:00
|
|
|
{
|
2015-05-27 07:49:30 -05:00
|
|
|
runSumMaxMinTest<std::size_t>(0);
|
|
|
|
runSumMaxMinTest<std::size_t>(20);
|
2015-01-21 08:44:20 -06:00
|
|
|
}
|
2015-05-27 07:49:30 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(tupleReductionTestFloat)
|
|
|
|
{
|
|
|
|
runSumMaxMinTest<float>(0);
|
|
|
|
runSumMaxMinTest<float>(20);
|
|
|
|
runSumMaxMinTest<float>(-20);
|
|
|
|
}
|
|
|
|
|
2015-01-21 08:44:20 -06:00
|
|
|
BOOST_AUTO_TEST_CASE(singleContainerReductionTest)
|
|
|
|
{
|
|
|
|
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<int> x(end-start);
|
|
|
|
assert(comm.indexSet()->size()==x.size());
|
2015-05-28 07:05:09 -05:00
|
|
|
for(auto it=comm.indexSet()->begin(), itend=comm.indexSet()->end(); it!=itend; ++it)
|
|
|
|
x[it->local()]=it->global();
|
2015-01-21 08:44:20 -06:00
|
|
|
int value = 1;
|
|
|
|
int oldvalue = value;
|
2015-01-23 13:48:53 -06:00
|
|
|
comm.computeReduction(x,Opm::Reduction::makeGlobalSumFunctor<int>(),value);
|
2015-01-21 08:44:20 -06:00
|
|
|
BOOST_CHECK(value==oldvalue+((N-1)*N)/2);
|
|
|
|
}
|
|
|
|
#endif
|