Skip to content

Commit

Permalink
#180: add osrirr1.hb new working version and disable Ifpack2 precondi…
Browse files Browse the repository at this point in the history
…tioner
  • Loading branch information
tlamonthezie committed Sep 22, 2023
1 parent 07486b1 commit 08f79ec
Show file tree
Hide file tree
Showing 5 changed files with 2,317 additions and 10,454 deletions.
39 changes: 18 additions & 21 deletions packages/belos/tpetra/example/TFQMR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@


# TODO: First solve circular dependency between Belos and Ifpack2
ASSERT_DEFINED(${PACKAGE_NAME}_ENABLE_Tpetra)
IF (${PACKAGE_NAME}_ENABLE_Tpetra)

# ASSERT_DEFINED(${PACKAGE_NAME}_ENABLE_Tpetra)
# ASSERT_DEFINED(${PACKAGE_NAME}_ENABLE_Ifpack2)
# IF (${PACKAGE_NAME}_ENABLE_Tpetra AND ${PACKAGE_NAME}_ENABLE_Ifpack2)
TRIBITS_ADD_EXECUTABLE(
TFQMR_Tpetra_File_Ex
SOURCES TFQMRTpetraExFile.cpp
COMM serial mpi
)

# TRIBITS_ADD_EXECUTABLE_AND_TEST(
# TFQMR_Tpetra_File_Ex
# SOURCES TFQMRTpetraExFile.cpp
# COMM serial mpi
# )
TRIBITS_ADD_EXECUTABLE(
Pseudo_Block_TFQMR_Tpetra_File_Ex
SOURCES PseudoBlockTFQMRTpetraExFile.cpp
COMM serial mpi
)

# TRIBITS_ADD_EXECUTABLE_AND_TEST(
# Pseudo_Block_TFQMR_Tpetra_File_Ex
# SOURCES PseudoBlockTFQMRTpetraExFile.cpp
# COMM serial mpi
# )
TRIBITS_COPY_FILES_TO_BINARY_DIR(Tpetra_CopyExampleTFQMRFiles
SOURCE_DIR ${Belos_SOURCE_DIR}/tpetra/example/TFQMR
SOURCE_FILES osrirr1.hb
EXEDEPS TFQMR_Tpetra_File_Ex Pseudo_Block_TFQMR_Tpetra_File_Ex
)

# TRIBITS_COPY_FILES_TO_BINARY_DIR(Tpetra_CopyExampleTFQMRFiles
# SOURCE_DIR ${Belos_SOURCE_DIR}/tpetra/example/TFQMR
# SOURCE_FILES bcsstk14.hb
# EXEDEPS TFQMR_Tpetra_File_Ex Pseudo_Block_TFQMR_Tpetra_File_Ex
# )

# ENDIF()
ENDIF()
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
// This driver reads a problem from a Harwell-Boeing (HB) file.
// Multiple right-hand-sides are created randomly.
// The initial guesses are all set to zero.
//
//
// Adapted from PseudoBlockTFQMREpetraExFile.cpp (with original comments)

// All preconditioning has been commented out

// Ifpack2
#include <Ifpack2_Factory.hpp>
#include <Ifpack2_Preconditioner.hpp>
// #include <Ifpack2_Factory.hpp>
// #include <Ifpack2_Preconditioner.hpp>

// Teuchos
#include <Teuchos_Assert.hpp>
Expand Down Expand Up @@ -92,7 +95,7 @@ int run(int argc, char *argv[]) {
using STM = typename Teuchos::ScalarTraits<MT>;

using LinearProblem = typename Belos::LinearProblem<ST, MV, OP>;
using Preconditioner = typename Ifpack2::Preconditioner<ST, LO, GO, NT>;
// using Preconditioner = typename Ifpack2::Preconditioner<ST, LO, GO, NT>;
using PseudoBlockTFQMRSolMgr = ::Belos::PseudoBlockTFQMRSolMgr<ST, MV, OP>;

Teuchos::GlobalMPISession session(&argc, &argv, NULL);
Expand All @@ -107,7 +110,7 @@ int run(int argc, char *argv[]) {
int frequency = -1; // how often residuals are printed by solver
int numRhs = 1;
int maxiters = -1; // maximum iterations allowed
std::string filename("bcsstk14.hb");
std::string filename("osrirr1.hb");
MT tol = STM::squareroot(STM::eps()); // relative residual tolerance

Teuchos::CommandLineProcessor cmdp(false, true);
Expand All @@ -131,36 +134,36 @@ int run(int argc, char *argv[]) {

procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor

// Create the preconditioner
std::string precType = "RILUK";
RCP<Preconditioner> prec = Ifpack2::Factory::create<MAT>(precType, A);
assert(prec != Teuchos::null);
// Create the preconditioner.
// std::string precType = "RILUK";
// RCP<Preconditioner> prec = Ifpack2::Factory::create<MAT>(precType, A);
// assert(prec != Teuchos::null);

// Specify parameters for the preconditioner
int lFill = 2; // if (argc > 2) lFill = atoi(argv[2]);
int overlap = 2; // if (argc > 3) overlap = atoi(argv[3]);
ST absThres = 0.0; // if (argc > 4) absThres = atof(argv[4]);
ST relThresh = 1.0; // if (argc >5) relThresh = atof(argv[5]);

if (procVerbose) {
std::cout << std::endl << std::endl;
std::cout << "Constructing RILUK preconditioner" << std::endl;
std::cout << "Using Level of fill = " << lFill << std::endl;
std::cout << "Using Level Overlap = " << overlap << std::endl;
std::cout << "Using Absolute Threshold Value of " << absThres << std::endl;
std::cout << "Using Relative Threshold Value of " << relThresh << std::endl;
}

ParameterList precParams;
precParams.set("fact: iluk level-of-fill", lFill);
precParams.set("fact: iluk level-of-overlap", overlap);
precParams.set("fact: absolute threshold", absThres);
precParams.set("fact: relative threshold", relThresh);
prec->setParameters(precParams);

// Initialize and build the preconditioner
prec->initialize();
prec->compute();
// // Specify parameters for the preconditioner
// int lFill = 2; // if (argc > 2) lFill = atoi(argv[2]);
// int overlap = 2; // if (argc > 3) overlap = atoi(argv[3]);
// ST absThres = 0.0; // if (argc > 4) absThres = atof(argv[4]);
// ST relThresh = 1.0; // if (argc >5) relThresh = atof(argv[5]);

// if (procVerbose) {
// std::cout << std::endl << std::endl;
// std::cout << "Constructing RILUK preconditioner" << std::endl;
// std::cout << "Using Level of fill = " << lFill << std::endl;
// std::cout << "Using Level Overlap = " << overlap << std::endl;
// std::cout << "Using Absolute Threshold Value of " << absThres << std::endl;
// std::cout << "Using Relative Threshold Value of " << relThresh << std::endl;
// }

// ParameterList precParams;
// precParams.set("fact: iluk level-of-fill", lFill);
// precParams.set("fact: iluk level-of-overlap", overlap);
// precParams.set("fact: absolute threshold", absThres);
// precParams.set("fact: relative threshold", relThresh);
// prec->setParameters(precParams);

// // Initialize and build the preconditioner
// prec->initialize();
// prec->compute();

// Specify parameters for the PseudoBlockTFQMR solver manager
const int numGlobalElements = map->getGlobalNumElements();
Expand All @@ -183,10 +186,10 @@ int run(int argc, char *argv[]) {
B->randomize();

RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));
if (leftPrec)
problem->setLeftPrec(prec);
else
problem->setRightPrec(prec);
// if (leftPrec)
// problem->setLeftPrec(prec);
// else
// problem->setRightPrec(prec);

bool set = problem->setProblem();
if (set == false) {
Expand Down
87 changes: 45 additions & 42 deletions packages/belos/tpetra/example/TFQMR/TFQMRTpetraExFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
// Multiple right-hand-sides are created randomly.
// The initial guesses are all set to zero.
//
// Adapted from TFQMREpetraExFile.cpp (with original comments)

// All preconditioning has been commented out

// Ifpack2
#include <Ifpack2_Factory.hpp>
#include <Ifpack2_Preconditioner.hpp>
// #include <Ifpack2_Factory.hpp>
// #include <Ifpack2_Preconditioner.hpp>

// Teuchos
#include <Teuchos_Assert.hpp>
Expand Down Expand Up @@ -91,7 +94,7 @@ int run(int argc, char *argv[]) {
using STM = typename Teuchos::ScalarTraits<MT>;

using LinearProblem = typename Belos::LinearProblem<ST, MV, OP>;
using Preconditioner = typename Ifpack2::Preconditioner<ST, LO, GO, NT>;
// using Preconditioner = typename Ifpack2::Preconditioner<ST, LO, GO, NT>;
using TFQMRSolMgr = ::Belos::TFQMRSolMgr<ST, MV, OP>;

Teuchos::GlobalMPISession session(&argc, &argv, NULL);
Expand All @@ -106,7 +109,7 @@ int run(int argc, char *argv[]) {
int frequency = -1; // how often residuals are printed by solver
int numRhs = 1;
int maxiters = -1; // maximum iterations allowed
std::string filename("bcsstk14.hb");
std::string filename("osrirr1.hb");
MT tol = STM::squareroot (STM::eps()); // 1.e-5 // relative residual tolerance

if (procVerbose)
Expand Down Expand Up @@ -141,40 +144,40 @@ int run(int argc, char *argv[]) {
procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor

// Create the preconditioner
if (procVerbose)
std::cout << "Create preconditioner" << std::endl;
std::string precType = "RILUK";
RCP<Preconditioner> prec = Ifpack2::Factory::create<MAT>(precType, A);
assert(prec != Teuchos::null);

// Specify parameters for the preconditioner
int lFill = 2; // if (argc > 2) lFill = atoi(argv[2]);
int overlap = 2; // if (argc > 3) overlap = atoi(argv[3]);
ST absThresh = 0.0; // if (argc > 4) AThresh = atof(argv[4]);
ST relThresh = 1.0; // if (argc >5) RThresh = atof(argv[5]);

if (procVerbose) {
std::cout << std::endl << std::endl;
std::cout << "Constructing ILU preconditioner" << std::endl;
std::cout << "Using Level of fill = " << lFill << std::endl;
std::cout << "Using Level Overlap = " << overlap << std::endl;
std::cout << "Using Absolute Threshold Value of " << absThresh << std::endl;
std::cout << "Using Relative Threshold Value of " << relThresh << std::endl;
}

if (procVerbose)
std::cout << "Init preconditioner" << std::endl;

ParameterList precParams;
precParams.set("fact: iluk level-of-fill", lFill);
precParams.set("fact: iluk level-of-overlap", overlap);
precParams.set("fact: absolute threshold", absThresh);
precParams.set("fact: relative threshold", relThresh);
prec->setParameters(precParams);

// Initialize and build the preconditioner
prec->initialize();
prec->compute();
// if (procVerbose)
// std::cout << "Create preconditioner" << std::endl;
// std::string precType = "RILUK";
// RCP<Preconditioner> prec = Ifpack2::Factory::create<MAT>(precType, A);
// assert(prec != Teuchos::null);

// // Specify parameters for the preconditioner
// int lFill = 2; // if (argc > 2) lFill = atoi(argv[2]);
// int overlap = 2; // if (argc > 3) overlap = atoi(argv[3]);
// ST absThresh = 0.0; // if (argc > 4) AThresh = atof(argv[4]);
// ST relThresh = 1.0; // if (argc >5) RThresh = atof(argv[5]);

// if (procVerbose) {
// std::cout << std::endl << std::endl;
// std::cout << "Constructing ILU preconditioner" << std::endl;
// std::cout << "Using Level of fill = " << lFill << std::endl;
// std::cout << "Using Level Overlap = " << overlap << std::endl;
// std::cout << "Using Absolute Threshold Value of " << absThresh << std::endl;
// std::cout << "Using Relative Threshold Value of " << relThresh << std::endl;
// }

// if (procVerbose)
// std::cout << "Init preconditioner" << std::endl;

// ParameterList precParams;
// precParams.set("fact: iluk level-of-fill", lFill);
// precParams.set("fact: iluk level-of-overlap", overlap);
// precParams.set("fact: absolute threshold", absThresh);
// precParams.set("fact: relative threshold", relThresh);
// prec->setParameters(precParams);

// // Initialize and build the preconditioner
// prec->initialize();
// prec->compute();

// Specify parameters for the TFQMR solver manager
const int numGlobalElements = map->getGlobalNumElements();
Expand All @@ -198,10 +201,10 @@ int run(int argc, char *argv[]) {
RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));
if (leftPrec)
problem->setLeftPrec(prec);
else
problem->setRightPrec(prec);
// if (leftPrec)
// problem->setLeftPrec(prec);
// else
// problem->setRightPrec(prec);

bool set = problem->setProblem();
if (set == false) {
Expand Down
Loading

0 comments on commit 08f79ec

Please sign in to comment.