Ifpack2: Error for factory create
Created by: freaklovesmango
I wanted to use the Preconditioner from Ifpack2 for Belos and Tpetra but I got the following error
error: no matching function for call to ‘Ifpack2::Factory::create(const string&, Teuchos::RCP<Tpetra::CrsMatrix<> >&)’
prec = factory.create (precName, A);
Edit: The following includes the notes:
main.cpp:195:40: error: no matching function for call to ‘Ifpack2::Factory::create(const string&, Teuchos::RCP<Tpetra::CrsMatrix<> >&)’
prec = factory.create (precName, A);
^
In file included from /home/freaklovesmango/build-trilinos-tpetra/install/Trilinos/include/Ifpack2_Factory.hpp:1:0,
from main.cpp:23:
/home/freaklovesmango/build-trilinos-tpetra/install/Trilinos/include/Ifpack2_Factory_decl.hpp:135:3: note: candidate: template<class MatrixType> static Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type, typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > Ifpack2::Factory::create(const string&, const Teuchos::RCP<const T>&)
create (const std::string& precType,
^
/home/freaklovesmango/build-trilinos-tpetra/install/Trilinos/include/Ifpack2_Factory_decl.hpp:135:3: note: template argument deduction/substitution failed:
main.cpp:195:40: note: types ‘const T’ and ‘Tpetra::CrsMatrix<>’ have incompatible cv-qualifiers
prec = factory.create (precName, A);
^
main.cpp:195:40: note: ‘Teuchos::RCP<Tpetra::CrsMatrix<> >’ is not derived from ‘const Teuchos::RCP<const T>’
In file included from /home/freaklovesmango/build-trilinos-tpetra/install/Trilinos/include/Ifpack2_Factory.hpp:1:0,
from main.cpp:23:
/home/freaklovesmango/build-trilinos-tpetra/install/Trilinos/include/Ifpack2_Factory_decl.hpp:175:3: note: candidate: template<class MatrixType> static Teuchos::RCP<Ifpack2::Preconditioner<typename MatrixType::scalar_type, typename MatrixType::local_ordinal_type, typename MatrixType::global_ordinal_type, typename MatrixType::node_type> > Ifpack2::Factory::create(const string&, const Teuchos::RCP<const T>&, int)
create (const std::string& precType,
^
/home/freaklovesmango/build-trilinos-tpetra/install/Trilinos/include/Ifpack2_Factory_decl.hpp:175:3: note: template argument deduction/substitution failed:
main.cpp:195:40: note: types ‘const T’ and ‘Tpetra::CrsMatrix<>’ have incompatible cv-qualifiers
prec = factory.create (precName, A);
^
main.cpp:195:40: note: ‘Teuchos::RCP<Tpetra::CrsMatrix<> >’ is not derived from ‘const Teuchos::RCP<const T>’
My code is based on this example here: https://trilinos.org/docs/dev/packages/ifpack2/doc/html/classIfpack2_1_1Factory.html#aa19b22421fb0aeebe7a30d025b662aa6
#include "Ifpack2_Factory.hpp"
// ...
using Teuchos::ParameterList;
using Teuchos::RCP;
typedef double Scalar;
typedef Tpetra::CrsMatrix<Scalar> crs_matrix_type;
typedef Ifpack2::Preconditioner<Scalar> prec_type;
// ...
Ifpack2::Factory factory;
RCP<crs_matrix_type> A;
// ... fill A and call fillComplete() ...
// Use ILUT (incomplete LU with thresholding) on each process.
const std::string precType = "ILUT";
RCP<prec_type> prec = factory.create (precType, A);
ParameterList params;
params.set ("fact: ilut level-of-fill", 5.0); // ILUT(fill=5, drop=0)
prec->setParameters (params);
prec->initialize ();
prec->compute ();
// now prec can be used as a preconditioner
This is (basically) my actual code:
#include <Tpetra_MultiVector.hpp>
#include <Tpetra_CrsMatrix.hpp>
#include <Tpetra_Core.hpp>
#include <Tpetra_Version.hpp>
#include <Ifpack2_Factory.hpp>
int main(int argc, char *argv[])
{
using Teuchos::ParameterList;
using Teuchos::parameterList;
using Teuchos::RCP;
using Teuchos::rcp;
typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_type;
[...]
RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm ();
const global_ordinal_type indexBase = 0;
int numGlobalElementsMap = 5;
RCP<map_type> matrixMap = rcp (new map_type(numGlobalElementsMap, numGlobalElementsMap, indexBase, comm));
RCP<crs_type> A =
rcp(new crs_type(matrixMap, matrixMap, 0));
A->fillComplete();
// The name of the type of preconditioner to use.
const std::string precondType ("ILUT");
// Ifpack2 expects double-precision arguments here.
const double fillLevel = 2.0;
const double dropTol = 0.0;
const double absThreshold = 0.1;
const bool verbose = true;
const bool debug = false;
RCP<ParameterList> plist = parameterList ("Preconditioner");
plist->set ("Ifpack2::Preconditioner", precondType);
ParameterList precParams ("Ifpack2");
precParams.set ("fact: ilut level-of-fill", fillLevel);
precParams.set ("fact: drop tolerance", dropTol);
precParams.set ("fact: absolute threshold", absThreshold);
plist->set ("Ifpack2", precParams);
RCP<prec_type> prec;
//ParameterList listPrec;
ParameterList ifpack2Params;
//Ifpack Factory;
Ifpack2::Factory factory;
// Get the preconditioner type
const std::string precName = plist->get<std::string> ("Ifpack2::Preconditioner");
prec = factory.create (precName, A);
if (plist->isSublist ("Ifpack2"))
ifpack2Params = plist->sublist ("Ifpack2");
else
ifpack2Params.setName ("Ifpack2");
prec->setParameters (ifpack2Params);
prec->setParameters (ifpack2Params);
prec->initialize();
prec->compute();