Commit 9915f5f8 authored by Dmitry Bagaev's avatar Dmitry Bagaev
Browse files

Improvements in Solver

1) Parameters parsing in inner solvers
2) Parameters parsing in trillions solvers
3) Added xml parsing test
4) Trilinos without mpi support will not compile, disable trillions
solvers if compiling without mpi
parent 57c8d057
......@@ -2,11 +2,11 @@
namespace INMOST {
SolverTrilinosBelos::SolverTrilinosBelos(SolverParameters &parameters): SolverTrilinos(parameters) {
SolverTrilinosBelos::SolverTrilinosBelos() {
}
SolverTrilinosBelos::SolverTrilinosBelos(const SolverInterface *other): SolverTrilinos(other) {
SolverTrilinosBelos::SolverTrilinosBelos(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
......@@ -33,9 +33,9 @@ namespace INMOST {
else {
List->set("Num Blocks", 100);
List->set("Block Size", 1);
List->set("Maximum Iterations", parameters.get<int>("maximum_iterations"));
List->set("Maximum Iterations", iters);
List->set("Maximum Restarts", 20);
List->set("Convergence Tolerance", parameters.get<double>("relative_tolerance"));
List->set("Convergence Tolerance", rtol);
}
Teuchos::RCP<Belos::LinearProblem<double, Epetra_MultiVector, Epetra_Operator> > Problem =
......
......@@ -8,7 +8,7 @@ namespace INMOST {
class SolverTrilinosBelos : public SolverTrilinos {
public:
SolverTrilinosBelos(SolverParameters &parameters);
SolverTrilinosBelos();
SolverTrilinosBelos(const SolverInterface *other);
......
......@@ -2,11 +2,11 @@
namespace INMOST {
SolverTrilinosIfpack::SolverTrilinosIfpack(SolverParameters &parameters): SolverTrilinos(parameters) {
SolverTrilinosIfpack::SolverTrilinosIfpack() {
}
SolverTrilinosIfpack::SolverTrilinosIfpack(const SolverInterface *other): SolverTrilinos(other) {
SolverTrilinosIfpack::SolverTrilinosIfpack(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
......@@ -38,10 +38,11 @@ namespace INMOST {
if (have_params && local_list.isSublist("AztecOO")) {
Teuchos::ParameterList AztecOOParams = local_list.sublist("AztecOO");
if (AztecOOParams.isParameter("Max Iterations")) {
parameters.set("maximum_iterations", to_string(AztecOOParams.get<int>("Max Iterations")));
iters = AztecOOParams.get<int>("Max Iterations");
}
if (AztecOOParams.isParameter("Tolerance")) {
parameters.set("relative_tolerance", to_string(AztecOOParams.get<double>("Tolerance")));
rtol = AztecOOParams.get<double>("Tolerance");
}
if (AztecOOParams.isSublist("AztecOO Settings")) {
AztecSolver.SetParameters(AztecOOParams.sublist("AztecOO Settings"));
......@@ -50,7 +51,7 @@ namespace INMOST {
AztecSolver.SetAztecOption(AZ_diagnostics, AZ_none);
AztecSolver.SetAztecOption(AZ_output, AZ_none);
AztecSolver.SetAztecOption(AZ_solver, AZ_bicgstab);
AztecSolver.SetAztecOption(AZ_overlap, parameters.get<INMOST_DATA_ENUM_TYPE>("additive_schwartz_overlap"));
AztecSolver.SetAztecOption(AZ_overlap, overlap);
}
Ifpack *Factory = new Ifpack();
......@@ -62,23 +63,24 @@ namespace INMOST {
PrecType = ifpacklist.get<std::string>("Prec Type");
}
if (ifpacklist.isParameter("Overlap")) {
parameters.set("additive_schwartz_overlap", to_string(ifpacklist.get<int>("Overlap")));
overlap = ifpacklist.get<int>("Overlap");
}
}
Prec = Factory->Create(PrecType, matrix, parameters.get<INMOST_DATA_ENUM_TYPE>("additive_schwartz_overlap"));
Prec = Factory->Create(PrecType, matrix, overlap);
Teuchos::ParameterList List;
if (have_params && local_list.isSublist("Ifpack") &&
local_list.sublist("Ifpack").isSublist("Ifpack Settings")) {
List = local_list.sublist("Ifpack").sublist("Ifpack Settings");
} else {
List.set("fact: level-of-fill", parameters.get<int>("fill_level"));
//Do not delete (int) please
List.set("fact: level-of-fill", (int) fill);
}
Prec->SetParameters(List);
Prec->Initialize();
Prec->Compute();
AztecSolver.SetPrecOperator(Prec);
AztecSolver.Iterate(parameters.get<INMOST_DATA_ENUM_TYPE>("maximum_iterations"), parameters.get<INMOST_DATA_REAL_TYPE>("relative_tolerance"));
AztecSolver.Iterate(iters, rtol);
const double *stats = AztecSolver.GetAztecStatus();
bool success = true;
std::string reason = "";
......
......@@ -8,7 +8,7 @@ namespace INMOST {
class SolverTrilinosIfpack: public SolverTrilinos {
public:
SolverTrilinosIfpack(SolverParameters &parameters);
SolverTrilinosIfpack();
SolverTrilinosIfpack(const SolverInterface *other);
......
......@@ -2,11 +2,11 @@
namespace INMOST {
SolverTrilinosML::SolverTrilinosML(SolverParameters &parameters): SolverTrilinos(parameters) {
SolverTrilinosML::SolverTrilinosML() {
}
SolverTrilinosML::SolverTrilinosML(const SolverInterface *other): SolverTrilinos(other) {
SolverTrilinosML::SolverTrilinosML(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
......@@ -38,10 +38,11 @@ namespace INMOST {
if (have_params && local_list.isSublist("AztecOO")) {
Teuchos::ParameterList AztecOOParams = local_list.sublist("AztecOO");
if (AztecOOParams.isParameter("Max Iterations")) {
parameters.set("maximum_iterations", to_string(AztecOOParams.get<int>("Max Iterations")));
iters = AztecOOParams.get<int>("Max Iterations");
}
if (AztecOOParams.isParameter("Tolerance")) {
parameters.set("relative_tolerance", to_string(AztecOOParams.get<double>("Tolerance")));
rtol = AztecOOParams.get<double>("Tolerance");
}
if (AztecOOParams.isSublist("AztecOO Settings")) {
AztecSolver.SetParameters(AztecOOParams.sublist("AztecOO Settings"));
......@@ -50,7 +51,7 @@ namespace INMOST {
AztecSolver.SetAztecOption(AZ_diagnostics, AZ_none);
AztecSolver.SetAztecOption(AZ_output, AZ_none);
AztecSolver.SetAztecOption(AZ_solver, AZ_bicgstab);
AztecSolver.SetAztecOption(AZ_overlap, parameters.get<INMOST_DATA_ENUM_TYPE>("additive_schwartz_overlap"));
AztecSolver.SetAztecOption(AZ_overlap, overlap);
}
Teuchos::ParameterList List;
......@@ -65,7 +66,7 @@ namespace INMOST {
ML_Epetra::MultiLevelPreconditioner *Prec = new ML_Epetra::MultiLevelPreconditioner(*matrix, List, true);
AztecSolver.SetPrecOperator(Prec);
AztecSolver.Iterate(parameters.get<INMOST_DATA_ENUM_TYPE>("maximum_iterations"), parameters.get<INMOST_DATA_ENUM_TYPE>("relative_tolerance"));
AztecSolver.Iterate(iters, rtol);
const double *stats = AztecSolver.GetAztecStatus();
bool success = true;
std::string reason = "";
......
......@@ -8,7 +8,7 @@ namespace INMOST {
class SolverTrilinosML: public SolverTrilinos {
public:
SolverTrilinosML(SolverParameters &parameters);
SolverTrilinosML();
SolverTrilinosML(const SolverInterface *other);
......
......@@ -10,3 +10,5 @@ if(USE_PARTITIONER)
add_subdirectory(pmesh_test001)
endif()
endif()
add_subdirectory(xml_reader_test000)
......@@ -24,7 +24,7 @@ if(USE_SOLVER_PETSC)
message("linking solver_test000 with PETSc")
target_link_libraries(solver_test000 ${PETSC_LIBRARIES})
endif()
if(USE_SOLVER_TRILINOS)
if(USE_SOLVER_TRILINOS AND USE_MPI)
message("linking solver_test000 with Trilinos")
target_link_libraries(solver_test000 ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES})
endif()
......@@ -58,7 +58,7 @@ if(USE_SOLVER_PETSC)
add_test(NAME solver_test000_serial_petsc COMMAND $<TARGET_FILE:solver_test000> 0 petsc)
endif()
if(USE_SOLVER_TRILINOS)
if(USE_SOLVER_TRILINOS AND USE_MPI)
add_test(NAME solver_test000_serial_trilinos_aztec COMMAND $<TARGET_FILE:solver_test000> 0 trilinos_aztec)
add_test(NAME solver_test000_serial_trilinos_ifpack COMMAND $<TARGET_FILE:solver_test000> 0 trilinos_ifpack)
add_test(NAME solver_test000_serial_trilinos_ml COMMAND $<TARGET_FILE:solver_test000> 0 trilinos_ml)
......
......@@ -52,7 +52,7 @@ if(HAVE_SOLVER_MPTILU2)
add_test(NAME solver_test002_serial_inner_mptilu2 COMMAND $<TARGET_FILE:solver_test002> inner_mptilu2 20)
endif()
if(USE_SOLVER_TRILINOS)
if(USE_SOLVER_TRILINOS AND USE_MPI)
add_test(NAME solver_test002_serial_trilinos_aztec COMMAND $<TARGET_FILE:solver_test002> trilinos_aztec 20)
add_test(NAME solver_test002_serial_trilinos_belos COMMAND $<TARGET_FILE:solver_test002> trilinos_belos 20)
add_test(NAME solver_test002_serial_trilinos_ml COMMAND $<TARGET_FILE:solver_test002> trilinos_ml 20)
......
......@@ -127,18 +127,16 @@ int main(int argc, char ** argv)
std::string reason;
{
Solver s(type); // Declare the linear solver by specified type
SolverParameters &p = s.GetParameters();
p.set("gmres_substeps", "3");
p.set("reorder_nonzeros", "0");
p.set("rescale_iterations", "8");
p.set("adapt_ddpq_tolerance", "0");
p.set("drop_tolerance", "0.001");
p.set("reuse_tolerance", "0.00001");
p.set("ddpq_tolerance", "0.7");
s.SetParameter("gmres_substeps", "3");
s.SetParameter("reorder_nonzeros", "0");
s.SetParameter("rescale_iterations", "8");
s.SetParameter("adapt_ddpq_tolerance", "0");
s.SetParameter("drop_tolerance", "0.001");
s.SetParameter("reuse_tolerance", "0.00001");
s.SetParameter("ddpq_tolerance", "0.7");
t = Timer();
s.SetMatrix(mat); // Compute the preconditioner for the original matrix
......
project(xml_reader_test000)
set(SOURCE main.cpp)
add_executable(xml_reader_test000 ${SOURCE})
target_link_libraries(xml_reader_test000 inmost)
if(USE_MPI)
message("linking xml_reader_test000 with MPI")
target_link_libraries(xml_reader_test000 ${MPI_LIBRARIES})
if(MPI_LINK_FLAGS)
set_target_properties(xml_reader_test000 PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()
endif(USE_MPI)
add_test(NAME xml_reader_test000_all COMMAND $<TARGET_FILE:xml_reader_test000>)
#include <cstdlib>
#include <inmost.h>
#include <istream>
#include <string>
#include <cassert>
using namespace INMOST;
const std::string xml_string = "<SolverParameters>\n"
" <!-- Links to files for external solvers, prefix processed inside -->\n"
" <PETSc File=\"petsc_options.txt\"/>\n"
" <Trilinos_Ifpack file=\"trilinos_ifpack.xml\"/>\n"
" <Trilinos_Belos file=\"trilinos_belos.xml\"/>\n"
" <Trilinos_ML file=\"trilinos_ml.xml\"/>\n"
" <Trilinos_AztecOO file=\"trilinos_aztec.xml\"/>\n"
" <!-- internal solvers parameters -->\n"
" <inner_ilu2>\n"
" <!-- for prefix=\"pressure_solver\" -->\n"
" <pressure_solver>\n"
" <absolute_tolerance value=\"1.0e-8\"/>\n"
" <relative_tolerance value=\"1.0e-4\"/>\n"
" <drop_tolerance value=\"1.0e-2\"/>\n"
" <reuse_tolerance value=\"1.0e-3\"/>\n"
" </pressure_solver>\n"
" <!-- for prefix=\"diffusion_solver\" -->\n"
" <diffusion_solver> \n"
" <absolute_tolerance value=\"1.0e-6\"/>\n"
" <relative_tolerance value=\"1.0e-8\"/>\n"
" <drop_tolerance value=\"1.0e-2\"/>\n"
" <reuse_tolerance value=\"1.0e-3\"/>\n"
" </diffusion_solver>\n"
" <!-- for prefix=\"advection_solver\" -->\n"
" </inner_ilu2>\n"
" <inner_mptiluc2>\n"
" <!-- link external files -->\n"
" <pressure_solver Include=\"mptiluc2_pressure_solver.xml\"/>\n"
" </inner_mptiluc2>\n"
" <!-- link external files -->\n"
" <inner_mptilu2 Include=\"mptilu2.xml\"/>\n"
"</SolverParameters>\n";
int main(int argc, char **argv) {
std::stringstream input(xml_string);
assert(!input.fail());
XMLReader reader("", input);
XMLReader::XMLTree tree = reader.ReadXML();
//Check root
assert(tree.tag.name == "SolverParameters");
assert(tree.tag.attributes.size() == 0);
assert(tree.children.size() == 8);
//Check PETSc child
XMLReader::XMLTree petsc_tree = tree.children[0];
assert(petsc_tree.tag.name == "PETSc");
assert(petsc_tree.tag.attributes.size() == 1);
assert(petsc_tree.tag.attributes[0].name == "File");
assert(petsc_tree.tag.attributes[0].value == "petsc_options.txt");
//Check Trilinos_Ifpack child
XMLReader::XMLTree Trilinos_Ifpack_tree = tree.children[1];
assert(Trilinos_Ifpack_tree.tag.name == "Trilinos_Ifpack");
assert(Trilinos_Ifpack_tree.tag.attributes.size() == 1);
assert(Trilinos_Ifpack_tree.tag.attributes[0].name == "file");
assert(Trilinos_Ifpack_tree.tag.attributes[0].value == "trilinos_ifpack.xml");
//Check Trilinos_Belos child
XMLReader::XMLTree Trilinos_Belos_tree = tree.children[2];
assert(Trilinos_Belos_tree.tag.name == "Trilinos_Belos");
assert(Trilinos_Belos_tree.tag.attributes.size() == 1);
assert(Trilinos_Belos_tree.tag.attributes[0].name == "file");
assert(Trilinos_Belos_tree.tag.attributes[0].value == "trilinos_belos.xml");
//Check Trilinos_Belos child
XMLReader::XMLTree Trilinos_ML_tree = tree.children[3];
assert(Trilinos_ML_tree.tag.name == "Trilinos_ML");
assert(Trilinos_ML_tree.tag.attributes.size() == 1);
assert(Trilinos_ML_tree.tag.attributes[0].name == "file");
assert(Trilinos_ML_tree.tag.attributes[0].value == "trilinos_ml.xml");
//Check Trilinos_Belos child
XMLReader::XMLTree Trilinos_AztecOO_tree = tree.children[4];
assert(Trilinos_AztecOO_tree.tag.name == "Trilinos_AztecOO");
assert(Trilinos_AztecOO_tree.tag.attributes.size() == 1);
assert(Trilinos_AztecOO_tree.tag.attributes[0].name == "file");
assert(Trilinos_AztecOO_tree.tag.attributes[0].value == "trilinos_aztec.xml");
//Check inner_ilu2 child
XMLReader::XMLTree inner_ilu2_tree = tree.children[5];
assert(inner_ilu2_tree.tag.name == "inner_ilu2");
assert(inner_ilu2_tree.tag.attributes.size() == 0);
assert(inner_ilu2_tree.children.size() == 2);
//Check inner_ilu2 pressure_solver
XMLReader::XMLTree inner_ilu2_pressure_solver = inner_ilu2_tree.children[0];
assert(inner_ilu2_pressure_solver.tag.name == "pressure_solver");
assert(inner_ilu2_pressure_solver.tag.attributes.size() == 0);
assert(inner_ilu2_pressure_solver.children.size() == 4);
assert(inner_ilu2_pressure_solver.children[0].tag.name == "absolute_tolerance");
assert(inner_ilu2_pressure_solver.children[0].tag.attributes.size() == 1);
assert(inner_ilu2_pressure_solver.children[0].tag.attributes[0].name == "value");
assert(inner_ilu2_pressure_solver.children[0].tag.attributes[0].value == "1.0e-8");
assert(inner_ilu2_pressure_solver.children[1].tag.name == "relative_tolerance");
assert(inner_ilu2_pressure_solver.children[1].tag.attributes.size() == 1);
assert(inner_ilu2_pressure_solver.children[1].tag.attributes[0].name == "value");
assert(inner_ilu2_pressure_solver.children[1].tag.attributes[0].value == "1.0e-4");
assert(inner_ilu2_pressure_solver.children[2].tag.name == "drop_tolerance");
assert(inner_ilu2_pressure_solver.children[2].tag.attributes.size() == 1);
assert(inner_ilu2_pressure_solver.children[2].tag.attributes[0].name == "value");
assert(inner_ilu2_pressure_solver.children[2].tag.attributes[0].value == "1.0e-2");
assert(inner_ilu2_pressure_solver.children[3].tag.name == "reuse_tolerance");
assert(inner_ilu2_pressure_solver.children[3].tag.attributes.size() == 1);
assert(inner_ilu2_pressure_solver.children[3].tag.attributes[0].name == "value");
assert(inner_ilu2_pressure_solver.children[3].tag.attributes[0].value == "1.0e-3");
//Check inner_ilu2 diffusion_solver
XMLReader::XMLTree inner_ilu2_diffusion_solver = inner_ilu2_tree.children[1];
assert(inner_ilu2_diffusion_solver.tag.name == "diffusion_solver");
assert(inner_ilu2_diffusion_solver.tag.attributes.size() == 0);
assert(inner_ilu2_diffusion_solver.children.size() == 4);
assert(inner_ilu2_diffusion_solver.children[0].tag.name == "absolute_tolerance");
assert(inner_ilu2_diffusion_solver.children[0].tag.attributes.size() == 1);
assert(inner_ilu2_diffusion_solver.children[0].tag.attributes[0].name == "value");
assert(inner_ilu2_diffusion_solver.children[0].tag.attributes[0].value == "1.0e-6");
assert(inner_ilu2_diffusion_solver.children[1].tag.name == "relative_tolerance");
assert(inner_ilu2_diffusion_solver.children[1].tag.attributes.size() == 1);
assert(inner_ilu2_diffusion_solver.children[1].tag.attributes[0].name == "value");
assert(inner_ilu2_diffusion_solver.children[1].tag.attributes[0].value == "1.0e-8");
assert(inner_ilu2_diffusion_solver.children[2].tag.name == "drop_tolerance");
assert(inner_ilu2_diffusion_solver.children[2].tag.attributes.size() == 1);
assert(inner_ilu2_diffusion_solver.children[2].tag.attributes[0].name == "value");
assert(inner_ilu2_diffusion_solver.children[2].tag.attributes[0].value == "1.0e-2");
assert(inner_ilu2_diffusion_solver.children[3].tag.name == "reuse_tolerance");
assert(inner_ilu2_diffusion_solver.children[3].tag.attributes.size() == 1);
assert(inner_ilu2_diffusion_solver.children[3].tag.attributes[0].name == "value");
assert(inner_ilu2_diffusion_solver.children[3].tag.attributes[0].value == "1.0e-3");
//Check inner_mptiluc2 child
XMLReader::XMLTree inner_mptiluc2_tree = tree.children[6];
assert(inner_mptiluc2_tree.tag.name == "inner_mptiluc2");
assert(inner_mptiluc2_tree.tag.attributes.size() == 0);
assert(inner_mptiluc2_tree.children.size() == 1);
assert(inner_mptiluc2_tree.children[0].tag.name == "pressure_solver");
assert(inner_mptiluc2_tree.children[0].tag.attributes.size() == 0);
//Check inner_mptilu2 child
XMLReader::XMLTree inner_mptilu2_tree = tree.children[7];
assert(inner_mptilu2_tree.tag.name == "inner_mptilu2");
assert(inner_mptilu2_tree.tag.attributes.size() == 0);
assert(inner_mptilu2_tree.children.size() == 0);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment