mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Also test cusparseSolver with jacobi matrix
This commit is contained in:
@@ -87,24 +87,18 @@ getDuneSolution(Matrix<bz>& matrix, Vector<bz>& rhs)
|
||||
}
|
||||
|
||||
template <int bz>
|
||||
Dune::BlockVector<Dune::FieldVector<double, bz>>
|
||||
testCusparseSolver(const boost::property_tree::ptree& prm, Matrix<bz>& matrix, Vector<bz>& rhs)
|
||||
void
|
||||
createBridge(const boost::property_tree::ptree& prm, std::unique_ptr<Opm::BdaBridge<Matrix<bz>, Vector<bz>, bz> >& bridge)
|
||||
{
|
||||
|
||||
const int linear_solver_verbosity = prm.get<int>("verbosity");
|
||||
const int maxit = prm.get<int>("maxiter");
|
||||
const double tolerance = prm.get<double>("tol");
|
||||
const bool opencl_ilu_parallel(true); // unused
|
||||
const int platformID = 0; // unused
|
||||
const bool opencl_ilu_parallel(true);
|
||||
const int platformID = 0;
|
||||
const int deviceID = 0;
|
||||
const std::string accelerator_mode("cusparse");
|
||||
const std::string linsolver("ilu0");
|
||||
Dune::InverseOperatorResult result;
|
||||
|
||||
Vector<bz> x(rhs.size());
|
||||
|
||||
auto wellContribs = Opm::WellContributions::create("cusparse", false);
|
||||
std::unique_ptr<Opm::BdaBridge<Matrix<bz>, Vector<bz>, bz> > bridge;
|
||||
try {
|
||||
bridge = std::make_unique<Opm::BdaBridge<Matrix<bz>, Vector<bz>, bz> >(accelerator_mode,
|
||||
linear_solver_verbosity,
|
||||
@@ -114,12 +108,6 @@ testCusparseSolver(const boost::property_tree::ptree& prm, Matrix<bz>& matrix, V
|
||||
deviceID,
|
||||
opencl_ilu_parallel,
|
||||
linsolver);
|
||||
auto mat2 = matrix; // deep copy to make sure nnz values are in contiguous memory
|
||||
// matrix created by readMatrixMarket() did not have contiguous memory
|
||||
bridge->solve_system(&mat2, &mat2, /*numJacobiBlocks=*/0, rhs, *wellContribs, result);
|
||||
bridge->get_result(x);
|
||||
|
||||
return x;
|
||||
} catch (const std::logic_error& error) {
|
||||
BOOST_WARN_MESSAGE(true, error.what());
|
||||
if (strstr(error.what(), "Could not get device") != nullptr)
|
||||
@@ -129,6 +117,38 @@ testCusparseSolver(const boost::property_tree::ptree& prm, Matrix<bz>& matrix, V
|
||||
}
|
||||
}
|
||||
|
||||
template <int bz>
|
||||
Dune::BlockVector<Dune::FieldVector<double, bz>>
|
||||
testCusparseSolver(Opm::BdaBridge<Matrix<bz>, Vector<bz>, bz>& bridge, Matrix<bz>& matrix, Vector<bz>& rhs)
|
||||
{
|
||||
Dune::InverseOperatorResult result;
|
||||
Vector<bz> x(rhs.size());
|
||||
auto wellContribs = Opm::WellContributions::create("cusparse", false);
|
||||
auto mat2 = matrix; // deep copy to make sure nnz values are in contiguous memory
|
||||
// matrix created by readMatrixMarket() did not have contiguous memory
|
||||
bridge.solve_system(&mat2, &mat2, /*numJacobiBlocks=*/0, rhs, *wellContribs, result);
|
||||
bridge.get_result(x);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
template <int bz>
|
||||
Dune::BlockVector<Dune::FieldVector<double, bz>>
|
||||
testCusparseSolverJacobi(Opm::BdaBridge<Matrix<bz>, Vector<bz>, bz>& bridge, Matrix<bz>& matrix, Vector<bz>& rhs)
|
||||
{
|
||||
Dune::InverseOperatorResult result;
|
||||
Vector<bz> x(rhs.size());
|
||||
auto wellContribs = Opm::WellContributions::create("cusparse", false);
|
||||
auto mat2 = matrix; // deep copy to make sure nnz values are in contiguous memory
|
||||
// matrix created by readMatrixMarket() did not have contiguous memory
|
||||
auto mat3 = matrix; // another deep copy, to make sure Jacobi matrix memory is different
|
||||
// the sparsity pattern and values are actually the same
|
||||
bridge.solve_system(&mat2, &mat3, /*numJacobiBlocks=*/2, rhs, *wellContribs, result);
|
||||
bridge.get_result(x);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
namespace pt = boost::property_tree;
|
||||
|
||||
void test3(const pt::ptree& prm)
|
||||
@@ -136,17 +156,31 @@ void test3(const pt::ptree& prm)
|
||||
const int bz = 3;
|
||||
Matrix<bz> matrix;
|
||||
Vector<bz> rhs;
|
||||
std::unique_ptr<Opm::BdaBridge<Matrix<bz>, Vector<bz>, bz> > bridge;
|
||||
readLinearSystem("matr33.txt", "rhs3.txt", matrix, rhs);
|
||||
Vector<bz> rhs2 = rhs; // deep copy, getDuneSolution() changes values in rhs vector
|
||||
auto duneSolution = getDuneSolution<bz>(matrix, rhs);
|
||||
auto sol = testCusparseSolver<bz>(prm, matrix, rhs2);
|
||||
|
||||
createBridge(prm, bridge); // create bridge with openclSolver
|
||||
// should create bridge only once
|
||||
|
||||
// test cusparseSolver without Jacobi matrix
|
||||
auto sol = testCusparseSolver<bz>(*bridge, matrix, rhs2);
|
||||
BOOST_REQUIRE_EQUAL(sol.size(), duneSolution.size());
|
||||
for (size_t i = 0; i < sol.size(); ++i) {
|
||||
for (int row = 0; row < bz; ++row) {
|
||||
BOOST_CHECK_CLOSE(sol[i][row], duneSolution[i][row], 1e-3);
|
||||
}
|
||||
}
|
||||
|
||||
// test cusparseSolver with Jacobi matrix
|
||||
auto solJacobi = testCusparseSolverJacobi<bz>(*bridge, matrix, rhs2);
|
||||
BOOST_REQUIRE_EQUAL(solJacobi.size(), duneSolution.size());
|
||||
for (size_t i = 0; i < solJacobi.size(); ++i) {
|
||||
for (int row = 0; row < bz; ++row) {
|
||||
BOOST_CHECK_CLOSE(solJacobi[i][row], duneSolution[i][row], 1e-3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user