Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#180: Belos: Provide Tpetra version of TFQMR examples #183

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

tlamonthezie
Copy link

@tlamonthezie tlamonthezie commented Sep 12, 2023

Fixes #180

PR to Trilinos: trilinos#12327

Currently these examples cannot build inside Trilinos (Commented in CmakeLists.txt) because of a circular dependency

Circular Dependency to Ifpack2 has to be fixed first
The 2 examples can only be compiled when adding Ifpack2 as a dependency of Belos (like Ifpack) and by disabling dependencies from ifpack2 to Belos because there is a circular dependency between these 2 packages to fix first.
So it should work after dependency fix.

Possible Obsolete HB Matrix File Reader
This example shows also how to use the Tpetra::Utils:readHBMatrix which does not require TriUtil (epetra does require it)
The fact is that Tpetra fail to open orsirr1.hb file found in the epetra tests and this data file is very old so it might be obsolete for now ? (there is no HB version option found in Tpetra::Utils:readHBMatrix it just complains about an invalid file format)

To see the problem you can change the following (using the TriUtil HB reader)

Belos::Tpetra::HarwellBoeingReader<Tpetra::CrsMatrix<ST> > reader( comm );
RCP<Tpetra::CrsMatrix<ST> > A = reader.readFromFile( filename );
RCP<const Tpetra::Map<> > map = A->getRowMap();

to that (Tpetra Utils HB reader)

RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
RCP<const MAP> map = A->getRowMap();`

It does not work with osrirr1.hb but works like it has been done here with another .hb data file found in trilinos

@tlamonthezie tlamonthezie added NGA-internal NGA workers will take care of these EpetraMPI T2 pkg: Belos labels Sep 12, 2023
@tlamonthezie tlamonthezie self-assigned this Sep 12, 2023
@tlamonthezie tlamonthezie marked this pull request as draft September 12, 2023 09:55
Copy link

@antoinemeyer5 antoinemeyer5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments in TFQMRTpetraExFile.cpp

@tlamonthezie tlamonthezie changed the title #180: Belos: Provide Tpetra version of TFQMR examples #180: Belos: Provide Tpetra version of TFQMR examples Sep 14, 2023
@tlamonthezie tlamonthezie marked this pull request as ready for review September 14, 2023 15:25
@jwillenbring
Copy link

Heidi provided the following response: The Tpetra HB matrix reader needs to be fixed then. This is a common format for matrices to be stored in and not being able to read them in for examples and tests is a problem for the solver packages. Not fixing the reader will just be postponing the inevitable.

I think this means this goes into the problem area for now.

@tlamonthezie
Copy link
Author

Finally a new version of orsiss.hb has been found and is working with the Tpetra::Utils::readHBMatrix method and will be part of this PR

@github-actions
Copy link

github-actions bot commented Sep 22, 2023

⚡ Code quality check ⚡


🔴 clang-tidy found 74 issues! Click here to see details.

int run(int argc, char *argv[]) {
using Teuchos::ParameterList;
using Teuchos::RCP;
using Teuchos::rcp;
using ST = typename Tpetra::MultiVector<ScalarType>::scalar_type;

!Line: 75 - warning: function 'run' has cognitive complexity of 45 (threshold 25) [readability-function-cognitive-complexity]
!Line: 115 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 127 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 130 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 134 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 138 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 141 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 144 - note: +1
!Line: 184 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 189 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 191 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 193 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 195 - note: +1, nesting level increased to 1
!Line: 210 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 211 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 220 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 230 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 234 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 247 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 249 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 252 - note: +3, including nesting penalty of 2, nesting level increased to 3
!Line: 257 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 257 - note: +1
!Line: 259 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 261 - note: +1, nesting level increased to 1
!Line: 263 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 267 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 267 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 267 - note: +3, including nesting penalty of 2, nesting level increased to 3
!Line: 267 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 267 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 267 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 267 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 269 - note: +1, including nesting penalty of 0, nesting level increased to 1

int run(int argc, char *argv[]) {
using Teuchos::ParameterList;
using Teuchos::RCP;
using Teuchos::rcp;
using ST = typename Tpetra::MultiVector<ScalarType>::scalar_type;

!Line: 75 - warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays]

Teuchos::GlobalMPISession session(&argc, &argv, NULL);
RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
bool verbose = false;
bool success = true;

!Line: 100 - warning: variable 'session' of type 'Teuchos::GlobalMPISession' can be declared 'const' [misc-const-correctness]

Teuchos::GlobalMPISession session(&argc, &argv, NULL);
RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
bool verbose = false;
bool success = true;

!Line: 100 - warning: use nullptr [modernize-use-nullptr]

MT tol = STM::squareroot (STM::eps()); // 1.e-5 // relative residual tolerance
if (procVerbose)
std::cout << "Init cli processor" << std::endl;
Teuchos::CommandLineProcessor cmdp(false, true);

!Line: 113 - warning: variable 'tol' is not initialized [cppcoreguidelines-init-variables]

if (procVerbose)
std::cout << "Init cli processor" << std::endl;
Teuchos::CommandLineProcessor cmdp(false, true);
cmdp.setOption("verbose", "quiet", &verbose, "Print messages and results.");
cmdp.setOption("left-prec", "right-prec", &leftPrec, "Left preconditioning or right.");

!Line: 115 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

Teuchos::CommandLineProcessor cmdp(false, true);
cmdp.setOption("verbose", "quiet", &verbose, "Print messages and results.");
cmdp.setOption("left-prec", "right-prec", &leftPrec, "Left preconditioning or right.");
cmdp.setOption("frequency", &frequency, "Solvers frequency for printing residuals (#iters).");
cmdp.setOption("filename", &filename, "Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol", &tol, "Relative residual tolerance used by GMRES solver.");

!Line: 118 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("frequency", &frequency, "Solvers frequency for printing residuals (#iters).");
cmdp.setOption("filename", &filename, "Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol", &tol, "Relative residual tolerance used by GMRES solver.");
cmdp.setOption("num-rhs", &numRhs, "Number of right-hand sides to be solved for.");
cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");

!Line: 121 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("filename", &filename, "Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol", &tol, "Relative residual tolerance used by GMRES solver.");
cmdp.setOption("num-rhs", &numRhs, "Number of right-hand sides to be solved for.");
cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {

!Line: 122 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("num-rhs", &numRhs, "Number of right-hand sides to be solved for.");
cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}

!Line: 124 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}
if (!verbose)

!Line: 125 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}
if (!verbose)
frequency = -1; // reset frequency if test is not verbose

!Line: 127 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

if (!verbose)
frequency = -1; // reset frequency if test is not verbose
// Get the problem
if (procVerbose)
std::cout << "Read Matrix from HB file" << std::endl;

!Line: 130 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (procVerbose)
std::cout << "Read Matrix from HB file" << std::endl;
RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
if (procVerbose)
std::cout << "Read Matrix from HB file OK" << std::endl;

!Line: 134 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
if (procVerbose)
std::cout << "Read Matrix from HB file OK" << std::endl;
RCP<const MAP> map = A->getRowMap();
if (procVerbose)

!Line: 136 - warning: variable 'A' is not initialized [cppcoreguidelines-init-variables]

RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
if (procVerbose)
std::cout << "Read Matrix from HB file OK" << std::endl;
RCP<const MAP> map = A->getRowMap();
if (procVerbose)

!Line: 136 - warning: variable name 'A' is too short, expected at least 3 characters [readability-identifier-length]

if (procVerbose)
std::cout << "Read Matrix from HB file OK" << std::endl;
RCP<const MAP> map = A->getRowMap();
if (procVerbose)
std::cout << "Read Map OK" << std::endl;

!Line: 138 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

RCP<const MAP> map = A->getRowMap();
if (procVerbose)
std::cout << "Read Map OK" << std::endl;
procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor

!Line: 140 - warning: variable 'map' is not initialized [cppcoreguidelines-init-variables]

if (procVerbose)
std::cout << "Read Map OK" << std::endl;
procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor
// Create the preconditioner

!Line: 141 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (maxiters == -1)
maxiters = numGlobalElements - 1; // maximum number of iterations to run
RCP<ParameterList> belosList = rcp(new ParameterList());
belosList->set("Maximum Iterations", maxiters); // Maximum number of iterations allowed
belosList->set("Convergence Tolerance", tol); // Relative convergence tolerance requested
if (leftPrec)

!Line: 184 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (leftPrec)
belosList->set("Explicit Residual Test", true); // Need to check for the explicit residual before returning
if (verbose) {
belosList->set("Verbosity", Belos::Errors + Belos::Warnings + Belos::TimingDetails + Belos::StatusTestDetails);
if (frequency > 0)
belosList->set("Output Frequency", frequency);

!Line: 189 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (frequency > 0)
belosList->set("Output Frequency", frequency);
} else
belosList->set("Verbosity", Belos::Errors + Belos::Warnings);
// Construct solution std::vector and random right-hand-sides

!Line: 193 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

} else
belosList->set("Verbosity", Belos::Errors + Belos::Warnings);
// Construct solution std::vector and random right-hand-sides
RCP<MV> X = rcp(new MV(map, numRhs));
X->putScalar(0.0);

!Line: 195 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

RCP<MV> X = rcp(new MV(map, numRhs));
X->putScalar(0.0);
RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));
// if (leftPrec)

!Line: 199 - warning: variable 'X' is not initialized [cppcoreguidelines-init-variables]

RCP<MV> X = rcp(new MV(map, numRhs));
X->putScalar(0.0);
RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));
// if (leftPrec)

!Line: 199 - warning: variable name 'X' is too short, expected at least 3 characters [readability-identifier-length]

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

!Line: 201 - warning: variable 'B' is not initialized [cppcoreguidelines-init-variables]

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

!Line: 201 - warning: variable name 'B' is too short, expected at least 3 characters [readability-identifier-length]

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

!Line: 203 - warning: variable 'problem' is not initialized [cppcoreguidelines-init-variables]

if (set == false) {
if (procVerbose)
std::cout << std::endl << "ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
return -1;
}

!Line: 210 - warning: redundant boolean literal supplied to boolean operator [readability-simplify-boolean-expr]

if (procVerbose)
std::cout << std::endl << "ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
return -1;
}
// Create the TFQMR solver manager

!Line: 211 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

RCP<TFQMRSolMgr> solver = rcp(new TFQMRSolMgr(problem, belosList));
// Print out information about problem
if (procVerbose) {
std::cout << std::endl << std::endl;
std::cout << "Dimension of matrix: " << numGlobalElements << std::endl;

!Line: 217 - warning: variable 'solver' is not initialized [cppcoreguidelines-init-variables]

std::vector<ST> actualResids(numRhs);
std::vector<ST> rhsNorm(numRhs);
MV resids(map, numRhs);
OPT::Apply(*A, *X, resids);
MVT::MvAddMv(-1.0, resids, 1.0, *B, resids);
MVT::MvNorm(resids, actualResids);

!Line: 240 - warning: variable 'actualResids' is not initialized [cppcoreguidelines-init-variables]

std::vector<ST> rhsNorm(numRhs);
MV resids(map, numRhs);
OPT::Apply(*A, *X, resids);
MVT::MvAddMv(-1.0, resids, 1.0, *B, resids);
MVT::MvNorm(resids, actualResids);
MVT::MvNorm(*B, rhsNorm);

!Line: 241 - warning: variable 'rhsNorm' is not initialized [cppcoreguidelines-init-variables]

MV resids(map, numRhs);
OPT::Apply(*A, *X, resids);
MVT::MvAddMv(-1.0, resids, 1.0, *B, resids);
MVT::MvNorm(resids, actualResids);
MVT::MvNorm(*B, rhsNorm);
if (procVerbose) {

!Line: 242 - warning: variable 'resids' is not initialized [cppcoreguidelines-init-variables]

for (int i = 0; i < numRhs; i++) {
ST actRes = actualResids[i] / rhsNorm[i];
std::cout << "Problem " << i << " : \t" << actRes << std::endl;
if (actRes > tol)
badRes = true;
}

!Line: 249 - warning: kernel performance could be improved by unrolling this loop with a '#pragma unroll' directive [altera-unroll-loops]

ST actRes = actualResids[i] / rhsNorm[i];
std::cout << "Problem " << i << " : \t" << actRes << std::endl;
if (actRes > tol)
badRes = true;
}
}

!Line: 250 - warning: variable 'actRes' is not initialized [cppcoreguidelines-init-variables]

if (actRes > tol)
badRes = true;
}
}
if (ret != Belos::Converged || badRes) {

!Line: 252 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (procVerbose)
std::cout << std::endl << "ERROR: Belos did not converge!" << std::endl;
} else {
success = true;
if (procVerbose)
std::cout << std::endl << "SUCCESS: Belos converged!" << std::endl;

!Line: 259 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (procVerbose)
std::cout << std::endl << "SUCCESS: Belos converged!" << std::endl;
}
}
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);

!Line: 263 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

int run(int argc, char *argv[]) {
using Teuchos::ParameterList;
using Teuchos::RCP;
using Teuchos::rcp;
using ST = typename Tpetra::MultiVector<ScalarType>::scalar_type;

!Line: 76 - warning: function 'run' has cognitive complexity of 39 (threshold 25) [readability-function-cognitive-complexity]
!Line: 125 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 128 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 135 - note: +1
!Line: 170 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 174 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 176 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 178 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 179 - note: +1, nesting level increased to 1
!Line: 195 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 196 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 205 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 226 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 228 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 231 - note: +3, including nesting penalty of 2, nesting level increased to 3
!Line: 235 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 235 - note: +1
!Line: 237 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 238 - note: +1, nesting level increased to 1
!Line: 240 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 243 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 243 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 243 - note: +3, including nesting penalty of 2, nesting level increased to 3
!Line: 243 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 243 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 243 - note: +1, including nesting penalty of 0, nesting level increased to 1
!Line: 243 - note: +2, including nesting penalty of 1, nesting level increased to 2
!Line: 245 - note: +1, including nesting penalty of 0, nesting level increased to 1

int run(int argc, char *argv[]) {
using Teuchos::ParameterList;
using Teuchos::RCP;
using Teuchos::rcp;
using ST = typename Tpetra::MultiVector<ScalarType>::scalar_type;

!Line: 76 - warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays]

Teuchos::GlobalMPISession session(&argc, &argv, NULL);
RCP<const Teuchos::Comm<int>> comm = Tpetra::getDefaultComm();
bool verbose = false;
bool success = true;

!Line: 101 - warning: variable 'session' of type 'Teuchos::GlobalMPISession' can be declared 'const' [misc-const-correctness]

Teuchos::GlobalMPISession session(&argc, &argv, NULL);
RCP<const Teuchos::Comm<int>> comm = Tpetra::getDefaultComm();
bool verbose = false;
bool success = true;

!Line: 101 - warning: use nullptr [modernize-use-nullptr]

MT tol = STM::squareroot(STM::eps()); // relative residual tolerance
Teuchos::CommandLineProcessor cmdp(false, true);
cmdp.setOption("verbose", "quiet", &verbose, "Print messages and results.");
cmdp.setOption("left-prec", "right-prec", &leftPrec, "Left preconditioning or right.");
cmdp.setOption("frequency", &frequency, "Solvers frequency for printing residuals (#iters).");

!Line: 114 - warning: variable 'tol' is not initialized [cppcoreguidelines-init-variables]

Teuchos::CommandLineProcessor cmdp(false, true);
cmdp.setOption("verbose", "quiet", &verbose, "Print messages and results.");
cmdp.setOption("left-prec", "right-prec", &leftPrec, "Left preconditioning or right.");
cmdp.setOption("frequency", &frequency, "Solvers frequency for printing residuals (#iters).");
cmdp.setOption("filename", &filename, "Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol", &tol, "Relative residual tolerance used by GMRES solver.");

!Line: 116 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("frequency", &frequency, "Solvers frequency for printing residuals (#iters).");
cmdp.setOption("filename", &filename, "Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol", &tol, "Relative residual tolerance used by GMRES solver.");
cmdp.setOption("num-rhs", &numRhs, "Number of right-hand sides to be solved for.");
cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");

!Line: 119 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("filename", &filename, "Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol", &tol, "Relative residual tolerance used by GMRES solver.");
cmdp.setOption("num-rhs", &numRhs, "Number of right-hand sides to be solved for.");
cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {

!Line: 120 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("num-rhs", &numRhs, "Number of right-hand sides to be solved for.");
cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}

!Line: 122 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

cmdp.setOption("maxiters", &maxiters,
"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}
if (!verbose) frequency = -1; // reset frequency if test is not verbose

!Line: 123 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

if (cmdp.parse(argc, argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}
if (!verbose) frequency = -1; // reset frequency if test is not verbose
// Get the problem

!Line: 125 - warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]

if (!verbose) frequency = -1; // reset frequency if test is not verbose
// Get the problem
RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
RCP<const MAP> map = A->getRowMap();

!Line: 128 - warning: statement should be inside braces [hicpp-braces-around-statements,readability-braces-around-statements]

RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
RCP<const MAP> map = A->getRowMap();
procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor

!Line: 131 - warning: variable 'A' is not initialized [cppcoreguidelines-init-variables]

RCP<MAT> A;
Tpetra::Utils::readHBMatrix(filename, comm, A);
RCP<const MAP> map = A->getRowMap();
procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor

!Line: 131 - warning: variable name 'A' is too short, expected at least 3 characters [readability-identifier-length]

RCP<const MAP> map = A->getRowMap();
procVerbose = verbose && (comm->getRank() == 0); // Only print on zero processor
// Create the preconditioner.
// std::string precType = "RILUK";

!Line: 133 - warning: variable 'map' is not initialized [cppcoreguidelines-init-variables]

if (maxiters == -1) maxiters = numGlobalElements - 1; // maximum number of iterations to run
RCP<ParameterList> belosList = rcp(new ParameterList());
belosList->set("Maximum Iterations", maxiters); // Maximum number of iterations allowed
belosList->set("Convergence Tolerance", tol); // Relative convergence tolerance requested
if (leftPrec)
belosList->set("Explicit Residual Test", true); // Need to check for the explicit residual before returning

!Line: 170 - warning: statement should be inside braces [hicpp-braces-around-statements,readability-braces-around-statements]

if (leftPrec)
belosList->set("Explicit Residual Test", true); // Need to check for the explicit residual before returning
if (verbose) {
belosList->set("Verbosity", Belos::Errors + Belos::Warnings + Belos::TimingDetails + Belos::StatusTestDetails);
if (frequency > 0) belosList->set("Output Frequency", frequency);
} else

!Line: 174 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

if (frequency > 0) belosList->set("Output Frequency", frequency);
} else
belosList->set("Verbosity", Belos::Errors + Belos::Warnings);
// Construct solution std::vector and random right-hand-sides
RCP<MV> X = rcp(new MV(map, numRhs));

!Line: 178 - warning: statement should be inside braces [hicpp-braces-around-statements,readability-braces-around-statements]

} else
belosList->set("Verbosity", Belos::Errors + Belos::Warnings);
// Construct solution std::vector and random right-hand-sides
RCP<MV> X = rcp(new MV(map, numRhs));
X->putScalar(0.0);

!Line: 179 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

RCP<MV> X = rcp(new MV(map, numRhs));
X->putScalar(0.0);
RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));

!Line: 183 - warning: variable 'X' is not initialized [cppcoreguidelines-init-variables]

RCP<MV> X = rcp(new MV(map, numRhs));
X->putScalar(0.0);
RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));

!Line: 183 - warning: variable name 'X' is too short, expected at least 3 characters [readability-identifier-length]

RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));
// if (leftPrec)
// problem->setLeftPrec(prec);

!Line: 185 - warning: variable 'B' is not initialized [cppcoreguidelines-init-variables]

RCP<MV> B = rcp(new MV(map, numRhs));
B->randomize();
RCP<LinearProblem> problem = rcp(new LinearProblem(A, X, B));
// if (leftPrec)
// problem->setLeftPrec(prec);

!Line: 185 - warning: variable name 'B' is too short, expected at least 3 characters [readability-identifier-length]

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

!Line: 188 - warning: variable 'problem' is not initialized [cppcoreguidelines-init-variables]

if (set == false) {
if (procVerbose)
std::cout << std::endl << "ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
return -1;
}

!Line: 195 - warning: redundant boolean literal supplied to boolean operator [readability-simplify-boolean-expr]

if (procVerbose)
std::cout << std::endl << "ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
return -1;
}
// Create the PseudoBlockTFQMR solver manager

!Line: 196 - warning: statement should be inside braces [google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements]

RCP<PseudoBlockTFQMRSolMgr> solver = rcp(new PseudoBlockTFQMRSolMgr(problem, belosList));
// Print out information about problem
if (procVerbose) {
std::cout << std::endl << std::endl;
std::cout << "Dimension of matrix: " << numGlobalElements << std::endl;

!Line: 202 - warning: variable 'solver' is not initialized [cppcoreguidelines-init-variables]

std::vector<ST> actualResids(numRhs);
std::vector<ST> rhsNorm(numRhs);
MV resid(map, numRhs);
OPT::Apply(*A, *X, resid);
MVT::MvAddMv(-1.0, resid, 1.0, *B, resid);
MVT::MvNorm(resid, actualResids);

!Line: 219 - warning: variable 'actualResids' is not initialized [cppcoreguidelines-init-variables]

std::vector<ST> rhsNorm(numRhs);
MV resid(map, numRhs);
OPT::Apply(*A, *X, resid);
MVT::MvAddMv(-1.0, resid, 1.0, *B, resid);
MVT::MvNorm(resid, actualResids);
MVT::MvNorm(*B, rhsNorm);

!Line: 220 - warning: variable 'rhsNorm' is not initialized [cppcoreguidelines-init-variables]

MV resid(map, numRhs);
OPT::Apply(*A, *X, resid);
MVT::MvAddMv(-1.0, resid, 1.0, *B, resid);
MVT::MvNorm(resid, actualResids);
MVT::MvNorm(*B, rhsNorm);
if (procVerbose) {

!Line: 221 - warning: variable 'resid' is not initialized [cppcoreguidelines-init-variables]

for (int i = 0; i < numRhs; i++) {
ST actRes = actualResids[i] / rhsNorm[i];
std::cout << "Problem " << i << " : \t" << actRes << std::endl;
if (actRes > tol) badRes = true;
}
}

!Line: 228 - warning: kernel performance could be improved by unrolling this loop with a '#pragma unroll' directive [altera-unroll-loops]

ST actRes = actualResids[i] / rhsNorm[i];
std::cout << "Problem " << i << " : \t" << actRes << std::endl;
if (actRes > tol) badRes = true;
}
}

!Line: 229 - warning: variable 'actRes' is not initialized [cppcoreguidelines-init-variables]

if (actRes > tol) badRes = true;
}
}
if (ret != Belos::Converged || badRes) {
success = false;

!Line: 231 - warning: statement should be inside braces [hicpp-braces-around-statements,readability-braces-around-statements]

if (procVerbose) std::cout << std::endl << "ERROR: Belos did not converge!" << std::endl;
} else {
success = true;
if (procVerbose) std::cout << std::endl << "SUCCESS: Belos converged!" << std::endl;
}
}

!Line: 237 - warning: statement should be inside braces [hicpp-braces-around-statements,readability-braces-around-statements]

if (procVerbose) std::cout << std::endl << "SUCCESS: Belos converged!" << std::endl;
}
}
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);
return success ? EXIT_SUCCESS : EXIT_FAILURE;

!Line: 240 - warning: statement should be inside braces [hicpp-braces-around-statements,readability-braces-around-statements]


@stmcgovern stmcgovern merged commit 5972f11 into NGA-FY23-develop Sep 22, 2023
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Belos: Provide Tpetra version of TFQMR examples
4 participants