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

#205: Belos: clean MINRES Tpetra test_minres_diag test #206

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

tlamonthezie
Copy link

@tlamonthezie tlamonthezie commented Sep 20, 2023

Fixes #205

PR to Trilinos: trilinos#12322 (including #70, #177, #206)

This solves also other problems related to the test_minres_diag Tpetra test

This PR comes in addition to #70 and #177 to include the Belos Tpetra MINRES tests into Trilinos.

This PR provides the following to the test_minres_diag Tpetra test in Belos:

  • Reorder includes
  • Make class names CamelCase (mainly operator classes)
  • Pass scalar type using C++ templates to the classes instead of explicit double type
  • Use Teuchos version Teuchos::reduceAll istead of MPI one (MPI_REDUCE_ALL)
  • Fixes a bug occuring when applying a DiagonalOperator2 operator (was commented in the Tpetra version until this PR)

@tlamonthezie tlamonthezie self-assigned this Sep 20, 2023
@tlamonthezie tlamonthezie added NGA-internal NGA workers will take care of these EpetraMPI T2 labels Sep 20, 2023
@github-actions
Copy link

github-actions bot commented Sep 20, 2023

⚡ Code quality check ⚡


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

RCP<MV> B, X;
X = rcp( new MV(rowMap, numRHS) );
MVT::MvRandom( *X );
B = rcp( new MV(rowMap, numRHS ) );
OPT::Apply( *A, *X, *B );
MVT::MvInit( *X, 0.0 );

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

RCP<MV> B, X;
X = rcp( new MV(rowMap, numRHS) );
MVT::MvRandom( *X );
B = rcp( new MV(rowMap, numRHS ) );
OPT::Apply( *A, *X, *B );
MVT::MvInit( *X, 0.0 );

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

using Teuchos::RCP;
using Teuchos::rcp;
//************************************************************************************************
template <class MV>

!Line: 64 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

using Teuchos::rcp;
//************************************************************************************************
template <class MV>
class VectorOperator {

!Line: 65 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

class VectorOperator {
public:
VectorOperator(int m_in, int n_in) : m(m_in), n(n_in){};
virtual ~VectorOperator(){};

!Line: 70 - warning: class 'VectorOperator' defines a non-default destructor, a copy constructor and a copy assignment operator but does not define a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions,hicpp-special-member-functions]

class VectorOperator {
public:
VectorOperator(int m_in, int n_in) : m(m_in), n(n_in){};
virtual ~VectorOperator(){};

!Line: 70 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

virtual ~VectorOperator(){};
virtual void operator()(const MV &x, MV &y) = 0;
int size(int dim) const { return (dim == 1) ? m : n; };

!Line: 74 - warning: use '= default' to define a trivial destructor [hicpp-use-equals-default,modernize-use-equals-default]

VectorOperator(const VectorOperator &) : m(0), n(0){};
VectorOperator *operator=(const VectorOperator &) { return NULL; };
};
//************************************************************************************************

!Line: 85 - warning: all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter]

VectorOperator *operator=(const VectorOperator &) { return NULL; };
};
//************************************************************************************************
template <class ST, class MV>

!Line: 86 - warning: operator=() does not handle self-assignment properly [cert-oop54-cpp]

VectorOperator *operator=(const VectorOperator &) { return NULL; };
};
//************************************************************************************************
template <class ST, class MV>

!Line: 86 - warning: use a trailing return type for this function [modernize-use-trailing-return-type]

VectorOperator *operator=(const VectorOperator &) { return NULL; };
};
//************************************************************************************************
template <class ST, class MV>

!Line: 86 - warning: all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter]

class DiagonalOperator : public VectorOperator<MV> {
public:
DiagonalOperator(int n_in, ST v_in) : VectorOperator<MV>(n_in, n_in), v(v_in){};
~DiagonalOperator(){};

!Line: 92 - warning: class 'DiagonalOperator' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions,hicpp-special-member-functions]

class DiagonalOperator : public VectorOperator<MV> {
public:
DiagonalOperator(int n_in, ST v_in) : VectorOperator<MV>(n_in, n_in), v(v_in){};
~DiagonalOperator(){};

!Line: 92 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

~DiagonalOperator(){};
void operator()(const MV &x, MV &y) { y.scale(v, x); };
private:
ST v;

!Line: 96 - warning: use '= default' to define a trivial destructor [hicpp-use-equals-default,modernize-use-equals-default]

void operator()(const MV &x, MV &y) { y.scale(v, x); };
private:
ST v;
};

!Line: 98 - warning: overloading 'operator()' is disallowed [fuchsia-overloaded-operator]

void operator()(const MV &x, MV &y) { y.scale(v, x); };
private:
ST v;
};

!Line: 98 - warning: parameter name 'x' is too short, expected at least 3 characters [readability-identifier-length]

void operator()(const MV &x, MV &y) { y.scale(v, x); };
private:
ST v;
};

!Line: 98 - warning: parameter name 'y' is too short, expected at least 3 characters [readability-identifier-length]

class DiagonalOperator2 : public VectorOperator<MV> {
public:
DiagonalOperator2<ST, MV>(int n_in, int min_gid_in, ST v_in)
: VectorOperator<MV>(n_in, n_in), min_gid(min_gid_in), v(v_in) {}
~DiagonalOperator2(){};

!Line: 107 - warning: class 'DiagonalOperator2' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions,hicpp-special-member-functions]

class DiagonalOperator2 : public VectorOperator<MV> {
public:
DiagonalOperator2<ST, MV>(int n_in, int min_gid_in, ST v_in)
: VectorOperator<MV>(n_in, n_in), min_gid(min_gid_in), v(v_in) {}
~DiagonalOperator2(){};

!Line: 107 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

DiagonalOperator2<ST, MV>(int n_in, int min_gid_in, ST v_in)
: VectorOperator<MV>(n_in, n_in), min_gid(min_gid_in), v(v_in) {}
~DiagonalOperator2(){};
void operator()(const MV &x, MV &y) {

!Line: 109 - warning: 2 adjacent parameters of 'DiagonalOperator2<ST, MV>' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
!Line: 109 - note: the first parameter in the range is 'n_in'
!Line: 109 - note: the last parameter in the range is 'min_gid_in'

~DiagonalOperator2(){};
void operator()(const MV &x, MV &y) {
auto yLocalData = y.getLocalViewHost(Tpetra::Access::ReadWrite);
auto xLocalData = x.getLocalViewHost(Tpetra::Access::ReadOnly);

!Line: 112 - warning: use '= default' to define a trivial destructor [hicpp-use-equals-default,modernize-use-equals-default]

void operator()(const MV &x, MV &y) {
auto yLocalData = y.getLocalViewHost(Tpetra::Access::ReadWrite);
auto xLocalData = x.getLocalViewHost(Tpetra::Access::ReadOnly);
for (size_t j = 0; j < x.getNumVectors(); ++j) {
for (size_t i = 0; i < x.getLocalLength(); ++i) {

!Line: 114 - warning: overloading 'operator()' is disallowed [fuchsia-overloaded-operator]

void operator()(const MV &x, MV &y) {
auto yLocalData = y.getLocalViewHost(Tpetra::Access::ReadWrite);
auto xLocalData = x.getLocalViewHost(Tpetra::Access::ReadOnly);
for (size_t j = 0; j < x.getNumVectors(); ++j) {
for (size_t i = 0; i < x.getLocalLength(); ++i) {

!Line: 114 - warning: parameter name 'x' is too short, expected at least 3 characters [readability-identifier-length]

void operator()(const MV &x, MV &y) {
auto yLocalData = y.getLocalViewHost(Tpetra::Access::ReadWrite);
auto xLocalData = x.getLocalViewHost(Tpetra::Access::ReadOnly);
for (size_t j = 0; j < x.getNumVectors(); ++j) {
for (size_t i = 0; i < x.getLocalLength(); ++i) {

!Line: 114 - warning: parameter name 'y' is too short, expected at least 3 characters [readability-identifier-length]

for (size_t i = 0; i < x.getLocalLength(); ++i) {
yLocalData(i, j) = (min_gid + i + 1) * v * xLocalData(i, j); // NOTE: square operator!
}
}
};

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

class ComposedOperator : public VectorOperator<MV> {
public:
ComposedOperator(int n, const RCP<VectorOperator<MV>> &pA_in, const RCP<VectorOperator<MV>> &pB_in);
virtual ~ComposedOperator(){};

!Line: 133 - warning: class 'ComposedOperator' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions,hicpp-special-member-functions]

class ComposedOperator : public VectorOperator<MV> {
public:
ComposedOperator(int n, const RCP<VectorOperator<MV>> &pA_in, const RCP<VectorOperator<MV>> &pB_in);
virtual ~ComposedOperator(){};

!Line: 133 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

virtual ~ComposedOperator(){};
virtual void operator()(const MV &x, MV &y);
private:
RCP<VectorOperator<MV>> pA;

!Line: 137 - warning: use '= default' to define a trivial destructor [hicpp-use-equals-default,modernize-use-equals-default]

ComposedOperator<MV>::ComposedOperator(int n_in, const RCP<VectorOperator<MV>> &pA_in,
const RCP<VectorOperator<MV>> &pB_in)
: VectorOperator<MV>(n_in, n_in), pA(pA_in), pB(pB_in) {}
template <class MV>
void ComposedOperator<MV>::operator()(const MV &x, MV &y) {

!Line: 147 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

ComposedOperator<MV>::ComposedOperator(int n_in, const RCP<VectorOperator<MV>> &pA_in,
const RCP<VectorOperator<MV>> &pB_in)
: VectorOperator<MV>(n_in, n_in), pA(pA_in), pB(pB_in) {}
template <class MV>
void ComposedOperator<MV>::operator()(const MV &x, MV &y) {

!Line: 147 - warning: 2 adjacent parameters of 'ComposedOperator<MV>' of similar type ('const RCP<VectorOperator<MV>> &') are easily swapped by mistake [bugprone-easily-swappable-parameters]
!Line: 147 - note: the first parameter in the range is 'pA_in'
!Line: 148 - note: the last parameter in the range is 'pB_in'

void ComposedOperator<MV>::operator()(const MV &x, MV &y) {
MV ytemp(y.getMap(), y.getNumVectors(), false);
(*pB)(x, ytemp);
(*pA)(ytemp, y);
}

!Line: 152 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

void ComposedOperator<MV>::operator()(const MV &x, MV &y) {
MV ytemp(y.getMap(), y.getNumVectors(), false);
(*pB)(x, ytemp);
(*pA)(ytemp, y);
}

!Line: 152 - warning: parameter name 'x' is too short, expected at least 3 characters [readability-identifier-length]

void ComposedOperator<MV>::operator()(const MV &x, MV &y) {
MV ytemp(y.getMap(), y.getNumVectors(), false);
(*pB)(x, ytemp);
(*pA)(ytemp, y);
}

!Line: 152 - warning: parameter name 'y' is too short, expected at least 3 characters [readability-identifier-length]

class TrilinosInterface : public OP {
public:
TrilinosInterface(const RCP<VectorOperator<MV>> pA_in, const RCP<const Teuchos::Comm<int>> pComm_in,
const RCP<const MP> pMap_in)
: pA(pA_in), pComm(pComm_in), pMap(pMap_in), use_transpose(false) {}

!Line: 161 - warning: class 'TrilinosInterface' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions,hicpp-special-member-functions]

class TrilinosInterface : public OP {
public:
TrilinosInterface(const RCP<VectorOperator<MV>> pA_in, const RCP<const Teuchos::Comm<int>> pComm_in,
const RCP<const MP> pMap_in)
: pA(pA_in), pComm(pComm_in), pMap(pMap_in), use_transpose(false) {}

!Line: 161 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

void apply(const MV &X, MV &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
ST beta = Teuchos::ScalarTraits<ST>::zero()) const override;
virtual ~TrilinosInterface(){};
bool hasTransposeApply() const { return (use_transpose); }; // always set to false (in fact the default)

!Line: 167 - warning: default arguments on virtual or override methods are prohibited [google-default-arguments]

void apply(const MV &X, MV &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
ST beta = Teuchos::ScalarTraits<ST>::zero()) const override;
virtual ~TrilinosInterface(){};
bool hasTransposeApply() const { return (use_transpose); }; // always set to false (in fact the default)

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

void apply(const MV &X, MV &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
ST beta = Teuchos::ScalarTraits<ST>::zero()) const override;
virtual ~TrilinosInterface(){};
bool hasTransposeApply() const { return (use_transpose); }; // always set to false (in fact the default)

!Line: 167 - warning: parameter name 'Y' is too short, expected at least 3 characters [readability-identifier-length]

void apply(const MV &X, MV &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
ST beta = Teuchos::ScalarTraits<ST>::zero()) const override;
virtual ~TrilinosInterface(){};
bool hasTransposeApply() const { return (use_transpose); }; // always set to false (in fact the default)

!Line: 167 - warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]

void apply(const MV &X, MV &Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, ST alpha = Teuchos::ScalarTraits<ST>::one(),
ST beta = Teuchos::ScalarTraits<ST>::zero()) const override;
virtual ~TrilinosInterface(){};
bool hasTransposeApply() const { return (use_transpose); }; // always set to false (in fact the default)

!Line: 167 - warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]

virtual ~TrilinosInterface(){};
bool hasTransposeApply() const { return (use_transpose); }; // always set to false (in fact the default)
RCP<const MP> getDomainMap() const override { return pMap; }
RCP<const MP> getRangeMap() const override { return pMap; }

!Line: 170 - warning: use '= default' to define a trivial destructor [hicpp-use-equals-default,modernize-use-equals-default]

RCP<const MP> getDomainMap() const override { return pMap; }
RCP<const MP> getRangeMap() const override { return pMap; }
private:
RCP<VectorOperator<MV>> pA;
RCP<const Teuchos::Comm<int>> pComm;

!Line: 174 - warning: use a trailing return type for this function [modernize-use-trailing-return-type]

RCP<const MP> getRangeMap() const override { return pMap; }
private:
RCP<VectorOperator<MV>> pA;
RCP<const Teuchos::Comm<int>> pComm;
RCP<const MP> pMap;

!Line: 175 - warning: use a trailing return type for this function [modernize-use-trailing-return-type]

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: default arguments on virtual or override methods are prohibited [google-default-arguments]

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

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

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: parameter name 'Y' is too short, expected at least 3 characters [readability-identifier-length]

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: parameter 'mode' is unused [misc-unused-parameters]

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: 2 adjacent parameters of 'apply' of similar type ('ST') are easily swapped by mistake [bugprone-easily-swappable-parameters]
!Line: 186 - note: the first parameter in the range is 'alpha'
!Line: 186 - note: the last parameter in the range is 'beta'

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: parameter 'alpha' is unused [misc-unused-parameters]

void TrilinosInterface<OP, ST, MP, MV>::apply(const MV &X, MV &Y, Teuchos::ETransp mode, ST alpha, ST beta) const {
(*pA)(X, Y);
}
//************************************************************************************************

!Line: 186 - warning: parameter 'beta' is unused [misc-unused-parameters]

class IterativeInverseOperator : public VectorOperator<MV> {
public:
IterativeInverseOperator(int n_in, int blocksize, const RCP<VectorOperator<MV>> &pA_in,
std::string opString = "Iterative Solver", bool print_in = false);
virtual ~IterativeInverseOperator() {}

!Line: 193 - warning: class 'IterativeInverseOperator' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions,hicpp-special-member-functions]

class IterativeInverseOperator : public VectorOperator<MV> {
public:
IterativeInverseOperator(int n_in, int blocksize, const RCP<VectorOperator<MV>> &pA_in,
std::string opString = "Iterative Solver", bool print_in = false);
virtual ~IterativeInverseOperator() {}

!Line: 193 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

virtual ~IterativeInverseOperator() {}
virtual void operator()(const MV &b, MV &x);
private:
RCP<VectorOperator<MV>> pA; // operator which will be inverted

!Line: 198 - warning: use '= default' to define a trivial destructor [hicpp-use-equals-default,modernize-use-equals-default]

IterativeInverseOperator<OP, ST, MP, MV>::IterativeInverseOperator(int n_in, int blocksize,
const RCP<VectorOperator<MV>> &pA_in,
std::string opString, bool print_in)
: VectorOperator<MV>(n_in, n_in), // square operator
pA(pA_in),
print(print_in),

!Line: 218 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

IterativeInverseOperator<OP, ST, MP, MV>::IterativeInverseOperator(int n_in, int blocksize,
const RCP<VectorOperator<MV>> &pA_in,
std::string opString, bool print_in)
: VectorOperator<MV>(n_in, n_in), // square operator
pA(pA_in),
print(print_in),

!Line: 218 - warning: 2 adjacent parameters of 'IterativeInverseOperator<OP, ST, MP, MV>' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
!Line: 218 - note: the first parameter in the range is 'n_in'
!Line: 218 - note: the last parameter in the range is 'blocksize'

IterativeInverseOperator<OP, ST, MP, MV>::IterativeInverseOperator(int n_in, int blocksize,
const RCP<VectorOperator<MV>> &pA_in,
std::string opString, bool print_in)
: VectorOperator<MV>(n_in, n_in), // square operator
pA(pA_in),
print(print_in),

!Line: 218 - warning: parameter 'blocksize' is unused [misc-unused-parameters]

timer(opString) {
int n_global;
pComm = Tpetra::getDefaultComm();
Teuchos::reduceAll<int, int>(*pComm, Teuchos::REDUCE_SUM, 1, &n_in, &n_global);
pMap = rcp(new MP(n_global, n_in, 0, pComm));

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

pProb = rcp(new Belos::LinearProblem<ST, MV, OP>());
pProb->setOperator(pPE);
int max_iter = 100;
const ST tol = sqrt(std::numeric_limits<ST>::epsilon());
int verbosity = Belos::Errors + Belos::Warnings;

!Line: 233 - warning: 'pProb' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]

void IterativeInverseOperator<OP, ST, MP, MV>::operator()(const MV &b, MV &x) {
int pid = pComm->getRank();
// Initialize the solution to zero
x.putScalar(0.0);

!Line: 251 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

void IterativeInverseOperator<OP, ST, MP, MV>::operator()(const MV &b, MV &x) {
int pid = pComm->getRank();
// Initialize the solution to zero
x.putScalar(0.0);

!Line: 251 - warning: parameter name 'b' is too short, expected at least 3 characters [readability-identifier-length]

void IterativeInverseOperator<OP, ST, MP, MV>::operator()(const MV &b, MV &x) {
int pid = pComm->getRank();
// Initialize the solution to zero
x.putScalar(0.0);

!Line: 251 - warning: parameter name 'x' is too short, expected at least 3 characters [readability-identifier-length]

} else
std::cout << std::endl << "pid[" << pid << "] Minres did not converge" << std::endl;
}
}
//************************************************************************************************

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

RCP<DiagonalOperator2<ST, MV>> D2 = rcp(new DiagonalOperator2<ST, MV>(n, map->getMinGlobalIndex(), 1.0));
IterativeInverseOperator<OP, ST, MP, MV> A2(n, 1, D2, "Belos (inv(D2))", true);
// should return x=(1, 1/2, 1/3, ..., 1/10)
A2(X, Y);

!Line: 309 - warning: variable 'D2' is not initialized [cppcoreguidelines-init-variables]

RCP<DiagonalOperator2<ST, MV>> D2 = rcp(new DiagonalOperator2<ST, MV>(n, map->getMinGlobalIndex(), 1.0));
IterativeInverseOperator<OP, ST, MP, MV> A2(n, 1, D2, "Belos (inv(D2))", true);
// should return x=(1, 1/2, 1/3, ..., 1/10)
A2(X, Y);

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

IterativeInverseOperator<OP, ST, MP, MV> A2(n, 1, D2, "Belos (inv(D2))", true);
// should return x=(1, 1/2, 1/3, ..., 1/10)
A2(X, Y);
if (pid == 0) {

!Line: 310 - warning: variable 'A2' is not initialized [cppcoreguidelines-init-variables]

IterativeInverseOperator<OP, ST, MP, MV> A2(n, 1, D2, "Belos (inv(D2))", true);
// should return x=(1, 1/2, 1/3, ..., 1/10)
A2(X, Y);
if (pid == 0) {

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

RCP<DiagonalOperator<ST, MV>> D = rcp(new DiagonalOperator<ST, MV>(n, 4.0));
RCP<IterativeInverseOperator<OP, ST, MP, MV>> Inner =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, D, "Belos (inv(D))", false));
// ComposedOperator computed inv(D)*B*x
RCP<DiagonalOperator<ST, MV>> B = rcp(new DiagonalOperator<ST, MV>(n, 4.0));

!Line: 321 - warning: variable 'D' is not initialized [cppcoreguidelines-init-variables]

RCP<DiagonalOperator<ST, MV>> D = rcp(new DiagonalOperator<ST, MV>(n, 4.0));
RCP<IterativeInverseOperator<OP, ST, MP, MV>> Inner =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, D, "Belos (inv(D))", false));
// ComposedOperator computed inv(D)*B*x
RCP<DiagonalOperator<ST, MV>> B = rcp(new DiagonalOperator<ST, MV>(n, 4.0));

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

RCP<IterativeInverseOperator<OP, ST, MP, MV>> Inner =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, D, "Belos (inv(D))", false));
// ComposedOperator computed inv(D)*B*x
RCP<DiagonalOperator<ST, MV>> B = rcp(new DiagonalOperator<ST, MV>(n, 4.0));
RCP<ComposedOperator<MV>> C = rcp(new ComposedOperator<MV>(n, Inner, B));

!Line: 322 - warning: variable 'Inner' is not initialized [cppcoreguidelines-init-variables]

RCP<DiagonalOperator<ST, MV>> B = rcp(new DiagonalOperator<ST, MV>(n, 4.0));
RCP<ComposedOperator<MV>> C = rcp(new ComposedOperator<MV>(n, Inner, B));
// Outer computes inv(C) = inv(inv(D)*B)*x = inv(B)*D*x = x
RCP<IterativeInverseOperator<OP, ST, MP, MV>> Outer =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, C, "Belos (inv(C)=inv(inv(D)*B))", true));

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

RCP<DiagonalOperator<ST, MV>> B = rcp(new DiagonalOperator<ST, MV>(n, 4.0));
RCP<ComposedOperator<MV>> C = rcp(new ComposedOperator<MV>(n, Inner, B));
// Outer computes inv(C) = inv(inv(D)*B)*x = inv(B)*D*x = x
RCP<IterativeInverseOperator<OP, ST, MP, MV>> Outer =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, C, "Belos (inv(C)=inv(inv(D)*B))", true));

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

RCP<ComposedOperator<MV>> C = rcp(new ComposedOperator<MV>(n, Inner, B));
// Outer computes inv(C) = inv(inv(D)*B)*x = inv(B)*D*x = x
RCP<IterativeInverseOperator<OP, ST, MP, MV>> Outer =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, C, "Belos (inv(C)=inv(inv(D)*B))", true));

!Line: 327 - warning: variable 'C' is not initialized [cppcoreguidelines-init-variables]

RCP<ComposedOperator<MV>> C = rcp(new ComposedOperator<MV>(n, Inner, B));
// Outer computes inv(C) = inv(inv(D)*B)*x = inv(B)*D*x = x
RCP<IterativeInverseOperator<OP, ST, MP, MV>> Outer =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, C, "Belos (inv(C)=inv(inv(D)*B))", true));

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

RCP<IterativeInverseOperator<OP, ST, MP, MV>> Outer =
rcp(new IterativeInverseOperator<OP, ST, MP, MV>(n, 1, C, "Belos (inv(C)=inv(inv(D)*B))", true));
// should return x=1/4
(*Inner)(X, Y);

!Line: 330 - warning: variable 'Outer' is not initialized [cppcoreguidelines-init-variables]

int main(int argc, char *argv[]) {
return run<double>(argc, argv);
// return run<float>(argc, argv); // FAILS
}

!Line: 377 - warning: declaration must be declared within the '__llvm_libc' namespace [llvmlibc-implementation-in-namespace]

int main(int argc, char *argv[]) {
return run<double>(argc, argv);
// return run<float>(argc, argv); // FAILS
}

!Line: 377 - warning: use a trailing return type for this function [modernize-use-trailing-return-type]

RCP<MV> X_exact (new MV(map, numrhs));
MVT::MvRandom (*X_exact);
// Compute the right-hand side as B = A*X.
RCP<MV> B = MVT::Clone (*X_exact, numrhs);
OPT::Apply (*A, *X_exact, *B);

!Line: 146 - warning: variable 'X_exact' is not initialized [cppcoreguidelines-init-variables]

RCP<MV> B = MVT::Clone (*X_exact, numrhs);
OPT::Apply (*A, *X_exact, *B);
// Choose an initial guess of all zeros.
RCP<MV> X = MVT::Clone (*X_exact, numrhs);
MVT::MvInit (*X, ST(0.0));

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

RCP<MV> B = MVT::Clone (*X_exact, numrhs);
OPT::Apply (*A, *X_exact, *B);
// Choose an initial guess of all zeros.
RCP<MV> X = MVT::Clone (*X_exact, numrhs);
MVT::MvInit (*X, ST(0.0));

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

RCP<MV> X = MVT::Clone (*X_exact, numrhs);
MVT::MvInit (*X, ST(0.0));
// **********************************************************************
//
// Set parameters that the user asked us to pick intelligently.

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

RCP<MV> X = MVT::Clone (*X_exact, numrhs);
MVT::MvInit (*X, ST(0.0));
// **********************************************************************
//
// Set parameters that the user asked us to pick intelligently.

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

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

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

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

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

MV resid(A->getMap(), numrhs);
OPT::Apply( *A, *X, resid );
MVT::MvAddMv( -1.0, resid, 1.0, *B, resid );
MVT::MvNorm( resid, actualResids );
MVT::MvNorm( *B, rhsNorm );
if (proc_verbose) {

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

RCP<MV> X, B;
X = rcp(new MV(map, numrhs));
MVT::MvRandom( *X );
B = rcp(new MV(map, numrhs));
OPT::Apply(*A, *X, *B);
MVT::MvInit(*X, 0.0);

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

RCP<MV> X, B;
X = rcp(new MV(map, numrhs));
MVT::MvRandom( *X );
B = rcp(new MV(map, numrhs));
OPT::Apply(*A, *X, *B);
MVT::MvInit(*X, 0.0);

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

std::vector<MT> actualResids( numrhs );
std::vector<MT> 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: 216 - warning: variable 'actualResids' is not initialized [cppcoreguidelines-init-variables]

std::vector<MT> 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: 217 - warning: variable 'rhsNorm' is not initialized [cppcoreguidelines-init-variables]


@tlamonthezie tlamonthezie marked this pull request as ready for review September 21, 2023 13:04
@tlamonthezie tlamonthezie force-pushed the 205-clean-minres-tpetra-test-minres-diag branch from 1b8a045 to faf0709 Compare September 21, 2023 13:08
Copy link
Collaborator

@cwschilly cwschilly left a comment

Choose a reason for hiding this comment

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

LGTM

@stmcgovern stmcgovern merged commit 482c52a 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: clean MINRES Tpetra test_minres_diag test
4 participants